:root {
  --bark: #140e09;
  --ink: #fff6e4;
  --gold: #f0c14a;
  --cream: #f3e2c4;
  --green: #1f9d4a;
  --wood: #24160f;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bark);
  color: var(--ink);
  font-family: "Nunito Sans", "Trebuchet MS", sans-serif;
  overflow: hidden;
}

body {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; cursor: pointer; }

button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

button:disabled { cursor: default; }

::selection { background: var(--gold); color: #1a120c; }

.shell {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(120% 42% at 50% -8%, rgba(240, 193, 74, 0.28), transparent 56%),
    radial-gradient(70% 40% at 100% 100%, rgba(31, 157, 74, 0.16), transparent 50%),
    var(--bark);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.mast {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  border-bottom: 1px solid rgba(240, 193, 74, 0.35);
}

.badge {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 50%;
  position: relative;
  background: radial-gradient(circle at 38% 38%, #ffe56a, #f0b429);
  box-shadow: 0 0 0 2px var(--gold), 0 3px 0 #5a3414;
}

.badge span {
  position: absolute;
  top: 4px;
  left: 12px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #e23b3b;
}

.badge span::before,
.badge span::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #e23b3b;
}

.badge span::before { left: 7px; top: 2px; }
.badge span::after { left: 13px; top: 5px; width: 6px; height: 6px; }

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

.brand {
  margin: 0;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
}

.titles h1 {
  margin: 0;
  font-family: "Paytone One", "Trebuchet MS", sans-serif;
  font-size: 20px;
  font-weight: 400;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mini {
  flex: 0 0 auto;
  border: 1px solid rgba(240, 193, 74, 0.65);
  background: transparent;
  color: #ffe7ad;
  border-radius: 999px;
  min-height: 34px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 800;
}

main {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.view {
  display: none;
  height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
}

.view.is-on { display: block; }

#run.is-on {
  display: flex;
  overflow: hidden;
}

.play {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.hud {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 2px;
}

.hud-block { min-width: 0; }

.hud-score { flex: 1; text-align: center; }

.hud-block span,
.goal,
.record,
.end-stats dt {
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hud-block > span {
  display: block;
  font-size: 10px;
  font-weight: 800;
  color: #e7c98a;
}

.hud-score strong {
  font-family: "Paytone One", "Trebuchet MS", sans-serif;
  font-size: 28px;
  font-weight: 400;
  line-height: 0.95;
  color: #ffe08a;
  text-shadow: 0 2px 0 #6a3e10;
}

.hud-block strong {
  font-family: "Paytone One", "Trebuchet MS", sans-serif;
  font-size: 18px;
  font-weight: 400;
  color: var(--ink);
}

.feathers { display: flex; gap: 3px; height: 18px; align-items: flex-end; }

.feathers i {
  display: block;
  width: 12px;
  height: 16px;
  background: #3a2a1c;
  clip-path: polygon(50% 0, 100% 38%, 78% 100%, 22% 100%, 0 38%);
}

.feathers i.is-on { background: var(--gold); }

.route-line {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 0 12px 4px;
  font-size: 12px;
  font-weight: 800;
  min-width: 0;
}

.route-line span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#laneName { color: #c6ec7a; flex: 0 0 auto; }

.route-line b {
  margin-left: auto;
  color: var(--gold);
  font-weight: 800;
  flex: 0 0 auto;
}

.pips { display: inline-flex; gap: 3px; flex: 0 0 auto; }

.pips i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #5a3c22;
}

.pips i.is-on { background: var(--gold); }

.ripen {
  margin: 0 12px 4px;
  align-self: flex-start;
  color: #062414;
  background: var(--gold);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 800;
}

.ripen:empty { display: none; }

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: 0 10px;
  border-radius: 18px;
  overflow: hidden;
  background: #8fd4ff;
  box-shadow: inset 0 0 0 2px rgba(240, 193, 74, 0.55), 0 8px 0 rgba(0, 0, 0, 0.28);
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.screws { position: absolute; inset: 0; pointer-events: none; z-index: 4; }

.screws i {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff1c4, #c4922a 42%, #6a4a16);
}

.screws i:nth-child(1) { top: 7px; left: 7px; }
.screws i:nth-child(2) { top: 7px; right: 7px; }
.screws i:nth-child(3) { bottom: 7px; left: 7px; }
.screws i:nth-child(4) { bottom: 7px; right: 7px; }

.toast {
  position: absolute;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  z-index: 6;
  max-width: calc(100% - 24px);
  margin: 0;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--gold);
  background: rgba(20, 14, 9, 0.92);
  color: #ffe7ad;
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  opacity: 0;
  pointer-events: none;
}

.toast.is-on { opacity: 1; }

.veil {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 5;
  flex-direction: column;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px;
}

.veil.is-open { display: flex; }

.veil img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 40%;
  z-index: 0;
}

#startVeil::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(180deg, rgba(8, 16, 8, 0.05) 15%, rgba(10, 8, 6, 0.9) 78%);
  pointer-events: none;
}

.veil-copy, .veil .act, .veil-card { position: relative; z-index: 2; }

.veil-copy h2,
.veil-card h2 {
  margin: 0;
  font-family: "Paytone One", "Trebuchet MS", sans-serif;
  font-size: 26px;
  font-weight: 400;
  line-height: 1.05;
}

.veil-copy p,
.veil-card p {
  margin: 4px 0 0;
  font-size: 14px;
  line-height: 1.35;
  color: var(--cream);
}

.veil-copy p:last-child {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.veil-dim {
  justify-content: center;
  background: rgba(8, 6, 4, 0.62);
}

.veil-card {
  background: linear-gradient(180deg, rgba(36, 22, 14, 0.96), rgba(16, 10, 8, 0.96));
  border: 1px solid rgba(240, 193, 74, 0.5);
  border-radius: 18px;
  padding: 12px;
}

.veil-actions { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }

.act {
  position: relative;
  overflow: hidden;
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 999px;
  color: #062414;
  background: linear-gradient(180deg, #5eef86, #149443);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.5), 0 4px 0 #0c5a28;
  font-family: "Paytone One", "Trebuchet MS", sans-serif;
  font-size: 16px;
}

.act::after, .leap::after {
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  top: 4px;
  height: 34%;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.35);
  pointer-events: none;
}

.act:active, .dock button:active { transform: translateY(2px); }

.act:disabled {
  filter: saturate(0.45);
  box-shadow: none;
}

.meter {
  height: 7px;
  margin: 8px 12px 0;
  border-radius: 99px;
  overflow: hidden;
  background: #2a1a10;
  border: 1px solid rgba(240, 193, 74, 0.4);
}

.meter span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--green), var(--gold));
}

