* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: #333;
}

.container {
    max-width: 1280px;
    margin: 0 auto;
    min-width: 0;
}

header {
    text-align: center;
    color: white;
    margin-bottom: 40px;
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.subtitle {
    font-size: 1.1em;
    opacity: 0.9;
}

.card {
    background: white;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    margin-bottom: 30px;
}

.guide-card {
    background: linear-gradient(135deg, #ffffff 0%, #f5f7ff 100%);
    border: 1px solid rgba(102, 126, 234, 0.15);
}

.guide-card h2 {
    margin-bottom: 15px;
    color: #2f3a8f;
}

.guide-text {
    margin-bottom: 14px;
    line-height: 1.6;
}

.guide-list {
    margin-left: 20px;
    margin-bottom: 18px;
    line-height: 1.8;
}

.guide-list li {
    margin-bottom: 6px;
}

.guide-note {
    margin-top: 14px;
    padding: 12px 14px;
    background: #eef2ff;
    border-left: 4px solid #667eea;
    border-radius: 8px;
    line-height: 1.6;
}

.terms-card {
    background: white;
}

.terms-card h2 {
    margin-bottom: 18px;
    color: #2f3a8f;
}

.terms-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
}

.term-item {
    background: #f8f9ff;
    border: 1px solid #e3e8ff;
    border-radius: 10px;
    padding: 14px;
}

.term-item strong {
    display: block;
    color: #334155;
    margin-bottom: 8px;
}

.term-item p {
    color: #4b5563;
    line-height: 1.6;
}

.explain-card {
    background: linear-gradient(135deg, #ffffff 0%, #f8fbff 100%);
    border: 1px solid rgba(102, 126, 234, 0.15);
}

.explain-card h2 {
    margin-bottom: 15px;
    color: #2f3a8f;
}

.explain-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
}

.explain-item {
    background: #f8f9ff;
    border: 1px solid #e3e8ff;
    border-radius: 10px;
    padding: 14px;
}

.explain-item strong {
    display: block;
    color: #334155;
    margin-bottom: 8px;
}

.explain-item p {
    color: #4b5563;
    line-height: 1.6;
}

.preset-group {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin: 8px 0 4px;
}

.input-card {
    background: white;
    margin-bottom: 30px;
}

.input-card h2 {
    margin-bottom: 25px;
    color: #667eea;
    font-size: 1.5em;
    border-bottom: 2px solid #667eea;
    padding-bottom: 10px;
}

.form-group {
    margin-bottom: 25px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
}

.format-hint {
    font-size: 0.85em;
    color: #666;
    font-weight: normal;
    margin-left: 5px;
}

.radio-group {
    display: flex;
    gap: 20px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.radio-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.radio-label input[type="radio"] {
    margin-right: 8px;
    cursor: pointer;
    width: 18px;
    height: 18px;
}

.radio-label span {
    font-weight: 500;
    color: #555;
}

input[type="text"] {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 1em;
    transition: all 0.3s ease;
    text-transform: uppercase;
}

input[type="text"]:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    background-color: #f8f9ff;
}

input[type="text"].error {
    border-color: #dc3545;
    background-color: #fff5f5;
}

.input-info {
    font-size: 0.85em;
    margin-top: 5px;
    color: #666;
    height: 20px;
}

.input-info.valid {
    color: #28a745;
}

.input-info.invalid {
    color: #dc3545;
}

.error-message {
    background-color: #f8d7da;
    border: 2px solid #dc3545;
    color: #721c24;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: none;
    animation: slideDown 0.3s ease;
}

.error-message.show {
    display: block;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.button-group {
    display: flex;
    gap: 12px;
    margin-top: 30px;
    flex-wrap: wrap;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 120px;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background-color: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background-color: #5a6268;
}

.btn-copy {
    background-color: #17a2b8;
    color: white;
    padding: 6px 12px;
    font-size: 0.85em;
    min-width: auto;
}

.btn-copy:hover {
    background-color: #138496;
}

.result-container {
    animation: slideDown 0.5s ease;
}

.section {
    background: white;
    margin-bottom: 25px;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.summary-section {
    border: 1px solid rgba(102, 126, 234, 0.18);
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
}

.summary-item {
    background: #f8f9fa;
    border-radius: 10px;
    padding: 14px;
    border: 1px solid #e8ebf5;
}

.summary-label {
    display: block;
    font-size: 0.82em;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #6b7280;
    margin-bottom: 6px;
}

.summary-item strong {
    display: block;
    font-size: 0.95em;
    color: #1f2937;
    word-break: break-word;
}

.section h2 {
    color: #667eea;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid #667eea;
    font-size: 1.4em;
}

.section h3 {
    color: #555;
    margin-top: 15px;
    margin-bottom: 10px;
    font-size: 1.1em;
}

.section-note {
    margin-bottom: 14px;
    padding: 12px 14px;
    background: #f8f9ff;
    border-left: 4px solid #667eea;
    border-radius: 8px;
    line-height: 1.6;
    color: #334155;
}

.round-steps {
    margin: 0 0 16px 20px;
    padding: 0 0 0 8px;
    line-height: 1.7;
    color: #374151;
}

.round-steps li {
    margin-bottom: 8px;
}

.code {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    margin: 10px 0;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    overflow-x: auto;
    word-break: break-all;
    border-left: 4px solid #667eea;
    line-height: 1.5;
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.code-header strong {
    color: #333;
}

.result-box {
    background: linear-gradient(135deg, #f5f7ff 0%, #e9f0ff 100%);
    padding: 20px;
    border-radius: 12px;
    margin: 20px 0;
    border-left: 4px solid #667eea;
}

.result-box p {
    font-weight: 600;
    color: #667eea;
    margin-bottom: 10px;
    font-size: 0.95em;
}

.round {
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    margin: 15px 0;
    padding: 20px;
    border-radius: 10px;
    transition: all 0.3s ease;
}

.round summary {
    cursor: pointer;
    font-weight: 700;
    color: #667eea;
    list-style: none;
    outline: none;
}

.round summary::-webkit-details-marker {
    display: none;
}

.round summary::after {
    content: '▾';
    float: right;
    color: #667eea;
}

.round[open] summary::after {
    content: '▴';
}

.round-body {
    margin-top: 15px;
}

.round:hover {
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.1);
}

.round h3 {
    color: #667eea;
    margin-bottom: 15px;
    padding-bottom: 8px;
    border-bottom: 1px solid #ddd;
}

.sbox-table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
    font-size: 0.9em;
}

.sbox-table th {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px;
    text-align: center;
    font-weight: 600;
}

.sbox-table td {
    border: 1px solid #ddd;
    padding: 10px;
    text-align: center;
}

.sbox-table tr:nth-child(even) {
    background-color: #f8f9fa;
}

.sbox-table tr:hover {
    background-color: #e9f0ff;
}

/* Responsive Design */
@media (max-width: 768px) {
    header h1 {
        font-size: 2em;
    }

    .subtitle {
        font-size: 1em;
    }

    .card {
        padding: 20px;
    }

    .radio-group {
        flex-direction: column;
        gap: 10px;
    }

    .button-group {
        flex-direction: column;
    }

    .preset-group {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }

    .section {
        padding: 15px;
    }

    .round {
        padding: 15px;
    }

    .sbox-table {
        font-size: 0.8em;
    }

    .sbox-table th,
    .sbox-table td {
        padding: 8px 4px;
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px;
    }

    header h1 {
        font-size: 1.5em;
    }

    .card {
        padding: 15px;
    }

    input[type="text"] {
        font-size: 0.9em;
    }

    .code {
        font-size: 0.8em;
        padding: 12px;
    }
}
