/* SolveWit shared styles: brand, layout, buttons, dialogs, stats, effects. */
:root {
  --bg: #f4f0ff;
  --bg-2: #ece5ff;
  --card: #ffffff;
  --ink: #1d1838;
  --muted: #6c6889;
  --line: #e4dcfb;
  --brand: #6b4cf6;
  --brand-2: #5636e0;
  --brand-ink: #ffffff;
  --brand-grad: linear-gradient(135deg, #8064ff 0%, #5636e0 100%);
  --accent: #ffb703;
  --good: #22d18b;
  --pink: #ff5d8f;
  --sky: #3ab7ff;
  --shadow-sm: 0 2px 8px rgba(60, 40, 160, .08);
  --shadow: 0 12px 34px rgba(60, 40, 160, .14);
  --shadow-lg: 0 24px 60px rgba(60, 40, 160, .22);
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #120f26;
    --bg-2: #1a1638;
    --card: #1f1a3d;
    --ink: #f3f0ff;
    --muted: #a7a2c8;
    --line: #342d62;
    --brand: #8b70ff;
    --brand-2: #6b4cf6;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, .3);
    --shadow: 0 12px 34px rgba(0, 0, 0, .38);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
  position: relative;
  overflow-x: hidden;
}
/* soft glowing color blobs behind everything */
body::before {
  content: "";
  position: fixed; inset: -20vmax;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(38vmax 38vmax at 12% 8%, rgba(128, 100, 255, .22), transparent 60%),
    radial-gradient(30vmax 30vmax at 92% 18%, rgba(255, 183, 3, .16), transparent 60%),
    radial-gradient(34vmax 34vmax at 80% 92%, rgba(34, 209, 139, .14), transparent 60%),
    radial-gradient(30vmax 30vmax at 6% 86%, rgba(255, 93, 143, .12), transparent 60%);
}
button { font: inherit; color: inherit; }
a { color: var(--brand); }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}
.top-inner {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  max-width: 1040px;
  margin: 0 auto;
  padding: 8px 14px;
}
.top-left, .top-right { display: flex; gap: 4px; align-items: center; }
.top-right { justify-content: flex-end; }
.logo { margin: 0; line-height: 0; }
.logo a { display: inline-block; border-radius: 10px; }
.logo img { display: block; height: 40px; width: auto; }
.icon-btn {
  width: 42px; height: 42px;
  display: inline-grid; place-items: center;
  border: 0; border-radius: 12px;
  background: transparent; cursor: pointer; text-decoration: none; color: var(--ink);
  transition: background .15s, transform .15s;
}
.icon-btn:hover { background: color-mix(in srgb, var(--brand) 12%, transparent); }
.icon-btn:active { transform: scale(.94); }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg .fill { fill: currentColor; }

/* ---------- buttons ---------- */
.ctl {
  min-height: 48px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  font-weight: 800;
  cursor: pointer;
  padding: 8px 14px;
  box-shadow: 0 3px 0 var(--line), var(--shadow-sm);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation;
  transition: transform .08s, box-shadow .08s, border-color .15s, opacity .15s;
}
.ctl:hover:not(:disabled) { border-color: var(--brand); }
.ctl:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.ctl:disabled { opacity: .45; cursor: default; }
.ctl.primary {
  background: var(--brand-grad); color: var(--brand-ink); border-color: transparent;
  box-shadow: 0 4px 0 #3f24b8, 0 10px 22px rgba(86, 54, 224, .32);
}
.ctl.primary:active:not(:disabled) { box-shadow: 0 1px 0 #3f24b8, 0 4px 10px rgba(86, 54, 224, .3); }
.ctl.armed { background: #ff5d5d; color: #fff; border-color: #ff5d5d; box-shadow: 0 3px 0 #c43c3c; }
.ctl.big { width: 100%; min-height: 54px; font-size: 18px; }
.link { background: none; border: 0; padding: 0; color: var(--brand); font-weight: 800; text-decoration: underline; cursor: pointer; }

/* ---------- game page layout ---------- */
.game { max-width: 540px; margin: 0 auto; padding: 14px 14px 10px; scroll-margin-top: 70px; }
.game-head { text-align: center; margin-bottom: 12px; }
.game-title {
  margin: 0; font-size: 26px; font-weight: 900; letter-spacing: -0.02em;
}
.game-sub { color: var(--muted); font-size: 14px; }
.game-sub b { color: var(--ink); }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--brand) 12%, var(--card));
  color: var(--brand); font-weight: 800; font-size: 13px;
}
.hud { display: grid; grid-template-columns: auto 1fr 1fr; gap: 10px; align-items: stretch; margin-bottom: 14px; }
.hud.no-thumb { grid-template-columns: 1fr 1fr 1fr; }
.hud-stat {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 6px 10px; text-align: center; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; justify-content: center;
}
.hud-num { display: block; font-size: 26px; font-weight: 900; line-height: 1.1; font-variant-numeric: tabular-nums; }
.hud-lbl { font-size: 12px; color: var(--muted); }
.hud-lbl b { color: var(--ink); }

