/* Logic: clean puzzle paper, soft region colours. */

:root {
  --ink: #1d1b16;
  --line: rgba(30, 27, 22, 0.14);
  --wall: #2b2822;
  --r0: #f6d7c3;
  --r1: #d7ead0;
  --r2: #cfe0f2;
  --r3: #f1e3b0;
  --r4: #e4d4ef;
  --r5: #cdebe6;
  --r6: #f3cfd8;
  --r7: #e1e5c4;
  --r8: #d9d6f0;
  --r9: #f0dcc7;
  --star: #c98700;
  --bad: #d23c2e;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --ink: #eceae4;
    --line: rgba(255, 255, 255, 0.08);
    --wall: #0b0c0e;
    --r0: #4d3a2f;
    --r1: #33452f;
    --r2: #2f3e50;
    --r3: #4a4326;
    --r4: #43354f;
    --r5: #2b4744;
    --r6: #4d2f38;
    --r7: #404427;
    --r8: #37354f;
    --r9: #4b3a2a;
    --star: #ffcf3d;
    --bad: #ff6b5e;
  }
}
:root[data-theme='dark'] {
  --ink: #eceae4;
  --line: rgba(255, 255, 255, 0.08);
  --wall: #0b0c0e;
  --r0: #4d3a2f;
  --r1: #33452f;
  --r2: #2f3e50;
  --r3: #4a4326;
  --r4: #43354f;
  --r5: #2b4744;
  --r6: #4d2f38;
  --r7: #404427;
  --r8: #37354f;
  --r9: #4b3a2a;
  --star: #ffcf3d;
  --bad: #ff6b5e;
}
:root[data-theme='hallows'] {
  --ink: #f4e8cc;
  --line: rgba(232, 176, 74, 0.1);
  --wall: #0d0818;
  --r0: #3a2a4f;
  --r1: #2c2a48;
  --r2: #34284a;
  --r3: #3f2f3f;
  --r4: #2a2f4a;
  --r5: #3a2f52;
  --r6: #442a45;
  --r7: #30304a;
  --r8: #3c3150;
  --r9: #332a40;
  --star: #ffc27a;
  --bad: #ff7a5c;
}
:root[data-theme='hallows'] .hw-candle {
  display: none;
}
:root[data-theme='hallows'] .title-main {
  font-family: var(--font-display);
  letter-spacing: 0;
}
body {
  min-height: var(--app-height);
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}
#announce {
  margin: 0;
  top: 0;
}
.app {
  display: flex;
  flex-direction: column;
  height: calc(var(--app-height) - var(--safe-top) - var(--safe-bottom));
  min-height: 520px;
  max-width: 520px;
  margin: 0 auto;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px 6px;
}
.title-btn {
  appearance: none;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 12px;
  color: var(--text);
  min-width: 0;
}
.title-btn:hover {
  background: var(--accent-soft);
}
.title-main {
  display: block;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.title-main::after {
  content: ' ▾';
  font-size: 0.7em;
  color: var(--text-muted);
}
.title-sub {
  display: block;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
}
.score {
  display: flex;
  gap: 8px;
}
.chip {
  min-width: 64px;
  text-align: center;
  padding: 6px 12px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.chip small {
  display: block;
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.chip b {
  display: block;
  font-size: 1.3rem;
  font-variant-numeric: tabular-nums;
}

.stage {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 8px 14px;
  container-type: size;
}
.board-wrap {
  margin: auto;
  width: min(100cqw, 100cqh, 600px);
}

/* ---------- Star Battle ---------- */

.sb-grid {
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  aspect-ratio: 1;
  border: 3px solid var(--wall);
  border-radius: 8px;
  overflow: hidden;
  background: var(--wall);
}
.sb-cell {
  position: relative;
  appearance: none;
  border: 0;
  padding: 0;
  background: var(--rc);
  box-shadow: inset -1px -1px 0 var(--line);
  cursor: pointer;
  color: var(--ink);
}
.reg0 { --rc: var(--r0); }
.reg1 { --rc: var(--r1); }
.reg2 { --rc: var(--r2); }
.reg3 { --rc: var(--r3); }
.reg4 { --rc: var(--r4); }
.reg5 { --rc: var(--r5); }
.reg6 { --rc: var(--r6); }
.reg7 { --rc: var(--r7); }
.reg8 { --rc: var(--r8); }
.reg9 { --rc: var(--r9); }
/* Region walls: thick lines where the region changes. */
.sb-cell.et { border-top: 2.5px solid var(--wall); }
.sb-cell.eb { border-bottom: 2.5px solid var(--wall); }
.sb-cell.el { border-left: 2.5px solid var(--wall); }
.sb-cell.er { border-right: 2.5px solid var(--wall); }
.sb-cell::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
}
.sb-cell.star::after {
  width: 64%;
  height: 64%;
  background: var(--star);
  clip-path: polygon(50% 2%, 62% 36%, 98% 37%, 69% 59%, 80% 95%, 50% 74%, 20% 95%, 31% 59%, 2% 37%, 38% 36%);
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.3));
  animation: pop 0.2s ease;
}
.sb-cell.dot::after,
.sb-cell.auto::after {
  width: 18%;
  height: 18%;
  border-radius: 50%;
  background: var(--ink);
  opacity: 0.55;
}
.sb-cell.auto::after {
  opacity: 0.2;
}
.sb-cell.bad.star::after {
  background: var(--bad);
}
.sb-cell:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
  z-index: 1;
}
.sb-grid.solved .sb-cell.star::after {
  animation: glow 1s ease 2;
}
@keyframes pop {
  from {
    transform: scale(0.4);
  }
}
@keyframes glow {
  50% {
    transform: scale(1.25) rotate(20deg);
  }
}
@media (prefers-reduced-motion: reduce) {
  .sb-cell.star::after,
  .sb-grid.solved .sb-cell.star::after {
    animation: none;
  }
}

