/* Fern Golf — the course screen: the canvases, the heads-up display that
   floats over them, and the dialogs that appear in play (hole finished, how
   to play, no course). Built on css/ui.css. */

:root {
  /* How far the HUD sits in from the screen edge (and any notch). */
  --hud-t: max(12px, var(--safe-t));
  --hud-r: max(14px, var(--safe-r));
  --hud-b: max(12px, var(--safe-b));
  --hud-l: max(14px, var(--safe-l));
  --club: 56px;
}
@media (min-width: 900px) and (min-height: 600px) {
  :root { --hud-t: 18px; --hud-r: 20px; --hud-b: 18px; --hud-l: 20px; --club: 68px; }
}

/* ------------------------------ the course ------------------------------ */
#game {
  position: fixed;
  inset: 0;
  /* The sky. The course pictures are transparent round the course, so
     whatever the camera does, open space is sky, never the page colour. */
  background: linear-gradient(#c6dfe8, #eaf4ee);
}
/* Each biome's sky. */
html.biome-autumn #game { background: linear-gradient(#c9b4a6, #efe2d2); }
html.biome-highland #game { background: linear-gradient(#a9b7bf, #e1e6e6); }
html.biome-tropical #game { background: linear-gradient(#6ec8ee 0%, #bfe9f6 60%, #f4f8f2 100%); }
html.biome-twilight #game { background: linear-gradient(#3d3a6e, #e3946a); }
html.biome-desert #game { background: linear-gradient(#86c3e6, #f5e7c8); }
html.biome-neon #game { background: linear-gradient(#0b0b1f 0%, #1d1240 55%, #4a1650 100%); }
html.biome-sugar #game { background: linear-gradient(#f7b6d8 0%, #fcd6ea 55%, #fff1f8 100%); }

#ground-full, #ground, #course { position: absolute; top: 0; left: 0; }
/* The course pictures (js/draw.js): the whole hole, and on top of it a
   sharper screen-sized one when zoomed in. Both are moved by transform. */
#ground-full, #ground { z-index: 0; pointer-events: none; transform-origin: 0 0; }
#course {
  z-index: 1;
  width: 100%;
  height: 100%;
  display: block;
  cursor: default;
  /* No scroll, pinch-zoom or long-press callout stealing a drag on a
     touchscreen: the browser leaves every gesture on the course to the game. */
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
/* Over the golfer a drag takes a shot; anywhere else it moves the view.
   While dragging the pointer is captured, so the cursor is set on the page. */
#course.cursor-aim, body.is-aiming, body.is-aiming #course { cursor: crosshair; }
#course.cursor-grab { cursor: grab; }
#course.cursor-grabbing, body.is-panning, body.is-panning #course { cursor: grabbing; }

/* --------------------------------- HUD ---------------------------------- */
.hole-card, .hud-corner, .club-bar, .zoom-hole { position: absolute; z-index: 5; user-select: none; }
body.menu-open .hole-card, body.menu-open .hud-corner, body.menu-open .club-bar,
body.menu-open .zoom-hole, body.menu-open .pad-hints, body.menu-open .shot-dist { visibility: hidden; }

/* Top left: the hole. A green number block, the hole's name and course,
   then par, the shot you are on, your best and how far the pin is. */
