/* ==========================================================================
   MARU — styles
   Brand: one saturated blue field, a white line, a yellow ring.
   Change the brand colours here (and in manifest.webmanifest + tools/make_assets.py).
   ========================================================================== */

:root {
  --field: #2747E6;        /* the playing field (background) */
  --field-deep: #1C36C4;   /* sheets, cards */
  --night: #0E1A6B;        /* text on yellow, deep shadow */
  --paper: #F5F7FF;        /* the white line, primary text */
  --sun: #FFD23F;          /* the moving ring, primary buttons */
  --sun-edge: #C99A12;     /* the pressable edge under yellow buttons */
  --coral: #FF8A9E;        /* misses */
  --mist: rgba(245, 247, 255, 0.74);
  --hair: rgba(245, 247, 255, 0.18);

  --font: ui-rounded, "SF Pro Rounded", "Hiragino Maru Gothic ProN", "Arial Rounded MT Bold",
          system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --radius-pill: 999px;
  --radius-sheet: 26px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --field: #1F3BC9; --field-deep: #172DA2; }
}
:root[data-theme="dark"] { --field: #1F3BC9; --field-deep: #172DA2; }

:root[data-contrast="on"] { --mist: var(--paper); --hair: rgba(245, 247, 255, 0.45); }
@media (prefers-contrast: more) { :root { --mist: var(--paper); --hair: rgba(245, 247, 255, 0.45); } }

*, *::before, *::after { box-sizing: border-box; }

html { height: 100%; background: var(--field); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--field);
  color: var(--paper);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: var(--sun); }
:focus-visible { outline: 3px solid var(--sun); outline-offset: 3px; border-radius: 8px; }
[hidden] { display: none !important; }
.offscreen { position: fixed; left: -9999px; top: 0; opacity: 0; }
.haptic-proxy { position: fixed; width: 1px; height: 1px; overflow: hidden; opacity: 0; pointer-events: none; }

/* -------------------------------------------------------------- frame ---- */

.app {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 520px;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  padding: var(--safe-top) calc(16px + var(--safe-right)) var(--safe-bottom) calc(16px + var(--safe-left));
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  flex: none;
}

.brand { display: flex; align-items: center; gap: 8px; height: 48px; padding-right: 6px; color: var(--paper); }
.mark { width: 34px; height: 34px; }
.mark-ring { stroke: var(--sun); }
.wordmark { height: 23px; width: auto; margin-top: 3px; }

.bar-actions { display: flex; gap: 2px; }
.icon-btn {
  display: grid; place-items: center;
  width: 46px; height: 46px; border-radius: 50%;
}
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: var(--paper); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:active { background: var(--hair); }
body[data-screen="play"] .bar-actions,
body[data-screen="play"] .brand { opacity: 0.35; pointer-events: none; }

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 4px 0 12px;
  text-align: center;
}

/* --------------------------------------------- what shows on which screen */

.hud, .ring-tag, .panel-home, .panel-results, .arena, .foot, .banner { display: none; }
body[data-screen="home"] .arena,
body[data-screen="home"] .panel-home,
body[data-screen="home"] .foot,
body[data-screen="home"] .banner:not([hidden]) { display: flex; }
body[data-screen="play"] .hud,
body[data-screen="play"] .arena,
body[data-screen="play"] .ring-tag { display: flex; }
body[data-screen="results"] .panel-results { display: flex; }
body[data-screen="results"] .main { justify-content: flex-start; padding-top: 8px; }
body[data-screen="results"] .banner:not([hidden]) { display: flex; }

/* -------------------------------------------------------------- arena ---- */

