:root {
  --cell: 30px;
  --rowclue: 66px;
  --colclue: 66px;
  --clue-font: 13px;

  --bg: #ffffff;
  --ink: #33404f;          /* filled cells / dark text */
  --title: #263140;
  --blue: #2f78ee;         /* accent: icons, primary buttons */
  --page-bg: linear-gradient(180deg, #ffffff 0%, #eef3fb 100%);
  --line: #d9dee6;         /* thin gridlines */
  --line-strong: #1e2a38;  /* 5-block dividers + frame */
  --clue-bg: #eaeef7;      /* clue pill background */
  --clue-ink: #33404f;
  --clue-done: #b7c0cd;
  --cross: #465264;        /* X mark */
  --hl: rgba(47, 120, 238, 0.10);
  --heart: #f5333f;
  --heart-lost: #d9dee6;
  --panel: #eef1f6;
}

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

html, body {
  margin: 0;
  min-height: 100%;
  /* Same full-screen backdrop as the menu, so the menu and game screens match. */
  background: var(--page-bg);
  background-attachment: fixed;
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

/* --- Main menu page --- */
.menu-page {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--page-bg);
}
.menu-page.hidden { display: none; }
#appPage.hidden { display: none; }
.menu-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.hero-svg { width: 220px; height: auto; filter: drop-shadow(0 10px 18px rgba(47, 120, 238, 0.18)); }
.brand {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: var(--blue);
  margin: 10px 0 22px;
}
.btn.big-blue {
  width: 100%;
  font-size: 18px;
  font-weight: 800;
  padding: 18px;
  border-radius: 14px;
  background: var(--blue);
  border: 0;
  color: #fff;
  box-shadow: 0 8px 20px rgba(47, 120, 238, 0.35);
}
.btn.big-blue:hover { background: #2565d6; }
.btn.ghost {
  width: 100%;
  background: transparent;
  border: 0;
  color: #7c8695;
  font-weight: 600;
  margin-top: 8px;
}
.btn.ghost:hover { background: #eef2f8; }

/* Full-screen like the menu: transparent over the page gradient, with the header
   spanning the whole width so back/burger sit at the true screen corners. The
   board, lives and toolbar center themselves within it. */
.app {
  min-height: 100vh;
  min-height: 100dvh; /* dvh tracks the visible viewport so mobile browser chrome
                         does not cut off the bottom toolbar (e.g. Firefox) */
  display: flex;
  flex-direction: column;
  padding: 8px 14px calc(16px + env(safe-area-inset-bottom, 0px));
}

/* --- Header --- */
.topbar {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  padding: 6px 2px 10px;
}
.titlewrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
}
.title {
  margin: 0;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  color: var(--title);
}
.timer {
  font-size: 14px;
  font-weight: 600;
  color: #9aa4b0;
  margin-top: 2px;
  letter-spacing: 0.3px;
  font-variant-numeric: tabular-nums;
}
.icon-btn {
  width: 40px;
  height: 40px;
  border: 0;
  background: transparent;
  color: var(--blue);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
}
.icon-btn:hover { background: #f0f3f8; }
.icon-btn svg { width: 26px; height: 26px; }

/* --- Lives --- */
.lives {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 4px 0 14px;
}
.lives svg { width: 30px; height: 30px; }
.heart-full { color: var(--heart); }
.heart-lost { color: var(--heart-lost); }

/* --- Board --- */
.stage {
  display: flex;
  justify-content: center;
  flex: 1;
}
.board {
  display: grid;
  grid-template-columns: var(--rowclue) repeat(var(--cols), var(--cell));
  grid-template-rows: var(--colclue) repeat(var(--rows), var(--cell));
  /* pinch-zoom lets two fingers zoom the board (solvable on small screens),
     while single-finger drags still reach our paint handlers. */
  touch-action: pinch-zoom;
  align-content: start;
}
.board.hint-arming .cell { cursor: help; }
.corner { grid-row: 1; grid-column: 1; }

/* Clue pills. */
.colclue {
  grid-row: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 1px;
  margin: 0 1px;
  padding-bottom: 4px;
  border-radius: 7px 7px 0 0;
  background: var(--clue-bg);
  color: var(--clue-ink);
  font-size: var(--clue-font);
  font-weight: 700;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}
.rowclue {
  grid-column: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  margin: 1px 4px 1px 0;
  padding: 0 8px;
  border-radius: 7px;
  background: var(--clue-bg);
  color: var(--clue-ink);
  font-size: var(--clue-font);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.colclue.done, .rowclue.done { color: var(--clue-done); }

/* Cells. Borders sit inside a fixed-size track (border-box), so thicker
   separators never shift alignment. */
.cell {
  position: relative;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
}
.cell[data-r="0"] { border-top: 3px solid var(--line-strong); }
.cell[data-c="0"] { border-left: 3px solid var(--line-strong); }
.cell.sep-r { border-right: 2px solid var(--line-strong); }
.cell.sep-b { border-bottom: 2px solid var(--line-strong); }
.cell.last-c { border-right: 3px solid var(--line-strong); }
.cell.last-r { border-bottom: 3px solid var(--line-strong); }

.cell.filled { background: var(--ink); }

/* Cross drawn as two bars -- no font glyph needed. */
.cell.crossed::before,
.cell.crossed::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 16%;
  width: 2px;
  height: 68%;
  margin-left: -1px;
  background: var(--cross);
  border-radius: 1px;
}
.cell.crossed::before { transform: rotate(45deg); }
.cell.crossed::after { transform: rotate(-45deg); }

.cell.mistake::before,
.cell.mistake::after { background: #e74c3c; }
.cell.mistake { animation: flash 0.45s ease-out; }
@keyframes flash {
  0% { background: #ffd7d2; }
  100% { background: #fff; }
}

.cell.hintpop { animation: pop 0.4s ease-out; }
@keyframes pop {
  0% { transform: scale(0.4); }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* Hide crosses once solved so only the picture remains. */
.board.solved .cell.crossed::before,
.board.solved .cell.crossed::after { display: none; }

/* --- Bottom toolbar --- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 26px;
  padding: 22px 0 6px;
}
.toolbar.hidden, .endbar.hidden { display: none; }

/* --- End-of-game bar (condensed result + actions, replaces the toolbar) --- */
.endbar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 8px 6px;
  text-align: center;
}
.endbar-emoji { font-size: 30px; line-height: 1; }
.endbar-title { font-size: 20px; font-weight: 800; color: var(--title); }
.endbar-lines {
  color: #7c8695;
  font-weight: 600;
  font-size: 13px;
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
}
.endbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
}
.endbar-actions .btn { padding: 9px 14px; font-size: 14px; }
.tool-toggle {
  position: relative;
  display: inline-flex;
  background: var(--panel);
  border-radius: 999px;
  padding: 5px;
  gap: 4px;
}
/* Sliding white "thumb" that animates between the two options. */
.tool-toggle::before {
  content: "";
  position: absolute;
  top: 5px;
  left: 5px;
  width: 62px;
  height: 46px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 2px 6px rgba(30, 42, 56, 0.18);
  transition: transform 0.2s cubic-bezier(0.34, 1.3, 0.5, 1);
}
.tool-toggle[data-tool="cross"]::before { transform: translateX(0); }
.tool-toggle[data-tool="fill"]::before { transform: translateX(66px); }
.tool-opt {
  position: relative;
  z-index: 1;
  width: 62px;
  height: 46px;
  border: 0;
  background: transparent;
  border-radius: 999px;
  color: #7c8695;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease;
}
.tool-opt svg { width: 24px; height: 24px; transition: transform 0.2s ease; }
.tool-opt.active { color: var(--ink); }
.tool-opt.active svg { animation: toolpop 0.25s ease; }
@keyframes toolpop {
  0% { transform: scale(0.7); }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.hint-btn {
  position: relative;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 999px;
  background: var(--panel);
  color: var(--blue);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.hint-btn svg { width: 28px; height: 28px; }
.hint-btn:disabled { color: #b7c0cd; cursor: default; }
/* Armed hint mode: highlight the button and gently pulse it. */
.hint-btn.armed { background: var(--blue); color: #fff; animation: hintpulse 1.1s ease-in-out infinite; }
.hint-btn.armed .hint-badge { background: #fff; color: var(--blue); }
@keyframes hintpulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(47, 120, 238, 0.45); }
  50% { box-shadow: 0 0 0 7px rgba(47, 120, 238, 0); }
}
.hint-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--blue);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.hint-btn:disabled .hint-badge { background: #b7c0cd; }

/* --- Sheets / overlays --- */
.sheet {
  position: fixed;
  inset: 0;
  background: rgba(20, 28, 40, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 16px;
}
.sheet.hidden { display: none; }
.sheet-card {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  padding: 18px 20px 22px;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.sheet-head h2 { margin: 0; font-size: 20px; color: var(--title); }
.close-btn {
  width: 34px; height: 34px; border: 0; background: transparent;
  color: #7c8695; cursor: pointer; border-radius: 8px;
}
.close-btn svg { width: 22px; height: 22px; }

.picker-card { max-width: 440px; }
.picker-body { max-height: 70vh; overflow-y: auto; }
.picker-group-title {
  font-size: 13px; font-weight: 700; color: #7c8695;
  text-transform: uppercase; letter-spacing: 0.5px;
  margin: 14px 2px 8px;
}
.picker-group-title:first-child { margin-top: 2px; }
.picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
  gap: 10px 8px;
}
.picker-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border: 1px solid #dbe1ea;
  background: #f6f8fb;
  border-radius: 10px;
  min-height: 48px;
  padding: 4px 2px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
}
.picker-cell .pc-num { font-size: 15px; line-height: 1; }
.picker-cell .pc-time {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 10px;
  font-weight: 600;
  color: #7c8695;
  line-height: 1;
}
.picker-cell .pc-time svg { width: 10px; height: 10px; color: #e0a92a; }
.picker-cell:hover { background: #eef2f8; }
.picker-cell.solved { background: #eefaf1; border-color: #bfe6cd; }
.picker-cell.current { background: var(--blue); border-color: var(--blue); color: #fff; }
.picker-cell.current .pc-time { color: #d9e6ff; }
.picker-cell.current .pc-time svg { color: #ffe08a; }
.pc-check {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #2fbf6b;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
.pc-check svg { width: 12px; height: 12px; }

.menu-danger { color: #c0392b; }

.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: #f6f8fb;
  border-radius: 10px;
  padding: 14px 16px;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  margin-bottom: 8px;
}
.menu-item:hover { background: #eef2f8; }
.menu-help { margin-top: 8px; color: #63707f; font-size: 13px; line-height: 1.5; }
.menu-help p { margin: 6px 0 0; }

.result-card { position: relative; text-align: center; max-width: 340px; }
.card-close { position: absolute; top: 6px; right: 6px; }
.result-emoji { font-size: 46px; }
.result-card h2 { margin: 6px 0 2px; font-size: 26px; color: var(--title); }
.result-name { margin: 0 0 2px; color: #7c8695; font-weight: 600; }
.result-stats { margin: 0 0 18px; color: #9aa4b0; font-weight: 600; font-size: 14px; font-variant-numeric: tabular-nums; }
/* Completed (review) modal: both lines share one size. */
.result-line { margin: 0 0 3px; color: #7c8695; font-weight: 600; font-size: 15px; font-variant-numeric: tabular-nums; }
.result-line-last { margin-bottom: 18px; }
.result-actions { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }
.result-share {
  margin-top: 10px;
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.result-share svg { width: 18px; height: 18px; }

.btn {
  font-size: 15px;
  padding: 11px 16px;
  border: 1px solid #cfd6df;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: #f2f5f9; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: #2565d6; }