.hole-card {
  top: var(--hud-t);
  left: var(--hud-l);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(46vw, 420px);
  padding: 6px 16px 6px 6px;
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow-float);
}
.hc-num {
  display: grid;
  place-items: center;
  width: 46px; height: 46px;
  flex: none;
  padding-bottom: 4px;
  border-radius: 14px;
  background: var(--green);
  box-shadow: inset 0 -4px 0 var(--green-lip);
  color: #fff;
  font: 700 24px/1 var(--font-display);
}
.hc-text { min-width: 0; }
.hc-line1 { display: flex; align-items: baseline; gap: 7px; white-space: nowrap; overflow: hidden; }
.hc-name { font: 600 17px/1.15 var(--font-display); overflow: hidden; text-overflow: ellipsis; }
.hc-course { font: 700 var(--fs-small)/1.15 var(--font-ui); color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; }
.hc-name:empty + .hc-course { font: 600 17px/1.15 var(--font-display); color: var(--ink); }
.hc-line2 { display: flex; align-items: center; gap: 10px; margin-top: 4px; font: 600 var(--fs-small)/1 var(--font-ui); color: var(--ink-2); white-space: nowrap; }
.hc-line2 b { color: var(--ink); font-weight: 800; font-variant-numeric: tabular-nums; }
.hc-line2 b.is-under { color: var(--green-ink); }
.hc-pin { display: inline-flex; align-items: center; gap: 3px; }
.hc-pin .ico { font-size: 13px; color: var(--coral); }
/* Eagle Hunt holes: a coin at the end of the card, grey until eagled. */
.hud-eagle { width: 26px; height: 26px; flex: none; margin-left: 2px; }
.hud-eagle svg, .eagle-badge svg { width: 100%; height: 100%; }
.eagle-disc { fill: var(--surface-2); }
.eagle-bird { fill: var(--ink-3); }
.is-earned > svg .eagle-disc, .is-earned .eagle-badge .eagle-disc, .eagle-badge.is-earned .eagle-disc { fill: var(--gold); }
.is-earned > svg .eagle-bird, .is-earned .eagle-badge .eagle-bird, .eagle-badge.is-earned .eagle-bird { fill: #7a4f00; }

/* Top right: wind, coins, level, pause. */
.hud-corner {
  top: var(--hud-t);
  right: var(--hud-r);
  display: flex;
  align-items: center;
  gap: 8px;
}
/* The wind shows as a windsock in the landing area while aiming, so the
   corner has no wind pill. */
.hud-wind { display: none !important; }
.wind-dial {
  display: grid;
  place-items: center;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--blue-soft);
  color: var(--blue-lip);
  font-size: 16px;
}
.wind-arrow { transition: transform 0.4s ease; }
.hud-wind b { font-weight: 600; }
/* At the start of a windy hole the wind badge swells a few times. */
.hud-wind.is-pulse { animation: wind-pulse 0.7s ease-in-out 3; }
@keyframes wind-pulse { 45% { transform: scale(1.12); box-shadow: var(--shadow-float), 0 0 0 6px rgba(69, 182, 247, 0.3); } }
.hud-cash b { font-weight: 600; }
.hud-points { padding-left: 8px; }
.hud-points .ico { font-size: 20px; color: var(--gold-lip); }
.hud-points b { font-weight: 600; }
.hud-points.is-bump, .hud-cash.is-bump { animation: pill-bump 0.55s cubic-bezier(.2, 1.5, .4, 1); }
@keyframes pill-bump { 0% { transform: scale(1); } 35% { transform: scale(1.3); box-shadow: var(--shadow-float), 0 0 0 8px rgba(255, 203, 61, 0.45); } 100% { transform: scale(1); } }
body.is-awarding .hud-corner { z-index: 33; }

/* Bottom centre: the clubs. Each is a picture with its name; the chosen one
   is a raised green block. A club you cannot hit from this lie fades back. */
.club-bar {
  left: 50%;
  bottom: var(--hud-b);
  transform: translateX(-50%);
  padding: 0;
  border-radius: 22px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-float);
}
#club-list { position: relative; display: flex; align-items: stretch; gap: 0; }
/* The chosen club: a green block the bar's full height, sliding along. */
.club-sel {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0;
  border-radius: 22px;
  background: var(--green);
  box-shadow: inset 0 -4px 0 var(--green-lip);
  pointer-events: none;
}
.club-sel.is-ready { transition: transform 0.32s cubic-bezier(.3, 1.25, .5, 1), width 0.32s ease; }
.club-sel.is-off { opacity: 0; }
.club {
  display: grid;
  grid-template-rows: 1fr auto;
  justify-items: center;
  gap: 2px;
  position: relative;
  z-index: 1;
  width: calc(var(--club) + 6px);
  height: calc(var(--club) + 14px);
  padding: 8px 0 10px;
  border-radius: 22px;
  color: var(--ink-2);
  transition: color 0.2s ease, transform 120ms ease;
}
.club .club-icon { display: grid; place-items: center; min-height: 0; width: 100%; }
.club .club-icon img { width: 68%; height: 100%; max-height: calc(var(--club) - 22px); object-fit: contain; transform: scale(var(--hover, 1)); transform-origin: 50% 80%; transition: transform 90ms ease; pointer-events: none; }
.club .n { font: 700 var(--fs-label)/1 var(--font-ui); }
.club.is-selected { color: #fff; }
.club.is-disabled { opacity: 0.3; }
.club.is-disabled .club-icon img { filter: grayscale(1); }
.club:not(.is-selected):not(.is-disabled):active { transform: scale(0.94); }

/* Bottom left: see the whole hole, and back. */
.zoom-hole { left: var(--hud-l); bottom: var(--hud-b); }
.zoom-hole[aria-pressed="true"] { background: var(--green); color: #fff; box-shadow: 0 3px 0 var(--green-lip), 0 10px 22px rgba(23, 51, 43, 0.18); }

/* How far the last shot went, top centre for a moment. */
.shot-dist {
  position: absolute;
  z-index: 6;
  left: 50%;
  /* Below the hole card and the corner pills, so a long tag never covers them. */
  top: calc(var(--hud-t) + 66px);
  transform: translateX(-50%);
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(23, 51, 43, 0.78);
  color: #fff;
  font: 500 15px/1 var(--font-display);
  white-space: nowrap;
  pointer-events: none;
  animation: shot-dist 2.6s ease both;
}
.shot-dist b { font-weight: 700; font-variant-numeric: tabular-nums; }
.shot-dist { display: flex; align-items: center; gap: 6px; }
.sd-tag { padding: 4px 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.18); font: 600 13px/1 var(--font-display); }
.sd-tag.is-good { background: var(--green); }
.sd-tag.is-wind { background: rgba(69, 182, 247, 0.85); }
@keyframes shot-dist {
  0% { opacity: 0; transform: translate(-50%, -8px); }
  12%, 80% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -4px); }
}