.arena {
  position: relative;
  aspect-ratio: 1;
  width: min(80vw, 44vh, 380px);
  width: min(80vw, 44svh, 380px);
  container-type: inline-size;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  cursor: pointer;
}
body[data-screen="play"] .arena {
  width: min(94vw, 60vh, 520px);
  width: min(94vw, 60svh, 520px);
}
.arena canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.callout {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  line-height: 1.05;
}
.callout b { font-size: 11.5cqw; font-weight: 900; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.callout span { font-size: 5.2cqw; font-weight: 800; }
.callout small { font-size: 3.8cqw; font-weight: 700; color: var(--mist); margin-top: 0.3em; font-variant-numeric: tabular-nums; }
.callout.grade-maru b, .callout.grade-maru span { color: var(--sun); }
.callout.grade-miss b, .callout.grade-miss span { color: var(--coral); }
.callout.show { animation: callout 0.95s cubic-bezier(.2, .9, .3, 1.2) both; }
@keyframes callout {
  0% { opacity: 0; transform: scale(0.6); }
  14% { opacity: 1; transform: scale(1.08); }
  24% { transform: scale(1); }
  78% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---------------------------------------------------------------- hud ---- */

.hud { flex-direction: column; gap: 10px; width: 100%; max-width: 420px; }
.hud-row { display: flex; justify-content: space-between; align-items: baseline; font-weight: 700; color: var(--mist); }
.hud-score { font-size: 1.6rem; font-weight: 900; color: var(--paper); font-variant-numeric: tabular-nums; }

.pips { display: flex; justify-content: space-between; gap: 6px; list-style: none; margin: 0; padding: 0; }
.pip {
  flex: 1;
  max-width: 30px;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2.5px solid var(--hair);
  transition: transform 0.15s ease, background-color 0.15s ease;
}
.pip.is-current { border-color: var(--paper); transform: scale(1.12); }
.pip[data-grade], .grid [data-grade] .dot, .vs-dots i[data-grade] { border-color: transparent; }
.pip[data-grade="maru"], .grid [data-grade="maru"] .dot, .vs-dots [data-grade="maru"] { background: transparent; border: 4px solid var(--sun); }
.pip[data-grade="great"], .grid [data-grade="great"] .dot, .vs-dots [data-grade="great"] { background: var(--paper); }
.pip[data-grade="good"], .grid [data-grade="good"] .dot, .vs-dots [data-grade="good"] { background: var(--sun); }
.pip[data-grade="close"], .grid [data-grade="close"] .dot, .vs-dots [data-grade="close"] { background: rgba(245, 247, 255, 0.5); }
.pip[data-grade="miss"], .grid [data-grade="miss"] .dot, .vs-dots [data-grade="miss"] { background: transparent; border: 2.5px dashed var(--coral); }

.ring-tag {
  min-height: 1.6em;
  margin: 0;
  justify-content: center;
  font-weight: 800;
  color: var(--sun);
  font-size: 1.05rem;
}

/* --------------------------------------------------------------- home ---- */

.panel { flex-direction: column; align-items: center; width: 100%; }
.panel-home { gap: 10px; }
.pitch {
  margin: 4px 0 0;
  font-size: clamp(1.6rem, 7.4vw, 2.2rem);
  font-weight: 900;
  line-height: 1.08;
  letter-spacing: -0.02em;
  max-width: 16ch;
  text-wrap: balance;
}
.sub { margin: 0 0 8px; color: var(--mist); max-width: 30ch; text-wrap: balance; }
.meta { margin: 6px 0 0; color: var(--mist); font-size: 0.95rem; max-width: 34ch; text-wrap: balance; }

.cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 360px;
  min-height: 58px;
  padding: 0 24px;
  border-radius: var(--radius-pill);
  background: var(--sun);
  color: var(--night);
  font-size: 1.18rem;
  font-weight: 900;
  letter-spacing: -0.01em;
  text-decoration: none;
  box-shadow: 0 5px 0 var(--sun-edge);
  transform: translateY(0);
  transition: transform 0.06s ease, box-shadow 0.06s ease;
}
.cta:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--sun-edge); }

.btn-outline {
  width: 100%;
  max-width: 360px;
  min-height: 54px;
  border-radius: var(--radius-pill);
  border: 2.5px solid var(--paper);
  font-size: 1.08rem;
  font-weight: 800;
}
.btn-outline:active { background: var(--hair); }

.btn-small {
  flex: none;
  min-height: 40px;
  min-width: 64px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  background: var(--paper);
  color: var(--night);
  font-weight: 800;
  font-size: 0.95rem;
}

.link-btn { min-height: 44px; padding: 0 10px; color: var(--mist); font-weight: 700; text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 2px; }

.banner {
  width: 100%;
  max-width: 420px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 18px;
  background: var(--field-deep);
  text-align: left;
}
.banner p { margin: 0; }
.banner b { color: var(--sun); }
.banner-btn { flex: none; min-height: 44px; padding: 0 16px; border-radius: var(--radius-pill); background: var(--sun); color: var(--night); font-weight: 900; }

.foot {
  flex-wrap: wrap;
  justify-content: center;
  gap: 0 4px;
  padding: 4px 0 14px;
  flex: none;
}
.foot button { min-height: 44px; padding: 0 9px; color: var(--mist); font-size: 0.93rem; font-weight: 700; }
.foot button:active { color: var(--paper); }

/* ------------------------------------------------------------ results ---- */