.board-wrap {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  aspect-ratio: 1 / 1;
  display: grid; place-items: center;
}
.board {
  display: block;
  touch-action: none;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  border-radius: 18px;
  box-shadow: var(--shadow-lg), 0 0 0 6px color-mix(in srgb, var(--card) 85%, transparent);
  background: var(--line);
  outline: none;
}
.board:focus-visible { box-shadow: 0 0 0 4px var(--accent), var(--shadow-lg); }
.board-wrap.win-pop .board { animation: winpop .6s ease; }
@keyframes winpop {
  0% { transform: scale(1); }
  35% { transform: scale(1.045); box-shadow: 0 0 0 8px var(--good), var(--shadow-lg); }
  100% { transform: scale(1); }
}
.confetti {
  position: absolute; top: 40%;
  width: 9px; height: 14px; border-radius: 2px;
  pointer-events: none; z-index: 3;
  animation: confetti 1.6s cubic-bezier(.2,.6,.4,1) forwards;
}
.confetti.round { width: 10px; height: 10px; border-radius: 50%; }
@keyframes confetti {
  0% { transform: translate(0, 0) rotate(0); opacity: 1; }
  30% { transform: translate(calc(var(--dx) * .5), -150px) rotate(calc(var(--rot) * .4)); opacity: 1; }
  100% { transform: translate(var(--dx), 230px) rotate(var(--rot)); opacity: 0; }
}

.controls { display: grid; grid-template-columns: 1fr 1.3fr 1fr; gap: 10px; margin: 16px auto 0; max-width: 480px; }
.status { text-align: center; color: var(--muted); font-size: 14px; min-height: 1.5em; margin: 10px 0 0; }
.after {
  text-align: center; margin: 10px auto 0; max-width: 420px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow);
}
.after-btns { display: grid; gap: 10px; }
.next { color: var(--muted); margin: 4px 0 10px; text-align: center; }
.next b { color: var(--ink); font-variant-numeric: tabular-nums; }
.practice-bar { text-align: center; margin-top: 12px; color: var(--muted); font-size: 14px; }
.new-day {
  display: block; width: 100%; margin: 0 0 12px;
  border: 0; border-radius: 14px; padding: 11px;
  background: var(--accent); color: #1d1838; font-weight: 900; cursor: pointer;
  box-shadow: 0 3px 0 #c98f00;
}
.back-home { display: inline-flex; align-items: center; gap: 4px; font-weight: 800; text-decoration: none; font-size: 14px; }

