/* Simon Says — a disc of thick glass. Theme colours arrive as custom
   properties from themes.js; everything here derives from them. */

:root {
  --bg-a: #ece6dd;
  --bg-b: #cdd3cf;
  --ink: #2b2622;
  --ink-soft: #6d655c;
  --paper: #f8f5ef;
  --paper-2: #ebe6dd;
  --disc: #f4f0e9;
  --disc-rim: #d9d2c6;
  --accent: #3f6fb5;
  --c0: #d1514a; --c1: #4a9b62; --c2: #3f6fb5; --c3: #dcae3c; --c4: #8a5fb3; --c5: #e07c4b;
  --line: color-mix(in oklab, var(--ink) 12%, transparent);
  --glass-fill: 0.5;
  --radius: 18px;
  --ease: cubic-bezier(0.4, 0.1, 0.2, 1);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --white-a: 255 255 255;
}
:root[data-dark="1"] {
  --glass-fill: 0.42;
  --white-a: 200 210 255;
}

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

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background: linear-gradient(165deg, var(--bg-a), var(--bg-b));
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  transition: background 0.8s, color 0.5s;
}

/* ---------------------------------------------------------- background */
.bg { position: fixed; inset: 0; overflow: hidden; z-index: 0; pointer-events: none; }
.bg .blob { position: absolute; border-radius: 50%; filter: blur(70px); opacity: 0.5; will-change: transform; transition: background 1s; }
.bg .b1 { width: 60vmax; height: 60vmax; left: -22vmax; top: -26vmax; background: color-mix(in oklab, var(--c3) 40%, transparent); animation: drift 50s ease-in-out infinite alternate; }
.bg .b2 { width: 55vmax; height: 55vmax; right: -22vmax; bottom: -22vmax; background: color-mix(in oklab, var(--c2) 38%, transparent); animation: drift 64s ease-in-out infinite alternate-reverse; }
.bg .b3 { width: 40vmax; height: 40vmax; left: 28vw; bottom: -26vmax; background: color-mix(in oklab, var(--c0) 30%, transparent); animation: drift 76s ease-in-out infinite alternate; }
@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(8vmax, 6vmax) scale(1.12); }
}