/* ---------- Calcudoku ---------- */

.board-wrap.calc {
  width: min(100cqw, 100cqh - 120px, 560px);
}
.cc-grid {
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  aspect-ratio: 1;
  border: 3px solid var(--wall);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}
.cc-cell {
  position: relative;
  appearance: none;
  border: 0;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: inset -1px -1px 0 var(--line);
  cursor: pointer;
  font: inherit;
  container-type: inline-size;
}
.cc-cell.et { border-top: 2.5px solid var(--wall); }
.cc-cell.eb { border-bottom: 2.5px solid var(--wall); }
.cc-cell.el { border-left: 2.5px solid var(--wall); }
.cc-cell.er { border-right: 2.5px solid var(--wall); }
.cc-cell.line {
  background: color-mix(in srgb, var(--accent-soft) 45%, var(--surface));
}
.cc-cell.sel {
  background: color-mix(in srgb, var(--star) 35%, var(--surface));
}
.cc-cell .cage {
  position: absolute;
  top: 3px;
  left: 4px;
  font-size: max(9px, 17cqi);
  font-weight: 700;
  line-height: 1;
  color: var(--text-muted);
}
.cc-cell b {
  font-size: 48cqi;
  font-weight: 800;
}
.cc-cell.bad b {
  color: var(--bad);
}
.cc-cell .notes {
  position: absolute;
  inset: 30% 6% 6%;
  font-size: max(8px, 15cqi);
  line-height: 1.15;
  color: var(--text-muted);
  text-align: center;
  word-spacing: 2px;
}
.cc-grid.solved .cc-cell b {
  animation: pop 0.4s ease;
}
.pad {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin: 12px auto 0;
  width: min(100%, 520px);
}
.pad-key {
  appearance: none;
  flex: 1 1 0;
  min-width: 44px;
  min-height: 48px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1.3rem;
  font-weight: 800;
  cursor: pointer;
}
.pad-key.wide {
  flex: 1 1 40%;
  min-height: 42px;
  font-size: 0.95rem;
}
.pad-key.on {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: transparent;
}
.pad-key:active {
  transform: scale(0.96);
}

/* ---------- Number grids (Futoshiki, Skyscrapers) ---------- */

