/* Puzzle app shell — mobile-first, portrait, safe areas, light/dark via [data-theme]. */

:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #20242d;
  --text: #eef1f6;
  --text-dim: #99a1b3;
  --accent: #6c8cff;
  --good: #35c07a;
  --bad: #ef5f6b;
  --line: #2b3040;
  --radius: 16px;
  --tap: 44px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

:root[data-theme="light"] {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #e9ecf2;
  --text: #14161c;
  --text-dim: #5d6474;
  --accent: #3a5bd9;
  --good: #17945a;
  --bad: #d43b48;
  --line: #d8dce5;
}

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

/* the shell toggles views with the [hidden] attribute; display rules below would otherwise win */
[hidden] { display: none !important; }


html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-t) + 8px) calc(var(--safe-r) + 14px) calc(var(--safe-b) + 8px) calc(var(--safe-l) + 14px);
}

/* ---------- home ---------- */

.home { display: flex; flex-direction: column; height: 100%; gap: 14px; }
.home-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding-top: 6px; }
.home-head h1 { margin: 0; font-size: 28px; letter-spacing: -0.4px; }
.sub { margin: 2px 0 0; color: var(--text-dim); font-size: 14px; }
.head-tools { display: flex; gap: 8px; }

.cards { display: flex; flex-direction: column; gap: 12px; overflow-y: auto; padding-bottom: 6px; }

.card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 96px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.card:active { background: var(--surface-2); transform: scale(0.995); }
.card .glyph {
  flex: 0 0 56px; height: 56px; border-radius: 14px;
  background: var(--surface-2);
  display: grid; place-items: center;
  color: var(--accent);
}
.card .glyph svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.card h3 { margin: 0 0 3px; font-size: 18px; }
.card .blurb { margin: 0; color: var(--text-dim); font-size: 13px; }
.card .stat { margin: 6px 0 0; font-size: 12px; color: var(--text-dim); }
.card .chev { margin-left: auto; color: var(--text-dim); }
.card .chev svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

.home-foot { margin-top: auto; padding-top: 8px; }
.home-foot p { margin: 0; font-size: 12px; color: var(--text-dim); text-align: center; }
.small { font-size: 11px; opacity: 0.7; }

/* ---------- play ---------- */

.play { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.play-head { display: flex; align-items: center; gap: 10px; padding: 2px 0 10px; flex: 0 0 auto; }
.play-head h2 { margin: 0; font-size: 19px; font-weight: 600; }
.spacer { flex: 1; }
.game-root { flex: 1 1 auto; min-height: 0; position: relative; }

.icon-btn {
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn[aria-pressed="false"] .snd-wave { opacity: 0.15; }

/* ---------- shared bits games can use ---------- */

.btn {
  min-height: var(--tap);
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn:active { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn[disabled] { opacity: 0.4; pointer-events: none; }
.seg { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.seg button {
  flex: 1; min-height: 38px; border: 0; border-radius: 9px; background: transparent;
  color: var(--text-dim); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.18); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 24px);
  transform: translate(-50%, 12px);
  max-width: 80vw;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
