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

:root {
    --page-bg: #eef3fb;
    --surface: #ffffff;
    --surface-soft: #f7f9fc;
    --surface-muted: #eef2f7;
    --text-primary: #1f2937;
    --text-secondary: #526071;
    --text-muted: #7a8797;
    --border-color: #dbe3ef;
    --border-strong: #344054;
    --accent: #4f7cff;
    --accent-strong: #3d68e6;
    --accent-soft: #e8efff;
    --accent-contrast: #ffffff;
    --success: #1f8f55;
    --success-soft: #e8f7ef;
    --danger: #c0394d;
    --danger-soft: #fdecef;
    --info: #305fce;
    --info-soft: #ebf1ff;
    --overlay: rgba(15, 23, 42, 0.52);
    --shadow-sm: 0 10px 28px rgba(15, 23, 42, 0.08);
    --shadow-md: 0 16px 40px rgba(15, 23, 42, 0.14);
    --shadow-lg: 0 24px 56px rgba(15, 23, 42, 0.2);
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --transition-fast: 0.2s ease;
    --transition-base: 0.3s ease;
    --board-bg: #24324a;
    --cell-bg: #ffffff;
    --cell-text: #1f2937;
    --cell-focus-bg: #eef4ff;
    --cell-fixed-bg: #f2f5fa;
    --cell-fixed-text: #5f6b7a;
    --cell-selected-bg: #dfeaff;
    --cell-error-bg: #ffe3e7;
    --cell-error-text: #b42339;
}

body {
    font-family: 'Arial', sans-serif;
    background: var(--page-bg);
    min-height: 100vh;
    padding: 24px;
    overflow-x: hidden;
    overflow-y: auto;
    transition: background var(--transition-base), color var(--transition-base);
    color: var(--text-primary);
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-image: none;
    filter: blur(0px);
    opacity: 1;
    z-index: -1;
    transition: all var(--transition-base);
}

body.dark-theme {
    --page-bg: #0f1727;
    --surface: #162031;
    --surface-soft: #1d2940;
    --surface-muted: #24324b;
    --text-primary: #ecf2ff;
    --text-secondary: #b5c0d5;
    --text-muted: #93a0b7;
    --border-color: #31415b;
    --border-strong: #9fb3d9;
    --accent: #79a7ff;
    --accent-strong: #5f95fc;
    --accent-soft: rgba(121, 167, 255, 0.18);
    --accent-contrast: #0f1727;
    --success: #74d7a2;
    --success-soft: rgba(116, 215, 162, 0.16);
    --danger: #ff9aa8;
    --danger-soft: rgba(255, 154, 168, 0.18);
    --info: #9bb8ff;
    --info-soft: rgba(155, 184, 255, 0.18);
    --overlay: rgba(2, 6, 23, 0.72);
    --shadow-sm: 0 12px 28px rgba(2, 6, 23, 0.35);
    --shadow-md: 0 18px 44px rgba(2, 6, 23, 0.45);
    --shadow-lg: 0 26px 60px rgba(2, 6, 23, 0.55);
    --board-bg: #9fb3d9;
    --cell-bg: #1b263a;
    --cell-text: #ecf2ff;
    --cell-focus-bg: #24324b;
    --cell-fixed-bg: #202d43;
    --cell-fixed-text: #9facbf;
    --cell-selected-bg: #2b4164;
    --cell-error-bg: #522736;
    --cell-error-text: #ffb4bf;
}