.board-wrap.futoshiki,
.board-wrap.skyscrapers {
  width: min(100cqw, 100cqh - 120px, 540px);
}
.ng-grid {
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(0, 1fr));
  grid-template-rows: repeat(var(--n), minmax(0, 1fr));
  aspect-ratio: 1;
}
.ng-cell {
  position: relative;
  appearance: none;
  border: 0;
  padding: 0;
  background: var(--surface);
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  container-type: inline-size;
}
.ng-cell.given {
  color: var(--ink);
  cursor: default;
}
.ng-cell.line {
  background: color-mix(in srgb, var(--accent-soft) 45%, var(--surface));
}
.ng-cell.sel {
  background: color-mix(in srgb, var(--star) 35%, var(--surface));
}
.ng-cell b {
  font-size: 50cqi;
  font-weight: 800;
}
.ng-cell.bad b {
  color: var(--bad);
}
.ng-cell .notes {
  position: absolute;
  inset: 8%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: max(8px, 17cqi);
  line-height: 1.15;
  color: var(--text-muted);
  text-align: center;
  word-spacing: 2px;
}
.ng-grid.solved .ng-cell b {
  animation: pop 0.4s ease;
}
/* Futoshiki: squares with gaps for the signs. */
.ng-grid.futoshiki {
  --gap: min(4.5cqw, 26px);
  gap: var(--gap);
  padding: 4px;
}
.futoshiki .ng-cell {
  border-radius: 10px;
  border: 2px solid var(--wall);
  overflow: visible;
}
.futoshiki .sign {
  position: absolute;
  font-style: normal;
  font-weight: 800;
  font-size: max(16px, 42cqi);
  line-height: 1;
  color: var(--ink);
  opacity: 0.75;
  pointer-events: none;
}
.futoshiki .sign-r {
  top: 50%;
  right: calc(var(--gap) / -2 - 2px);
  transform: translate(50%, -50%);
}
.futoshiki .sign-b {
  left: 50%;
  bottom: calc(var(--gap) / -2 - 2px);
  transform: translate(-50%, 50%);
}
.futoshiki .sign.bad {
  color: var(--bad);
  opacity: 1;
}
/* Skyscrapers: clues around a boxed grid. */
.sky-frame {
  display: grid;
  grid-template-columns: 2.2em minmax(0, 1fr) 2.2em;
  grid-template-rows: 2.2em auto 2.2em;
}
.sky-row {
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
}
.sky-col {
  display: grid;
  grid-template-rows: repeat(var(--n), 1fr);
}
.sky-clue {
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: clamp(0.9rem, 4.5cqw, 1.5rem);
  color: var(--text-muted);
}
.sky-clue.bad {
  color: var(--bad);
}
.ng-grid.skyscrapers {
  border: 3px solid var(--wall);
  border-radius: 8px;
  overflow: hidden;
}
.skyscrapers .ng-cell {
  box-shadow: inset -1px -1px 0 var(--line);
}

/* ---------- Light Up ---------- */

