/* RSA Cipher Styling */
:root {
    --primary-color: #2563eb;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --light-bg: #f9fafb;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

/* Header */
header {
    text-align: center;
    color: white;
    margin-bottom: 30px;
    animation: fadeInDown 0.6s ease;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.95;
    margin-bottom: 15px;
}

.nav-links {
    margin-top: 15px;
}

.nav-link {
    color: white;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.2);
    padding: 8px 20px;
    border-radius: 20px;
    transition: all 0.3s ease;
    display: inline-block;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

/* Main Content */
.main-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Card */
.card {
    background: white;
    padding: 30px;
    border-radius: 15px;
    box-shadow: var(--shadow-lg);
    animation: fadeInUp 0.6s ease;
}

.card h2 {
    color: var(--primary-color);
    margin-bottom: 20px;
    font-size: 1.5rem;
}

/* Input Groups */
.input-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 15px;
}

.input-group {
    margin-bottom: 15px;
}

.input-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-secondary);
}

.input-group input,
.input-group textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.input-group input:focus,
.input-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.hint {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 5px;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow);
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: #1d4ed8;
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background: var(--text-secondary);
    color: white;
}

.btn-secondary:hover {
    background: #4b5563;
    transform: translateY(-2px);
}

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-success:hover {
    background: #059669;
    transform: translateY(-2px);
}

.btn-warning {
    background: var(--warning-color);
    color: white;
}

.btn-warning:hover {
    background: #d97706;
    transform: translateY(-2px);
}

.btn-copy {
    background: var(--primary-color);
    color: white;
    margin-top: 15px;
}

.btn-copy:hover {
    background: #1d4ed8;
}

.btn-copy.copied {
    background: var(--success-color);
}

.button-group {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 15px;
}

.button-group .btn {
    flex: 1;
    min-width: 150px;
}

/* Keys Display */
#keysCard {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border-left: 4px solid var(--primary-color);
}

.keys-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 25px;
}

.key-box {
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.key-box h3 {
    margin-bottom: 15px;
    font-size: 1.2rem;
}

.public-key {
    background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%);
    border: 2px solid var(--success-color);
}

.public-key h3 {
    color: #065f46;
}

.private-key {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border: 2px solid var(--warning-color);
}

.private-key h3 {
    color: #92400e;
}

.key-param {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    margin-bottom: 8px;
    background: white;
    border-radius: 6px;
}

.param-label {
    font-weight: 600;
    color: var(--text-secondary);
}

.param-value {
    font-family: 'Courier New', monospace;
    font-weight: bold;
    color: var(--primary-color);
    font-size: 1.1rem;
}

.params-detail {
    border-top: 2px solid var(--border-color);
    padding-top: 20px;
}

.params-detail h4 {
    margin-bottom: 15px;
    color: var(--text-primary);
}

.param-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.param-item {
    background: rgba(37, 99, 235, 0.05);
    padding: 12px;
    border-radius: 8px;
    border-left: 3px solid var(--primary-color);
}