/* -------------------------------------------------------------- layout */
.app {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.top { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px 4px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 40px; height: 40px; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.22)); }
.brand span { display: flex; flex-direction: column; line-height: 1.1; }
.brand b { font-family: var(--serif); font-weight: 600; font-size: 22px; letter-spacing: 0.02em; }
.brand small { font-size: 11.5px; color: var(--ink-soft); letter-spacing: 0.08em; text-transform: uppercase; margin-top: 2px; }
.menu { display: flex; gap: 4px; }

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}
.icon-btn:hover { background: color-mix(in oklab, var(--ink) 8%, transparent); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg, .btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 4px 16px 6px; }
.stat {
  background: rgb(var(--white-a) / 0.3);
  border: 1px solid rgb(var(--white-a) / 0.35);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  border-radius: 12px;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
}
:root[data-dark="1"] .stat { background: rgb(var(--white-a) / 0.07); border-color: rgb(var(--white-a) / 0.12); }
.stat span { font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
.stat b { font-family: var(--serif); font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; transition: transform 0.25s var(--ease); }
.stat b.bump { animation: bump 0.4s var(--ease); }
@keyframes bump { 40% { transform: scale(1.22); } }

.stage { flex: 1; min-height: 0; container-type: size; display: grid; place-items: center; padding: 8px 16px; }

.actions { display: flex; gap: 10px; padding: 6px 16px 14px; }
.btn {
  appearance: none;
  flex: 1;
  border: 1px solid color-mix(in oklab, var(--ink) 14%, transparent);
  background: rgb(var(--white-a) / 0.5);
  color: var(--ink);
  font: 500 15px var(--sans);
  padding: 11px 12px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  transition: transform 0.15s, background 0.2s, opacity 0.2s, box-shadow 0.2s;
}
:root[data-dark="1"] .btn { background: rgb(var(--white-a) / 0.1); }
.btn svg { width: 19px; height: 19px; }
.btn:hover { background: rgb(var(--white-a) / 0.75); }
:root[data-dark="1"] .btn:hover { background: rgb(var(--white-a) / 0.16); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.btn.primary {
  background: linear-gradient(180deg, color-mix(in oklab, var(--accent) 82%, white), color-mix(in oklab, var(--accent) 85%, black));
  color: #fff;
  border-color: color-mix(in oklab, var(--accent) 70%, black);
  box-shadow: 0 6px 14px -5px color-mix(in oklab, var(--accent) 70%, black), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.sound-off { color: var(--ink-soft); }
.btn.subtle { flex: 0 0 auto; background: transparent; box-shadow: none; color: var(--ink-soft); font-size: 13.5px; margin: 18px auto 0; display: flex; }

/* ---------------------------------------------------------------- disc */
.disc-wrap {
  width: min(100cqw, 100cqh);
  aspect-ratio: 1;
  position: relative;
  touch-action: none;
}
.disc-wrap.shake { animation: shake 0.42s ease-in-out; }
@keyframes shake {
  20% { transform: translateX(-2.2%); }
  40% { transform: translateX(2%); }
  60% { transform: translateX(-1.4%); }
  80% { transform: translateX(0.8%); }
}
.plate {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 40%, color-mix(in oklab, var(--disc) 92%, white), var(--disc) 60%, color-mix(in oklab, var(--disc) 85%, var(--disc-rim)));
  box-shadow:
    inset 0 0 0 1.2% var(--disc-rim),
    inset 0 0.8% 2% rgb(var(--white-a) / 0.5),
    inset 0 -1.6% 3.5% rgba(0, 0, 0, 0.14),
    0 30px 55px -22px rgba(0, 0, 0, 0.45),
    0 8px 18px -6px rgba(0, 0, 0, 0.2);
  transition: background 0.6s, box-shadow 0.6s;
}
:root[data-dark="1"] .plate { box-shadow: inset 0 0 0 1.2% var(--disc-rim), inset 0 0.8% 2% rgb(var(--white-a) / 0.14), inset 0 -1.6% 3.5% rgba(0, 0, 0, 0.5), 0 30px 55px -22px rgba(0, 0, 0, 0.8), 0 0 70px -10px color-mix(in oklab, var(--c1) 30%, transparent); }
.disc { position: absolute; inset: 0; width: 100%; height: 100%; display: block; overflow: visible; }

.seg {
  --c: var(--c0);
  cursor: pointer;
  transform-box: view-box;
  transform-origin: 200px 200px;
  transition: transform 0.14s var(--ease), filter 0.18s;
  will-change: transform, filter;
}
.seg .base { fill: var(--c); fill-opacity: var(--glass-fill); stroke: var(--c); stroke-opacity: var(--glass-fill); stroke-width: 7; stroke-linejoin: round; transition: fill-opacity 0.18s, stroke-opacity 0.18s; }
.seg .bloom { opacity: 0; transition: opacity 0.2s; pointer-events: none; }
.seg .gloss { fill: url(#gloss); pointer-events: none; stroke: url(#gloss); stroke-width: 7; stroke-linejoin: round; }
.seg .edge { fill: none; stroke: rgb(var(--white-a) / 0.6); stroke-width: 1.3; pointer-events: none; }
.seg .shade { fill: none; stroke: rgba(0, 0, 0, 0.18); stroke-width: 9; stroke-linejoin: round; pointer-events: none; opacity: 0.6; }
.seg.lit { filter: drop-shadow(0 0 14px var(--c)) drop-shadow(0 0 3px var(--c)) brightness(1.08); transition-duration: 0.06s; }
.seg.lit .base { fill-opacity: 1; stroke-opacity: 1; transition-duration: 0.06s; }
.seg.lit .bloom { opacity: 1; transition-duration: 0.08s; }
.seg.pressed { transform: scale(0.965); }
.seg.dim .base { fill-opacity: 0.22; stroke-opacity: 0.22; }
.disc-wrap.fail .seg { filter: saturate(0.3); }
@media (hover: hover) { .seg:hover:not(.lit) .base { fill-opacity: calc(var(--glass-fill) + 0.14); } }

.centre-plate { fill: var(--disc); stroke: var(--disc-rim); stroke-width: 1.2; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.18)); transition: fill 0.6s; }
.ring { fill: none; stroke-linecap: round; transform: rotate(-90deg); transform-origin: 200px 200px; }
.ring.track { stroke: color-mix(in oklab, var(--ink) 10%, transparent); stroke-width: 3; }
.ring.progress { stroke: var(--accent); stroke-width: 3; stroke-dasharray: 377; stroke-dashoffset: 377; transition: stroke-dashoffset 0.22s var(--ease), opacity 0.3s; opacity: 0; }
.ring.countdown { stroke: color-mix(in oklab, var(--accent) 55%, transparent); stroke-width: 1.6; stroke-dasharray: 440; stroke-dashoffset: 440; opacity: 0; transition: opacity 0.3s; }
.disc-wrap.input .ring.countdown, .disc-wrap.input .ring.progress, .disc-wrap.showing .ring.progress { opacity: 1; }

.centre {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  position: absolute;
  left: 50%;
  top: 50%;
  width: 29%;
  height: 29%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-family: var(--sans);
  padding: 0;
  line-height: 1;
}
.centre b { font-family: var(--serif); font-weight: 600; font-size: clamp(28px, 11cqmin, 64px); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; transition: transform 0.3s var(--ease); }
.centre b.bump { animation: bump 0.45s var(--ease); }
.centre span { font-size: clamp(9px, 2.6cqmin, 13px); letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); margin-top: 0.4em; white-space: nowrap; transition: color 0.3s; }
.disc-wrap.input .centre span { color: var(--accent); animation: pulseText 1.6s ease-in-out infinite; }
.disc-wrap.idle .centre span { animation: pulseText 2.4s ease-in-out infinite; }
@keyframes pulseText { 50% { opacity: 0.45; } }

/* -------------------------------------------------------- sheets, dialogs */
.backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(20, 18, 28, 0.42); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); animation: fade 0.25s; }
@keyframes fade { from { opacity: 0; } }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0 auto;
  z-index: 21;
  max-width: 560px;
  max-height: 86dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.25);
  padding-bottom: env(safe-area-inset-bottom);
  animation: rise 0.32s var(--ease);
}
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.sheet header { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 6px 22px; flex: 0 0 auto; }
.sheet h2, .dialog h2 { font-family: var(--serif); font-weight: 600; font-size: 24px; margin: 0; letter-spacing: 0.01em; }
.sheet-body { overflow: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 2px 22px 26px; font-size: 15px; line-height: 1.55; }
.sheet-body h3 { font-family: var(--serif); font-weight: 600; font-size: 17px; margin: 20px 0 8px; color: var(--ink); }
.prose p { margin: 0 0 12px; }
.prose ul { margin: 0; padding-left: 20px; }
.prose li { margin: 4px 0; }
.muted { color: var(--ink-soft); }
.about { font-size: 13px; margin-top: 22px; text-align: center; }

