/* ===== Variables & Base ===== */
:root {
    --bg-dark: #0f1419;
    --bg-card: #1a2332;
    --bg-cell: #243447;
    --bg-cell-hover: #2d3f54;
    --border-grid: #3d5568;
    --border-box: #4a6572;
    --text-primary: #e7e9ea;
    --text-muted: #8b98a5;
    --accent: #1d9bf0;
    --accent-hover: #1a8cd8;
    --success: #00ba7c;
    --error: #f4212e;
    --given-color: #e7e9ea;
    --user-color: #78b4fa;
    --note-color: #8b98a5;
    --navbar-bg: rgba(26, 35, 50, 0.95);
    --navbar-border: rgba(61, 85, 104, 0.5);
    --bg-gradient-start: #0f1419;
    --bg-gradient-mid: #1a2332;
    --bg-gradient-end: #0f1419;
}

/* Light theme */
[data-theme="light"] {
    --bg-dark: #eef2f5;
    --bg-card: #ffffff;
    --bg-cell: #f0f4f8;
    --bg-cell-hover: #e2e8f0;
    --border-grid: #cbd5e1;
    --border-box: #94a3b8;
    --text-primary: #1e293b;
    --text-muted: #64748b;
    --accent: #0ea5e9;
    --accent-hover: #0284c7;
    --success: #059669;
    --error: #dc2626;
    --given-color: #1e293b;
    --user-color: #2563eb;
    --note-color: #64748b;
    --navbar-bg: rgba(255, 255, 255, 0.98);
    --navbar-border: rgba(203, 213, 225, 0.8);
    --bg-gradient-start: #eef2f5;
    --bg-gradient-mid: #ffffff;
    --bg-gradient-end: #eef2f5;
}

[data-theme="light"] .text-white {
    color: var(--text-primary) !important;
}
[data-theme="light"] .text-white-50 {
    color: var(--text-muted) !important;
}

.text-accent {
    color: var(--accent);
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
}

body.game-page {
    background: linear-gradient(160deg, var(--bg-gradient-start) 0%, var(--bg-gradient-mid) 50%, var(--bg-gradient-end) 100%);
}

/* ===== Navbar ===== */
.navbar {
    background: var(--navbar-bg) !important;
    border-bottom: 1px solid var(--navbar-border);
}

.navbar-brand {
    color: var(--text-primary) !important;
}

.navbar .btn,
.navbar .navbar-theme-toggle {
    color: var(--text-primary) !important;
    border-color: var(--border-grid);
}
.navbar .btn:hover,
.navbar .navbar-theme-toggle:hover {
    border-color: var(--accent) !important;
    color: var(--accent) !important;
}

/* Theme toggle */
.navbar-theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border-radius: 50%;
    border: 1px solid;
    background: transparent;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.navbar-theme-toggle:hover {
    background: var(--bg-cell-hover);
}
.navbar-theme-toggle i {
    font-size: 1.1rem;
}
.navbar-theme-toggle .icon-sun { display: none; }
.navbar-theme-toggle .icon-moon { display: inline-block; }
[data-theme="light"] .navbar-theme-toggle .icon-sun { display: inline-block; }
[data-theme="light"] .navbar-theme-toggle .icon-moon { display: none; }

/* ===== Home page difficulty buttons ===== */
.btn-difficulty {
    border-radius: 12px;
    font-weight: 600;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border: 2px solid transparent;
}