body.eye-care-theme {
    --page-bg: #f1efdf;
    --surface: #fbfaf3;
    --surface-soft: #f2f0e5;
    --surface-muted: #e7e3d2;
    --text-primary: #38392f;
    --text-secondary: #666655;
    --text-muted: #878574;
    --border-color: #d7d2bd;
    --border-strong: #7e7b65;
    --accent: #6f8f63;
    --accent-strong: #5f7b55;
    --accent-soft: #dfe8d9;
    --accent-contrast: #f8f7f0;
    --success: #5f8b59;
    --success-soft: #e3eedf;
    --danger: #b45c5c;
    --danger-soft: #f4dfdf;
    --info: #6b7c56;
    --info-soft: #ebf0df;
    --overlay: rgba(56, 57, 47, 0.42);
    --shadow-sm: 0 10px 24px rgba(76, 72, 53, 0.08);
    --shadow-md: 0 18px 38px rgba(76, 72, 53, 0.12);
    --shadow-lg: 0 24px 48px rgba(76, 72, 53, 0.16);
    --board-bg: #7e7b65;
    --cell-bg: #fcfbf6;
    --cell-text: #38392f;
    --cell-focus-bg: #f1ede2;
    --cell-fixed-bg: #ece8d8;
    --cell-fixed-text: #6d6a59;
    --cell-selected-bg: #dde8d7;
    --cell-error-bg: #f5e0df;
    --cell-error-text: #9e4343;
}

button,
input {
    font: inherit;
}

button {
    border: none;
    background: none;
}

button:disabled,
input:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.btn,
.panel-btn,
.settings-btn,
.settings-btn-panel,
.file-upload-btn,
.url-load-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    padding: 11px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--surface-soft);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

.btn:hover,
.panel-btn:hover,
.settings-btn:hover,
.settings-btn-panel:hover,
.file-upload-btn:hover,
.url-load-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
    border-color: color-mix(in srgb, var(--border-color) 35%, var(--accent));
}

.btn:focus-visible,
.panel-btn:focus-visible,
.settings-btn:focus-visible,
.settings-btn-panel:focus-visible,
.file-upload-btn:focus-visible,
.url-load-btn:focus-visible,
.difficulty-btn:focus-visible,
.theme-btn:focus-visible,
.number-btn:focus-visible,
.cell input:focus-visible,
.url-input:focus-visible,
#archiveName:focus-visible,
.close:focus-visible,
.panel-close:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn-primary {
    background: var(--accent);
    color: var(--accent-contrast);
    border-color: var(--accent);
}

.btn-primary:hover {
    background: var(--accent-strong);
    border-color: var(--accent-strong);
}

.btn-secondary,
.btn-info,
.btn-warning {
    background: var(--surface-soft);
    color: var(--text-secondary);
    border-color: var(--border-color);
}

.btn-danger {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: transparent;
}

.btn-danger:hover {
    background: var(--danger);
    color: #ffffff;
    border-color: var(--danger);
}

.difficulty-btn,
.theme-btn {
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    background: var(--surface);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

.difficulty-btn:hover,
.theme-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
    border-color: color-mix(in srgb, var(--border-color) 35%, var(--accent));
}

.difficulty-btn.active,
.theme-btn.active {
    background: var(--accent-soft);
    color: var(--accent-strong);
    border-color: color-mix(in srgb, var(--accent) 50%, var(--border-color));
}

.side-panel {
    position: fixed;
    left: -344px;
    top: 0;
    width: 320px;
    height: 100vh;
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    transition: left var(--transition-base), background var(--transition-base), border-color var(--transition-base);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-right: 1px solid var(--border-color);
}

.side-panel.open {
    left: 0;
}

.side-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--surface);
    position: sticky;
    top: 0;
    z-index: 1;
    flex-shrink: 0;
}

.side-panel-header h2 {
    font-size: 18px;
    line-height: 1.2;
    font-weight: 700;
    color: var(--text-primary);
}

.panel-close,
.close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    font-size: 28px;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 50%;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.panel-close {
    width: 28px;
    height: 28px;
    font-size: 22px;
}

.panel-close:hover,
.close:hover {
    background: var(--surface-muted);
    color: var(--text-primary);
}

.side-panel-content {
    padding: var(--space-6);
    overflow-y: auto;
    flex: 1;
}

.panel-section {
    margin-bottom: var(--space-8);
}

.panel-section:last-child {
    margin-bottom: 0;
}

.panel-section h3 {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: var(--space-3);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
}

.difficulty-grid,
.button-grid,
.theme-toggle {
    display: grid;
    gap: var(--space-2);
}

