  /* ── Dark Grey (default) ── */
  :root {
    --bg:          #0c0c10;
    --surface:     #454341;
    --surface2:    #1a1a24;
    --border:      #a0a0a8;
    --border2:     #ebebf2;
    --text:        #ddd9cc;
    --muted:       #b7b3e3;
    --gold:        #c4a45a;
    --gold-dim:    #8a6e30;
    --blue:        #5b8fc9;
    --red:         #c95b5b;
    --green:       #5bc97a;
    --cell-given:  #c4a45a;
    --cell-user:   #ddd9cc;
    --cell-err:    #c95b5b;
    --sel-bg:      #9f9fa6;
    --peer-bg:     #161620;
    --same-bg:     #1a1a2e;
    --given-bg:    #1f1f2e;
    --grid-border: #ebebf2;
  }

  /* ── Cream theme ── */
  [data-theme="cream"] {
    --bg:          #f5f0e8;
    --surface:     #fdf8f0;
    --surface2:    #ede8de;
    --border:      #d4cbbe;
    --border2:     #b8ad9e;
    --text:        #3a3228;
    --muted:       #8a7d6e;
    --gold:        #8b6914;
    --gold-dim:    #b8922a;
    --blue:        #2e6da4;
    --red:         #b83232;
    --green:       #2e7d46;
    --cell-given:  #7a5c10;
    --cell-user:   #2a4a7a;
    --cell-err:    #b83232;
    --sel-bg:      #f5e0a9;
    --peer-bg:     #f0ebe0;
    --same-bg:     #e4ddd0;
    --given-bg:    #e2d9c4;
    --grid-border: #8b6914;
  }

  /* ── Light Blue theme ── */
  [data-theme="blue"] {
    --bg:          #e8f0f8;
    --surface:     #f2f7fc;
    --surface2:    #dde8f2;
    --border:      #b8cfe0;
    --border2:     #8ab0cc;
    --text:        #1a3248;
    --muted:       #5a7a96;
    --gold:        #1a5c8a;
    --gold-dim:    #2e7ab0;
    --blue:        #1a5c8a;
    --red:         #c04040;
    --green:       #2a7a48;
    --cell-given:  #0e4470;
    --cell-user:   #1a3248;
    --cell-err:    #c04040;
    --sel-bg:      #6fdcf7;
    --peer-bg:     #dceaf5;
    --same-bg:     #d0e4f0;
    --given-bg:    #c2d8ee;
    --grid-border: #2e7ab0;
  }

  /* ── Light Green theme ── */
  [data-theme="green"] {
    --bg:          #e8f2ec;
    --surface:     #f2faf4;
    --surface2:    #daeee0;
    --border:      #b4d4bc;
    --border2:     #88b894;
    --text:        #1a3824;
    --muted:       #527a5c;
    --gold:        #1a6e38;
    --gold-dim:    #2e8a4c;
    --blue:        #1a5c8a;
    --red:         #b83232;
    --green:       #1a6e38;
    --cell-given:  #0e5228;
    --cell-user:   #1a3824;
    --cell-err:    #b83232;
    --sel-bg:      #dfebe2;
    --peer-bg:     #d8eedd;
    --same-bg:     #cce6d2;
    --given-bg:    #bcdec6;
    --grid-border: #2e8a4c;
  }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  html, body {
    background: var(--bg);
    color: var(--text);
    font-family: 'DM Sans', sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 28px 16px 40px;
    gap: 0;
    transition: background 0.25s ease, color 0.25s ease;
  }

  /* ── Header ── */
  header {
    text-align: center;
    margin-bottom: 28px;
  }
  header h1 {
    font-family: 'Cinzel', serif;
    font-weight: 700;
    font-size: clamp(28px, 5vw, 44px);
    letter-spacing: 0.25em;
    color: var(--gold);
    text-transform: uppercase;
    line-height: 1;
  }
  header p {
    font-size: 12px;
    letter-spacing: 0.18em;
    color: var(--muted);
    text-transform: uppercase;
    margin-top: 6px;
  }

  /* ── Difficulty Bar ── */
  .diff-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 22px;
    flex-wrap: wrap;
    justify-content: center;
  }
  .diff-btn {
    font-family: 'DM Sans', sans-serif;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    padding: 7px 16px;
    border-radius: 3px;
    border: 1px solid var(--border2);
    background: var(--surface);
    color: var(--muted);
    cursor: pointer;
    transition: all 0.18s ease;
  }
  .diff-btn:hover { border-color: var(--gold-dim); color: var(--text); }
  .diff-btn.active { border-color: var(--gold); background: var(--surface2); color: var(--gold); }

  /* ── Stats Row ── */
  .stats {
    display: flex;
    gap: 24px;
    margin-bottom: 18px;
    align-items: center;
  }
  .stat { text-align: center; }
  .stat-label { font-size: 10px; letter-spacing: 0.15em; text-transform: uppercase; color: var(--muted); }
  .stat-value { font-family: 'DM Mono', monospace; font-size: 20px; font-weight: 400; color: var(--text); margin-top: 2px; }
  #timer-val { color: var(--gold); }

  /* ── Board Wrapper ── */
  .board-wrap {
    position: relative;
   
  }


  /* ── Grid ── */
  #grid {
  display: grid !important;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  width: 100%;
  aspect-ratio: 1 / 1; /* Forces a perfect 1:1 square ratio at any width */
  margin: 5 auto;
  border: 2px solid var(--grid-border);
  border-radius: 2px;
  overflow: hidden;
  box-sizing: border-box;
}
  .cell {
    display: flex;
    align-items: center;
    justify-content: center;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    font-family: 'DM Mono', monospace;
    font-size: clamp(14px, 3.5vw, 22px);
    font-weight: 400;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
    position: relative;
    user-select: none;
  }
  /* thicker box borders */
  .cell[data-col="2"], .cell[data-col="5"] { border-right: 2px solid var(--border2); }
  .cell[data-row="2"], .cell[data-row="5"] { border-bottom: 2px solid var(--border2); }
  .cell:last-child { border-right: none; }

  /* given vs user */
  .cell.given { color: var(--cell-given); font-weight: 600; cursor: default; background: var(--given-bg); }
  .cell.user-entry { color: var(--cell-user); font-weight: 700; }
  .cell.error { color: var(--cell-err) !important; }

  /* selection states */
  .cell.selected { background: var(--sel-bg); }
 /* .cell.peer     { background: var(--peer-bg); }
  .cell.same-num { background: var(--same-bg); } */

  /* pencil marks */
  .cell.pencil-cell {
    font-size: clamp(5px, 1.1vw, 8px);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    padding: 2px;
    gap: 0;
    align-items: stretch;
    justify-items: stretch;
  }
  .pencil-mark {
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'DM Mono', monospace;
    font-size: clamp(5px, 1.1vw, 8px);
    color: var(--muted);
    line-height: 1;
  }

  /* ── Number Pad ── */
  /* Center the Numpad Container */