.panel-results { gap: 6px; }
.panel-results p { margin: 0; }
.res-title { color: var(--mist); font-weight: 800; }
.res-score { line-height: 0.95; }
#resScore { font-size: clamp(4.6rem, 25vw, 6.4rem); font-weight: 900; color: var(--sun); letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }
.res-of { font-size: 1.4rem; font-weight: 800; color: var(--mist); margin-left: 4px; }
.res-tier { font-size: 1.45rem; font-weight: 900; }
.res-badges { min-height: 1.4em; color: var(--sun); font-weight: 800; font-size: 0.95rem; white-space: pre-wrap; }

.grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px 14px;
  list-style: none;
  margin: 8px 0 4px;
  padding: 0;
  width: 100%;
  max-width: 330px;
}
.grid li { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.grid .dot { width: 42px; height: 42px; border-radius: 50%; border: 2.5px solid var(--hair); }
.grid .num { font-size: 0.85rem; font-weight: 800; color: var(--mist); font-variant-numeric: tabular-nums; }
.grid li.pop { animation: pop 0.38s cubic-bezier(.2, .9, .3, 1.4) both; animation-delay: calc(0.5s + var(--i) * 0.06s); }
@keyframes pop { from { opacity: 0; transform: scale(0.3); } to { opacity: 1; transform: scale(1); } }

.res-facts { color: var(--mist); font-weight: 700; font-size: 0.95rem; }
.res-rank { font-weight: 800; color: var(--paper); background: var(--field-deep); padding: 8px 14px; border-radius: var(--radius-pill); }

.versus { flex-direction: column; gap: 8px; width: 100%; max-width: 380px; padding: 12px 14px; border-radius: 18px; background: var(--field-deep); }
.versus:not([hidden]) { display: flex; }
.vs-row { display: grid; grid-template-columns: minmax(0, 1fr) auto 3.2ch; gap: 10px; align-items: center; text-align: left; }
.vs-name { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vs-row b { text-align: right; font-variant-numeric: tabular-nums; }
.vs-dots { display: flex; gap: 3px; }
.vs-dots i { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--hair); }
.vs-dots [data-grade="maru"], .vs-dots [data-grade="miss"] { border-width: 2px; }
.vs-verdict { font-weight: 900; color: var(--sun); }

.actions { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; margin-top: 12px; }
.actions-quiet { display: flex; flex-wrap: wrap; justify-content: center; gap: 0 6px; }
.share-fallback {
  width: 100%; max-width: 360px; margin-top: 8px; padding: 10px;
  border-radius: 12px; border: 2px solid var(--hair); background: var(--field-deep); color: var(--paper);
  font: 600 0.95rem/1.4 var(--font); resize: none;
}
.next { color: var(--mist); font-weight: 700; margin-top: 2px !important; }
.next time { color: var(--paper); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------- sheets ---- */

dialog.sheet {
  position: fixed;
  inset: auto 0 0 0;
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  max-height: 88svh;
  margin: 0 auto;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  background: var(--field-deep);
  color: var(--paper);
  overflow: auto;
  overscroll-behavior: contain;
}
dialog.sheet[open] { animation: sheet-in 0.26s cubic-bezier(.2, .8, .3, 1) both; }
dialog.sheet::backdrop { background: rgba(8, 14, 60, 0.62); }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 700px) and (min-height: 600px) {
  dialog.sheet { inset: 0; margin: auto; border-radius: var(--radius-sheet); max-height: 84vh; }
}

.sheet-head {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 12px 8px 22px;
  background: var(--field-deep);
}
.sheet-head h2 { margin: 0; font-size: 1.35rem; font-weight: 900; }
.close { width: 46px; height: 46px; border-radius: 50%; font-size: 1.15rem; font-weight: 900; }
.close:active { background: var(--hair); }
.sheet-body { padding: 4px 22px calc(26px + var(--safe-bottom)); text-align: left; }
.sheet-body h3 { margin: 22px 0 8px; font-size: 1.05rem; font-weight: 900; }
.sheet-body p { margin: 0 0 10px; }
.lead { font-size: 1.12rem; font-weight: 800; }
.fine { font-size: 0.9rem; color: var(--mist); }
.center { text-align: center; }
.muted { color: var(--mist); }
.plain { margin: 0; padding-left: 1.1em; }
.plain li { margin-bottom: 6px; }
.how-art { display: block; width: 150px; margin: 4px auto 6px; }
.kinds { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
.kinds dt { font-weight: 900; color: var(--sun); }
.kinds dd { margin: 0; }
.legend { font-weight: 800; }
.cta-link { display: flex; margin: 10px auto 6px; }
.noscript { text-align: center; padding: 40px 20px; }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 6px 0 10px; }
.stat { display: flex; flex-direction: column; align-items: center; padding: 10px 4px; border-radius: 16px; background: rgba(245, 247, 255, 0.08); }
.stat b { font-size: 1.7rem; font-weight: 900; font-variant-numeric: tabular-nums; }
.stat span { font-size: 0.82rem; color: var(--mist); font-weight: 700; text-align: center; }

.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; height: 130px; align-items: end; }
.week-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; height: 100%; }
.week-bar { width: 100%; max-width: 30px; height: calc(var(--h) * 80px); min-height: 3px; border-radius: 8px 8px 3px 3px; background: var(--paper); }
.week-col.is-today .week-bar { background: var(--sun); }
.week-score { font-size: 0.72rem; color: var(--mist); font-weight: 700; font-variant-numeric: tabular-nums; }
.week-day { font-size: 0.8rem; font-weight: 800; }

