@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.container {
    width: 100%;
    max-width: 1000px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 30px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    animation: slideUp 0.6s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 40px 30px;
    text-align: center;
    color: white;
    position: relative;
    overflow: hidden;
}

.header::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
    animation: rotate 20s linear infinite;
}

@keyframes rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.header h1 {
    font-size: 2.5em;
    font-weight: 700;
    margin-bottom: 10px;
    position: relative;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

.header p {
    font-size: 1.1em;
    opacity: 0.9;
    position: relative;
    font-weight: 300;
}

.content {
    padding: 40px;
}

.algorithm-selector {
    display: flex;
    gap: 20px;
    margin-bottom: 15px;
    justify-content: center;
    animation: fadeIn 0.6s ease-out forwards;
    opacity: 0;
}

.algorithm-btn {
    padding: 15px 30px;
    border: none;
    border-radius: 15px;
    font-size: 1.1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #e2e8f0;
    color: #4a5568;
    flex: 1;
    max-width: 250px;
}

.algorithm-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 10px 20px -5px rgba(102, 126, 234, 0.4);
}

.algorithm-btn:hover {
    transform: translateY(-2px);
}

.language-indicator {
    text-align: center;
    margin-bottom: 20px;
    animation: fadeIn 0.6s ease-out 0.1s forwards;
    opacity: 0;
}

.language-badge {
    display: inline-block;
    padding: 8px 20px;
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    color: white;
    border-radius: 50px;
    font-weight: 600;
    font-size: 0.9em;
    box-shadow: 0 5px 15px -5px rgba(72, 187, 120, 0.4);
}

.input-group {
    margin-bottom: 25px;
    animation: fadeIn 0.6s ease-out forwards;
    opacity: 0;
}

.input-group:nth-child(1) { animation-delay: 0.2s; }
.input-group:nth-child(2) { animation-delay: 0.3s; }

@keyframes fadeIn {
    to { opacity: 1; }
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #4a5568;
    font-size: 0.95em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 15px;
    color: #a0aec0;
    font-size: 1.2em;
}

textarea, input {
    width: 100%;
    padding: 15px 20px 15px 50px;
    border: 2px solid #e2e8f0;
    border-radius: 15px;
    font-family: 'Inter', sans-serif;
    font-size: 1em;
    transition: all 0.3s ease;
    background: white;
    resize: vertical;
}

textarea:focus, input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

textarea {
    min-height: 120px;
}

