@charset "UTF-8";

/* 
  Theme: "Midnight Luxury"
  Concept: Premium, elegant, dark mode.
  Palette: Deep Slate, Gold, Platinum.
  Fonts: Fraunces (Headings), Montserrat/Outfit (UI).
*/

:root {
  /* --- Palette --- */
  --bg-main: #0f172a;       /* Slate 900 */
  --bg-surface: #1e293b;    /* Slate 800 */
  --bg-surface-2: #334155;  /* Slate 700 */
  
  --text-main: #f8fafc;     /* Slate 50 */
  --text-muted: #94a3b8;    /* Slate 400 */
  
  --primary: #fbbf24;       /* Amber 400 (Gold) */
  --primary-hover: #f59e0b; /* Amber 500 */
  
  --accent: #38bdf8;        /* Sky 400 */
  --error: #ef4444;         /* Red 500 */
  --success: #22c55e;       /* Green 500 */

  /* Grid lines */
  --grid-line: #475569;     /* Slate 600 */
  --grid-line-thick: #fbbf24; /* Gold */

  /* UI */
  --radius-xl: 24px;
  --radius-lg: 16px; 
  --radius-md: 12px;
  --radius-sm: 8px;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-glow: 0 0 15px rgba(251, 191, 36, 0.3);

  --font-heading: 'Fraunces', serif;
  --font-ui: 'Outfit', sans-serif;
}

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

body {
  font-family: var(--font-ui);
  color: var(--text-main);
  background-color: var(--bg-main);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  display: flex; flex-direction: column;
}

/* Typography */
h1, h2, h3 {
  font-family: var(--font-heading);
  font-weight: 700;
}
button { font-family: var(--font-ui); }

/* --- Common Util --- */
.hide { display: none !important; }
.btn {
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
}

/* --- Splash Screen --- */
.splash-screen {
  position: fixed; inset: 0;
  z-index: 9999;
  background: var(--bg-main);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  transition: opacity 0.5s ease;
}
.splash-text {
  font-family: var(--font-heading);
  font-size: 3rem;
  color: var(--primary);
  margin-top: 1rem;
}

/* --- Home Screen --- */
.home-body {
    width: 100%;
    flex: 1; /* Take remaining height of body */
    display: flex;
    flex-direction: column;
}

.home-container {
  width: 100%; 
  height: 100%; /* Fill the .home-body */
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
}

.home-box {
  background: rgba(30, 41, 59, 0.8);
  backdrop-filter: blur(12px);
  padding: 3.5rem 2rem;
  border-radius: var(--radius-xl);
  border: 1px solid rgba(255,255,255,0.05);
  text-align: center;
  width: 90%; max-width: 400px;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}

.game-title {
  font-size: 3.5rem;
  color: var(--primary);
  margin-bottom: 0.5rem;
  text-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

.game-subtitle {
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 0.8rem;
  margin-bottom: 3rem;
}

/* Difficulty Selector */
.difficulty-selector { margin-bottom: 2.5rem; width: 100%; }
.label { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 0.5rem; }
.difficulty-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
  width: 100%;
}
.diff-btn {
  background: var(--bg-surface-2);
  color: var(--text-muted);
  border: 1px solid transparent;
  padding: 0.8rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}
.diff-btn.active {
  background: rgba(251, 191, 36, 0.15);
  color: var(--primary);
  border-color: var(--primary);
  font-weight: 600;
}

#startBtn { margin-bottom: 2rem; width: 100%; }
.home-footer { display: flex; gap: 1rem; justify-content: center; width: 100%; }

.btn.primary {
  background: var(--primary);
  color: #0f172a;
  padding: 1rem 2rem;
  border-radius: 50px;
  font-size: 1.1rem;
  box-shadow: var(--shadow-glow);
}
.btn.primary:hover { transform: translateY(-2px); box-shadow: 0 4px 20px rgba(251, 191, 36, 0.4); }

.btn.secondary {
  background: transparent;
  color: var(--text-main);
  border: 1px solid rgba(255,255,255,0.2);
  padding: 1rem 2rem;
  border-radius: 50px;
  font-size: 1.1rem;
  font-weight: 600;
}
.btn.secondary:hover { border-color: var(--text-main); color: var(--text-main); }

/* --- Game Screen --- */
.game-body {
  width: 100%; max-width: 600px;
  margin: 0 auto;
  display: flex; flex-direction: column;
  height: 100%;
}

