:root {
  --bg: #1a1712;
  --card: #26221b;
  --line: #3a3429;
  --text: #f4efe4;
  --muted: #a89f8e;
  --accent: #e9a23b;
  --accent-ink: #1a1712;
  --danger: #e5574b;
  --p-bg: #c8322a;
  --p-fg: #fff;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }

/* ---------- Setup / stats ---------- */
.screen { min-height: 100dvh; }
#setup, #stats {
  max-width: 560px; margin: 0 auto;
  padding: calc(16px + var(--safe-t)) 16px calc(120px + var(--safe-b));
}
.top { display: flex; align-items: center; gap: 14px; margin: 8px 4px 20px; }
.logo { width: 46px; height: 46px; flex: none; }
.logo svg { width: 100%; height: 100%; fill: var(--accent); }
h1 { font-size: 26px; line-height: 1.1; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 17px; margin: 0 0 6px; letter-spacing: -0.01em; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.card { background: var(--card); border-radius: 18px; padding: 16px; margin-bottom: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.link { background: none; border: 0; color: var(--accent); padding: 6px 0; font-weight: 600; font-size: 15px; }

.players { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.players li { display: flex; align-items: center; gap: 4px; }
.swatch {
  width: 38px; height: 38px; border-radius: 50%; flex: none; margin-right: 4px;
  border: 3px solid rgba(255,255,255,.18);
}
.players input {
  flex: 1; width: 0; min-width: 0; height: 44px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  padding: 0 10px; font: inherit; font-size: 17px; margin-right: 2px;
}
.players input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.mini {
  width: 30px; height: 44px; border-radius: 10px; border: 0; padding: 0;
  background: transparent; color: var(--muted); font-size: 18px; flex: none;
}
.mini:disabled { opacity: .25; }
.add {
  margin-top: 10px; width: 100%; height: 46px; border-radius: 12px;
  border: 1px dashed var(--line); background: transparent; color: var(--muted); font-weight: 600;
}

.time-pick { display: flex; align-items: center; justify-content: center; gap: 22px; margin: 8px 0 14px; }
.time-pick > div { text-align: center; }
.time-pick small { display: block; color: var(--muted); font-size: 13px; }
.big-time { font-size: 48px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.03em; min-width: 3.2ch; text-align: center; display: inline-block; }
.round {
  width: 52px; height: 52px; border-radius: 50%; border: 0;
  background: var(--line); font-size: 26px; line-height: 1;
}
.round:active { transform: scale(.94); }
.chips { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.chips button {
  height: 38px; padding: 0; border-radius: 19px; border: 1px solid var(--line);
  background: transparent; font-weight: 600; font-variant-numeric: tabular-nums;
}
.chips button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.toggles { padding: 4px 16px; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row b { display: block; font-weight: 600; }
.row small { display: block; color: var(--muted); font-size: 13px; }
.row input {
  flex: none; width: 51px; height: 31px; margin: 0; position: relative;
  -webkit-appearance: none; appearance: none; border-radius: 16px; background: var(--line);
  transition: background-color .2s; cursor: pointer;
}
.row input::before {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.3); transition: transform .22s cubic-bezier(.3,.7,.3,1.2);
}
.row input:checked { background: var(--accent); }
.row input:checked::before { transform: translateX(20px); }
.row input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.bottom-cta {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 12px 16px calc(12px + var(--safe-b));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  display: grid; gap: 8px; max-width: 560px; margin: 0 auto;
}
.primary, .secondary {
  height: 56px; border-radius: 16px; border: 0; font-size: 18px; font-weight: 700;
}
.primary { background: var(--accent); color: var(--accent-ink); }
.secondary { background: var(--card); color: var(--text); font-weight: 600; font-size: 16px; height: 48px; }
.primary:active, .secondary:active { transform: scale(.98); }

/* ---------- Game ---------- */
#game {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  background: var(--p-bg); color: var(--p-fg);
  transition: background-color .35s ease, color .35s ease;
  user-select: none; -webkit-user-select: none;
  padding-top: var(--safe-t);
}
.g-top { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px 0; }
.pill {
  background: rgba(0,0,0,.18); padding: 6px 12px; border-radius: 14px;
  font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums;
}
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: rgba(0,0,0,.18); font-size: 22px; line-height: 1; color: inherit;
}
.tap-area {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2vh; padding: 8px 16px; cursor: pointer; min-height: 0;
}
.g-name {
  font-size: clamp(30px, 9vw, 64px); font-weight: 800; letter-spacing: -0.03em;
  text-align: center; line-height: 1.05; max-width: 100%; overflow-wrap: anywhere;
}
.ring-wrap { position: relative; width: min(78vw, 46vh, 420px); aspect-ratio: 1; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 12; }
.ring .track { stroke: rgba(0,0,0,.16); }
.ring .bar {
  stroke: currentColor; stroke-linecap: round;
  stroke-dasharray: 565.49; stroke-dashoffset: 0;
  transition: stroke-dashoffset .25s linear, stroke .3s;
}
.ring-text { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.g-time {
  font-size: min(20vw, 12vh, 110px); font-weight: 800; font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em; line-height: 1;
}
.g-sub { font-size: 15px; font-weight: 600; opacity: .8; margin-top: 6px; min-height: 1.4em; text-align: center; }
.g-hint { font-size: 14px; opacity: .7; text-align: center; }
.g-next { font-size: 16px; font-weight: 600; background: rgba(0,0,0,.16); padding: 8px 16px; border-radius: 20px; }
.g-next i { font-style: normal; display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin: 0 4px 0 2px; vertical-align: -1px; border: 2px solid rgba(255,255,255,.6); }

.g-bar {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  padding: 8px 12px calc(12px + var(--safe-b));
}
.g-bar button {
  height: 64px; border: 0; border-radius: 16px; background: rgba(0,0,0,.2); color: inherit;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 13px; font-weight: 600;
}
.g-bar button span { font-size: 20px; line-height: 1; }
.g-bar button em { font-style: normal; }
.g-bar button:active { transform: scale(.95); background: rgba(0,0,0,.3); }
.g-bar button:disabled { opacity: .35; }

/* warning / overtime */
#game.warn .g-time { animation: pulse 1s ease-in-out infinite; }
#game.over .ring .bar { stroke: #fff; }
#game.over::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: #b0160c; mix-blend-mode: multiply; animation: flash 1.2s ease-in-out infinite;
}
#game.over .g-time { color: #fff; }
@keyframes pulse { 50% { transform: scale(1.06); } }
@keyframes flash { 0%, 100% { opacity: .25; } 50% { opacity: .75; } }

.paused-layer {
  position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center;
  background: rgba(10,8,5,.72); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); color: #fff;
}
.paused-layer div { text-align: center; }
.paused-layer b { display: block; font-size: 44px; letter-spacing: -0.02em; }
.paused-layer span { opacity: .75; }

.flip { animation: flipIn .35s cubic-bezier(.2,.8,.2,1); }
@keyframes flipIn { from { transform: scale(.94); opacity: .4; } }

/* ---------- Sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 10; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0,0,0,.5); animation: fade .2s; }
.sheet-card {
  position: absolute; left: 0; right: 0; bottom: 0; max-width: 560px; margin: 0 auto;
  background: var(--card); color: var(--text); border-radius: 22px 22px 0 0;
  padding: 8px 16px calc(16px + var(--safe-b));
  animation: up .28s cubic-bezier(.2,.8,.2,1);
}
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 8px; }
.sheet-btn {
  display: block; width: 100%; height: 50px; margin-top: 8px; border: 0; border-radius: 14px;
  background: var(--line); font-weight: 600; text-align: left; padding: 0 16px;
}
.sheet-btn.danger { color: var(--danger); }
.sheet-btn.plain { background: transparent; text-align: center; color: var(--muted); }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

/* ---------- Stats ---------- */
.st { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.st th { text-align: right; font-size: 12px; color: var(--muted); font-weight: 600; padding: 0 4px 8px; }
.st th:first-child { text-align: left; }
.st td { text-align: right; padding: 10px 4px; border-top: 1px solid var(--line); font-size: 15px; }
.st td:first-child { text-align: left; font-weight: 600; white-space: nowrap; max-width: 34vw; overflow: hidden; text-overflow: ellipsis; }
.st .dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 8px; vertical-align: -1px; }
.st .bad { color: var(--danger); }

.toast {
  position: fixed; left: 50%; bottom: calc(100px + var(--safe-b)); transform: translateX(-50%);
  background: #000c; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 20;
  animation: fade .2s; max-width: calc(100% - 32px); text-align: center;
}

@media (orientation: landscape) and (max-height: 500px) {
  .tap-area { flex-direction: row; flex-wrap: wrap; gap: 4px 24px; }
  .ring-wrap { width: min(62vh, 40vw); }
  .g-name { width: 100%; font-size: 28px; }
  .g-hint { display: none; }
  .g-bar button { height: 48px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
