:root {
  --bg: #09090b;
  --surface: #0f0f11;
  --surface-2: #18181b;
  --border: #232327;
  --border-2: #3a3a41;
  --text: #fafafa;
  --text-2: #a1a1aa;
  --text-3: #8e8e97;
  --accent: #f2836b;
  --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(10px, 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: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

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

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

.streak {
  margin-right: 4px;
  font-size: 13px;
  color: var(--text-3);
  white-space: nowrap;
}

.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 .field-card,
.screen.loading .dock { visibility: hidden; }

/* The whole play screen (field, margins, dock) is the touch surface; buttons excepted. */
#screen {
  touch-action: none;
  margin: 0 calc(-1 * var(--gutter));
  padding: 0 var(--gutter);
  cursor: grab;
}

#screen.running { cursor: grabbing; }
#screen.ended { cursor: pointer; }
#screen[data-control="finger"].running { cursor: none; }
#screen .btn { cursor: pointer; }

.field-hit {
  flex: none;
  padding: 0 0 8px;
  -webkit-user-select: none;
  user-select: none;
}

.field-card {
  position: relative;
  margin: 0 auto;
  border-radius: 12px;
  overflow: hidden;
}

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

.pill {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 6px 12px 7px;
  border: 1px solid var(--border-2);
  border-radius: 11px;
  background: rgba(20, 20, 23, 0.94);
  text-align: center;
  pointer-events: none;
  transition: opacity 0.2s;
}

.pill.fade { opacity: 0; }

.pill-main {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.pill-main .medal-word[data-medal="gold"] { color: var(--gold); }
.pill-main .medal-word[data-medal="silver"] { color: var(--silver); }
.pill-main .medal-word[data-medal="bronze"] { color: var(--bronze); }

.pill-sub {
  margin-top: 1px;
  font-size: 12.5px;
  color: var(--text-2);
}

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

.pill .tag {
  color: var(--accent);
  font-weight: 600;
}

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

.dock {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  min-height: 0;
}

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

.stat {
  flex: 1 1 0;
  min-width: 0;
}

.stat-val {
  font-size: 28px;
  line-height: 1.05;
  font-weight: 650;
  letter-spacing: -0.03em;
  white-space: nowrap;
}

.stat-val.dim { color: var(--text-3); }
.stat-val.warn { color: var(--accent); }
.stat-val.pulse { animation: pulse 0.32s ease-out; }

@keyframes pulse {
  0% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

#count { transform-origin: left center; }

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

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

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

.rung {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
}

.rung i {
  flex: none;
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-2);
}

.rung[data-medal="gold"].got i { background: var(--gold); }
.rung[data-medal="silver"].got i { background: var(--silver); }
.rung[data-medal="bronze"].got i { background: var(--bronze); }
.rung.got { color: var(--text-2); }
.rung.target { border-color: var(--border-2); }

.rung b {
  margin-left: auto;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.rung.got b, .rung.target b { color: var(--text); }
.rung.pop { animation: pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1); }

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

/* ---------- buttons ---------- */

.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 { transform: scale(0.97); }
.btn:focus-visible { outline: 2px solid var(--text-2); outline-offset: 2px; }

.btn-control {
  flex: none;
  width: 58px;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border-color: var(--border-2);
  color: #e4e4e7;
  font-size: 11px;
  font-weight: 600;
}

.btn-control svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#screen[data-control="drag"] .ic-finger,
#screen[data-control="finger"] .ic-drag { display: none; }

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

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

.btn-small {
  height: 34px;
  padding: 0 13px;
  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 -3px;
}

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

@media (max-height: 600px) {
  .top { height: 44px; }
  .stat-val { font-size: 24px; }
  .btn { height: 48px; }
  .rung { height: 30px; }
  .dock { gap: 6px; }
}

@media (max-width: 389px) {
  .stat-val { font-size: 24px; }
  .btn-restart { min-width: 84px; padding: 0 12px; }
  .ladder { gap: 6px; }
  .rung { gap: 5px; padding: 0 8px; }
  .rung b { font-size: 12px; }
}

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