/* Controller hints along the bottom, only while a controller is in use. */
.pad-hints {
  display: none;
  position: absolute;
  z-index: 5;
  right: var(--hud-r);
  bottom: var(--hud-b);
  max-width: 34vw;
  padding: 8px 12px;
  border-radius: 14px;
  background: rgba(23, 51, 43, 0.72);
  color: rgba(255, 255, 255, 0.9);
  font: 600 var(--fs-label)/1.5 var(--font-ui);
  pointer-events: none;
}
.pad-hints b { color: var(--gold); }
body.pad-active .pad-hints { display: block; }
.hint-card { display: none; }

/* New-hole title: number, name and par in the middle of the course, fading
   in and out over the flyover. Never takes a tap. */
.hole-intro {
  position: absolute;
  z-index: 6;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: min(80vw, 640px);
  text-align: center;
  color: #fff;
  pointer-events: none;
  user-select: none;
  opacity: 0;
}
.hi-hole { font: 600 clamp(30px, 5.4vw, 60px)/1.05 var(--font-display); text-shadow: 0 3px 0 rgba(10, 40, 30, 0.22), 0 6px 22px rgba(10, 40, 30, 0.4); }
.hi-num { color: var(--gold); }
.hi-par {
  display: inline-block;
  margin-top: 10px;
  padding: 7px 16px;
  border-radius: 999px;
  background: rgba(23, 51, 43, 0.72);
  font: 600 clamp(14px, 2vw, 20px)/1 var(--font-display);
}
.hole-intro.is-playing { animation: hole-intro 1.9s ease-out forwards; }
.hole-intro.is-leaving { animation: hole-intro-out 0.3s ease-out forwards; }
@keyframes hole-intro {
  0% { opacity: 0; transform: translate(-50%, -42%); }
  14%, 70% { opacity: 1; transform: translate(-50%, -50%); }
  100% { opacity: 0; transform: translate(-50%, -54%); }
}
@keyframes hole-intro-out { to { opacity: 0; } }

/* "Birdie!" rising over the course as the ball drops. */
.hole-shout {
  position: absolute;
  z-index: 6;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  color: #fff;
  font: 700 clamp(36px, 6.4vw, 70px)/1 var(--font-display);
  text-shadow: 0 4px 0 rgba(10, 40, 30, 0.25), 0 8px 24px rgba(10, 40, 30, 0.45);
  white-space: nowrap;
  pointer-events: none;
  animation: shout 1.3s cubic-bezier(.2, .8, .3, 1) both;
}
@keyframes shout {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.7); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
  75% { opacity: 1; transform: translate(-50%, -62%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -78%) scale(1); }
}

/* Which build is running, top centre. Never takes a tap. */
.build-stamp {
  position: absolute;
  z-index: 4;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.75);
  font: 700 9px/1 var(--font-ui);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  user-select: none;
  white-space: nowrap;
}
body.menu-open .build-stamp { display: none; }

/* ------------------------------ how to play ----------------------------- */
#rules { z-index: 40; }
.rules-card { width: min(680px, 100%); padding: 16px 20px 20px; }
.rules-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.rules-head h2 { font-size: var(--fs-title); }
.rules-steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.rules-steps li { display: flex; gap: 10px; padding: 12px; border-radius: var(--r-tile); background: var(--green-soft); }
.rules-n { display: grid; place-items: center; width: 28px; height: 28px; flex: none; border-radius: 9px; background: var(--green); box-shadow: inset 0 -3px 0 var(--green-lip); color: #fff; font: 700 15px/1 var(--font-display); padding-bottom: 2px; }
.rules-steps h3 { font-size: var(--fs-body); margin-bottom: 3px; }
.rules-steps p { font-size: var(--fs-small); color: var(--ink-2); line-height: 1.35; }
.rules-list { display: grid; gap: 8px; margin: 14px 0 0; font-size: var(--fs-small); color: var(--ink-2); line-height: 1.45; }
.rules-list strong, .pad-help strong { color: var(--ink); }
.rules-card kbd { display: inline-block; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); box-shadow: 0 2px 0 var(--lip); font: 700 0.92em/1.4 var(--font-ui); color: var(--ink); }
.pad-help { margin-top: 14px; padding: 12px 14px; border-radius: var(--r-tile); background: var(--surface-2); font-size: var(--fs-small); color: var(--ink-2); line-height: 1.45; }
.pad-help h3 { display: flex; align-items: center; gap: 6px; font-size: var(--fs-body); margin-bottom: 6px; color: var(--ink); }
.pad-help h3 .ico { font-size: 20px; }
.pad-help p + p { margin-top: 6px; }
@media (max-width: 620px) { .rules-steps { grid-template-columns: 1fr; } }