.difficulty-grid,
.button-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.theme-toggle {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.panel-btn {
    width: 100%;
}

.background-controls {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.url-input-group {
    display: flex;
    gap: var(--space-2);
}

.url-input,
#archiveName {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: 11px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text-primary);
    background: var(--surface);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}

.url-input::placeholder,
#archiveName::placeholder {
    color: var(--text-muted);
}

.url-input:focus,
#archiveName:focus {
    outline: none;
    border-color: color-mix(in srgb, var(--accent) 60%, var(--border-color));
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent-soft) 80%, transparent);
}

.image-name {
    font-size: 12px;
    color: var(--text-muted);
    padding: 10px 12px;
    background: var(--surface-soft);
    border-radius: var(--radius-sm);
    text-align: center;
    min-height: 40px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border: 1px dashed var(--border-color);
}

.image-name:empty {
    display: none;
}

.slider-control {
    display: grid;
    grid-template-columns: 56px 1fr auto;
    align-items: center;
    gap: 10px;
}

.slider-control label {
    font-size: 13px;
    color: var(--text-secondary);
}

.slider-control input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 999px;
    background: var(--surface-muted);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.slider-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--surface);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
}

.slider-control input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--surface);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
}

.slider-control span {
    font-size: 12px;
    color: var(--text-muted);
    min-width: 42px;
    text-align: right;
}

.container {
    width: 100%;
    max-width: 1120px;
    margin: 0 auto;
    position: relative;
}

.top-bar {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    margin-bottom: var(--space-5);
}

h1 {
    display: block;
    margin: 0;
    text-align: center;
    font-size: clamp(28px, 4vw, 38px);
    line-height: 1.1;
    color: var(--text-primary);
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.settings-btn {
    flex-shrink: 0;
    margin-left: auto;
}

.settings-btn-panel {
    width: 100%;
    margin-bottom: var(--space-3);
}

.game-area {
    display: flex;
    gap: var(--space-6);
    align-items: flex-start;
    justify-content: center;
}

.number-panel {
    flex-shrink: 0;
    width: 220px;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    box-shadow: var(--shadow-md);
}


.number-panel-title {
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: var(--space-4);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.number-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-2);
    width: 100%;
}

.number-btn {
    min-height: 56px;
    aspect-ratio: 1;
    border: 1px solid var(--border-color);
    background: var(--surface-soft);
    border-radius: 14px;
    font-size: 21px;
    font-weight: 700;
    color: var(--text-primary);
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.number-btn:hover {
    background: var(--accent-soft);
    color: var(--accent-strong);
    border-color: color-mix(in srgb, var(--accent) 45%, var(--border-color));
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

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

.number-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.clear-btn {
    grid-column: 1 / -1;
    min-height: 52px;
    aspect-ratio: auto;
    font-size: 14px;
    color: var(--text-secondary);
}

.sudoku-board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 0;
    border: 4px solid var(--board-bg);
    border-radius: 20px;
    overflow: hidden;
    width: min(100%, 620px);
    aspect-ratio: 1;
    background: var(--board-bg);
    box-shadow: var(--shadow-md);
}

.cell {
    aspect-ratio: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--cell-bg);
    cursor: pointer;
    border: 1px solid var(--border-color);
    transition: background var(--transition-fast), border-color var(--transition-fast);
}

.cell input {
    width: 100%;
    height: 100%;
    border: none;
    text-align: center;
    font-size: clamp(20px, 2.4vw, 28px);
    font-weight: 700;
    background: transparent;
    color: var(--cell-text);
    cursor: pointer;
}

.cell input:focus {
    outline: none;
    background: var(--cell-focus-bg);
}

.cell.fixed {
    background: var(--cell-fixed-bg);
}

.cell.fixed input {
    cursor: default;
    color: var(--cell-fixed-text);
}

.cell.selected {
    background: var(--cell-selected-bg) !important;
}

.cell.error {
    background: var(--cell-error-bg) !important;
}

.cell.error input {
    color: var(--cell-error-text);
}