/* Check constraints on small screens */
@media (max-height: 700px) {
    .game-body { padding-bottom: 0; }
    .game-header { padding: 0.5rem 1rem; }
    #sudoku-keypad { margin-bottom: 0.5rem; }
}

/* Header */
.game-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.5rem;
  margin-bottom: 0.5rem;
}
.game-info {
    display: flex; flex-direction: column; align-items: center; gap: 0.2rem;
}
.timer-box { 
    display: flex; align-items: center; gap: 0.4rem; 
    font-variant-numeric: tabular-nums; 
    font-size: 1.2rem; font-weight: 500; color: var(--text-main);
}
.difficulty-badge {
    font-size: 0.75rem; color: var(--primary); text-transform: uppercase; letter-spacing: 0.05em;
    font-weight: 700;
}
.mistakes-box { font-size: 0.8rem; color: var(--text-muted); }

.icon-btn {
    background: transparent;
    color: var(--text-muted);
    padding: 0.5rem;
    border-radius: 50%;
}
.icon-btn:hover { background: var(--bg-surface-2); color: var(--text-main); }

/* Board */
.container {
    padding: 0 1rem;
    margin-bottom: 1rem;
    display: flex; justify-content: center;
}
.sudoku-container {
    border-collapse: collapse;
    margin: 0 auto;
    background: var(--bg-surface);
    border: 2px solid var(--grid-line-thick); /* Gold border wrapper */
    border-radius: 4px; /* Slight rounding on outer */
    overflow: hidden;
    position: relative;
    box-shadow: var(--shadow-lg);
}
/* Grid Lines */
.sudoku-container td {
    padding: 0;
    width: 38px; height: 38px;
    border: 1px solid var(--grid-line);
    position: relative;
}
/* Thicker Section Borders */
.sudoku-container td:nth-child(3n) { border-right: 2px solid var(--grid-line-thick); }
.sudoku-container tr:nth-child(3n) td { border-bottom: 2px solid var(--grid-line-thick); }
.sudoku-container td:last-child { border-right: none; }
.sudoku-container tr:last-child td { border-bottom: none; }

/* Responsive Cell Size */
@media (min-width: 400px) {
    .sudoku-container td { width: 44px; height: 44px; }
}

/* Inputs */
.sudoku-container input {
    width: 100%; height: 100%;
    margin: 0;
    text-align: center;
    font-size: 1.5rem;
    color: var(--accent);
    background: transparent;
    border: none;
    outline: none;
    font-family: var(--font-ui);
    cursor: default;
    caret-color: transparent; 
}

/* States */
.sudoku-container .disabled {
    background: #151e2e; /* Slightly darker */
    color: #e2e8f0; /* Givens are white/grey */
    font-weight: 700;
}
.selected-cell {
    background: rgba(34, 211, 238, 0.35) !important; /* Fresh Cyan/Teal */
    box-shadow: 0 0 15px rgba(34, 211, 238, 0.25) !important;
    border: 1px solid rgba(34, 211, 238, 0.5) !important;
}
.highlighted {
    background: rgba(56, 189, 248, 0.1); 
}
.same-number {
    background: rgba(56, 189, 248, 0.5) !important; /* Highlight all same numbers, override disabled */
    color: #fff !important;
}
.invalid {
    background: rgba(239, 68, 68, 0.2) !important;
    color: var(--error) !important;
}
.related { /* Row/Col highlight */
    position: relative;
}
.related::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(56, 189, 248, 0.15);
    pointer-events: none;
    z-index: 1; /* Sit above the input background */
}

/* Notes Grid (Pseudo-element or inner HTML) */
.notes-grid {
    position: absolute; inset: 0;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    pointer-events: none;
}
.note-num {
    display: flex; align-items: center; justify-content: center;
    font-size: 9px;
    color: var(--text-muted);
}


/* Controls Area */
.controls-area {
    padding: 1.5rem 1.5rem 0 1.5rem;
    display: flex; flex-direction: column; gap: 1rem;
    flex: 1;
}