.notice-card { width: min(440px, 100%); text-align: center; display: grid; gap: 10px; }
.notice-card h2, .notice-card h3 { font-size: var(--fs-title); }
.notice-card .btn-row { margin-top: 6px; }

/* ------------------------------- pause card ----------------------------- */
/* Over the dimmed course: the round's scorecard, Resume, and the way on. */
#pause { z-index: 32; }
.pause-card { width: min(1000px, 100%); display: grid; gap: 12px; padding: 16px 20px 18px; }
.pause-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.pause-head .label { margin-bottom: 4px; }
.pause-head h2 { font-size: var(--fs-title); }
.pause-total { min-height: 28px; padding: 0 12px; font: 600 var(--fs-body)/1 var(--font-display); }
.pause-note { margin-top: -4px; }
.pause-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.pause-card #pause-resume { max-width: 420px; justify-self: center; }
.pause-row { width: min(640px, 100%); justify-self: center; }
.pause-row .btn { padding: 0 10px; font-size: var(--fs-body); }
#pause-sound.is-off { --b-ink: var(--ink-3); }

.scorecard { display: grid; gap: 8px; }
.sc-block {
  display: grid;
  grid-template-columns: 44px repeat(9, minmax(0, 1fr)) 42px repeat(9, minmax(0, 1fr)) 42px 46px;
  grid-template-rows: repeat(3, auto);
  grid-auto-flow: row;
  border-radius: var(--r-tile);
  background: var(--surface-2);
  overflow: hidden;
}
.sc-label { display: flex; align-items: center; padding: 0 0 0 10px; font: 800 var(--fs-label)/1 var(--font-ui); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); }
.sc-cell { display: grid; place-items: center; min-height: 30px; font: 600 var(--fs-body)/1 var(--font-display); font-variant-numeric: tabular-nums; color: var(--ink-2); }
.sc-hole { min-height: 26px; font-size: var(--fs-small); color: var(--ink-3); }
.sc-cell.is-here { background: rgba(53, 198, 103, 0.14); }
.sc-hole.is-here { color: var(--green-ink); }
.sc-total, .sc-sum { background: rgba(23, 51, 43, 0.05); color: var(--ink); }
.sc-total { background: rgba(23, 51, 43, 0.09); }
.sc-hole.sc-sum { font: 800 var(--fs-label)/1 var(--font-ui); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); }
.sc-cell.is-none { color: var(--lip); }
.sc-hole.sc-total { font: 800 var(--fs-label)/1 var(--font-ui); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); }
.sc-score { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; color: var(--ink); font-weight: 600; }
.sc-score.is-birdie { background: var(--green); color: #fff; }
.sc-score.is-eagle { background: var(--gold); color: #5b3d00; box-shadow: 0 0 0 2px var(--surface-2), 0 0 0 4px var(--gold); }
.sc-score.is-bogey { background: var(--coral-soft); color: var(--coral-ink); border-radius: 7px; }
.sc-score.is-double { background: var(--coral); color: #fff; border-radius: 7px; }
.sc-score.is-live { color: var(--green-ink); box-shadow: inset 0 0 0 2px var(--green); }

/* A short phone: a tighter card, so 18 holes still fit. */
@media (max-height: 430px) {
  .pause-card { gap: 8px; padding: 12px 18px 14px; }
  .pause-card .btn.is-big { min-height: var(--tap); font-size: var(--fs-head); }
  .sc-cell { min-height: 24px; }
  .sc-hole { min-height: 20px; }
  .sc-score { width: 22px; height: 22px; font-size: 13px; }
  .scorecard { gap: 6px; }
  .pause-row .btn { min-height: 40px; }
}
@media (min-width: 900px) and (min-height: 600px) {
  .pause-card { width: min(1000px, 100%); gap: 16px; padding: 22px 26px 24px; }
  .sc-cell { min-height: 38px; }
  .sc-score { width: 30px; height: 30px; }
}

/* ----------------------------- hole finished ---------------------------- */
/* One box for every step. The first pops in; each later step slides in
   from the right inside the same box. The result and round steps size to
   their content; the cards step has a fixed height so the card fits it. */
:root {
  --done-h: min(340px, calc(100dvh - 28px));
  --done-card-w: calc((var(--done-h) - 40px) * 0.473);
}
@media (min-width: 900px) and (min-height: 600px) { :root { --done-h: 420px; } }
#done { background: rgba(16, 44, 36, 0.3); }
/* The popup's buttons can open the menu (another course, spend a skill
   point, create an account). The game keeps the popup up while the hole is
   finished, so it stands aside while the menu is open, and comes back if
   the menu is closed without starting anything. */
body.menu-open #done, body.menu-open #hole-shout { display: none !important; }
/* Confetti flies over the course as the ball drops, then over the card. */
.done-confetti { position: fixed; inset: 0; z-index: 31; width: 100%; height: 100%; pointer-events: none; }
#done .done-box {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(1000px, 100%);
  max-height: calc(100dvh - 24px);
  padding: 18px 24px 16px;
  overflow: hidden;
  text-align: center;
  animation: none;
}
#done .done-box.is-in { animation: pop-in 0.38s cubic-bezier(.2, .9, .3, 1.2) both; }
#done .done-step { display: none; min-height: 0; }
#done .done-actions { flex: none; display: grid; justify-items: center; gap: 8px; }
#done[data-step="cards"] .done-actions { display: none; }
.done-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.done-buttons .btn { min-width: 190px; margin-bottom: 0; }
#done .done-step.slide-on { animation: slide-x 0.42s cubic-bezier(.2, .8, .25, 1) both; }
@keyframes slide-x { from { opacity: 0; transform: translateX(60px); } to { opacity: 1; transform: none; } }

/* The result: the course and hole, the scorecard in one row, then in
   turn the XP line, a level up and the coins. */
#done[data-step="result"] .step-result { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.done-hole { color: var(--ink-3); }
.sc-score.is-new { animation: score-pop 0.6s cubic-bezier(.2, 1.5, .4, 1) 0.35s both; }
@keyframes score-pop { from { opacity: 0; transform: scale(0.2); } to { opacity: 1; transform: scale(1); } }
.xp-row { display: flex; align-items: center; gap: 12px; opacity: 0; transform: translateY(8px); transition: opacity 0.35s ease, transform 0.35s ease; }
.show-xp .xp-row { opacity: 1; transform: none; }
.xp-level { flex: none; min-width: 64px; font: 600 var(--fs-head)/1 var(--font-display); }
.xp-level.is-next { text-align: right; color: var(--ink-3); }
.xp-bar {
  position: relative;
  flex: 1 1 auto;
  display: block;
  height: 30px;
  border-radius: 15px;
  background: var(--surface-2);
  box-shadow: inset 0 2px 0 rgba(23, 51, 43, 0.06);
  overflow: hidden;
}
.xp-bar > i { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--green); box-shadow: inset 0 -4px 0 var(--green-lip); transition: none; }
.xp-bar.is-flash { animation: bar-flash 0.5s ease-out; }
/* The XP earned, inside the bar. */
.xp-in {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font: 600 16px/1 var(--font-display);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
}
.done-gains { display: flex; justify-content: center; gap: 10px; min-height: 34px; }
.gain { min-height: 34px; padding: 0 16px; font: 600 var(--fs-head)/1 var(--font-display); font-variant-numeric: tabular-nums; animation: gain-in 0.5s cubic-bezier(.2, 1.4, .4, 1) both; }
.gain .ico { font-size: 1.1em; }
.gain.is-level { background: var(--green); color: #fff; box-shadow: 0 3px 0 var(--green-lip); }
.gain .coin { width: 20px; height: 20px; }
@keyframes gain-in { from { opacity: 0; transform: translateY(10px) scale(0.8); } to { opacity: 1; transform: none; } }
/* Something earned on its way to the top bar. */
.sp-fly {
  position: fixed; left: 0; top: 0; z-index: 45;
  display: grid; place-items: center;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--gold); color: #7a4f00; font-size: 18px;
  box-shadow: 0 3px 0 var(--gold-lip), 0 0 0 4px rgba(255, 203, 61, 0.35), 0 8px 20px rgba(23, 51, 43, 0.3);
  pointer-events: none;
}
.sp-fly.is-coin { background: none; box-shadow: none; }
.sp-fly.is-coin .coin { width: 28px; height: 28px; box-shadow: 0 2px 0 #b97d00, 0 6px 16px rgba(23, 51, 43, 0.3); }
.save-line { display: flex; align-items: center; justify-content: center; gap: 4px; font-size: var(--fs-small); color: var(--ink-2); }
.save-x { padding: 0 6px; color: var(--ink-3); font-size: 20px; line-height: 1; }

/* The course slide. */
#done[data-step="course"] .step-course { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 6px 0 4px; }
.course-burst { display: grid; place-items: center; width: 58px; height: 58px; border-radius: 18px; background: var(--green); box-shadow: 0 5px 0 var(--green-lip); color: #fff; font-size: 30px; animation: badge-pop 0.6s cubic-bezier(.2, 1.5, .4, 1) both; }
@keyframes badge-pop { from { transform: scale(0) rotate(-30deg); } to { transform: none; } }
.step-course > .label { color: var(--ink-3); }
.course-title { font-size: clamp(26px, 7vh, 36px); }
.course-total { display: flex; align-items: center; gap: 10px; }
.course-total b { font: 700 clamp(36px, 10vh, 54px)/1 var(--font-display); }
.course-vs { min-height: 32px; padding: 0 14px; font: 600 var(--fs-head)/1 var(--font-display); }
.course-flags { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.course-flags .chip { min-height: 28px; }

/* A short phone: a tighter card. */
@media (max-height: 430px) {
  #done .done-box { padding: 14px 16px 12px; gap: 10px; }
  #done[data-step="result"] .step-result { gap: 10px; }
  .done-buttons .btn { min-height: 48px; font-size: var(--fs-head); }
}
@media (max-width: 620px) { .xp-level { min-width: 0; font-size: var(--fs-body); } }

/* Step 4: cards. The pack on the left, the words and the button on the
   right. Tap the pack: it tears open, the rarity shows and the box washes
   over in its colour, then the series, then the card turns over. */
#done[data-step="cards"] .done-box {
  height: var(--done-h);
  width: min(560px, 100%);
  display: grid;
  grid-template-columns: calc(var(--done-card-w) + 30px) minmax(0, 1fr);
  grid-template-rows: 1fr;
  column-gap: 20px;
  padding: 0 26px 0 0;
}
#done[data-step="cards"] .step-cards { display: contents; }
#done[data-step="cards"] .done-actions { display: none; }
.cards-stage { height: var(--done-h); padding: 20px 0 20px 30px; display: grid; align-content: center; }
.cards-text { display: flex; flex-direction: column; align-items: center; align-self: center; text-align: center; }
#done .step-cards.slide-on .cards-stage, #done .step-cards.slide-on .cards-text { animation: slide-x 0.42s cubic-bezier(.2, .8, .25, 1) both; }
.cards-title { font-size: clamp(24px, 7vh, 34px); }
.cards-count { min-height: 1.2em; margin-top: 4px; font: 700 var(--fs-body)/1.2 var(--font-ui); }
.cards-reveal { min-height: 92px; margin: 8px 0 10px; display: flex; flex-direction: column; justify-content: center; gap: 3px; }
.cards-eyebrow { min-height: 12px; color: var(--tier-ink, var(--ink-3)); }
.cards-name { font: 700 clamp(22px, 6.4vh, 30px)/1.1 var(--font-display); color: var(--tier-ink, var(--ink)); }
.cards-name.is-waiting { font: 600 var(--fs-head)/1.2 var(--font-display); color: var(--ink-2); animation: wait-glow 1.6s ease-in-out infinite; }
.cards-meta { min-height: 1.2em; font: 700 var(--fs-body)/1.2 var(--font-ui); }
.is-pop { animation: reveal-pop 0.45s cubic-bezier(.2, .9, .3, 1.3) both; }
@keyframes reveal-pop { from { opacity: 0; transform: scale(0.6) translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes wait-glow { 50% { opacity: 0.55; } }
#cards-go { min-width: 190px; }
/* Keep the buttons' room while they are away, so nothing jumps. */
#cards-go[hidden], #cards-skip[hidden] { display: inline-flex !important; visibility: hidden; }
.cards-skip { margin-top: 4px; }

.cards-tint {
  position: absolute;
  inset: 0;
  z-index: 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.7s ease;
  background: radial-gradient(circle at calc(var(--done-card-w) / 2 + 30px) 50%, var(--tier-wash, #fff) 0, color-mix(in srgb, var(--tier-wash, #fff) 55%, transparent) 40%, transparent 85%);
}
.cards-tint.is-on { opacity: 1; }
.cards-tint.is-on.is-soft { opacity: 0.4; }
.cards-stage, .cards-text { position: relative; z-index: 1; }

/* The card itself: a back and a face, turned over when opened. */
.tcard { border-radius: 13.4% / 6.35%; }
.flip { display: block; width: var(--done-card-w); perspective: 800px; }
.flip-inner { display: block; position: relative; transition: transform 0.6s cubic-bezier(.3, .8, .3, 1.15); transform-style: preserve-3d; }
.flip.is-open .flip-inner { transform: rotateY(180deg); }
.flip-back, .flip-front { display: block; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.flip-front { position: absolute; inset: 0; transform: rotateY(180deg); }
.tcard.is-back {
  position: relative;
  display: block;
  aspect-ratio: 193.54 / 409.4;
  overflow: hidden;
  background: linear-gradient(165deg, #3ecf72 0%, #1f9a49 55%, #2bb35c 100%);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.35), 0 6px 0 rgba(23, 51, 43, 0.14);
}
.tcard.is-back img { position: absolute; left: 50%; top: 50%; width: 62%; height: auto; transform: translate(-50%, -50%); opacity: 0.95; }
.tcard-count {
  position: absolute; top: 5%; right: -4px;
  padding: 3px 7px; border-radius: 10px;
  background: var(--ink); color: #fff;
  font: 700 11px/1 var(--font-ui);
}
.tcard-new {
  position: absolute; top: -8px; left: 50%; transform: translateX(-50%);
  padding: 4px 9px; border-radius: 10px;
  background: var(--coral); color: #fff;
  font: 800 10px/1 var(--font-ui); letter-spacing: 0.08em; text-transform: uppercase;
}

/* The drumroll: the card trembles and glows in its rarity's colour. */
#done .flip.is-charging .flip-back {
  animation: card-tremble 0.12s linear infinite;
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.6), 0 0 0 6px var(--tier-wash), 0 0 34px 8px var(--tier-wash);
  transition: box-shadow 0.4s ease;
}
#done .flip.is-charging-hard .flip-back {
  animation-duration: 0.07s;
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.8), 0 0 0 9px var(--tier-wash), 0 0 60px 18px var(--tier-wash);
}
#done .flip.is-charging-hard .flip-inner { scale: 1.04; transition: scale 0.4s ease; }
@keyframes card-tremble {
  0% { translate: 0 0; rotate: 0deg; } 25% { translate: -2px 1px; rotate: -1deg; }
  50% { translate: 2px -1px; rotate: 1deg; } 75% { translate: -1px -1px; rotate: -0.5deg; } 100% { translate: 0 0; rotate: 0deg; }
}

/* The pack: a foil wrapper over the card, crimped top and bottom. On a tap
   it tears along a jagged line: the top strip flies off, the rest drops. */
#done .flip .wrap {
  position: absolute;
  inset: -2px -4px;
  z-index: 3;
  display: block;
  pointer-events: none;
  transform: translateZ(2px);
  filter: drop-shadow(0 6px 0 rgba(23, 51, 43, 0.16));
}
#done .flip .wrap-half {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  border-radius: 18px;
  overflow: hidden;
  background:
    linear-gradient(115deg, transparent 20%, rgba(255, 255, 255, 0.3) 32%, transparent 44%, transparent 62%, rgba(255, 255, 255, 0.18) 72%, transparent 82%),
    linear-gradient(160deg, #46d67b 0%, #25a652 45%, #35c667 100%);
  transition: transform 0.55s cubic-bezier(.3, .1, .6, 1), opacity 0.55s ease;
}
#done .flip .wrap-top {
  clip-path: polygon(0 0, 100% 0, 100% 17%, 92% 19%, 84% 16.5%, 76% 19.5%, 68% 16.5%, 60% 19.5%, 52% 16.5%, 44% 19.5%, 36% 16.5%, 28% 19.5%, 20% 16.5%, 12% 19.5%, 4% 16.5%, 0 18%);
}
#done .flip .wrap-bot {
  clip-path: polygon(0 18%, 4% 16.5%, 12% 19.5%, 20% 16.5%, 28% 19.5%, 36% 16.5%, 44% 19.5%, 52% 16.5%, 60% 19.5%, 68% 16.5%, 76% 19.5%, 84% 16.5%, 92% 19%, 100% 17%, 100% 100%, 0 100%);
}
#done .flip .wrap-half img { width: 54%; height: auto; }
#done .flip .wrap-word { font: 600 12px/1 var(--font-display); letter-spacing: 0.16em; text-transform: uppercase; color: rgba(255, 255, 255, 0.9); }
#done .flip .wrap-crimp {
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 8%;
  background: repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.28) 0 3px, rgba(0, 0, 0, 0.08) 3px 6px), rgba(0, 0, 0, 0.08);
}
#done .flip .wrap-crimp.is-bot { top: auto; bottom: 0; }
#done .flip.is-unwrapped .wrap-top { transform: translate(40%, -140%) rotate(24deg); opacity: 0; }
#done .flip.is-unwrapped .wrap-bot { transform: translateY(18%) scale(0.96); opacity: 0; transition-delay: 0.08s; }
#done .flip.is-open .wrap { display: none; }
/* While sealed, the pack asks to be opened: it floats and a sheen sweeps it. */
#done .flip:not(.is-unwrapped) .flip-inner { animation: card-float 2.4s ease-in-out infinite; }
@keyframes card-float { 0%, 100% { translate: 0 0; rotate: 0deg; } 50% { translate: 0 -6px; rotate: -1.5deg; } }
#done .flip:not(.is-unwrapped) .wrap-bot::after {
  content: "";
  position: absolute;
  inset: -20% -60%;
  background: linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.4) 50%, transparent 60%);
  animation: card-sheen 2.8s ease-in-out 0.6s infinite;
}
@keyframes card-sheen { 0% { transform: translateX(-70%); } 45%, 100% { transform: translateX(70%); } }

