/* GummiGrid. Moonlit navy, muted region colors, green gummies. Dark is the default. */
:root {
  --bg: #14131f; --surface: #1f1e2e; --surface2: #2a2940; --ink: #e3e1ec; --muted: #8e8ba3;
  --x: #cfcde0; --grid: #0c0b14; --edge: rgba(232, 228, 244, .45); --gum: #6fd46a; --accent: #8fe07f;
  --gap: 2px;
  color-scheme: dark;
}
:root[data-mode="light"] {
  --bg: #f2f1ed; --surface: #e6e4de; --surface2: #d9d6ce; --ink: #2b2a33; --muted: #6f6d78;
  --x: #3d3c47; --grid: #c9c7bf; --edge: #55534d; --gum: #3fae4a; --accent: #2f8a3a;
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.4 Nunito, system-ui, sans-serif; overflow: hidden;
  touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:focus { outline: none; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#game { height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; grid-template-columns: 1fr;
  grid-template-areas: "top" "play" "tools";
  padding: max(8px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)); position: relative; }
#top { grid-area: top; display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 46px; }
.iconbtn { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); flex: none; }
.iconbtn:active { background: var(--surface); }
#tray { display: flex; gap: 5px; justify-content: center; flex-wrap: nowrap; min-width: 0; }
#tray svg { width: 20px; height: 20px; flex: none; transition: opacity .2s; }
#tray svg.off { opacity: .22; filter: grayscale(1); }

#play { grid-area: play; display: grid; place-items: center; min-height: 0; padding: 6px 0; }
#board { width: var(--size, 300px); height: var(--size, 300px); display: grid; gap: var(--gap); padding: var(--gap);
  background: var(--grid); border-radius: 10px; touch-action: none; }
.cell { position: relative; border-radius: 3px; display: grid; place-items: center; cursor: pointer; }
.cell svg { pointer-events: none; }
.cell .x { width: 40%; height: 40%; color: var(--x); }
.cell.auto .x { opacity: .38; }
.cell .gum { width: 80%; height: 80%; animation: pop .16s ease-out; }
.cell.hinted::after { content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: 0 0 0 3px var(--accent), 0 0 18px var(--accent); animation: fade 1.6s ease-out forwards; pointer-events: none; }
@keyframes pop { from { transform: scale(.55); opacity: .2 } to { transform: scale(1); opacity: 1 } }
@keyframes fade { 0%, 50% { opacity: 1 } 100% { opacity: 0 } }
#game.solved .cell .gum { animation: hop .5s ease-out both; animation-delay: calc(var(--i) * 60ms); }
@keyframes hop { 0% { transform: translateY(0) } 40% { transform: translateY(-14%) scale(1.06) } 100% { transform: translateY(0) } }

#tools { grid-area: tools; }
#tools .row { display: flex; gap: 8px; }
.tool { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px; border-radius: 14px;
  background: var(--surface); color: var(--ink); font-size: 12.5px; font-weight: 700; }
.tool svg { width: 22px; height: 22px; color: var(--muted); }
.tool:active { background: var(--surface2); }
#doneRow { display: none !important; align-items: center; }
#doneMsg { flex: 1; text-align: center; font-weight: 800; font-size: 18px; color: var(--accent); }
.tool.go { flex: 1.3; padding: 14px 0; background: var(--gum); color: #10230f; font-size: 15px; }
:root[data-mode="light"] .tool.go { color: #fff; }
#game.solved #toolRow { display: none; }
#game.solved #doneRow { display: flex !important; }

#note { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(max(12px, env(safe-area-inset-bottom)) + 72px);
  width: min(92%, 380px); text-align: center; padding: 10px 14px; border-radius: 14px; background: var(--surface2); color: var(--ink);
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; }
#note.show { opacity: 1; }

/* Wide screens (the Fold open sideways, a computer): tools go beside the board. */
@media (min-aspect-ratio: 5/4) and (min-width: 600px) {
  #game { grid-template-rows: auto 1fr; grid-template-columns: 1fr auto; grid-template-areas: "top top" "play tools"; column-gap: 16px; }
  #tools { display: flex; align-items: center; }
  #tools .row { flex-direction: column; width: 108px; }
  .tool { flex: none; padding: 12px 0; }
  #doneRow { gap: 12px; }
  #note { bottom: 24px; }
}

/* Settings and other sheets */
#overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: end center; z-index: 10; }
#overlay[hidden] { display: none; }
.sheet { width: min(100%, 460px); max-height: 92dvh; overflow: auto; background: var(--bg); border-radius: 22px 22px 0 0;
  padding: 20px 20px max(22px, env(safe-area-inset-bottom)); box-shadow: 0 -10px 40px rgba(0,0,0,.35); }
@media (min-width: 600px) { #overlay { place-items: center; } .sheet { border-radius: 22px; } }
.sheet h2 { margin: 0 0 4px; font-size: 20px; font-weight: 800; }
.sheet h3 { margin: 18px 0 8px; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.sheet p { margin: 6px 0; }
.sheet ul { margin: 6px 0; padding-left: 20px; }
.sheet li { margin: 4px 0; }
.seg { display: flex; background: var(--surface); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; padding: 9px 4px; border-radius: 9px; font-weight: 700; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--surface2); color: var(--ink); }
.hint-text { font-size: 13px; color: var(--muted); margin-top: 6px; }
.sheet .actions { display: flex; gap: 8px; margin-top: 20px; }
.sheet .actions button { flex: 1; padding: 12px; border-radius: 14px; background: var(--surface); font-weight: 700; }
.sheet .actions button.go { background: var(--gum); color: #10230f; }
:root[data-mode="light"] .sheet .actions button.go { color: #fff; }
.ver { color: var(--muted); font-size: 12px; font-weight: 400; margin-left: 6px; }
.demo { display: flex; gap: 10px; align-items: center; margin: 6px 0; }
.demo svg { width: 26px; height: 26px; flex: none; }