@media (min-width: 700px) and (min-height: 560px) {
  .sheet { bottom: auto; top: 50%; transform: translateY(-50%); border-radius: 24px; max-height: 80dvh; animation: pop 0.28s var(--ease); }
}
@keyframes pop { from { opacity: 0; transform: translateY(-50%) scale(0.96); } }

.dialog {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 22;
  width: min(92vw, 400px);
  background: var(--paper);
  border-radius: 24px;
  padding: 26px 24px 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  text-align: center;
  animation: popc 0.3s var(--ease);
  overflow: hidden;
}
@keyframes popc { from { opacity: 0; transform: translate(-50%, -50%) scale(0.94); } }
.dialog p { margin: 8px 0 18px; color: var(--ink-soft); font-size: 15.5px; line-height: 1.5; }
.dialog .row { display: flex; gap: 10px; }
.result .glow { position: absolute; inset: -40% -20% auto; height: 70%; background: radial-gradient(ellipse at 50% 40%, color-mix(in oklab, var(--accent) 40%, transparent), transparent 65%); pointer-events: none; opacity: 0.7; }
.result h2 { position: relative; font-size: 30px; }
.result .badge { display: inline-block; position: relative; margin-top: 6px; padding: 4px 12px; border-radius: 999px; font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; font-weight: 600; color: #fff; background: linear-gradient(90deg, var(--c3), var(--c0)); animation: shimmer 2.4s ease-in-out infinite; }
@keyframes shimmer { 50% { box-shadow: 0 0 18px color-mix(in oklab, var(--c3) 80%, white); } }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 12px; }
.result-stats div, .summary div { display: flex; flex-direction: column; align-items: center; background: var(--paper-2); border-radius: 12px; padding: 8px 4px; line-height: 1.2; }
.result-stats span, .summary span { font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
.result-stats b, .summary b { font-family: var(--serif); font-size: 19px; font-weight: 600; }
.final-score { display: flex; flex-direction: column; align-items: center; margin: 4px 0 18px; }
.final-score span { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); }
.final-score b { font-family: var(--serif); font-size: 44px; font-weight: 600; line-height: 1.05; }