.key-input {
    background: linear-gradient(135deg, #f5f7fa 0%, #e4e8f0 100%);
}

/* Стили для файловых кнопок */
.file-input-container, .file-output-container {
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.file-btn {
    padding: 10px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 0.9em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.file-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px -5px rgba(102, 126, 234, 0.4);
}

.save-btn {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
}

.save-btn:hover {
    box-shadow: 0 10px 20px -5px rgba(72, 187, 120, 0.4);
}

.file-name {
    font-size: 0.9em;
    color: #718096;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.keys-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-bottom: 25px;
    animation: fadeIn 0.6s ease-out 0.4s forwards;
    opacity: 0;
}

.key-field {
    position: relative;
}

.key-field label {
    font-size: 0.85em;
    color: #718096;
}

.key-field .input-icon {
    left: 10px;
}

.key-field input {
    padding: 12px 20px 12px 40px;
}

.button-group {
    display: flex;
    gap: 15px;
    margin: 30px 0;
    flex-wrap: wrap;
    animation: fadeIn 0.6s ease-out 0.5s forwards;
    opacity: 0;
}

.btn {
    flex: 1;
    padding: 15px 25px;
    border: none;
    border-radius: 15px;
    font-size: 1.1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-width: 160px;
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn:hover::before {
    width: 300px;
    height: 300px;
}

.btn-encrypt {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    color: white;
    box-shadow: 0 10px 20px -5px rgba(72, 187, 120, 0.4);
}

.btn-encrypt:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 30px -5px rgba(72, 187, 120, 0.6);
}

.btn-decrypt {
    background: linear-gradient(135deg, #f6ad55 0%, #ed8936 100%);
    color: white;
    box-shadow: 0 10px 20px -5px rgba(246, 173, 85, 0.4);
}

.btn-decrypt:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 30px -5px rgba(246, 173, 85, 0.6);
}

.btn-clear {
    background: linear-gradient(135deg, #fc8181 0%, #f56565 100%);
    color: white;
    box-shadow: 0 10px 20px -5px rgba(252, 129, 129, 0.4);
}

.btn-clear:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 30px -5px rgba(252, 129, 129, 0.6);
}

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 20px;
    margin: 30px 0;
    animation: fadeIn 0.6s ease-out 0.6s forwards;
    opacity: 0;
}

.stat-card {
    background: linear-gradient(135deg, #f7fafc 0%, #edf2f7 100%);
    padding: 20px;
    border-radius: 15px;
    text-align: center;
    transition: all 0.3s ease;
    border: 1px solid rgba(255,255,255,0.5);
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 30px -10px rgba(0,0,0,0.2);
}

.stat-label {
    font-size: 0.9em;
    color: #718096;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 2em;
    font-weight: 700;
    color: #4a5568;
    line-height: 1.2;
}

.stat-unit {
    font-size: 0.5em;
    color: #a0aec0;
    margin-left: 3px;
}

/* ===== НОВЫЕ СТИЛИ: Секция таблицы Виженера ===== */
.vigenere-table-section {
    margin: 30px 0;
    background: white;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    animation: fadeIn 0.6s ease-out 0.8s forwards;
    opacity: 0;
}

.section-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px 20px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s ease;
}

.section-header:hover {
    background: linear-gradient(135deg, #5a67d8 0%, #6b46a1 100%);
}

.section-header h3 {
    margin: 0;
    font-size: 1.2em;
    font-weight: 600;
}

.toggle-icon {
    font-size: 1.2em;
    transition: transform 0.3s ease;
}

.vigenere-table-container {
    padding: 20px;
    background: #f7fafc;
    max-height: 500px;
    overflow: hidden;
    transition: max-height 0.5s ease, padding 0.3s ease;
}

.vigenere-table-container.collapsed {
    max-height: 0;
    padding: 0 20px;
    overflow: hidden;
}

.table-wrapper {
    overflow-x: auto;
    margin-bottom: 20px;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    background: white;
    max-height: 350px;
    overflow-y: auto;
    position: relative;
}

.vigenere-table {
    border-collapse: collapse;
    width: 100%;
    font-size: 0.85em;
    font-family: 'Courier New', monospace;
}

.vigenere-table th,
.vigenere-table td {
    border: 1px solid #e2e8f0;
    padding: 8px 12px;
    text-align: center;
    min-width: 40px;
}

.vigenere-table th {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 10;
}

.vigenere-table th:first-child,
.vigenere-table td:first-child {
    position: sticky;
    left: 0;
    background: inherit;
    z-index: 5;
    font-weight: 600;
}

.vigenere-table th:first-child {
    background: linear-gradient(135deg, #5a67d8 0%, #6b46a1 100%);
    color: white;
    z-index: 11;
}

.vigenere-table td:first-child {
    background: #edf2f7;
    font-weight: 600;
    color: #4a5568;
    position: sticky;
    left: 0;
    z-index: 5;
}

.vigenere-table tr:hover td {
    background-color: #fef3c7;
}

.vigenere-table .highlight-cell {
    background-color: #fbbf24 !important;
    color: #1e293b !important;
    font-weight: 700;
    box-shadow: inset 0 0 0 2px #d97706;
}

.table-info {
    background: #edf2f7;
    padding: 15px;
    border-radius: 10px;
    font-size: 0.95em;
}

.table-info ul {
    margin: 10px 0 0 20px;
    color: #4a5568;
}

.table-info .highlight {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 2px 8px;
    border-radius: 15px;
    font-weight: 600;
}

/* ===== НОВЫЕ СТИЛИ: Пример шифрования ===== */
.encryption-example {
    margin: 20px 0;
    padding: 20px;
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border-radius: 15px;
    animation: fadeIn 0.6s ease-out 0.9s forwards;
    opacity: 0;
    border: 1px solid #fbbf24;
}

.encryption-example h4 {
    margin: 0 0 15px 0;
    color: #92400e;
    font-size: 1.1em;
    display: flex;
    align-items: center;
    gap: 10px;
}

.example-content {
    background: white;
    padding: 15px;
    border-radius: 10px;
    font-family: 'Courier New', monospace;
    overflow-x: auto;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}

.example-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    padding: 8px;
    border-radius: 8px;
    background: #f9fafb;
}

.example-label {
    min-width: 40px;
    font-weight: 700;
    color: #4b5563;
    font-size: 1.1em;
}

.example-text {
    font-size: 1.2em;
    letter-spacing: 2px;
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
}

.example-text span {
    display: inline-block;
    min-width: 30px;
    text-align: center;
    padding: 5px;
    border-radius: 5px;
    font-weight: 600;
}

.example-text .plain {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #93c5fd;
}

.example-text .key {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
}

.example-text .cipher {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #86efac;
}

/* Стили для матриц Плейфера */
.matrix-visualization {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-top: 20px;
    padding: 15px;
    background: #f7fafc;
    border-radius: 15px;
    animation: fadeIn 0.6s ease-out 0.8s forwards;
    opacity: 0;
}

.matrix {
    background: white;
    border-radius: 10px;
    padding: 10px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.matrix h4 {
    text-align: center;
    margin-bottom: 8px;
    color: #4a5568;
    font-size: 0.9em;
}

.matrix-key {
    font-size: 0.8em;
    color: #667eea;
    font-weight: normal;
    display: block;
    margin-top: 2px;
}

.matrix-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 2px;
}

.matrix-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #e2e8f0;
    font-size: 0.9em;
    font-weight: 600;
    color: #4a5568;
    background: white;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.matrix-cell:hover {
    background: #667eea;
    color: white;
    transform: scale(1.05);
}

.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-top: 30px;
    padding-top: 30px;
    border-top: 2px dashed #e2e8f0;
    animation: fadeIn 0.6s ease-out 0.7s forwards;
    opacity: 0;
}

.feature-item {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #4a5568;
    font-size: 0.95em;
    padding: 10px;
    border-radius: 10px;
    background: #f7fafc;
}

.feature-icon {
    color: #667eea;
    font-weight: 700;
    font-size: 1.2em;
}

.toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    color: white;
    padding: 15px 25px;
    border-radius: 50px;
    box-shadow: 0 10px 30px -5px rgba(72, 187, 120, 0.6);
    display: none;
    align-items: center;
    gap: 10px;
    animation: slideIn 0.3s ease-out;
    z-index: 1000;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast.error {
    background: linear-gradient(135deg, #fc8181 0%, #f56565 100%);
    box-shadow: 0 10px 30px -5px rgba(252, 129, 129, 0.6);
}

.toast.show {
    display: flex;
}

.copy-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: #e2e8f0;
    border: none;
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.9em;
    color: #4a5568;
    transition: all 0.3s ease;
    opacity: 0.7;
}

.copy-btn:hover {
    opacity: 1;
    background: #cbd5e0;
}

.result-wrapper {
    position: relative;
}

.result-wrapper textarea {
    padding-right: 80px;
}

/* Адаптивность для мобильных устройств */
@media (max-width: 768px) {
    .content {
        padding: 20px;
    }
    
    .header h1 {
        font-size: 1.8em;
    }
    
    .algorithm-selector {
        flex-direction: column;
        align-items: center;
    }
    
    .algorithm-btn {
        max-width: 100%;
    }
    
    .keys-container {
        grid-template-columns: 1fr;
    }
    
    .button-group {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
    }
    
    .stats {
        grid-template-columns: 1fr;
    }
    
    .matrix-visualization {
        grid-template-columns: repeat(2, 1fr);
    }

    .file-input-container, .file-output-container {
        flex-direction: column;
        align-items: flex-start;
    }

    .file-name {
        max-width: 100%;
    }
    
    /* Адаптация таблицы Виженера для мобильных */
    .vigenere-table th,
    .vigenere-table td {
        padding: 4px 6px;
        min-width: 30px;
        font-size: 0.75em;
    }
    
    .table-info {
        font-size: 0.85em;
    }
    
    .example-text {
        font-size: 1em;
    }
    
    .example-text span {
        min-width: 25px;
        padding: 3px;
    }
}

@media (max-width: 480px) {
    .matrix-visualization {
        grid-template-columns: 1fr;
    }
    
    .vigenere-table th,
    .vigenere-table td {
        padding: 2px 4px;
        min-width: 25px;
        font-size: 0.7em;
    }
    
    .example-row {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .example-label {
        min-width: auto;
    }
}