.numpad {
  display: flex !important;
  justify-content: center !important;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px; /* Adds clean spacing between buttons */
  margin: 15px auto !important;
  width: 100%;
}

/* Maintain Proper Button Sizes */
.numpad button, 
.numpad .numpad-btn {
  flex: 0 0 auto !important; /* Prevents buttons from squishing */
  min-width: 40px;            /* Set desired button width */
  height: 40px;                /* Set desired button height */
}

/* Center Action Buttons (Pencil, Hint, Check, etc.) */
.controls {
  display: flex !important;
  justify-content: center !important;
  flex-wrap: wrap;
  gap: 10px;
  margin: 15px auto !important;
  width: 100%;
}
  .num-btn {
    font-family: 'DM Mono', monospace;
    font-size: 18px;
    font-weight: 400;
    padding: 10px 0;
    border-radius: 3px;
    border: 1px solid var(--border2);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    transition: all 0.15s ease;
  }
  .num-btn:hover { border-color: var(--gold-dim); background: var(--surface2); }
  .num-btn.erase  { color: var(--muted); font-size: 14px; letter-spacing: 0.05em; }
  .num-btn.pencil-mode { color: var(--blue); border-color: var(--blue); }
  .num-btn.pencil-mode.on { background: var(--surface2); }

/* Active state for Pencil button */
#btn-pencil.active,
button#btn-pencil.active,
.ctrl-btn#btn-pencil.active {
  background-color: var(--accent, #0073aa) !important;
  color: #ffffff !important;
  border-color: var(--accent-dark, #005177) !important;
}

  .ctrl-btn {
    flex: 1;
    min-width: 90px;
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 10px 12px;
    border-radius: 3px;
    border: 1px solid var(--border2);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    transition: all 0.15s ease;
  }
  .ctrl-btn:hover { border-color: var(--gold-dim); background: var(--surface2); }
  .ctrl-btn.primary { border-color: var(--gold); color: var(--gold); }
  .ctrl-btn.primary:hover { background: rgba(196,164,90,0.08); }
  .ctrl-btn:disabled { opacity: 0.3; cursor: default; }

  /* ── Message ── */
  #msg-box {
    margin-top: 18px;
    min-height: 36px;
    text-align: center;
    font-size: 13px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-weight: 500;
  }
  #msg-box.ok  { color: var(--green); }
  #msg-box.err { color: var(--red); }
  #msg-box.info { color: var(--muted); }

  /* ── Theme Selector ── */
  .theme-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    align-items: center;
    justify-content: center;
  }
  .theme-label {
    font-size: 10px;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--muted);
    margin-right: 4px;
  }
  .theme-swatch {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease;
    position: relative;
  }
  .theme-swatch:hover { transform: scale(1.15); }
  .theme-swatch.active { border-color: var(--gold); transform: scale(1.12); }
  .theme-swatch[data-theme="dark"]  { background: #1a1a24; box-shadow: 0 0 0 1px #38384e; }
  .theme-swatch[data-theme="cream"] { background: #f5f0e8; box-shadow: 0 0 0 1px #b8ad9e; }
  .theme-swatch[data-theme="blue"]  { background: #c8dff0; box-shadow: 0 0 0 1px #8ab0cc; }
  .theme-swatch[data-theme="green"] { background: #c4e4cc; box-shadow: 0 0 0 1px #88b894; }

  /* ── Separator decorators ── */
  .ornament {
    font-family: 'Cinzel', serif;
    color: var(--gold-dim);
    font-size: 12px;
    letter-spacing: 0.3em;
    margin: 10px 0;
    text-align: center;
  }

  /* ── Overlay ── */
  #overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10,10,14,0.88);
    align-items: center;
    justify-content: center;
    z-index: 100;
  }
  #overlay.show { display: flex; }
  .overlay-card {
    background: var(--surface2);
    border: 1px solid var(--gold-dim);
    border-radius: 6px;
    padding: 36px 40px;
    text-align: center;
    max-width: 340px;
    animation: fadeIn 0.25s ease;
  }
  @keyframes fadeIn { from { opacity:0; transform:scale(0.95); } to { opacity:1; transform:scale(1); } }
  .overlay-card h2 {
    font-family: 'Cinzel', serif;
    font-weight: 600;
    font-size: 22px;
    color: var(--gold);
    letter-spacing: 0.2em;
    margin-bottom: 10px;
  }
  .overlay-card p { color: var(--muted); font-size: 14px; margin-bottom: 22px; }
  .overlay-card .time { font-family: 'DM Mono', monospace; font-size: 28px; color: var(--text); margin-bottom: 20px; }
  .overlay-close {
    font-family: 'Cinzel', serif;
    font-size: 13px;
    letter-spacing: 0.15em;
    padding: 10px 28px;
    border: 1px solid var(--gold);
    background: transparent;
    color: var(--gold);
    border-radius: 3px;
    cursor: pointer;
  }
  .overlay-close:hover { background: rgba(196,164,90,0.1); }