.dist { display: flex; flex-direction: column; gap: 6px; }
.dist-row { display: grid; grid-template-columns: 4.2em 1fr; align-items: center; gap: 8px; }
.dist-label { font-weight: 800; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.dist-bar { width: calc(var(--w) * 100%); min-width: 26px; padding: 2px 8px; border-radius: 6px; background: rgba(245, 247, 255, 0.22); font-weight: 800; font-size: 0.85rem; text-align: right; }
.dist-bar.is-today { background: var(--sun); color: var(--night); }

.ach { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.ach li { display: flex; flex-direction: column; padding: 10px 12px; border-radius: 14px; background: rgba(245, 247, 255, 0.06); opacity: 0.55; }
.ach li.got { opacity: 1; background: rgba(255, 210, 63, 0.14); }
.ach li.got b::before { content: "⭕ "; }
.ach span { font-size: 0.88rem; color: var(--mist); }

.past { list-style: none; margin: 0; padding: 0; }
.past li { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 12px; min-height: 52px; border-bottom: 1px solid var(--hair); }

.tabs { display: flex; gap: 6px; padding: 4px; margin-bottom: 14px; border-radius: var(--radius-pill); background: rgba(245, 247, 255, 0.08); }
.tabs button { flex: 1; min-height: 42px; border-radius: var(--radius-pill); font-weight: 800; color: var(--mist); }
.tabs button[aria-selected="true"] { background: var(--paper); color: var(--night); }
.board { list-style: none; margin: 8px 0 0; padding: 0; }
.board li { display: grid; grid-template-columns: 2.6em 1fr auto; align-items: center; gap: 4px 10px; min-height: 46px; border-bottom: 1px solid var(--hair); }
.board li.is-me { color: var(--sun); font-weight: 900; }
.board .rank { font-weight: 900; color: var(--mist); font-variant-numeric: tabular-nums; }
.board .val { font-weight: 900; font-variant-numeric: tabular-nums; }
.board .day { grid-column: 2; margin-top: -8px; color: var(--mist); font-size: 0.78rem; }
.board-me { font-weight: 900; color: var(--sun); text-align: center; }

.setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 60px; border-bottom: 1px solid var(--hair); font-weight: 700; }
.setting-name span { display: flex; flex-direction: column; }
.setting-name strong { color: var(--sun); font-size: 1.1rem; }
.setting.danger span { color: var(--mist); font-weight: 600; font-size: 0.92rem; }
.switch { position: relative; flex: none; width: 56px; height: 34px; border-radius: var(--radius-pill); background: rgba(245, 247, 255, 0.22); transition: background 0.15s; }
.switch::after { content: ""; position: absolute; top: 4px; left: 4px; width: 26px; height: 26px; border-radius: 50%; background: var(--paper); transition: transform 0.15s; }
.switch[aria-checked="true"] { background: var(--sun); }
.switch[aria-checked="true"]::after { transform: translateX(22px); background: var(--night); }

/* -------------------------------------------------------------- toast ---- */

.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-top) + 8px);
  z-index: 50;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: var(--radius-pill);
  background: var(--night);
  color: var(--paper);
  font-weight: 800;
  text-align: center;
  box-shadow: 0 8px 24px rgba(8, 14, 60, 0.35);
  transform: translate(-50%, -16px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ----------------------------------------------------------- viewport ---- */

@media (max-height: 720px) {
  .sub { display: none; }
  body[data-screen="home"] .arena { width: min(72vw, 38svh, 380px); }
}

@media (max-height: 640px) {
  .bar { height: 52px; }
  .pitch { font-size: 1.5rem; }
  .grid .dot { width: 34px; height: 34px; }
  .main { gap: 10px; }
}

@media (min-width: 700px) {
  .main { gap: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-delay: 0ms !important; transition-duration: 0.01ms !important; }
  .callout.show { animation: none; opacity: 1; }
}
.sheet-head h2:focus { outline: none; }
