:root {
  --bg: #09090b;
  --surface: #0e0e10;
  --surface-2: #18181b;
  --border: #232327;
  --border-2: #3a3a41;
  --text: #fafafa;
  --text-2: #a1a1aa;
  --text-3: #8e8e97;
  --accent: #f26b4f;
  --accent-ink: #1a0b07;
  --gold: #c9a95c;
  --silver: #b9b9c2;
  --bronze: #a87a5b;
  --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: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

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

.top-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

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

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

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

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

.screen.loading .card,
.screen.loading .status,
.screen.loading .ladder,
.screen.loading .recent,
.screen.loading .dock,
.screen.loading .controls { visibility: hidden; }

/* The whole stage is the drag surface, not just the card. */
.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 calc(-1 * var(--gutter));
  padding: 4px var(--gutter) 8px;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  cursor: grab;
}

.stage:active { cursor: grabbing; }
.screen.flying .stage { cursor: pointer; }

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

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

.toast {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
  padding: 8px 12px;
  border: 1px solid var(--border-2);
  border-radius: 10px;
  background: rgba(24, 24, 27, 0.95);
  font-size: 13px;
  font-weight: 550;
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.25s;
}

.toast.out { opacity: 0; }

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

.status {
  flex: none;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  height: 56px;
  overflow: hidden;
}

.now { min-width: 0; }

.now-line {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.now-main {
  font-size: 24px;
  line-height: 1.15;
  font-weight: 650;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.now-main.hint { font-size: 20px; letter-spacing: -0.01em; }

.pips {
  display: inline-flex;
  gap: 5px;
  flex: none;
}

.pips i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #52525b;
}

.pips i.on {
  border-color: var(--accent);
  background: rgba(242, 107, 79, 0.25);
}

.now-sub {
  margin-top: 3px;
  font-size: 14px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.now-sub .new { color: var(--accent); font-weight: 600; }

.best {
  flex: none;
  text-align: right;
  min-width: 76px;
}

.best-label {
  font-size: 12px;
  color: var(--text-3);
}

.best-val {
  font-size: 22px;
  line-height: 1.2;
  font-weight: 650;
  letter-spacing: -0.02em;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.best-val i, .rung i {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border-2);
}

.best-val[data-medal="gold"] i, .rung[data-medal="gold"] i { background: var(--gold); }
.best-val[data-medal="silver"] i, .rung[data-medal="silver"] i { background: var(--silver); }
.best-val[data-medal="bronze"] i, .rung[data-medal="bronze"] i { background: var(--bronze); }
.rung:not(.got) i { opacity: 0.35; }

.best-val.pop { animation: pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1); }

@keyframes pop {
  0% { transform: scale(0.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* ---------- medal ladder ---------- */

.ladder {
  flex: none;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 4px;
}

.rung {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 7px;
  align-items: center;
  height: 42px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  white-space: nowrap;
  overflow: hidden;
}

.rung i { grid-row: 1 / 3; }

.rung-name {
  font-size: 12px;
  line-height: 1.2;
  color: var(--text-3);
}

.rung-need {
  font-size: 13px;
  line-height: 1.25;
  font-weight: 600;
  color: var(--text-2);
}

.rung.got { border-color: var(--border-2); }
.rung.got .rung-name { color: var(--text-2); }
.rung.got .rung-need { color: var(--text); }

/* ---------- recent aims ---------- */

.recent {
  flex: none;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  height: 44px;
  margin-top: 8px;
}

.recent-empty {
  grid-column: 1 / -1;
  align-self: center;
  margin: 0;
  font-size: 13px;
  color: var(--text-3);
  text-align: center;
}

.chip {
  appearance: none;
  -webkit-appearance: none;
  min-width: 0;
  height: 44px;
  padding: 0 6px;
  border: 1px solid var(--border-2);
  border-radius: 10px;
  background: none;
  color: var(--text);
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.15s, background-color 0.15s;
}

.chip b {
  font-size: 13px;
  line-height: 1.15;
  font-weight: 650;
  white-space: nowrap;
}

.chip span {
  max-width: 100%;
  font-size: 11px;
  line-height: 1.2;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip[aria-pressed="true"] { border-color: var(--accent); }
.chip:active:not(:disabled) { background: var(--surface-2); }
.chip:disabled { opacity: 0.45; cursor: default; }
.chip:focus-visible { outline: 2px solid var(--text-2); outline-offset: 2px; }

/* The Best button is the small-screen stand-in for the chips. */
#btn-best { display: none; }

/* ---------- dock: nudges ---------- */

.dock {
  flex: none;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.nudge {
  display: flex;
  align-items: stretch;
  height: 52px;
  border: 1px solid var(--border-2);
  border-radius: 12px;
  overflow: hidden;
}

.nudge-btn {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 48px;
  border: 0;
  background: none;
  color: #e4e4e7;
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: manipulation;
}

.nudge-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nudge-btn:active:not(:disabled),
.nudge-btn.held { background: var(--surface-2); }
.nudge-btn:disabled { color: #4a4a52; cursor: default; }
.nudge-btn:focus-visible { outline: 2px solid var(--text-2); outline-offset: -2px; }

.nudge-val {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.nudge-lbl {
  font-size: 11px;
  line-height: 1.1;
  color: var(--text-3);
}

.nudge-val b {
  font-size: 19px;
  line-height: 1.2;
  font-weight: 650;
  letter-spacing: -0.01em;
}

/* ---------- controls ---------- */

.controls {
  flex: none;
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.btn {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid transparent;
  border-radius: 12px;
  height: 52px;
  padding: 0 16px;
  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.97); }
.btn:focus-visible { outline: 2px solid var(--text-2); outline-offset: 2px; }

.btn-primary {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: var(--accent-ink);
}

.launch-n {
  font-weight: 500;
  opacity: 0.7;
}

.btn-primary.flying {
  background: var(--surface-2);
  border-color: var(--border-2);
  color: var(--text);
}

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

.btn-toggle[aria-pressed="true"] {
  background: var(--surface-2);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-small {
  height: 34px;
  padding: 0 14px;
  border-color: var(--border-2);
  border-radius: 10px;
  font-size: 14px;
  color: #e4e4e7;
  position: relative;
}

/* Taller hit area than it looks. */
.btn-small::after {
  content: "";
  position: absolute;
  inset: -6px -4px;
}

/* ---------- 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); }

/* ---------- short screens: keep the system big ---------- */

@media (max-height: 720px) {
  .top { height: 44px; }
  .status { height: 50px; }
  .now-main { font-size: 21px; }
  .best-val { font-size: 19px; }
  /* The medal ladder and the recent aims share one slot: rules first, then your launches. */
  .ladder { gap: 6px; margin-top: 2px; }
  .rung { height: 44px; grid-template-columns: auto auto 1fr; grid-template-rows: auto; }
  .rung i { grid-row: auto; }
  .rung-name { display: none; }
  .recent { margin-top: 2px; }
  .screen:not(.has-launches) .recent { display: none; }
  .screen.has-launches .ladder { display: none; }
  .nudge, .btn { height: 48px; }
  .dock, .controls { margin-top: 6px; }
}

@media (max-height: 600px) {
  .ladder, .recent { display: none !important; }
  #btn-best { display: inline-block; }
}

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