/* Memory Match — system theme + layout. Follows prefers-color-scheme live. */
:root {
  color-scheme: light dark;
  --banner-h: 0px;
  --bg: #fdf6ec;
  --surface: #ffffff;
  --ink: #2b2118;
  --ink-dim: #7a6a58;
  --accent: #e0653a;
  --accent-ink: #ffffff;
  --line: #eadfd2;
  --good: #16a34a;
  --card-back: linear-gradient(135deg, #e0653a, #f2a541);
  --shadow: 0 8px 32px rgba(43, 33, 24, 0.12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14101f;
    --surface: #221c33;
    --ink: #f5efe8;
    --ink-dim: #b3a893;
    --accent: #f07b4d;
    --accent-ink: #1c120c;
    --line: #3a324e;
    --good: #4ade80;
    --card-back: linear-gradient(135deg, #f07b4d, #b45be0);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--banner-h);
  -webkit-touch-callout: none; /* no long-press callout anywhere in the app */
}
button { -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }
body.mm_banner { padding-bottom: var(--banner-h); }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px 2px;
  max-width: 480px; width: 100%; margin: 0 auto;
  flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, #e0653a, #f2a541);
  font-size: 20px;
}
.icon-btn {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  width: 40px; height: 40px; font-size: 18px; cursor: pointer;
}
.top-actions { display: flex; gap: 8px; }

main {
  max-width: 480px; width: 100%; margin: 0 auto;
  padding: 6px 16px 6px; /* 6px bottom = tight 6px gap above the banner zone (T11) */
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column;
}

/* ---- HUD ---- */
.hud {
  display: flex; gap: 8px; margin-top: 4px;
  flex: 0 0 auto;
}
.hud-item {
  flex: 1; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 6px 4px 5px; text-align: center;
}
.hud-label { display: block; font-size: 11px; color: var(--ink-dim); font-weight: 600; }
.hud-value { display: block; font-size: 17px; font-weight: 800; }
.best-line { font-size: 12px; color: var(--ink-dim); margin: 6px 0 0; text-align: center; flex: 0 0 auto; min-height: 15px; }

.size-row { display: flex; gap: 8px; margin: 8px 0; flex: 0 0 auto; }
.size-btn {
  flex: 1; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 9px 4px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.size-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ---- board: fills the remaining viewport height, so the whole game
 * always fits above the banner with no scrolling (checklist 2026-11-12). */
.board {
  flex: 1 1 auto; min-height: 0;
  display: grid; gap: 8px;
  grid-template-columns: repeat(var(--cols, 4), 1fr);
  grid-template-rows: repeat(var(--rows, 3), 1fr);
  width: min(360px, 100%);
  margin: 0 auto;
}
.card {
  position: relative; border: none; background: none; padding: 0;
  cursor: pointer; perspective: 400px; min-height: 0; min-width: 0;
}
.card-inner {
  position: absolute; inset: 0;
  transition: transform 0.35s ease;
  transform-style: preserve-3d;
}
.card.flipped .card-inner, .card.matched .card-inner { transform: rotateY(180deg); }
.card-face {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 10px; font-size: clamp(22px, 9vw, 40px);
  border: 1px solid var(--line);
}
.card-back { background: var(--card-back); color: #fff; font-size: clamp(18px, 7vw, 30px); }
.card-front {
  background: var(--surface); transform: rotateY(180deg);
}
.card.matched .card-front {
  background: color-mix(in srgb, var(--good) 18%, var(--surface));
  border-color: var(--good);
}
.card:disabled { cursor: default; }

.primary-btn, .ghost-btn {
  display: block; width: 100%; border-radius: 12px; font-size: 17px;
  font-weight: 700; padding: 13px; margin-top: 10px; cursor: pointer;
  flex: 0 0 auto;
}
.primary-btn { background: var(--accent); color: var(--accent-ink); border: none; }
.ghost-btn { background: transparent; color: var(--ink); border: 1px solid var(--line); }

/* ---- sheets / toast ---- */
.sheet {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, 0.45);
}
.sheet-card {
  background: var(--surface); color: var(--ink);
  width: 100%; max-width: 480px; max-height: calc(100dvh - var(--banner-h) - 16px);
  overflow-y: auto;
  border-radius: 16px 16px 0 0; padding: 18px 18px calc(18px + var(--banner-h));
  box-shadow: var(--shadow);
}
body.mm_banner .sheet-card { padding-bottom: calc(18px + var(--banner-h)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.sheet-card p { line-height: 1.55; font-size: 15px; }
.sheet-note { color: var(--ink-dim); font-size: 13px; }
.result-line { font-size: 18px; font-weight: 700; text-align: center; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(24px + var(--banner-h));
  z-index: 50; pointer-events: none;
  background: var(--ink); color: var(--bg);
  border-radius: 10px; padding: 12px 14px; text-align: center;
  font-size: 14px; font-weight: 600;
}
