/* Sudoku - Dark theme, desktop two-column layout */

:root {
    --bg: #0f0f1a;
    --surface: #1a1a2e;
    --surface-light: #252540;
    --border: #333355;
    --text: #e6e6f0;
    --text-muted: #8888aa;
    --accent: #6366f1;
    --accent-light: #818cf8;
    --green: #22c55e;
    --red: #ef4444;
    --gold: #eab308;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    user-select: none;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    height: 42px;
}

.header h1 {
    font-size: 1rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.icon-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    padding: 6px 10px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.15s;
}

.icon-btn:hover {
    background: var(--surface-light);
    color: var(--text);
}

/* ======================== */
/* MAIN TWO-COLUMN LAYOUT   */
/* ======================== */
.main-layout {
    display: flex;
    height: calc(100vh - 42px);
    overflow: hidden;
}

/* Left column: puzzle grid, as large as possible */
.puzzle-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Right column: rules + controls */
.controls-column {
    width: 320px;
    min-width: 280px;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border);
    background: var(--surface);
    overflow-y: auto;
}

/* Puzzle info bar */
.info-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-muted);
}

.timer {
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
}

/* Canvas container — fill available space */
.grid-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
    background: var(--bg);
    position: relative;
}

#sudoku-canvas {
    cursor: crosshair;
    border-radius: 4px;
    touch-action: none;
}

/* ======================== */
/* RULES PANEL (right side)  */
/* ======================== */
.rules-panel {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.rules-panel h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.rules-content {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.7;
    max-height: 280px;
    overflow-y: auto;
}

/* ======================== */
/* INPUT CONTROLS            */
/* ======================== */

/* Input mode buttons */
.input-modes {
    display: flex;
    justify-content: center;
    gap: 4px;
    padding: 12px 12px 8px;
}

.input-mode-btn {
    padding: 7px 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-light);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    flex: 1;
    text-align: center;
}

.input-mode-btn:hover {
    background: var(--border);
}

.input-mode-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* Numpad */
.numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    padding: 8px 16px;
}

.numpad-btn {
    aspect-ratio: 1.4;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-light);
    color: var(--text);
    font-size: 1.3rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.numpad-btn:hover {
    background: var(--border);
}

.numpad-btn:active {
    transform: scale(0.95);
    background: var(--accent);
}

.numpad-zero {
    grid-column: 1 / -1;
    aspect-ratio: auto;
    padding: 10px;
}

/* Action buttons */
.action-bar {
    display: flex;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px 16px;
}

.action-btn {
    padding: 8px 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-light);
    color: var(--text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.15s;
    flex: 1;
}

.action-btn:hover {
    background: var(--border);
    color: var(--text);
}

/* Color palette */
.color-palette {
    display: none;
    justify-content: center;
    gap: 4px;
    padding: 4px 16px 8px;
    flex-wrap: wrap;
}

.color-palette.visible {
    display: flex;
}

.color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
}

.color-swatch:hover {
    transform: scale(1.1);
}

.color-swatch.clear {
    background: var(--surface-light);
    border-color: var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Keyboard shortcuts */
.shortcuts-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    padding: 8px 16px 12px;
    border-top: 1px solid var(--border);
}

.shortcut {
    font-size: 0.7rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}

.shortcut .key {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 1px 5px;
    font-size: 0.65rem;
    font-family: 'Courier New', monospace;
    color: var(--text);
}

/* ======================== */
/* MODALS                    */
/* ======================== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 100;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.modal-overlay.visible {
    display: flex;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    max-width: 480px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal h2 {
    font-size: 1.1rem;
    margin-bottom: 16px;
}

.modal-close {
    float: right;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
}

/* Import form */
.import-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.import-form input {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 12px;
    color: var(--text);
    font-size: 0.9rem;
}

.import-form input::placeholder {
    color: var(--text-muted);
}

.import-form button {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    background: var(--accent);
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
}

.import-form button:hover {
    background: var(--accent-light);
}

.import-form button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* History list */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
}

.history-item:hover {
    border-color: var(--accent);
}

.history-item .title {
    font-weight: 600;
    font-size: 0.85rem;
}

.history-item .meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.history-item .time {
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Rules display (modal version) */
.rules-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.5;
    max-height: 300px;
    overflow-y: auto;
    white-space: pre-wrap;
}

/* Loading */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.loading .spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Completion */
.completion-overlay {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(15, 15, 26, 0.85);
    justify-content: center;
    align-items: center;
    flex-direction: column;
    gap: 12px;
    border-radius: 4px;
}

.completion-overlay.visible {
    display: flex;
}

.completion-overlay h2 {
    color: var(--green);
    font-size: 1.5rem;
}

.completion-overlay .time {
    font-family: 'Courier New', monospace;
    font-size: 1.2rem;
    color: var(--text);
}

/* Error message */
.error-msg {
    color: var(--red);
    font-size: 0.8rem;
    padding: 4px 0;
    display: none;
}

.error-msg.visible {
    display: block;
}

/* Saved puzzles list */
.saves-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
}

.saves-list h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* ======================== */
/* MOBILE: stack vertically  */
/* ======================== */
@media (max-width: 768px) {
    body {
        height: auto;
        overflow: auto;
    }

    .main-layout {
        flex-direction: column;
        height: auto;
    }

    .puzzle-column {
        flex: none;
    }

    .controls-column {
        width: 100%;
        max-width: 100%;
        min-width: 100%;
        border-left: none;
        border-top: 1px solid var(--border);
    }

    .rules-panel {
        max-height: none;
    }

    .rules-content {
        max-height: 150px;
    }

    .numpad {
        grid-template-columns: repeat(9, 1fr);
        max-width: 500px;
        margin: 0 auto;
    }

    .numpad-btn {
        aspect-ratio: 1;
        font-size: 1.2rem;
    }
}

/* Cage Combinations Panel */
.cage-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    width: 280px;
    max-height: 400px;
    overflow-y: auto;
    box-shadow: 0 4px 24px rgba(0,0,0,0.5);
    z-index: 200;
    font-size: 13px;
}
.cage-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    color: var(--text);
    position: sticky;
    top: 0;
    background: var(--surface);
}
#cage-panel-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    line-height: 1;
}
#cage-panel-close:hover { color: var(--text); }
#cage-panel-body {
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.cage-combo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: background 0.15s;
    user-select: none;
}
.cage-combo:hover { background: var(--surface-light); }
.cage-combo.eliminated {
    opacity: 0.35;
    text-decoration: line-through;
    background: rgba(255,80,80,0.05);
}
.cage-combo-digits {
    font-family: monospace;
    font-size: 14px;
    color: var(--text);
    letter-spacing: 1px;
}
.cage-combo-label {
    color: var(--text-muted);
    font-size: 11px;
}