.goal {
  margin: 4px 12px 0;
  font-size: 11px;
  font-weight: 800;
  color: #e7c98a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.seals {
  display: flex;
  gap: 4px;
  padding: 6px 10px 0;
}

.seals button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 30px;
  padding: 0 4px;
  border-radius: 999px;
  border: 1px solid rgba(240, 193, 74, 0.35);
  background: var(--wood);
  color: var(--cream);
  font-size: 11px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seals button.is-on {
  background: var(--gold);
  color: #2a160c;
  border-color: var(--gold);
}

.seals button.is-locked { opacity: 0.45; }

.dock {
  display: flex;
  gap: 8px;
  padding: 8px 10px 8px;
}

.dock button {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  min-height: 48px;
  border: 0;
  border-radius: 999px;
  color: #2a160c;
  background: linear-gradient(180deg, #ffe08a, #e0a82a);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7), 0 3px 0 #7a5410;
  font-family: "Paytone One", "Trebuchet MS", sans-serif;
  font-size: 15px;
  overflow: hidden;
}

.leap {
  flex: 1.4;
  color: #062414;
  background: linear-gradient(180deg, #5eef86, #149443);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55), 0 3px 0 #0c5a28;
}

.bridge {
  position: relative;
  display: flex;
  gap: 6px;
  padding: 10px 10px calc(8px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, #3a2416, #1a0f0a);
  border-top: 2px solid var(--gold);
}

.bridge::before {
  content: "";
  position: absolute;
  left: 16px;
  right: 16px;
  top: 18px;
  height: 2px;
  background: repeating-linear-gradient(90deg, #e7c27a 0 8px, transparent 8px 13px);
  opacity: 0.75;
  pointer-events: none;
}

.plank {
  position: relative;
  z-index: 1;
  flex: 1 1 0;
  min-width: 0;
  border: 0;
  border-radius: 8px 8px 12px 12px;
  padding: 6px 2px 7px;
  color: #2a160c;
  background: linear-gradient(180deg, #e0b56e, #8a552c 58%, #6b3f1e);
  box-shadow: inset 0 1px 0 rgba(255, 236, 196, 0.75), 0 3px 0 #3a2012;
  font-family: "Paytone One", "Trebuchet MS", sans-serif;
  font-size: 12px;
}

.plank span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nail {
  display: block;
  width: 7px;
  height: 7px;
  margin: 0 auto 3px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff, #9a6a32 55%, #4a2c12);
}

.plank.is-on {
  background: linear-gradient(180deg, #ffe7a4, #f0b429 46%, #c4891a);
  box-shadow: inset 0 1px 0 #fff6d4, 0 0 12px rgba(240, 193, 74, 0.45);
  transform: translateY(-3px);
}

.plank.is-on .nail {
  background: radial-gradient(circle at 35% 35%, #fff, #f0c14a 40%, #8a5a12);
}

.sheet {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 12px 20px;
}

.kicker {
  margin: 0;
  color: var(--gold);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.sheet h2,
.veil-card h2,
.subhead {
  font-family: "Paytone One", "Trebuchet MS", sans-serif;
  font-weight: 400;
  color: var(--ink);
}

.sheet h2 {
  margin: 0;
  font-size: 28px;
  line-height: 1.05;
}

.lead, .card p, .fruit-row p, .rules li {
  margin: 0;
  color: var(--cream);
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: break-word;
}

.banner, .card img {
  width: 100%;
  display: block;
  object-fit: cover;
  border-radius: 16px;
}

.banner { height: 168px; }

.card {
  background: linear-gradient(180deg, #2c1b12, #160e0a);
  border: 1px solid rgba(240, 193, 74, 0.35);
  border-radius: 16px;
  overflow: hidden;
}

.card img {
  height: 148px;
  border-radius: 0;
}

.card.is-locked img { filter: grayscale(0.55) brightness(0.72); }

.body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 8px; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card h3, .fruit-row h3, .subhead {
  margin: 0;
  font-family: "Paytone One", "Trebuchet MS", sans-serif;
  font-size: 18px;
  font-weight: 400;
  color: var(--ink);
}

.subhead { font-size: 16px; }

.state {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 3px 8px;
  background: var(--green);
  color: #062414;
  font-size: 11px;
  font-weight: 800;
}

.card.is-locked .state { background: #3a2a1c; color: var(--cream); }

.record { font-size: 12px; font-weight: 800; color: #e7c98a; }

.fruit-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--wood);
  border: 1px solid rgba(240, 193, 74, 0.28);
  border-radius: 14px;
  padding: 10px;
}

.dot, .swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  flex: 0 0 auto;
  margin-top: 3px;
}

.dot.apple { background: #e23d3d; }
.dot.pear { background: #d6e04a; }
.dot.plum { background: #7a3e86; }
.dot.citrus { background: #f39a1a; }
.dot.gold { background: #ffd34a; box-shadow: 0 0 0 2px #a86b12; }
.swatch.rake { background: #efe8dc; }
.swatch.barrow { background: #c48a45; }
.swatch.fork { background: #d9dde2; }
.swatch.can { background: #1f9d4a; }
.swatch.gap { background: #1c6e86; }

.rules, .records {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rules li, .records li {
  background: var(--wood);
  border-radius: 12px;
  padding: 8px 10px;
}

.records li {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 8px;
  color: var(--ink);
}

.records span { flex: 1 1 120px; min-width: 0; font-weight: 800; }

.records em { font-style: normal; color: #e7c98a; font-size: 12px; font-weight: 800; }

.records b { color: var(--gold); margin-left: auto; }

.quiet {
  align-self: flex-start;
  border: 0;
  background: transparent;
  color: var(--gold);
  font-weight: 800;
  min-height: 44px;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.end-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 8px 0;
}

.end-stats div {
  min-width: 0;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 10px;
  padding: 6px 8px;
}

.end-stats dt { font-size: 10px; font-weight: 800; color: #e7c98a; }

.end-stats dd {
  margin: 0;
  font-family: "Paytone One", "Trebuchet MS", sans-serif;
  font-size: 18px;
  overflow-wrap: break-word;
}

.end-stats div:last-child { grid-column: 1 / -1; }

@media (max-width: 360px) {
  .titles h1 { font-size: 17px; }
  .hud-score strong { font-size: 22px; }
  .card img, .banner { height: 120px; }
  .sheet h2 { font-size: 24px; }
  .plank { font-size: 11px; }
  .dock button { font-size: 14px; }
}

@media (max-height: 520px) {
  .mast { min-height: 0; padding-top: calc(4px + env(safe-area-inset-top)); padding-bottom: 4px; }
  .badge { width: 28px; height: 28px; }
  .badge span { transform: scale(0.75); top: 2px; left: 8px; }
  .brand { display: none; }
  .titles h1 { font-size: 15px; }
  .goal, .seals, .meter { display: none; }
  .hud { padding-top: 2px; }
  .hud-score strong { font-size: 20px; }
  .dock { padding-top: 4px; padding-bottom: 4px; }
  .dock button, .act { min-height: 40px; }
  .bridge { padding-top: 6px; padding-bottom: calc(4px + env(safe-area-inset-bottom)); }
  .plank { padding: 4px 2px 5px; }
  .plank.is-on { transform: none; }
  .veil { padding: 8px; }
  .veil-copy h2, .veil-card h2 { font-size: 18px; }
  .veil-copy p:last-child { -webkit-line-clamp: 2; }
  .sheet { padding-top: 8px; gap: 8px; }
}

@media (min-width: 420px) and (min-height: 700px) {
  .card img { height: 180px; }
  .banner { height: 200px; }
  .titles h1 { font-size: 24px; }
  .hud-score strong { font-size: 34px; }
}