/* ------------------------------------------------------------- results */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
th { text-align: left; vertical-align: bottom; font-weight: 500; color: var(--ink-soft); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; padding: 4px 4px; border-bottom: 1px solid var(--line); }
td { padding: 7px 4px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
th.rounds, th.score, td.rounds, td.score { text-align: right; }
td.score { font-family: var(--serif); font-weight: 600; font-size: 15px; }
td.rounds { font-weight: 600; }
tr[data-strict="1"] td.mode { color: var(--c0); font-weight: 600; }

/* ------------------------------------------------------------- settings */
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt {
  appearance: none;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  font: 500 14px var(--sans);
  padding: 8px 14px 8px 10px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}
.opt:active { transform: scale(0.97); }
.opt[aria-checked="true"] { border-color: var(--accent); background: color-mix(in oklab, var(--paper) 70%, white); box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 25%, transparent); }
:root[data-dark="1"] .opt[aria-checked="true"] { background: color-mix(in oklab, var(--paper-2) 80%, white); }
.opts.lang .opt, .opts.plain .opt { padding-left: 14px; min-width: 96px; justify-content: center; }
.swatch { display: inline-block; width: 24px; height: 24px; border-radius: 50%; flex: 0 0 auto; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15); }
.toggle { display: flex; align-items: center; gap: 12px; margin-top: 20px; cursor: pointer; font-size: 15px; line-height: 1.35; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle .track { flex: 0 0 auto; width: 46px; height: 28px; border-radius: 999px; background: color-mix(in oklab, var(--ink) 22%, var(--paper-2)); position: relative; transition: background 0.25s; }
.toggle .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.25s var(--ease); }
.toggle input:checked + .track { background: var(--accent); }
.toggle input:checked + .track::after { transform: translateX(18px); }
.toggle input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(10px);
  z-index: 15;
  background: rgba(30, 27, 36, 0.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  max-width: min(88vw, 420px);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ------------------------------------------------------- small screens */
@media (max-height: 640px) {
  .top { padding-top: 6px; }
  .brand small { display: none; }
  .brand b { font-size: 19px; }
  .stat b { font-size: 17px; }
  .actions { padding-bottom: 10px; }
  .btn { padding: 9px 10px; }
}
@media (max-width: 520px) {
  .btn { flex-direction: column; gap: 3px; padding: 8px 6px 7px; font-size: 12.5px; }
  .btn span { white-space: nowrap; }
  .btn svg { width: 21px; height: 21px; }
}
@media (min-width: 900px) and (min-height: 700px) {
  .brand b { font-size: 26px; }
  .stage { padding: 14px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .bg .blob { animation: none; }
  .seg, .sheet, .dialog, .backdrop, .disc-wrap, .stat b, .centre b { animation: none; transition-duration: 0.01s; }
  .centre span { animation: none !important; }
}
