:root {
  --bg: #09090b;
  --surface: #111113;
  --surface-2: #18181b;
  --border: #232327;
  --border-2: #3a3a41;
  --text: #fafafa;
  --text-2: #a1a1aa;
  --text-3: #8e8e97;
  --accent: #fb7185; /* rose: the player's ink */
  --shape: #ececef;
  --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; }

p { margin: 0; }

#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;
}

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

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

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

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

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

/* The touch target reaches the screen edges, so a stroke can start in the gutter. */
.stage {
  flex: none;
  display: flex;
  justify-content: center;
  margin: 0 calc(-1 * var(--gutter));
  padding: 4px var(--gutter);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.play.drawing .stage { cursor: crosshair; }

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

.play.drawing .card { border-color: var(--border-2); }

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

.timer {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.06);
  pointer-events: none;
}

.timer i {
  display: block;
  height: 100%;
  background: var(--shape);
  transform-origin: left center;
  will-change: transform;
}

.card-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  pointer-events: none;
  color: #3f3f46;
  font-size: 72px;
  font-weight: 650;
  letter-spacing: -0.04em;
}

.card-label small {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--text-3);
}

/* Canvas, status and strip sit as one group; spare height on tall phones goes above
   and (more of it) below the group, not into one big gap. */
.play-main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.spacer-top { flex: 1 1 0; max-height: 72px; }
.spacer-bottom { flex: 1.6 1 0; }

/* ---------- status ---------- */

.status {
  flex: none;
  height: 104px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 6px 2px;
}

.status-main {
  font-size: 20px;
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.status-sub {
  margin-top: 4px;
  font-size: 14px;
  line-height: 1.4;
  color: var(--text-2);
  text-wrap: pretty;
}

.status-sub:empty { display: none; }

.result { transition: opacity 0.2s; }

.result-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.score {
  font-size: 44px;
  line-height: 1;
  font-weight: 650;
  letter-spacing: -0.03em;
}

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

.verdict {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-2);
  transition: opacity 0.2s;
}

.result-bottom {
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 20px;
}

.note {
  font-size: 14px;
  color: #d4d4d8;
  transition: opacity 0.2s;
}

.legend {
  flex: none;
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text-3);
}

.legend span { display: inline-flex; align-items: center; gap: 5px; }

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

.sw-you { height: 4px; background: var(--accent); }
.sw-shape { height: 1.5px; background: var(--shape); }

.pending { opacity: 0; }

/* ---------- strip of rounds ---------- */

.strip {
  flex: none;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  padding: 2px 0 12px;
}

.slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.slot-box {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #3f3f46;
  font-size: 15px;
  font-weight: 600;
}

.slot.current .slot-box { border-color: #71717a; color: var(--text-2); }

.slot canvas { display: block; position: absolute; inset: 0; }

.slot-score {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  min-height: 18px;
}

.slot.empty .slot-score { color: transparent; }

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

.dock {
  flex: none;
  padding-top: 8px;
}

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

.btn {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid transparent;
  border-radius: 12px;
  height: 52px;
  padding: 0 18px;
  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, opacity 0.2s;
}

.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: 84px;
  border-color: var(--border-2);
  color: #e4e4e7;
}

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

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

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

.total-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 8px 0 18px;
}

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

.streak {
  font-size: 14px;
  color: var(--text-3);
}

.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: 14px;
  width: 100%;
  min-height: 80px;
  padding: 8px 16px 8px 8px;
  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: 7px;
  background: #0c0c0e;
}

.row-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.row-title {
  font-size: 15px;
  font-weight: 550;
  color: #e4e4e7;
}

.row-sub {
  font-size: 13px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

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

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

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

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

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0s !important; }
}