.lu-grid {
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(0, 1fr));
  grid-template-rows: repeat(var(--n), minmax(0, 1fr));
  aspect-ratio: 1;
  border: 3px solid var(--wall);
  border-radius: 8px;
  overflow: hidden;
  background: var(--wall);
  gap: 1px;
}
.lu-cell {
  position: relative;
  appearance: none;
  border: 0;
  padding: 0;
  font: inherit;
  display: grid;
  place-items: center;
  container-type: inline-size;
}
.lu-cell.white {
  background: var(--surface);
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.lu-cell.white.lit {
  background: color-mix(in srgb, var(--star) 28%, var(--surface));
}
.lu-cell.black {
  background: var(--wall);
  color: #fff;
}
.lu-cell.black b {
  font-size: 50cqi;
  font-weight: 800;
}
.lu-cell.black.met b {
  opacity: 0.45;
}
.lu-cell.black.bad b {
  color: var(--bad);
}
.lu-cell.bulb::after {
  content: '';
  width: 56%;
  height: 56%;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 35%, #fffbe0, var(--star) 60%, color-mix(in srgb, var(--star) 70%, #000));
  box-shadow: 0 0 12px color-mix(in srgb, var(--star) 70%, transparent);
  animation: pop 0.2s ease;
}
.lu-cell.bulb.bad::after {
  background: var(--bad);
  box-shadow: none;
}
.lu-cell.dot::after {
  content: '';
  width: 16%;
  height: 16%;
  border-radius: 50%;
  background: var(--text-muted);
}
.lu-cell:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

/* ---------- Tents ---------- */

.board-wrap.tents {
  width: min(100cqw, 100cqh - 30px, 600px);
}
.sky-frame.tents {
  grid-template-columns: 2.2em minmax(0, 1fr);
  grid-template-rows: 2.2em auto;
}
.sky-clue.met {
  opacity: 0.4;
}
.tt-grid {
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(0, 1fr));
  grid-template-rows: repeat(var(--n), minmax(0, 1fr));
  aspect-ratio: 1;
  border: 3px solid var(--wall);
  border-radius: 8px;
  overflow: hidden;
  background: color-mix(in srgb, #7cc26b 16%, var(--surface));
}
.tt-cell {
  position: relative;
  appearance: none;
  border: 0;
  padding: 0;
  background: transparent;
  box-shadow: inset -1px -1px 0 var(--line);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.tt-cell.tree {
  cursor: default;
}
.tt-cell.tree::after {
  content: '';
  width: 70%;
  height: 76%;
  background:
    linear-gradient(#7a5230, #7a5230) 50% 100% / 14% 28% no-repeat,
    radial-gradient(circle at 50% 38%, #3f9b4a 0 58%, transparent 60%);
  border-radius: 4px;
}
.tt-cell.tent::after {
  content: '';
  width: 64%;
  height: 56%;
  background: linear-gradient(to right, #e3853a 50%, #c96a26 50%);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  animation: pop 0.2s ease;
}
.tt-cell.tent.bad::after {
  background: var(--bad);
}
.tt-cell.grass {
  background: color-mix(in srgb, #7cc26b 40%, var(--surface));
}
.tt-cell.grass::after {
  content: '';
  width: 14%;
  height: 14%;
  border-radius: 50%;
  background: #3f8f3a;
  opacity: 0.6;
}
.tt-cell:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}
@media (prefers-reduced-motion: reduce) {
  .lu-cell.bulb::after,
  .tt-cell.tent::after {
    animation: none;
  }
}

/* ---------- Kakuro ---------- */

.board-wrap.kakuro {
  width: min(100cqw, 100cqh - 120px, 560px);
}
.ng-grid.kakuro {
  border: 3px solid var(--wall);
  border-radius: 8px;
  overflow: hidden;
  gap: 1px;
  background: var(--wall);
}
.kakuro .ng-cell {
  box-shadow: none;
}
.ng-block {
  position: relative;
  background: color-mix(in srgb, var(--wall) 88%, var(--surface));
  container-type: inline-size;
}
.ng-block.clue {
  background:
    linear-gradient(to top right, transparent calc(50% - 0.8px), rgba(255, 255, 255, 0.35) 50%, transparent calc(50% + 0.8px)),
    color-mix(in srgb, var(--wall) 88%, var(--surface));
}
.kk-sum {
  position: absolute;
  font-weight: 800;
  font-size: max(9px, 30cqi);
  line-height: 1;
  color: #fff;
}
.kk-sum.across {
  top: 8%;
  right: 10%;
}
.kk-sum.down {
  bottom: 8%;
  left: 10%;
}
.kk-sum.bad {
  color: var(--bad);
}

/* ---------- Bridges ---------- */

.board-wrap.bridges {
  width: min(100cqw, 100cqh, 620px);
}
.br-board {
  display: block;
  width: 100%;
  height: auto;
  max-height: 100cqh;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.br-sea {
  fill: color-mix(in srgb, var(--r2) 55%, var(--surface));
}
.br-dots circle {
  fill: var(--line);
}
.br-bridge line {
  stroke: var(--wall);
  stroke-width: 0.09;
  stroke-linecap: round;
}
.br-hit {
  stroke: transparent;
  stroke-width: 0.5;
  cursor: pointer;
}
.br-island {
  cursor: pointer;
  outline: none;
}
.br-island circle {
  fill: var(--surface);
  stroke: var(--wall);
  stroke-width: 0.07;
  transition: fill 0.2s ease;
}
.br-island text {
  font-size: 0.46px;
  font-weight: 800;
  fill: var(--ink);
  pointer-events: none;
}
.br-island.full circle {
  fill: color-mix(in srgb, var(--accent) 30%, var(--surface));
}
.br-island.over circle {
  fill: color-mix(in srgb, var(--bad) 30%, var(--surface));
  stroke: var(--bad);
}
.br-island.sel circle,
.br-island:focus-visible circle {
  stroke: var(--accent);
  stroke-width: 0.12;
}
.br-board.solved .br-island circle {
  fill: color-mix(in srgb, var(--star) 45%, var(--surface));
}

/* ---------- Menus ---------- */

.mode-block {
  display: grid;
  gap: 6px;
}
.size-row {
  display: flex;
  gap: 6px;
}
.size-row .btn {
  flex: 1;
  min-height: 38px;
  padding: 0.4em 0.6em;
  font-size: 0.88rem;
}
.results .stamp {
  opacity: 1;
  transform: none;
}
/* ---------- Toolbar and menus ---------- */

.toolbar {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 6px 8px 10px;
}
.tool {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 64px;
  min-height: 50px;
  padding: 6px 8px;
  border-radius: 14px;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
}
.tool:hover:not(:disabled) {
  background: var(--accent-soft);
}
.tool:disabled {
  opacity: 0.38;
}
.menu-list {
  display: grid;
  gap: 10px;
}
.menu-card {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}
.menu-card .menu-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
}
.menu-card b {
  display: block;
  font-size: 1.05rem;
}
.menu-card small {
  color: var(--text-muted);
}
.menu-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.menu-row .btn {
  flex: 1;
}
@media (prefers-reduced-motion: reduce) {
  .row.reveal .pegs .peg {
    animation: none;
  }
}