/* ---------- about / footer ---------- */
.about {
  max-width: 540px; margin: 30px auto 0; padding: 20px 22px;
  background: color-mix(in srgb, var(--card) 70%, transparent);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.about h2 { font-size: 20px; margin: 4px 0 6px; }
.about h2 + p { margin-top: 0; }
.about p, .about li { color: var(--muted); }
.about ul { padding-left: 20px; }
.about h3 { font-size: 16px; margin: 14px 0 4px; color: var(--ink); }
.about h3 + p { margin-top: 0; }
.about .guide-link {
  display: flex; align-items: center; gap: 10px; margin: 14px 0 4px; padding: 12px 14px;
  border-radius: 14px; text-decoration: none; font-weight: 800;
  background: color-mix(in srgb, var(--brand) 9%, var(--card)); border: 1px solid var(--line);
}
.about .guide-link:hover { border-color: var(--brand); }
.about .guide-link span { font-size: 22px; }

@media (max-width: 572px) {
  .about { margin-left: 12px; margin-right: 12px; }
}

/* ---------- "more games" cross-links ---------- */
.more-games { box-sizing: border-box; max-width: 564px; margin: 22px auto 0; padding: 0 12px; }
.more-games h2 { font-size: 20px; margin: 0 0 10px; text-align: center; }
.more-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.more-card {
  display: block; padding: 14px; border-radius: 18px; text-decoration: none; color: var(--ink);
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
  transition: transform .15s, border-color .15s;
}
.more-card:hover { transform: translateY(-3px); border-color: var(--brand); }
.more-card .mc-ico { font-size: 26px; display: block; }
.more-card b { display: block; font-size: 16px; margin: 4px 0 2px; }
.more-card small { color: var(--muted); font-size: 13px; line-height: 1.35; display: block; }

/* ---------- guide articles ---------- */
.crumbs { max-width: 720px; margin: 18px auto 0; padding: 0 16px; font-size: 13px; color: var(--muted); }
.crumbs a { color: var(--muted); font-weight: 700; text-decoration: none; }
.crumbs a:hover { color: var(--brand); }
.guide { max-width: 720px; margin: 10px auto 0; padding: 0 16px; }
.guide h1 { font-size: clamp(30px, 6vw, 42px); line-height: 1.1; letter-spacing: -0.03em; margin: 6px 0 10px; }
.guide .lede { font-size: 18px; color: var(--muted); margin: 0 0 18px; }
.guide h2 { font-size: 24px; margin: 28px 0 8px; letter-spacing: -0.01em; }
.guide h3 { font-size: 18px; margin: 18px 0 6px; }
.guide p, .guide li { color: color-mix(in srgb, var(--ink) 82%, var(--muted)); line-height: 1.6; }
.guide ul, .guide ol { padding-left: 22px; }
.guide li { margin: 4px 0; }
.guide .example {
  margin: 14px 0; padding: 12px 16px; border-radius: 14px;
  background: color-mix(in srgb, var(--brand) 7%, var(--card)); border: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.guide .example code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 15px; white-space: pre; display: block; line-height: 1.5; }
.guide .cells { display: inline-flex; gap: 3px; vertical-align: middle; margin: 2px 0; }
.guide .cells i { width: 18px; height: 18px; border-radius: 4px; background: var(--line); }
.guide .cells i.f { background: var(--brand); }
.guide-cta {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  margin: 26px 0 0; padding: 18px 20px; border-radius: 20px;
  background: var(--brand-grad); color: #fff; box-shadow: var(--shadow);
}
.guide-cta p { margin: 0; color: #fff; font-weight: 800; font-size: 18px; }
.guide-cta a { background: #fff; color: var(--brand-2); padding: 11px 18px; border-radius: 12px; font-weight: 900; text-decoration: none; }

.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 26px 16px 34px; }
.foot nav { display: flex; justify-content: center; gap: 16px; flex-wrap: wrap; margin-bottom: 6px; }
.foot a { color: var(--muted); font-weight: 700; text-decoration: none; }
.foot a:hover { color: var(--brand); }

/* ---------- dialogs ---------- */
dialog {
  border: 0; padding: 0; border-radius: 24px;
  background: var(--card); color: var(--ink);
  width: min(440px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  box-shadow: var(--shadow-lg);
}
dialog[open] { animation: pop-in .22s cubic-bezier(.2, .9, .3, 1.2); }
dialog::backdrop { background: rgba(20, 15, 50, .55); backdrop-filter: blur(3px); }
@keyframes pop-in { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.dlg { position: relative; padding: 24px 20px 20px; }
.dlg h2 { margin: 0 0 8px; font-size: 22px; text-align: center; }
.dlg h3 { font-size: 15px; margin: 18px 0 8px; text-align: center; color: var(--muted); }
.dlg hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.dlg-close {
  position: absolute; top: 8px; right: 8px;
  width: 38px; height: 38px; border: 0; border-radius: 10px;
  background: transparent; font-size: 26px; line-height: 1; cursor: pointer;
}
.dlg-close:hover { background: var(--line); }
.lead { text-align: center; color: var(--muted); margin: 0 0 14px; }
.small { font-size: 13px; color: var(--muted); text-align: center; }
.how { display: grid; gap: 12px; margin-bottom: 8px; }
.how-step { display: grid; grid-template-columns: 46px 1fr; gap: 12px; align-items: center; }
.how-step p { margin: 0; }
.how-ico {
  width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center;
  background: color-mix(in srgb, var(--brand) 10%, var(--card)); font-size: 22px; font-weight: 900; color: var(--brand);
}
.how-ico.good { color: var(--good); }
.stars { text-align: center; font-size: 36px; letter-spacing: 4px; animation: pop-in .4s .1s both; }
.res-title { margin-top: 2px !important; }
.res-grid, .stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0 16px; text-align: center; }
.res-grid > div, .stat-grid > div {
  background: color-mix(in srgb, var(--brand) 7%, var(--card)); border-radius: 14px; padding: 8px 2px;
}
.res-grid b, .stat-grid b { display: block; font-size: 22px; font-weight: 900; font-variant-numeric: tabular-nums; }
.res-grid span, .stat-grid span { font-size: 12px; color: var(--muted); }
.dist { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: 90px 1fr; gap: 8px; align-items: center; font-size: 13px; }
.bar-lbl { color: var(--muted); text-align: right; }
.bar {
  display: block; min-width: 26px;
  background: var(--line); color: var(--ink);
  border-radius: 6px; padding: 2px 8px; text-align: right; font-weight: 800;
}
.bar.today { background: var(--good); color: #fff; }
.opt {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer;
}
.opt small { display: block; color: var(--muted); }
.opt input { width: 22px; height: 22px; accent-color: var(--brand); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg);
  padding: 11px 18px; border-radius: 14px; font-weight: 800;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  z-index: 10; max-width: calc(100vw - 32px); text-align: center;
  box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 380px) {
  .logo img { height: 32px; }
  .hud-num { font-size: 22px; }
  .game-title { font-size: 22px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
