:root {
  --bg: #09090b;
  --surface: #111113;
  --surface-2: #18181b;
  --border: #232327;
  --border-2: #3a3a41;
  --text: #fafafa;
  --text-2: #a1a1aa;
  --text-3: #8e8e97;
  --accent: #f59e0b;
  --radius: 14px;
  --gutter: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
}

html {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  color: var(--text);
  font: 15px/1.4 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

#app {
  height: 100vh;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding:
    env(safe-area-inset-top, 0px)
    calc(var(--gutter) + env(safe-area-inset-right, 0px))
    max(12px, env(safe-area-inset-bottom, 0px))
    calc(var(--gutter) + env(safe-area-inset-left, 0px));
}

@media (min-width: 560px) {
  #app { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}

/* ---------- header ---------- */

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

.brand {
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.brand .num {
  margin-left: 4px;
  color: var(--text-3);
  font-weight: 500;
}

.progress { display: flex; gap: 6px; }

.progress i {
  width: 20px;
  height: 4px;
  border-radius: 2px;
  background: #2a2a2f;
  transition: background-color 0.2s;
}

.progress i.done { background: #6b6b74; }
.progress i.current { background: var(--text); }

/* ---------- play screen ---------- */

.screen {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.title-block {
  flex: none;
  padding: 2px 0 6px;
}

h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: -0.015em;
  text-wrap: balance;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.stage { flex: none; }

/* The touch target extends past the card to the screen edges and 12px above/below. */
.chart-hit {
  margin: 0 calc(-1 * var(--gutter));
  padding: 12px var(--gutter);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  cursor: crosshair;
}

.play.locked .chart-hit { cursor: default; }

.chart-card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.chart-card canvas {
  display: block;
  touch-action: none;
}

.hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 20px;
  text-align: center;
  background: rgba(17, 17, 19, 0.93);
  pointer-events: none;
  transition: opacity 0.2s;
}

.hint.out { opacity: 0; }

.hint p {
  margin: 0;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}

.hint-demo { width: 160px; height: 56px; overflow: visible; }

.hint-demo polyline {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 190;
  stroke-dashoffset: 190;
  animation: hint-draw 2.2s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}

@keyframes hint-draw {
  0% { stroke-dashoffset: 190; opacity: 1; }
  60% { stroke-dashoffset: 0; opacity: 1; }
  85% { stroke-dashoffset: 0; opacity: 0; }
  100% { stroke-dashoffset: 190; opacity: 0; }
}

/* ---------- dock ---------- */

.dock {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding-top: 4px;
}

.dock-draw {
  display: flex;
  gap: 10px;
}

.btn {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid transparent;
  border-radius: 12px;
  height: 52px;
  padding: 0 20px;
  font: 600 16px/1 var(--font);
  letter-spacing: -0.005em;
  color: inherit;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
}

.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:focus-visible { outline: 2px solid var(--text-2); outline-offset: 2px; }

.btn-primary {
  flex: 1;
  background: var(--text);
  color: #09090b;
}

.btn-primary:disabled {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-3);
  cursor: default;
}

.btn-secondary {
  flex: none;
  min-width: 96px;
  border-color: var(--border-2);
  color: #e4e4e7;
}

.btn-secondary:disabled {
  border-color: var(--border);
  color: #5b5b63;
  cursor: default;
}

.dock-reveal {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.reveal-foot {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.score {
  flex: none;
  font-size: 40px;
  line-height: 1;
  font-weight: 650;
  letter-spacing: -0.03em;
  transition: opacity 0.2s;
}

.reveal-foot .btn-primary { flex: 0 1 168px; }

.score .of, .total .of {
  margin-left: 3px;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--text-3);
}

.sw {
  display: inline-block;
  width: 16px;
  border-radius: 2px;
  vertical-align: middle;
}

.sw-you { height: 3px; background: var(--accent); }
.sw-act { height: 2px; background: var(--text); }

.reveal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 10px 0 12px;
  transition: opacity 0.25s;
}

.reveal-text {
  margin: 0 0 8px;
  font-size: 15px;
  line-height: 1.45;
  color: #d4d4d8;
}

.source {
  display: inline-block;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-3);
  text-decoration: underline;
  text-decoration-color: #4a4a52;
  text-underline-offset: 2px;
  padding: 4px 0;
}

.source:active { color: var(--text-2); }

#btn-next { flex: none; transition: opacity 0.25s, background-color 0.15s, transform 0.1s; }

.pending { opacity: 0; pointer-events: none; }

/* ---------- end screen ---------- */

.end {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-top: 8px;
}

.total {
  font-size: 56px;
  line-height: 1;
  font-weight: 650;
  letter-spacing: -0.035em;
  padding: 8px 0 20px;
}

.rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.row {
  appearance: none;
  -webkit-appearance: none;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 72px;
  padding: 10px 14px 10px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.15s, border-color 0.15s;
}

.row:active { background: var(--surface-2); border-color: var(--border-2); }

.row canvas {
  display: block;
  border-radius: 6px;
  background: #0c0c0e;
}

.row-title {
  font-size: 14px;
  line-height: 1.3;
  color: #d4d4d8;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.row-score {
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.end-actions {
  margin-top: auto;
  padding-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.end-actions .btn { flex: none; width: 100%; }

.countdown {
  margin: 0;
  text-align: center;
  font-size: 13px;
  color: var(--text-3);
}

.countdown b { color: var(--text-2); font-weight: 600; }

.countdown a { color: var(--text); }

/* ---------- error ---------- */

.error {
  justify-content: center;
  align-items: flex-start;
  gap: 6px;
  padding-bottom: 20vh;
}

.error-title { margin: 0; font-size: 17px; font-weight: 600; }
.error-detail { margin: 0; font-size: 13px; color: var(--text-3); }

/* ---------- readout ---------- */

.readout {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border: 1px solid var(--border-2);
  border-radius: 10px;
  background: rgba(28, 28, 32, 0.97);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  white-space: nowrap;
  visibility: hidden;
  will-change: transform;
}

.readout.show { visibility: visible; }

.ro-year {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-3);
}

.ro-val {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.ro-val b {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--text);
}

@media (prefers-reduced-motion: reduce) {
  .hint-demo polyline { animation: none; stroke-dashoffset: 0; }
  * { transition-duration: 0s !important; }
}