/* -------------------------------- rotate -------------------------------- */
body.is-portrait #game { filter: blur(14px); pointer-events: none; }
#rotate-lock {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(16, 44, 36, 0.45);
}
.rotate-card { display: grid; justify-items: center; gap: 18px; text-align: center; }
.rotate-phone { width: 72px; height: 110px; filter: drop-shadow(0 6px 0 rgba(23, 51, 43, 0.25)); animation: rotate-to-landscape 2.2s ease-in-out infinite; }
.rotate-card p { font: 600 clamp(20px, 6vw, 30px)/1.2 var(--font-display); color: #fff; text-shadow: 0 2px 0 rgba(10, 40, 30, 0.3); }
@keyframes rotate-to-landscape { 0%, 18% { transform: rotate(0deg); } 55%, 78% { transform: rotate(-90deg); } 100% { transform: rotate(0deg); } }

/* ----------------------------- special modes ---------------------------- */
/* Developer tools (never shown). */
.card-tools { display: none; }

/* Cover mode (the course photographer): only the course shows. */
html.cover-mode #splash,
html.cover-mode #game > :not(canvas),
html.cover-mode body > :not(#game):not(script) { display: none !important; }
/* The hidden frame the game uses to photograph a course. It must stay in
   view (so the browser keeps drawing it) but can't be seen or touched. */
.cover-camera { position: fixed; left: 0; top: 0; width: 720px; height: 540px; border: 0; opacity: 0; pointer-events: none; z-index: -1; }

/* Playing a hole from the editor: just the hole, the clubs, the wind and
   the pencil back to the editor. */
html.draft-play #hole-card,
html.draft-play #hud-level,
html.draft-play #hud-cash,
html.draft-play #menu-toggle,
html.draft-play #zoom-hole { display: none !important; }

/* The sprite editor's scene (?lab=1): just the hole. */
html.lab-mode #hud-editor,
html.lab-mode #hole-card,
html.lab-mode #hud-level,
html.lab-mode #hud-cash,
html.lab-mode #menu-toggle,
html.lab-mode #zoom-hole,
html.lab-mode .club-bar,
html.lab-mode #hud-wind,
html.lab-mode #hole-shout,
html.lab-mode .shot-dist,
html.cover-mode .shot-dist { display: none !important; }
html.lab-mode #game canvas { cursor: crosshair; }

/* Debug panel (draft play, ?debug=1). */
.debug-panel {
  position: absolute; left: 10px; top: 76px; z-index: 30; margin: 0;
  padding: 8px 10px; border-radius: 8px; pointer-events: none;
  background: rgba(10, 20, 14, 0.78); color: #d8f5df;
  font: 11px/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre;
}
body.menu-open .debug-panel { display: none; }

/* ----------------------------- small screens ---------------------------- */
/* A short phone: tighten the HUD so the course keeps the room. */
@media (max-height: 360px), (max-width: 700px) {
  :root { --club: 50px; }
  .hc-num { width: 40px; height: 40px; font-size: 21px; border-radius: 12px; }
  .hc-name, .hc-name:empty + .hc-course { font-size: 15px; }
  .hc-course { display: none; }
  .hc-name:empty + .hc-course { display: inline; }
  .hc-line2 { gap: 8px; }
  .hud-corner { gap: 6px; }
  .hud-corner .pill { min-height: 36px; font-size: 14px; }
  .hud-corner .ring, .hud-corner .icon-btn, .zoom-hole { width: 40px; height: 40px; }
}
@media (max-width: 700px) { .hc-line2 .hc-rec { display: none; } }

@media (prefers-reduced-motion: reduce) {
  .hole-intro.is-playing { animation-name: hole-intro-still; }
  @keyframes hole-intro-still { 0%, 100% { opacity: 0; } 12%, 72% { opacity: 1; } }
  .sc-score.is-new, .gain, .hud-points.is-bump, .hud-cash.is-bump, .is-pop, .cards-name.is-waiting,
  #done .flip .flip-inner, #done .flip .flip-back, #done .flip .wrap-bot::after,
  #done .done-step.slide-on, #done .step-cards.slide-on > *, .rotate-phone { animation: none !important; }
  .flip-inner { transition: none; }
  #done .flip .wrap-half { transition-duration: 0.2s; }
  .hud-wind.is-pulse { animation-iteration-count: 1; }
  .club, .club .club-icon img { transition: none; }
}