.cell:nth-child(9n+3),
.cell:nth-child(9n+6) {
    border-right: 3px solid var(--board-bg);
}

.cell:nth-child(n+19):nth-child(-n+27),
.cell:nth-child(n+46):nth-child(-n+54) {
    border-bottom: 3px solid var(--board-bg);
}

.message {
    margin-top: var(--space-4);
    min-height: 44px;
    padding: 0 14px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    opacity: 0;
    transform: translateY(4px);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    transition: opacity var(--transition-base), transform var(--transition-base), background var(--transition-base), border-color var(--transition-base), color var(--transition-base);
}

.message:not(:empty) {
    opacity: 1;
    transform: translateY(0);
}

.message.success {
    color: var(--success);
    background: var(--success-soft);
    border-color: color-mix(in srgb, var(--success) 20%, transparent);
}

.message.error {
    color: var(--danger);
    background: var(--danger-soft);
    border-color: color-mix(in srgb, var(--danger) 20%, transparent);
}

.message.info {
    color: var(--info);
    background: var(--info-soft);
    border-color: color-mix(in srgb, var(--info) 20%, transparent);
}

.modal {
    display: none;
    position: fixed;
    z-index: 2500;
    inset: 0;
    background: var(--overlay);
    animation: fadeIn var(--transition-base);
    padding: 24px;
}

.modal.show {
    display: flex;
    justify-content: center;
    align-items: center;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--surface);
    border-radius: var(--radius-lg);
    width: min(100%, 560px);
    max-height: min(80vh, 720px);
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    animation: slideIn var(--transition-base);
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-6);
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 24px;
    color: var(--text-primary);
}

.modal-body {
    padding: var(--space-6);
}

.archive-section + .archive-section {
    margin-top: var(--space-6);
}

.archive-section h3 {
    font-size: 18px;
    color: var(--text-primary);
    margin-bottom: var(--space-4);
}

#archiveList {
    max-height: 320px;
    overflow-y: auto;
}

.archive-item {
    background: var(--surface-soft);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    margin-bottom: var(--space-3);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast);
}

.archive-item:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
    border-color: color-mix(in srgb, var(--border-color) 35%, var(--accent));
}

.archive-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-2);
}

.archive-name {
    font-weight: 700;
    font-size: 16px;
    color: var(--text-primary);
}

.archive-info {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-secondary);
    margin-bottom: var(--space-3);
}

.archive-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.archive-actions .btn {
    min-height: 38px;
    padding: 8px 14px;
    font-size: 12px;
}

.empty-archive {
    text-align: center;
    padding: 28px 16px;
    color: var(--text-muted);
    font-size: 14px;
    background: var(--surface-soft);
    border-radius: var(--radius-md);
    border: 1px dashed var(--border-color);
}

@media (max-width: 900px) {
    .game-area {
        flex-direction: column;
        align-items: center;
    }

    .number-panel {
        width: min(100%, 420px);
    }
}

@media (max-width: 768px) {
    body {
        padding: 18px;
    }

    .top-bar {
        margin-bottom: var(--space-4);
    }

    .theme-toggle {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .modal {
        padding: 16px;
    }
}

@media (max-width: 600px) {
    body {
        padding: 14px;
    }

    .top-bar {
        min-height: auto;
        justify-content: center;
    }

    h1 {
        white-space: normal;
        width: 100%;
        font-size: clamp(24px, 7vw, 32px);
    }

    .settings-btn {
        width: 100%;
        margin-left: 0;
    }

    .number-panel {
        width: 100%;
        padding: var(--space-4);
    }

    .number-grid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }

    .clear-btn {
        grid-column: 1 / -1;
    }

    .side-panel {
        width: 280px;
        left: -300px;
    }

    .modal-content {
        width: 100%;
        border-radius: 20px;
    }

    .modal-header,
    .modal-body,
    .side-panel-header,
    .side-panel-content {
        padding: var(--space-5);
    }

    .archive-actions .btn {
        flex: 1 1 calc(50% - 4px);
    }
}