.btn-difficulty:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.btn-difficulty.EASY {
    background: linear-gradient(135deg, #00ba7c, #00d68f);
    color: #fff;
}

.btn-difficulty.MEDIUM {
    background: linear-gradient(135deg, #1d9bf0, #4db8f5);
    color: #fff;
}

.btn-difficulty.HARD {
    background: linear-gradient(135deg, #f59e0b, #fbbf24);
    color: #1a1a1a;
}

.btn-difficulty.EXPERT {
    background: linear-gradient(135deg, #ef4444, #f87171);
    color: #fff;
}

/* Home: Printable Sudoku button – visible in light and dark theme */
.btn-print-home {
    background: linear-gradient(135deg, #1d9bf0, #4db8f5);
    color: #fff !important;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    padding: 0.5rem 1rem;
    text-decoration: none;
    display: inline-block;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-print-home:hover {
    color: #fff !important;
    background: linear-gradient(135deg, #1a8cd8, #1d9bf0);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(29, 155, 240, 0.4);
}

/* ===== Stats ===== */
.stat-box {
    background: var(--bg-card);
    padding: 0.6rem 1.2rem;
    border-radius: 10px;
    font-weight: 600;
    color: var(--text-primary);
    border: 1px solid var(--border-grid);
    display: inline-flex;
    align-items: center;
}

.stat-box i {
    color: var(--accent);
}

/* ===== Sudoku grid ===== */
.sudoku-wrapper {
    background: var(--bg-card);
    padding: 1rem;
    border-radius: 16px;
    border: 1px solid var(--border-grid);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.sudoku-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 0;
    width: min( min(90vw, 450px), 450px );
    aspect-ratio: 1;
    margin: 0 auto;
    border: 2px solid var(--border-box);
    border-radius: 8px;
    overflow: hidden;
}

.cell {
    background: var(--bg-cell);
    border: 1px solid var(--border-grid);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
    font-size: clamp(14px, 4vw, 22px);
    font-weight: 600;
}

.cell:hover:not(.given) {
    background: var(--bg-cell-hover);
}

.cell.selected {
    background: rgba(29, 155, 240, 0.35);
    outline: 2px solid var(--accent);
    outline-offset: -2px;
    z-index: 1;
}

.cell.same-number {
    background: rgba(29, 155, 240, 0.15);
}

.cell.error {
    background: rgba(244, 33, 46, 0.2);
    animation: shake 0.4s ease;
}

.cell.given .cell-value {
    color: var(--given-color);
}

.cell:not(.given) .cell-value {
    color: var(--user-color);
}

.cell-value {
    position: relative;
    z-index: 2;
}

/* 3x3 box borders */
.cell:nth-child(3n) {
    border-right-width: 2px;
    border-right-color: var(--border-box);
}

.cell:nth-child(n+19):nth-child(-n+27),
.cell:nth-child(n+46):nth-child(-n+54) {
    border-bottom-width: 2px;
    border-bottom-color: var(--border-box);
}

.cell:nth-child(9n) {
    border-right-width: 2px;
    border-right-color: var(--border-box);
}

/* Notes inside cell */
.cell-notes {
    position: absolute;
    inset: 2px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    font-size: 0.5em;
    color: var(--note-color);
    align-items: center;
    justify-items: center;
    pointer-events: none;
}

.cell-notes span {
    font-weight: 600;
    font-size: clamp(8px, 0.75em, 12px);
}

/* ===== Actions ===== */
.actions-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
}

.btn-action {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-grid);
    border-radius: 10px;
    padding: 0.6rem 1rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: background 0.2s, transform 0.15s, border-color 0.2s;
}

.btn-action:hover {
    background: var(--bg-cell-hover);
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-1px);
}

.btn-action.active {
    background: rgba(29, 155, 240, 0.25);
    border-color: var(--accent);
    color: var(--accent);
}

.btn-action:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ===== Number pad ===== */
.numpad {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 0.4rem;
    max-width: 450px;
    margin-left: auto;
    margin-right: auto;
}

.numpad-btn {
    aspect-ratio: 1;
    border-radius: 10px;
    border: 1px solid var(--border-grid);
    background: var(--bg-card);
    color: var(--text-primary);
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s, border-color 0.15s;
}

.numpad-btn:hover {
    background: var(--bg-cell-hover);
    border-color: var(--accent);
    color: var(--accent);
    transform: scale(1.05);
}

.numpad-btn:active {
    transform: scale(0.98);
}

/* ===== New game buttons ===== */
.btn-new-game {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-grid);
    border-radius: 8px;
    padding: 0.4rem 0.9rem;
    font-size: 0.9rem;
    transition: background 0.2s, border-color 0.2s;
}

.btn-new-game:hover {
    background: var(--bg-cell-hover);
    border-color: var(--accent);
    color: var(--accent);
}

/* ===== Win modal ===== */
.modal-win .modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-box);
    border-radius: 16px;
}

.modal-win.modal-correct .modal-content {
    border-color: rgba(0, 186, 124, 0.5);
    box-shadow: 0 0 40px rgba(0, 186, 124, 0.2);
}

.modal-win.modal-wrong .modal-content {
    border-color: rgba(244, 33, 46, 0.4);
    box-shadow: 0 0 30px rgba(244, 33, 46, 0.15);
}

/* Celebration sparkles (correct solution) */
.sparkles-container {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: visible;
    border-radius: 16px;
}

.sparkle {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    left: 50%;
    top: 50%;
    opacity: 0;
    animation: sparkle-burst 1.2s ease-out forwards;
}

.sparkle.star {
    width: 0;
    height: 0;
    background: none;
    border-radius: 0;
    box-shadow: none;
}

.sparkle.star::before {
    content: '\2605';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-size: 12px;
    color: #fbbf24;
    opacity: 0;
    animation: sparkle-star 1.2s ease-out forwards;
}

@keyframes sparkle-burst {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 1;
    }
    30% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty))) scale(0);
        opacity: 0;
    }
}

