/* Polyrhythm: a lane rhythm game of falling polytopes. Light: pale lavender paper with ink lanes. Dark: a deep night
   stage with glowing lanes. house/theme.js sets data-theme="dark" on <html>. The canvas reads its colours from the
   --pr-* variables below (game.js re-reads them on the "taro:theme" event), so both themes live here. */
@font-face { font-family: "Jost"; font-style: normal; font-weight: 300 800; font-display: swap; src: url(/fonts/jost-latin-wght-normal.woff2) format("woff2"); }

:root {
  --bg: #F3F1FA;
  --bg2: #E9E5F6;
  --card: #FFFFFF;
  --ink: #17142E;
  --muted: #625D80;
  --line: #DAD4EE;
  --accent: #5B3FE0;
  --on-accent: #FFFFFF;
  --good: #1E7F55;
  --bad: #B42F4A;
  --backdrop: rgba(23, 20, 46, .45);
  --font: "Jost", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* the stage (read by game.js) */
  --pr-bg1: #FBFAFF;
  --pr-bg2: #E4E0F5;
  --pr-lane: rgba(40, 30, 110, .045);
  --pr-lane2: rgba(40, 30, 110, .085);
  --pr-line: rgba(50, 40, 120, .2);
  --pr-hit: #2A1F7A;
  --pr-ink: #17142E;
  --pr-dim: rgba(23, 20, 46, .55);
  --pr-poly: #6A50F0;
  --pr-vertex: #C9890C;
  --pr-edge: #0E8FB0;
  --pr-face: #7A55D8;
  --pr-miss: #C2334F;
  --pr-glow: 0;
  --pr-light: 48;   /* note lightness % */
  --pr-sat: 78;
  --lb-panel: var(--card); --lb-panel2: var(--bg2); --lb-text: var(--ink); --lb-muted: var(--muted); --lb-line: var(--line);
  --lb-accent: var(--accent); --lb-ink: var(--on-accent); --lb-bad: var(--bad); --lb-font: var(--font);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0A0B16;
  --bg2: #151730;
  --card: #141631;
  --ink: #EEEDFF;
  --muted: #A3A6CC;
  --line: #2A2D55;
  --accent: #9C8BFF;
  --on-accent: #120E33;
  --good: #6FD7A0;
  --bad: #FF8B9E;
  --backdrop: rgba(0, 0, 0, .55);
  --pr-bg1: #121433;
  --pr-bg2: #06070F;
  --pr-lane: rgba(150, 160, 255, .04);
  --pr-lane2: rgba(150, 160, 255, .075);
  --pr-line: rgba(160, 170, 255, .18);
  --pr-hit: #F4F2FF;
  --pr-ink: #F4F2FF;
  --pr-dim: rgba(238, 237, 255, .6);
  --pr-poly: #9C8BFF;
  --pr-vertex: #FFD166;
  --pr-edge: #4FD8F0;
  --pr-face: #B79CFF;
  --pr-miss: #FF6B86;
  --pr-glow: 1;
  --pr-light: 62;
  --pr-sat: 88;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { touch-action: manipulation; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); line-height: 1.45; min-height: 100vh; min-height: 100dvh;
  -webkit-text-size-adjust: 100%; padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
a { color: inherit; }
button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------ page frame */
.wrap { max-width: 1000px; margin: 0 auto; padding: 0 14px; }
.top { display: flex; justify-content: space-between; align-items: center; padding: 10px 0 0; }
.back { text-decoration: none; color: var(--muted); font-size: .95rem; white-space: nowrap; }
.top-actions { display: flex; gap: 4px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent; cursor: pointer; display: grid; place-items: center; font-weight: 700; font-size: 1.1rem; color: var(--ink); }
@media (hover: hover) { .icon-btn:hover { background: var(--bg2); } }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg .fill { fill: currentColor; stroke: none; }
.title-row { display: flex; align-items: baseline; justify-content: space-between; padding: 4px 0 8px; gap: 10px; }
h1 { font-weight: 700; font-size: 2rem; margin: 0; line-height: 1; letter-spacing: .01em; display: flex; align-items: center; gap: 9px; }
.h-mark { width: 22px; height: 24px; flex: none; background: linear-gradient(135deg, #4FD8F0, #7A55D8 55%, #E0479E); clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.sub { margin: 0; color: var(--muted); font-size: .95rem; white-space: nowrap; }

/* ------------------------------------------------------------ the stage */
.stage { position: relative; height: clamp(460px, 74vh, 700px); border-radius: 20px; overflow: hidden; background: var(--pr-bg2); border: 1px solid var(--line);
  box-shadow: 0 6px 28px rgba(23, 20, 46, .1); user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.pause-btn { position: absolute; top: 10px; left: 10px; z-index: 3; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: color-mix(in srgb, var(--card) 80%, transparent);
  display: grid; place-items: center; cursor: pointer; }
.pause-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); margin: 0; }

.ov { position: absolute; inset: 0; z-index: 4; display: flex; overflow-y: auto; padding: 16px; background: color-mix(in srgb, var(--pr-bg2) 55%, transparent);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); overscroll-behavior: contain; touch-action: pan-y; }
.ov-count { background: transparent; -webkit-backdrop-filter: none; backdrop-filter: none; pointer-events: none; align-items: center; justify-content: center; }
.count-n { font-size: 5.5rem; font-weight: 800; color: var(--pr-ink); text-shadow: 0 0 24px color-mix(in srgb, var(--accent) 60%, transparent); }
.panel { margin: auto; width: 100%; max-width: 430px; background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 18px 18px 16px; text-align: center;
  box-shadow: 0 8px 30px rgba(23, 20, 46, .16); }
.panel.small { max-width: 340px; }
.panel h2 { margin: 0 0 6px; font-size: 1.4rem; }
.song { margin: 0 0 12px; font-weight: 600; font-size: 1.05rem; }
.song small { display: block; font-weight: 400; color: var(--muted); font-size: .88rem; }
.note { margin: 10px 0 4px; font-size: .92rem; color: var(--muted); }
.note b { color: var(--ink); font-weight: 600; }
.fine { margin: 8px 0 0; color: var(--muted); font-size: .85rem; }
.fine.warn { color: var(--ink); }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: var(--bg2); border: 1px solid var(--line); border-radius: 16px; padding: 4px; }
.seg button { border: 0; background: transparent; border-radius: 12px; padding: 8px 4px; min-height: 52px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; color: var(--muted); }
.seg button b { font-weight: 700; font-size: 1rem; color: var(--ink); }
.seg button span { font-size: .78rem; line-height: 1.25; }
.seg button .k { font-weight: 600; color: var(--ink); }
.seg button:disabled { opacity: .55; cursor: default; }
.seg button:disabled .k { color: var(--muted); font-weight: 500; }
.seg.small { grid-template-columns: repeat(3, 1fr); }
.seg button[aria-checked="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 6px rgba(23, 20, 46, .18); }
.seg button[aria-checked="true"] b { color: var(--accent); }
.seg.small button { min-height: 40px; }
.go { border: 0; background: var(--accent); color: var(--on-accent); font-weight: 700; border-radius: 999px; min-height: 48px; padding: 0 34px; cursor: pointer; margin: 10px 4px 2px; font-size: 1.05rem; }
.btn { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: 0 16px; min-height: 42px; font-weight: 600; cursor: pointer; }
@media (hover: hover) { .btn:hover { border-color: var(--accent); } .go:hover { filter: brightness(1.08); } }
.row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
kbd { font: 600 .82rem/1 var(--font); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; padding: 2px 6px; background: var(--bg2); display: inline-block; min-width: 1.6em; text-align: center; }

/* ------------------------------------------------------------ results */
.panel.done { max-width: 470px; }
.kicker { margin: 0; color: var(--muted); font-size: .9rem; letter-spacing: .04em; }
.grade { margin: 6px 0 0; font-size: 1.15rem; font-weight: 700; }
.sch { font-weight: 600; color: var(--accent); letter-spacing: .02em; }
.big { margin: 0 0 2px; font-size: 2.5rem; font-weight: 800; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.badges { margin: 0 0 6px; display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; min-height: 0; }
.badges:empty { display: none; }
.badge { font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; padding: 4px 10px; border-radius: 999px; background: color-mix(in srgb, var(--pr-vertex) 22%, transparent); color: var(--ink); border: 1px solid var(--pr-vertex); }
.jg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 8px 0; }
.jg div { background: var(--bg2); border-radius: 12px; padding: 7px 4px; }
.jg dt { font-size: .78rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.jg dd { margin: 0; font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.jg .j-v dt { color: var(--pr-vertex); } .jg .j-e dt { color: var(--pr-edge); } .jg .j-f dt { color: var(--pr-face); } .jg .j-m dt { color: var(--pr-miss); }
.res-line { margin: 4px 0; font-size: .95rem; }
.hist-wrap { margin: 6px 0 4px; }
.hist { width: 100%; height: 64px; display: block; }
.hist-l { display: flex; justify-content: space-between; margin: 2px 0 0; color: var(--muted); font-size: .75rem; }
#btn-share { display: flex; align-items: center; justify-content: center; width: 100%; margin: 10px 0 0; }
.panel.done .go.tg-shareimg { margin: 8px 0 0; width: 100%; }
.rank { margin: 8px 0 0; min-height: 1.2em; color: var(--muted); font-size: .9rem; }
.lb-link { border: 0; background: none; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-weight: 600; min-height: 36px; }
.linkish { border: 0; background: none; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-weight: 600; padding: 0; font-size: inherit; }

/* ------------------------------------------------------------ dialogs, options, toast, footer */
dialog.dlg { border: 1px solid var(--line); border-radius: 20px; background: var(--card); color: var(--ink); max-width: min(480px, calc(100vw - 24px)); width: 100%; padding: 24px 22px;
  max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow: auto; }
dialog.dlg::backdrop { background: var(--backdrop); }
dialog.dlg h2 { margin: 0 0 10px; font-size: 1.35rem; }
dialog.dlg h3 { margin: 16px 0 6px; font-size: 1.02rem; display: flex; justify-content: space-between; align-items: baseline; }
dialog.dlg p { margin: 6px 0; }
dialog.dlg form:first-child { position: sticky; top: 0; height: 0; z-index: 3; }
.x { position: absolute; top: -14px; right: -12px; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--bg2); font-size: 1.5rem; cursor: pointer; line-height: 1; }
dialog.dlg .go { display: block; margin: 14px auto 0; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 10px 0 0; }
.stats div { background: var(--bg2); border-radius: 12px; padding: 10px 6px; text-align: center; }
.stats dt { font-size: .78rem; color: var(--muted); }
.stats dd { margin: 2px 0 0; font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats-today { margin: 0 0 6px; font-weight: 500; }
input[type="range"] { width: 100%; accent-color: var(--accent); height: 32px; }
output { font-weight: 700; color: var(--accent); }
.off-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.off-row span { flex: 1; }
.off-row b { min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; }
.btn.sq { width: 42px; padding: 0; font-size: 1.2rem; }
.cal { position: relative; margin: 10px 0 4px; border: 1px solid var(--line); border-radius: 16px; background: var(--pr-bg2); overflow: hidden; touch-action: none; cursor: pointer; user-select: none; -webkit-user-select: none; }
.cal-cv { display: block; width: 100%; height: 120px; }
.cal-msg { position: absolute; left: 0; right: 0; bottom: 6px; margin: 0 !important; text-align: center; font-size: .88rem; color: var(--pr-ink); padding: 0 10px; pointer-events: none; }
.chk { display: flex; align-items: center; gap: 10px; min-height: 40px; cursor: pointer; }
.chk input { width: 20px; height: 20px; accent-color: var(--accent); }
.toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 50; max-width: calc(100vw - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.ad-inline { margin: 18px 0; }
.foot { display: flex; flex-wrap: wrap; gap: 8px 18px; justify-content: center; padding: 18px 0 30px; color: var(--muted); font-size: .85rem; border-top: 1px solid var(--line); margin-top: 10px; }
.foot a { color: var(--muted); }

/* ------------------------------------------------------------ phones: the stage takes the screen */
@media (max-width: 640px) {
  .wrap { padding: 0 10px; }
  h1 { font-size: 1.6rem; }
  .stage { height: calc(100vh - 104px); height: calc(100dvh - 104px); min-height: 440px; border-radius: 16px; margin: 0 -4px; }
  .panel { padding: 16px 14px 14px; }
  .big { font-size: 2.1rem; }
  .ov { padding: 10px; }
}
/* while a song plays the page holds still: no scroll chaining from the stage */
body.pr-playing { overscroll-behavior: none; }
@media (prefers-reduced-motion: no-preference) {
  .count-n { animation: pr-pop .9s ease-out infinite; }
}
@keyframes pr-pop { 0% { transform: scale(1.25); opacity: .2; } 25% { transform: scale(1); opacity: 1; } 100% { transform: scale(.92); opacity: .85; } }