.param-name {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.param-val {
    display: block;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    color: var(--primary-color);
    font-size: 1.1rem;
}

/* Result Card */
.result-container {
    background: var(--light-bg);
    padding: 20px;
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
}

.result-label {
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.result-text {
    font-size: 1.25rem;
    font-family: 'Courier New', monospace;
    color: var(--text-primary);
    word-break: break-all;
    padding: 12px;
    background: white;
    border-radius: 6px;
    min-height: 50px;
    line-height: 1.6;
    margin-bottom: 12px;
}

/* Result Table */
.result-table-wrapper {
    overflow-x: auto;
    margin: 15px 0;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.result-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    font-family: 'Courier New', monospace;
}

.result-table thead th {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    color: white;
    padding: 12px 8px;
    text-align: center;
    font-weight: 600;
    font-size: 0.95rem;
    border: 1px solid #1d4ed8;
}

.result-table tbody td {
    padding: 10px 8px;
    text-align: center;
    border: 1px solid #e5e7eb;
    font-size: 0.9rem;
}

.result-table tbody td.label {
    background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
    font-weight: bold;
    color: var(--text-primary);
    text-align: left;
    padding-left: 15px;
    white-space: nowrap;
}

.result-table .ascii-row td:not(.label) {
    background: #dbeafe;
    color: #1e40af;
    font-weight: 600;
}

.result-table.encrypt-result .cipher-row td:not(.label) {
    background: #dcfce7;
    color: #15803d;
    font-weight: bold;
    font-size: 0.85rem;
}

.result-table.decrypt-result .plain-row td:not(.label) {
    background: #fef3c7;
    color: #92400e;
    font-weight: bold;
    font-size: 1.1rem;
}

.result-table .invalid-ascii {
    background: #fee2e2 !important;
    color: #991b1b !important;
    font-size: 0.85rem !important;
}

.result-meta {
    margin-top: 12px;
    padding: 10px;
    background: rgba(37, 99, 235, 0.05);
    border-radius: 6px;
    margin-bottom: 12px;
}

.result-info {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Process Card */
#processCard {
    background: linear-gradient(135deg, #fefcfb 0%, #fff5f0 100%);
    border-left: 4px solid var(--warning-color);
}

.process-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border-color);
}

.process-header h2 {
    margin: 0;
    color: var(--warning-color);
}

.process-status {
    background: var(--light-bg);
    padding: 8px 16px;
    border-radius: 20px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

.process-count {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.process-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 500px;
    overflow-y: auto;
    padding: 10px;
    background: white;
    border-radius: 8px;
}

/* Process Step */
.process-step {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background: linear-gradient(135deg, #f9fafb 0%, #ffffff 100%);
    border-radius: 10px;
    border: 2px solid transparent;
    transition: all 0.3s ease;
    animation: slideInStep 0.4s ease;
}

.process-step:hover {
    border-color: var(--primary-color);
    transform: translateX(5px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.process-step.encrypt {
    border-left: 4px solid var(--success-color);
}

.process-step.decrypt {
    border-left: 4px solid var(--warning-color);
}

.step-number {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 80px;
}

.step-light {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--success-color);
    box-shadow: 0 0 10px var(--success-color);
    animation: stepPulse 2s infinite;
}

.step-light.decrypt {
    background: var(--warning-color);
    box-shadow: 0 0 10px var(--warning-color);
}

.step-num {
    font-weight: bold;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.step-content {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: 'Courier New', monospace;
    flex-wrap: wrap;
}

.step-input {
    padding: 6px 12px;
    background: #e0e7ff;
    color: var(--primary-color);
    border-radius: 6px;
    font-weight: bold;
    font-size: 1rem;
}

.step-arrow {
    color: var(--text-secondary);
    font-weight: bold;
}

.step-output {
    padding: 6px 12px;
    background: #dcfce7;
    color: var(--success-color);
    border-radius: 6px;
    font-weight: bold;
    font-size: 1rem;
}

.step-output.decrypt {
    background: #fef3c7;
    color: var(--warning-color);
}

.step-formula {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-style: italic;
    padding: 4px 8px;
    background: var(--light-bg);
    border-radius: 4px;
}

/* Example Card */
.example-card {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border-left: 4px solid var(--warning-color);
}

.example-card h2 {
    color: #92400e;
}

.example-subtitle {
    color: #92400e;
    font-size: 0.95rem;
    margin-bottom: 20px;
    font-weight: 500;
    text-align: center;
}

.example-section {
    margin-bottom: 25px;
}

.example-section h3 {
    color: #78350f;
    margin-bottom: 12px;
    font-size: 1.2rem;
}

.table-wrapper {
    overflow-x: auto;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.example-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
}

.example-table thead th {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
    padding: 10px 6px;
    text-align: center;
    font-weight: 600;
    border: 1px solid #d97706;
    font-size: 0.9rem;
}

.example-table tbody td {
    padding: 8px 6px;
    text-align: center;
    border: 1px solid #e5e7eb;
}

.example-table tbody td.label {
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
    color: white;
    font-weight: bold;
    text-align: left;
    padding-left: 12px;
    white-space: nowrap;
}

.example-table .ascii-row td:not(.label) {
    background: #dbeafe;
    color: #1e40af;
    font-weight: 600;
}

.example-table .formula-row td:not(.label) {
    background: #f3f4f6;
    color: #4b5563;
    font-size: 0.75rem;
}

.example-table.encrypt-table .cipher-row td:not(.label) {
    background: #dcfce7;
    color: #15803d;
    font-weight: bold;
}

.example-table.decrypt-table .plain-row td:not(.label) {
    background: #fef3c7;
    color: #92400e;
    font-weight: bold;
    font-size: 1rem;
}

.example-note {
    background: white;
    padding: 15px;
    border-radius: 8px;
    margin-top: 15px;
    border-left: 4px solid var(--warning-color);
}

.example-note h4 {
    color: #92400e;
    margin-bottom: 10px;
    font-size: 1.1rem;
}

.example-note ul {
    padding-left: 20px;
}

.example-note li {
    margin-bottom: 8px;
    line-height: 1.6;
    color: #1f2937;
}

/* ASCII Reference Card */
.ascii-card {
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
    border-left: 4px solid var(--success-color);
}

.ascii-card h2 {
    color: #166534;
}

.ascii-subtitle {
    color: #166534;
    font-size: 0.95rem;
    margin-bottom: 20px;
    font-weight: 500;
    text-align: center;
}

.ascii-section {
    margin-bottom: 25px;
}

.ascii-section h3 {
    color: #15803d;
    margin-bottom: 12px;
    font-size: 1.1rem;
}

.ascii-table-wrapper {
    overflow-x: auto;
    margin-bottom: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.ascii-ref-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
}

.ascii-ref-table thead th {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    color: white;
    padding: 10px 8px;
    text-align: center;
    font-weight: 600;
    border: 1px solid #16a34a;
    font-size: 1rem;
}

.ascii-ref-table thead th:first-child {
    background: linear-gradient(135deg, #15803d 0%, #166534 100%);
}

.ascii-ref-table tbody td {
    padding: 10px 8px;
    text-align: center;
    border: 1px solid #e5e7eb;
    background: #f0fdf4;
    color: #166534;
    font-weight: 600;
    position: relative;
    transition: all 0.3s ease;
}

.ascii-ref-table tbody td[data-char] {
    cursor: pointer;
}

/* ASCII Lamp Indicator */
.ascii-lamp {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #d1d5db;
    transition: all 0.3s ease;
}

/* Purple Lamp for Character Row */
.ascii-lamp.purple-lamp {
    background: #d1d5db;
}

.ascii-ref-table tbody tr.char-row td.active .purple-lamp {
    background: #a855f7;
    box-shadow: 0 0 8px #a855f7, 0 0 15px #a855f7;
    animation: purplePulse 1s ease-in-out infinite;
}

@keyframes purplePulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.6;
        transform: scale(1.2);
    }
}

/* Character Row Styling */
.ascii-ref-table tbody tr.char-row td:not(.label) {
    background: #faf5ff;
    color: #7c3aed;
    font-weight: bold;
    font-size: 1.1rem;
}

.ascii-ref-table tbody tr.char-row td.active {
    background: #e9d5ff !important;
    border-color: #a855f7 !important;
    box-shadow: 0 0 12px rgba(168, 85, 247, 0.5);
}

/* ASCII Row Styling */
.ascii-ref-table tbody tr.ascii-row td:not(.label) {
    background: #f0fdf4;
    color: #166534;
}

/* ASCII Row Active State (Yellow) */
.ascii-ref-table tbody tr.ascii-row td.active {
    background: #fef3c7 !important;
    border-color: #f59e0b !important;
    box-shadow: 0 0 12px rgba(245, 158, 11, 0.5);
    transform: scale(1.05);
}

.ascii-ref-table tbody tr.ascii-row td.active .ascii-lamp {
    background: #f59e0b;
    box-shadow: 0 0 8px #f59e0b, 0 0 15px #f59e0b;
    animation: asciiPulse 1s ease-in-out infinite;
}

@keyframes asciiPulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.6;
        transform: scale(1.2);
    }
}

.ascii-ref-table tbody td.label {
    background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
    color: white;
    font-weight: bold;
    text-align: center;
    white-space: nowrap;
}

.ascii-note {
    background: white;
    padding: 15px;
    border-radius: 8px;
    margin-top: 15px;
    border-left: 4px solid var(--success-color);
}

.ascii-note h4 {
    color: #166534;
    margin-bottom: 10px;
    font-size: 1.1rem;
}

.ascii-note ul {
    padding-left: 20px;
}

.ascii-note li {
    margin-bottom: 8px;
    line-height: 1.6;
    color: #1f2937;
}

/* Info Card */
.info-card {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border-left: 4px solid var(--primary-color);
}

.info-content ol {
    padding-left: 20px;
}

.info-content li {
    margin-bottom: 12px;
    line-height: 1.6;
}

/* Footer */
footer {
    text-align: center;
    padding: 20px;
    color: white;
    margin-top: 40px;
}

/* Animations */
@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInStep {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes stepPulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.4;
    }
}

/* Responsive */
@media (max-width: 768px) {
    header h1 {
        font-size: 2rem;
    }
    
    .card {
        padding: 20px;
    }
    
    .input-row {
        grid-template-columns: 1fr;
    }
    
    .keys-container {
        grid-template-columns: 1fr;
    }
    
    .button-group {
        flex-direction: column;
    }
    
    .button-group .btn {
        width: 100%;
    }
    
    .process-step {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .step-number {
        min-width: auto;
    }
    
    .result-table thead th,
    .example-table thead th,
    .ascii-ref-table thead th {
        font-size: 0.8rem;
        padding: 8px 4px;
    }
    
    .result-table tbody td,
    .example-table tbody td,
    .ascii-ref-table tbody td {
        font-size: 0.75rem;
        padding: 6px 4px;
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px;
    }
    
    header h1 {
        font-size: 1.5rem;
    }
    
    .subtitle {
        font-size: 0.9rem;
    }
    
    .param-grid {
        grid-template-columns: 1fr;
    }
    
    .process-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .step-formula {
        font-size: 0.75rem;
        width: 100%;
        text-align: center;
    }
    
    .result-table thead th,
    .example-table thead th,
    .ascii-ref-table thead th {
        font-size: 0.7rem;
        padding: 6px 3px;
    }
    
    .result-table tbody td,
    .example-table tbody td,
    .ascii-ref-table tbody td {
        font-size: 0.7rem;
        padding: 5px 3px;
    }
    
    .result-table tbody td.label,
    .example-table tbody td.label,
    .ascii-ref-table tbody td.label {
        padding-left: 8px;
        font-size: 0.75rem;
    }
    
    .example-table .formula-row td:not(.label) {
        font-size: 0.65rem;
    }
    
    .ascii-section h3 {
        font-size: 1rem;
    }
}