@keyframes sparkle-star {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 1;
    }
    30% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty))) scale(0.2);
        opacity: 0;
    }
}

/* Wrong solution / game over animation */
.modal-wrong.modal-shake .modal-content {
    animation: wrongShake 0.6s ease-in-out;
}

.modal-wrong .modal-wrong-icon {
    animation: wrongPulse 0.5s ease-out;
}

@keyframes wrongShake {
    0%, 100% { transform: translateX(0); }
    15% { transform: translateX(-8px) rotate(-1deg); }
    30% { transform: translateX(8px) rotate(1deg); }
    45% { transform: translateX(-6px) rotate(-0.5deg); }
    60% { transform: translateX(6px) rotate(0.5deg); }
    75% { transform: translateX(-3px); }
}

@keyframes wrongPulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.15); opacity: 0.9; }
    100% { transform: scale(1); opacity: 1; }
}

/* Win trophy bounce */
.win-trophy {
    animation: trophyBounce 0.6s ease-out;
}

/* Win modal: visible "New Game" button */
.btn-win-new-game {
    background: linear-gradient(135deg, #00ba7c, #00d68f);
    color: #fff !important;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    padding: 0.5rem 1.25rem;
    text-decoration: none;
    display: inline-block;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-win-new-game:hover {
    color: #fff !important;
    background: linear-gradient(135deg, #00a36e, #00ba7c);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(0, 186, 124, 0.4);
}

@keyframes trophyBounce {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.2); }
    70% { transform: scale(0.95); }
    100% { transform: scale(1); opacity: 1; }
}

/* ===== Animations ===== */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-4px); }
    40% { transform: translateX(4px); }
    60% { transform: translateX(-2px); }
    80% { transform: translateX(2px); }
}

.cell.fill-in {
    animation: fillIn 0.3s ease;
}