/* Action Bar */
.action-bar {
    display: flex; justify-content: space-between;
}
.action-btn {
    display: flex; flex-direction: column; align-items: center; gap: 5px;
    background: transparent; border: none;
    color: var(--text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    position: relative;
}
.action-btn svg { width: 20px; height: 20px; }
.action-btn.active { color: var(--primary); }
.action-btn.active svg { stroke: var(--primary); fill: rgba(251,191,36,0.1); }
.action-btn:active { transform: scale(0.95); }

.badge {
    position: absolute; top: -5px; right: -5px;
    background: var(--bg-surface-2); color: #fff;
    font-size: 0.6rem; padding: 2px 5px; border-radius: 10px;
    min-width: 16px; text-align: center;
}
.action-btn.active .badge { background: var(--primary); color: #000; }
#hintCount { background: var(--accent); color: #0f172a; font-weight: bold; }

/* Keypad */
#sudoku-keypad {
    display: flex; flex-direction: column; gap: 0.5rem;
}

/* --- Keypad Grid Logic --- */
.keypad-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    width: 100%;
    justify-content: center;
}

.keypad-btn {
    flex: 1 0 18%; /* Basis approx 1/5th minus gap */
    aspect-ratio: 1.5;
    background: var(--bg-surface-2); /* Slate 700 */
    color: var(--text-main);
    font-size: 1.5rem;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    transition: all 0.1s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 700;
    box-shadow: 0 4px 0 var(--bg-main), 0 2px 4px rgba(0,0,0,0.4);
    border: 1px solid rgba(255,255,255,0.05);
}
.keypad-btn:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 var(--bg-main), inset 0 2px 4px rgba(0,0,0,0.5);
}

#newGameBtn {
    width: 100%;
    margin-top: auto; margin-bottom: 1.5rem;
    font-size: 1rem; padding: 0.8rem;
    background: linear-gradient(180deg, #fbbf24 0%, #f59e0b 100%);
    color: #0f172a;
    font-weight: 800;
    border-radius: 50px;
    box-shadow: 0 4px 0 #b45309, 0 5px 15px rgba(251, 191, 36, 0.3);
    transition: all 0.1s;
}
#newGameBtn:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 #b45309, inset 0 2px 5px rgba(0,0,0,0.2);
}

/* Popups */
.popup-overlay {
    display: none; 
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.9);
    z-index: 2000;
    /* Flex centering */
    align-items: center; 
    justify-content: center;
    backdrop-filter: blur(5px);
    overflow-y: auto; /* allow scroll if tall */
    padding: 1rem; /* prevent edge touching */
}
.active { display: flex !important; }

.popup-box, .popup {
    background: rgba(30, 41, 59, 0.95);
    padding: 3rem 2rem;
    border-radius: 30px; /* Explicit match */
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    text-align: center;
    width: 90%; max-width: 350px;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    backdrop-filter: blur(10px);
}
@keyframes popIn { from{transform:scale(0.8);opacity:0;} to{transform:scale(1);opacity:1;} }

.popup h3 { color: var(--primary); font-size: 1.8rem; margin-bottom: 0; padding-bottom: 3rem; }
.popup p { color: var(--text-muted); margin-bottom: 1.5rem; line-height: 1.5; }
.rules-list { text-align: left; margin: 0 0 1.5rem 1rem; color: var(--text-muted); font-size: 0.9rem; }
.rules-list li { margin-bottom: 0.5rem; }

u { text-decoration: none; color: var(--accent); font-weight: bold; }

.popup-buttons { display: flex; gap: 1rem; justify-content: center; }
.popup-buttons.column-layout { flex-direction: column; gap: 1rem; width: 100%; }

/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-main); }
::-webkit-scrollbar-thumb { background: var(--bg-surface-2); border-radius: 3px; }

/* --- Responsive Logic --- */


/* Mobile Portrait (Default/Small) */
@media (max-width: 550px) {
    .game-body {
        /* Ensure full height usage but prevent overflow */
        height: 100vh;
        overflow-y: hidden; /* Prevent scrolling if possible */
        justify-content: space-between;
    }
    
    .game-header { 
        padding: 0.5rem 1rem;
        flex-shrink: 0;
    }
    
    .container {
        /* Allow board to shrink if needed */
        flex-shrink: 1;
        display: flex;
        justify-content: center; /* Ensure horizontal center */
        align-items: center;
        width: 100%;
        margin: 0;
        padding: 0; /* Remove padding to maximize width */
    }

    .sudoku-container td {
        /* Smart resizing */
        width: 10.4vw; height: 10.4vw; /* Slightly reduced for safety margins */
        max-width: 44px; max-height: 44px;
        font-size: 1.3rem; 
    }
    
    /* Control Area flex properties */
    .controls-area {
        flex: 0 0 auto; /* Don't stretch infinitely, just take what's needed */
        padding: 0.5rem 1rem 1rem; /* minimal padding */
        gap: 0.5rem;
    }

    .action-bar { margin-bottom: 0.2rem; }
    .action-btn { gap: 2px; }
    .action-btn span { font-size: 0.7rem; }
    
    /* Keypad - Ensure it fits */
    .keypad-row { gap: 0.4rem; }
    .keypad-btn { 
        padding: 0;
        height: 3.5rem; /* Fixed comfortable touch height */
        font-size: 1.5rem;
    }

    /* New Game Button */
    #newGameBtn { 
        margin: 0.5rem 0 0;
        padding: 0.8rem;
    }
}

