/* ================================================================
   FLEXICALS: shared styles ("Night gym").
   Values come from Design system/tokens.json. Use them by role.
   ================================================================ */
@font-face {
  font-family: "Space Grotesk";
  src: url("../fonts/SpaceGrotesk-var.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
}

:root {
  --ground: #0D1014;
  --surface: #171C22;
  --line: #2A323B;
  --ink: #F2F5F7;
  --muted: #9AA6B2;
  --root: #3A4450;
  --plate-white: #FFFFFF;
  --on-accent: #0D1014;
  --accent: #C8F031;              /* each game page sets its own */
  --space-1: 4px; --space-2: 8px; --space-3: 14px; --space-5: 20px;
  --radius-sm: 4px; --radius-md: 14px; --radius-full: 999px;
  --sans: "Space Grotesk", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--ground); color: var(--ink);
  font: 500 17px/24px var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
a { color: inherit; }
h1, h2, p { margin: 0; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- page frame ---------- */
.screen {
  max-width: 430px; margin: 0 auto; min-height: 100vh; min-height: 100dvh;
  padding: calc(18px + env(safe-area-inset-top)) calc(var(--space-5) + env(safe-area-inset-right))
           calc(var(--space-5) + env(safe-area-inset-bottom)) calc(var(--space-5) + env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: var(--space-3);
}
.screen.fit { height: 100vh; height: 100dvh; overflow: hidden; }

/* ---------- type ---------- */
.wordmark { font-size: 15px; line-height: 20px; font-weight: 700; letter-spacing: 0.14em; text-decoration: none; }
.game-title { font-size: 40px; line-height: 40px; font-weight: 700; letter-spacing: -0.03em; }
.stat { font-size: 30px; line-height: 30px; font-weight: 700; }
.label { font-size: 15px; line-height: 20px; color: var(--muted); }
.caption { font-size: 13px; line-height: 16px; color: var(--muted); }
.muted { color: var(--muted); }

/* ---------- header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.top-icons { display: flex; gap: var(--space-1); margin-right: -10px; }
.icon-btn {
  width: 44px; height: 44px; border: 0; background: transparent; color: var(--ink);
  display: flex; align-items: center; justify-content: center; border-radius: var(--radius-md);
}
.title-row { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 2px 8px; }
.screen.fit .game-title { font-size: 38px; }

/* ---------- buttons ---------- */
.btn {
  min-height: 52px; padding: 0 16px; border-radius: var(--radius-md);
  border: 1.5px solid var(--ink); background: transparent; color: var(--ink);
  font-size: 17px; font-weight: 700; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; white-space: nowrap;
}
.btn.primary { border: 0; background: var(--accent); color: var(--on-accent); font-size: 20px; letter-spacing: 0.02em; }
.btn.grow { flex: 1 1 auto; }
.btn:disabled { border-color: var(--muted); color: var(--muted); border-style: dashed; background: transparent; cursor: default; }
.btn.primary:disabled { border: 1.5px dashed var(--muted); }
.actions { display: flex; gap: var(--space-2); }

/* ---------- panels ---------- */
.panel { background: var(--surface); border-radius: var(--radius-md); padding: 12px var(--space-3); }
.strip { display: flex; align-items: center; justify-content: space-between; width: 100%; border: 0; text-align: left; color: var(--ink); }
.strip > div { display: flex; flex-direction: column; gap: 2px; }
.strip > div.mid { gap: 8px; align-items: center; }
.strip > div.end { align-items: flex-end; }
.pips { display: flex; gap: var(--space-1); }
.pips i { display: block; width: 14px; height: 14px; border-radius: var(--radius-full); border: 1.5px solid var(--ink); }
.pips i.on { background: var(--ink); }

/* ---------- sheets (help, stats, result) ---------- */
.sheet-ov {
  position: fixed; inset: 0; z-index: 20; background: rgba(13, 16, 20, 0.86);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 430px; max-height: 100dvh; overflow-y: auto;
  background: var(--surface); border-radius: var(--radius-md) var(--radius-md) 0 0;
  padding: var(--space-3) var(--space-5) calc(var(--space-5) + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: var(--space-3);
}
@media (min-height: 700px) and (min-width: 480px) {
  .sheet-ov { align-items: center; }
  .sheet { border-radius: var(--radius-md); }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.sheet-head h2 { font-size: 20px; line-height: 24px; font-weight: 700; }
.sheet-head .icon-btn { margin-right: -10px; }
.sheet p { color: var(--ink); }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }
.stat-grid > div { background: var(--ground); border-radius: var(--radius-md); padding: 12px var(--space-3); display: flex; flex-direction: column; gap: 2px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 30; background: var(--ink); color: var(--on-accent); font-weight: 700; font-size: 15px;
  padding: 10px 16px; border-radius: var(--radius-md); max-width: calc(100vw - 40px); text-align: center;
}

/* ---------- small block rows (log, help, home) ---------- */
.mini { display: inline-flex; gap: 3px; align-items: center; }
.mini i { display: block; width: 14px; height: 14px; border-radius: var(--radius-sm); }
.mini i.p { background: var(--accent); }
.mini i.r { background: var(--root); width: 28px; }
.mini i.s { background: var(--plate-white); }
.mini.hollow i { background: transparent; border: 1.5px solid var(--muted); }

/* ================================================================
   HOME
   ================================================================ */
.hero { padding: 28px 0 10px; display: flex; flex-direction: column; gap: 10px; }
.hero h1 { font-size: 38px; line-height: 40px; font-weight: 700; letter-spacing: 0.1em; }
.hero p { font-size: 20px; line-height: 26px; color: var(--muted); }

.card {
  display: flex; flex-direction: column; gap: 22px; text-decoration: none;
  background: var(--surface); border-radius: var(--radius-md); padding: 18px var(--space-3) var(--space-3);
}
.card-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card .game-title { font-size: 36px; line-height: 38px; }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-foot .btn { min-width: 132px; }

.section-label { padding-top: 10px; }
.soon { display: flex; flex-direction: column; }
.soon-row { display: flex; align-items: center; gap: 12px; padding: 13px 0; border-top: 1px solid var(--line); }
.soon-row:last-child { border-bottom: 1px solid var(--line); }
.soon-row .chip { width: 14px; height: 14px; border-radius: var(--radius-sm); flex: none; }
.soon-row .name { flex: 1 1 auto; font-size: 20px; line-height: 24px; font-weight: 700; letter-spacing: -0.01em; }

.signup { display: flex; flex-direction: column; gap: var(--space-2); padding-top: 6px; }
.signup label { font-size: 17px; }
.signup-row { display: flex; gap: var(--space-2); }
.signup input[type=email] {
  flex: 1 1 auto; min-width: 0; min-height: 52px; padding: 0 var(--space-3);
  border-radius: var(--radius-md); border: 1.5px solid var(--muted); background: transparent; color: var(--ink);
}
.signup input::placeholder { color: var(--muted); }
.foot { margin-top: auto; padding-top: 24px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.foot a { color: var(--muted); }

.prose { display: flex; flex-direction: column; gap: var(--space-3); padding-bottom: 24px; }
.prose h1 { font-size: 30px; line-height: 34px; font-weight: 700; letter-spacing: -0.02em; padding-top: 16px; }
.prose h2 { font-size: 20px; line-height: 24px; font-weight: 700; padding-top: 8px; }
.prose p, .prose li { color: var(--ink); }
.prose ul { margin: 0; padding-left: 20px; }

/* ================================================================
   MEGAMORPH
   ================================================================ */
.bar { position: relative; width: 100%; height: 110px; display: flex; align-items: center; justify-content: center; flex: none; }
.bar::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 6px; margin-top: -3px; border-radius: 3px; background: var(--muted); }
.bar-in { position: relative; flex: none; display: flex; align-items: center; gap: var(--space-1); transform-origin: center; }
.plate, .rootblock, .slot { flex: none; display: flex; align-items: center; border-radius: var(--radius-md); white-space: nowrap; }
.plate { height: 86px; padding: 0 12px; border: 0; font-size: 20px; font-weight: 700; color: var(--on-accent); }
.plate.p { background: var(--accent); }
.plate.s { background: var(--plate-white); }
.rootblock { height: 66px; padding: 0 22px; background: var(--root); color: var(--plate-white); font-size: 30px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.slot { height: 72px; width: 26px; border: 1.5px dashed var(--muted); background: var(--surface); }
.bar.lift .bar-in { animation: lift 0.42s ease-out; }
.bar.miss .bar-in { animation: miss 0.3s ease-in-out; }
@keyframes lift { 0% { translate: 0 0; } 40% { translate: 0 -14px; } 100% { translate: 0 0; } }
@keyframes miss { 0%, 100% { translate: 0 0; } 25% { translate: -6px 0; } 75% { translate: 6px 0; } }

.sayline { min-height: 48px; display: flex; align-items: center; justify-content: center; gap: 10px; text-align: center; flex: none; }
.sayline .word { font-size: 28px; line-height: 34px; font-weight: 700; white-space: nowrap; }
.sayline .label { padding-top: 6px; white-space: nowrap; }
.sayline .word.m { font-size: 22px; }
.sayline .word.sm { font-size: 17px; }
.sayline .say { font-size: 17px; line-height: 24px; }
.sayline .say b { font-weight: 700; }

.tiles { display: flex; flex-direction: column; gap: var(--space-2); flex: none; }
.tile-row { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.tile { min-height: 44px; padding: 0 var(--space-3); border-radius: var(--radius-md); border: 0; font-size: 17px; font-weight: 700; color: var(--on-accent); }
.tile.p { background: var(--accent); }
.tile.s { background: var(--plate-white); }
.tile.used { background: transparent; border: 1.5px dashed var(--muted); color: var(--muted); }

.log { flex: 1 1 auto; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; margin-bottom: calc(-1 * var(--space-5)); padding-bottom: var(--space-5); }
.log-row { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); flex: none; }
.log-row .shape { width: 100px; flex: none; display: flex; justify-content: center; }
.log-row .w { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-row .pts { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.log-row.out .w, .log-row.out .pts { color: var(--muted); }

.example { display: flex; flex-direction: column; align-items: center; gap: 6px; background: var(--ground); border-radius: var(--radius-md); padding: 6px var(--space-3) 14px; }
.example .bar { height: 104px; }
.example .word { font-size: 28px; line-height: 34px; font-weight: 700; }

.result-card { width: 100%; max-width: 300px; height: auto; align-self: center; border-radius: var(--radius-md); display: block; }

/* shorter phones: tighten the fixed parts so the log keeps some room */
@media (max-height: 700px) {
  .screen.fit { gap: 10px; padding-top: calc(8px + env(safe-area-inset-top)); }
  .screen.fit .game-title { font-size: 32px; line-height: 34px; }
  .bar { height: 92px; }
  .plate { height: 74px; }
  .rootblock { height: 58px; font-size: 26px; }
  .slot { height: 62px; }
  .sayline { min-height: 44px; }
  .sayline .word { font-size: 24px; line-height: 30px; }
  .screen.fit .btn { min-height: 48px; }
}

/* very short screens: let the page scroll so the log is never squeezed out */
@media (max-height: 620px) {
  .screen.fit { height: auto; overflow: visible; }
  .log { overflow: visible; min-height: 120px; }
}

@media (prefers-reduced-motion: reduce) {
  .bar.lift .bar-in, .bar.miss .bar-in { animation: none; }
}