@keyframes fillIn {
    0% { transform: scale(1.2); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

/* ===== How to Play page ===== */
.how-to-play-page main {
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
}

.howto-hero {
    padding: 2rem 1rem;
}

.howto-hero-icon {
    width: 4rem;
    height: 4rem;
    margin-left: auto;
    margin-right: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border: 1px solid var(--border-grid);
    border-radius: 50%;
    color: var(--accent);
    font-size: 1.75rem;
}

.howto-card {
    background: var(--bg-card);
    border: 1px solid var(--border-grid);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.howto-card-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-grid);
}

.howto-card-icon {
    width: 3rem;
    height: 3rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    font-size: 1.25rem;
    color: #fff;
}

.howto-card-icon--goal { background: linear-gradient(135deg, #1d9bf0, #4db8f5); }
.howto-card-icon--rules { background: linear-gradient(135deg, #6366f1, #818cf8); }
.howto-card-icon--diff { background: linear-gradient(135deg, #8b5cf6, #a78bfa); }
.howto-card-icon--controls { background: linear-gradient(135deg, #0ea5e9, #38bdf8); }
.howto-card-icon--stats { background: linear-gradient(135deg, #64748b, #94a3b8); }

.howto-card-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.howto-card-body {
    padding: 1.5rem;
}

.howto-card-text {
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.howto-card-caption {
    color: var(--text-muted);
}

.howto-list {
    list-style: none;
    padding: 0;
    margin: 0;
    color: var(--text-muted);
}

.howto-list li {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-grid);
}

.howto-list li:last-child {
    border-bottom: none;
}

.howto-list-icon {
    color: var(--accent);
    margin-top: 0.2rem;
    flex-shrink: 0;
    width: 1.25rem;
    text-align: center;
}

.howto-mini-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    max-width: 120px;
}

.howto-mini-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-cell);
    border: 1px solid var(--border-grid);
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
}

.howto-diff-badge {
    padding: 1rem 0.75rem;
    border-radius: 12px;
    text-align: center;
    color: #fff;
    transition: transform 0.2s, box-shadow 0.2s;
}

.howto-diff-badge:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.howto-diff-easy { background: linear-gradient(135deg, #00ba7c, #00d68f); }
.howto-diff-medium { background: linear-gradient(135deg, #1d9bf0, #4db8f5); }
.howto-diff-hard { background: linear-gradient(135deg, #f59e0b, #fbbf24); color: #1a1a1a; }
.howto-diff-expert { background: linear-gradient(135deg, #ef4444, #f87171); }

.howto-control-item,
.howto-stat-item {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-cell);
    border: 1px solid var(--border-grid);
    border-radius: 12px;
}

.howto-control-icon {
    width: 2.75rem;
    height: 2.75rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(29, 155, 240, 0.2);
    color: var(--accent);
    border-radius: 10px;
    font-size: 1.1rem;
}

.howto-stat-icon {
    width: 2.75rem;
    height: 2.75rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-cell-hover);
    color: var(--accent);
    border-radius: 10px;
    font-size: 1.1rem;
}

.howto-stat-icon--mistakes {
    background: rgba(244, 33, 46, 0.15);
    color: var(--error);
}

.btn-howto-cta {
    background: linear-gradient(135deg, #00ba7c, #00d68f);
    color: #fff !important;
    border: none;
    border-radius: 14px;
    font-weight: 700;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-howto-cta:hover {
    color: #fff !important;
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 186, 124, 0.4);
}

/* FAQ / How to Play: Play Sudoku CTA – visible in light and dark theme */
.btn-play-cta {
    background: linear-gradient(135deg, #1d9bf0, #4db8f5);
    color: #fff !important;
    border: none;
    border-radius: 14px;
    font-weight: 700;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-play-cta:hover {
    color: #fff !important;
    background: linear-gradient(135deg, #1a8cd8, #1d9bf0);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(29, 155, 240, 0.4);
}

/* ===== FAQ accordion ===== */
.accordion-faq .accordion-item {
    background: var(--bg-card);
    border: 1px solid var(--border-grid);
    border-radius: 10px !important;
    margin-bottom: 0.75rem;
    overflow: hidden;
}

.accordion-faq .accordion-item:last-child {
    margin-bottom: 0;
}

.accordion-faq .accordion-button {
    background: var(--bg-card);
    color: var(--text-primary);
    font-weight: 600;
    border: none;
    box-shadow: none;
    padding: 1rem 1.25rem;
}

.accordion-faq .accordion-button:not(.collapsed) {
    background: var(--bg-cell-hover);
    color: var(--accent);
}

.accordion-faq .accordion-button:hover {
    background: var(--bg-cell-hover);
    color: var(--accent);
}

.accordion-faq .accordion-button::after {
    filter: invert(0.7);
}

[data-theme="light"] .accordion-faq .accordion-button::after {
    filter: none;
}

.accordion-faq .accordion-body {
    background: var(--bg-card);
    color: var(--text-muted);
    padding: 1rem 1.25rem 1.25rem;
    border-top: 1px solid var(--border-grid);
}

.faq-mini {
    flex: 1;
    min-width: 160px;
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    border-radius: 10px;
    border: 1px solid var(--border-grid);
}

/* ===== Responsive ===== */
@media (max-width: 520px) {
    .numpad {
        grid-template-columns: repeat(5, 1fr);
    }
    .numpad-btn:nth-child(n+6) {
        grid-column: span 1;
    }
    .actions-bar {
        gap: 0.5rem;
    }
    .btn-action span {
        display: none;
    }
}

@media (max-width: 768px) {
    .howto-card-header {
        padding: 1rem 1.25rem;
    }
    .howto-card-body {
        padding: 1.25rem;
    }
}