/* Very Short Screens (e.g. iPhone SE / SE2) */
@media (max-height: 650px) and (max-width: 500px) {
    .game-header { padding: 0.2rem 1rem; }
    .sudoku-container td { width: 9vw; height: 9vw; max-width: 38px; max-height: 38px; font-size: 1.1rem; }
    .keypad-btn { height: 2.8rem; font-size: 1.3rem; }
    .action-btn svg { width: 20px; height: 20px; }
    .controls-area { gap: 0.3rem; }
}

/* Very Small Mobile */
@media (max-width: 360px) {
    .sudoku-container td { font-size: 1.1rem; }
    .keypad-btn { padding: 0.6rem 0; font-size: 1.2rem; }
}

/* Landscape / Tablet / Desktop (e.g. 800x600) */
@media (min-width: 600px) {
    .game-body {
        flex-direction: row;
        align-items: center;
        justify-content: center;
        max-width: 1000px;
        gap: 1.5rem;
        padding: 0 1rem;
    }

    .game-header {
        position: absolute;
        top: 0; left: 0; right: 0;
        width: 100%;
        padding: 1rem 2rem;
        background: transparent;
        pointer-events: none;
    }
    .game-header > * { pointer-events: auto; }

    .container {
        margin: 0;
        justify-content: center;
        padding-top: 2rem; /* Reduced from 5rem */
    }

    .sudoku-container td {
        width: 40px; height: 40px;
        font-size: 1.4rem;
    }

    /* Controls Moves to Side */
    .controls-area {
        max-width: 300px; /* Reduced width */
        min-width: 260px;
        height: auto;
        justify-content: center;
        padding-top: 2rem; /* Match container */
    }
    
    .keypad-row {
        display: grid; /* Crucial Fix */
        grid-template-columns: repeat(3, 1fr); /* 3x3 Grid */
        gap: 0.6rem;
        width: 100%;
    }
    .keypad-btn { aspect-ratio: 1.5; font-size: 1.4rem; }
    
    #newGameBtn { margin-top: 1.5rem; }
    
    /* Ensure Action Bar fits */
    .action-bar { margin-bottom: 1rem; }
    .action-btn { flex: 1; }
}

/* 800x600 Specific Tweaks (Targeting the user's request) */
@media (min-width: 750px) and (min-height: 550px) {
    .sudoku-container td { width: 52px; height: 52px; font-size: 1.8rem; }
}

/* Short Landscape Mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .game-body { flex-direction: row; gap: 1rem; padding: 0.5rem; }
    .game-header { width: auto; flex-direction: column; padding: 0; position: relative; pointer-events: auto; }
    .game-header .game-info { display: none; }
    
    .container { padding-top: 0; }
    .sudoku-container td { width: 34px; height: 34px; font-size: 1.1rem; }
    
    .controls-area { padding-top: 0; gap: 0.5rem; }
    .keypad-row { grid-template-columns: repeat(5, 1fr); } /* 2 rows compact */
    .keypad-btn { padding: 0.3rem 0; font-size: 1.1rem; aspect-ratio: auto; }
    .action-btn { font-size: 0.6rem; }
    .action-btn svg { width: 18px; height: 18px; }
}

/* Optimization for 800x600 / Short Desktop Screens */
@media (min-width: 600px) and (max-height: 720px) {
    .home-box { padding: 1.5rem 2rem !important; }
    .game-title { font-size: 2.5rem !important; margin-bottom: 0.5rem !important; }
    .game-subtitle { margin-bottom: 1.5rem !important; }
    .difficulty-selector { margin-bottom: 1.5rem !important; }
    #startBtn { margin-bottom: 1.5rem !important; }
    
    .popup-box { padding: 1.5rem 2rem !important; }
    .popup h3 { padding-bottom: 1rem !important; margin-bottom: 0.5rem !important; }
}
