/* Fredoka (SIL Open Font License, vendor/fonts/OFL.txt), served from here
   rather than Google Fonts so it works offline and nothing goes to a third
   party. One variable font file covers every weight. */
@font-face {
  font-family: 'Fredoka';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url(../vendor/fonts/fredoka-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Fredoka';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url(../vendor/fonts/fredoka-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --ink: #1f3550;
  --chip: rgba(255, 255, 255, 0.86);
  --accent: #ef476f;
  --accent-ink: #c0294f;   /* accent dark enough for text and white-on-accent */
  --good: #047a5c;
  --shadow: 0 4px 14px rgba(20, 50, 80, 0.18);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #9fd3f5;
  font-family: 'Fredoka', system-ui, sans-serif;
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

#grab {
  position: fixed;
  left: 0;
  top: 0;
  border: 2px dashed rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  pointer-events: none;
  animation: grab-pulse 1.6s ease-in-out infinite;
}
@keyframes grab-pulse { 50% { border-color: rgba(255, 255, 255, 0.35); } }
@media (prefers-reduced-motion: reduce) { #grab { animation: none; } }

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.card .btn:focus-visible { outline-color: var(--accent-ink); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 18px;
  background: var(--chip);
  box-shadow: var(--shadow);
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.chip b { font-weight: 700; }
.chip.icon { width: 44px; height: 44px; padding: 0; justify-content: center; font-size: 20px; border-radius: 50%; }
button.chip:active { transform: scale(0.94); }
.chip.icon { position: relative; }
.chip.icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
/* A word under each camera button: the icons alone are easy to misread. */
.chip.icon .cap {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 3px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink);
  text-shadow: 0 0 3px #fff, 0 0 6px #fff;
  pointer-events: none;
}
button.chip[aria-pressed="true"] { background: var(--ink); color: #fff; }

#hud {
  position: fixed;
  top: calc(10px + var(--safe-top));
  left: 10px;
  right: 10px;
  pointer-events: none;
}
#hud .row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
#hud button { pointer-events: auto; }
#hud-name { margin-top: 6px; font-weight: 600; }
body.aiming #hud-name { visibility: hidden; }
#hud-total-chip.under b { color: var(--good); }
#hud-total-chip.over b { color: var(--accent-ink); }

#cam-controls {
  position: fixed;
  right: 10px;
  bottom: calc(28px + var(--safe-bottom));
  display: flex;
  gap: 10px;
}

/* The mulligan won on the bonus island: bottom left, clear of the camera
   buttons, until it's used. */
#mulligan {
  position: fixed;
  left: calc(10px + env(safe-area-inset-left, 0px));
  bottom: calc(28px + var(--safe-bottom));
  height: 44px;
  padding: 0 14px 0 8px;
  gap: 8px;
  background: #fff4c9;
  border: 2px solid #e0a800;
  font-weight: 600;
}
#mulligan:disabled { opacity: 0.6; cursor: default; }
#mulligan:not(:disabled) { animation: mulligan-glow 1.6s ease-in-out infinite; }
@keyframes mulligan-glow { 50% { box-shadow: 0 0 0 4px rgba(255, 210, 63, 0.45), var(--shadow); } }
@media (prefers-reduced-motion: reduce) { #mulligan:not(:disabled) { animation: none; } }
.gold-ball {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6c2, #ffd23f 45%, #c99400);
  box-shadow: inset 0 -1px 2px rgba(0, 0, 0, 0.2);
}

/* At the top, under the score chips: pulling back from the ball takes your
   finger down the screen, so anything lower would be under it. */
#power {
  position: fixed;
  left: 50%;
  top: calc(104px + var(--safe-top));
  width: min(260px, 60vw);
  height: 22px;
  transform: translateX(-50%);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: var(--shadow);
  overflow: hidden;
  pointer-events: none;
}
#power-fill { height: 100%; width: 0; background: #5ee07a; }
#power.cancel { background: rgba(31, 53, 80, 0.85); color: #fff; }
#power-text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
}

#hint {
  position: fixed;
  left: 10px;
  bottom: calc(32px + var(--safe-bottom));
  max-width: calc(100% - 250px);
  padding: 6px 10px;
  border-radius: 12px;
  background: rgba(31, 53, 80, 0.72);
  font-size: 13px;
  color: #fff;
  pointer-events: none;
}
.hint-touch { display: none; }
@media (pointer: coarse) {
  .hint-mouse { display: none; }
  .hint-touch { display: inline; }
}

#toast {
  position: fixed;
  top: calc(100px + var(--safe-top));
  left: 10px;
  transform: translateY(-8px);
  max-width: min(340px, calc(100% - 20px));
  padding: 10px 16px;
  border-radius: 16px;
  background: rgba(31, 53, 80, 0.9);
  color: #fff;
  font-size: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
#toast.show { opacity: 1; transform: translateY(0); }
#toast small { display: block; opacity: 0.85; font-size: 14px; margin-top: 2px; }

#overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(31, 53, 80, 0.28);
}
#overlay.show { display: flex; }
#overlay.clear { background: transparent; }

.card {
  width: min(420px, 100%);
  max-height: calc(100% - 16px);
  overflow-y: auto;
  padding: 22px 20px 20px;
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 18px 50px rgba(20, 50, 80, 0.3);
  text-align: center;
}
.card h1 { margin: 0; font-size: 40px; line-height: 1.05; letter-spacing: -0.5px; }
.card h1 .two { color: var(--accent-ink); }
.card h2 { margin: 0 0 4px; font-size: 30px; }
.card p { margin: 6px 0; font-size: 16px; }
.card .sub { opacity: 0.8; }
.card .big { font-size: 44px; font-weight: 700; margin: 4px 0; }
.card .new-best { color: var(--good); font-weight: 600; }
/* The end of a round: score and scorecard beside the route map when there's
   room (desktop, tablet), stacked on a phone. */
@media (min-width: 760px) and (min-height: 540px) {
  .card.wide {
    width: min(860px, 100%);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: center;
  }
  .card.wide .final-map .map { max-width: 380px; margin: 0 auto; }
}
.card .bonus-note { margin: 8px 0 0; padding: 8px 12px; border-radius: 12px; background: #fff4c9; font-size: 15px; }
.card .buttons { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.card .btn {
  height: 48px;
  border: 0;
  border-radius: 24px;
  background: #eef4fa;
  font-size: 18px;
  font-weight: 600;
}
.card .btn.primary { background: var(--accent-ink); color: #fff; }
.card .btn:active { transform: scale(0.97); }
.card .how { text-align: left; margin: 14px 0 0; padding-left: 20px; font-size: 15px; line-height: 1.45; }

/* Fixed columns and same-width digits, so the grid lines up whatever the
   scores are. */
.scorecard {
  width: 100%;
  margin-top: 12px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.scorecard col.label { width: 3em; }
.scorecard col.total { width: 2.8em; }
.scorecard th, .scorecard td { padding: 5px 0; border-bottom: 1px solid #e4ebf2; text-align: center; }
.scorecard th { font-weight: 500; opacity: 0.8; }
.scorecard th[scope="row"] { text-align: left; padding-left: 4px; }
.scorecard tr.par td { opacity: 0.75; }
.scorecard td.empty { opacity: 0.35; }
.scorecard td.under { color: var(--good); font-weight: 700; }
.scorecard td.over { color: var(--accent-ink); font-weight: 700; }
.scorecard td.void { opacity: 0.5; font-weight: 500; }
.scorecard td:last-child, .scorecard th:last-child { border-left: 1px solid #e4ebf2; }
.scorecard-note { margin: 6px 0 0; font-size: 12.5px; opacity: 0.75; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.scorecard td.current { background: #ffe9a8; box-shadow: inset 0 0 0 2px #e0b43c; }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; margin: 0; font-size: 18px; }

@media (max-width: 420px) {
  #hud .row { gap: 4px; }
  .chip { height: 34px; padding: 0 8px; font-size: 13.5px; }
  #hud-name { display: none; }   /* the hole's name is in the banner and the menu */
  #power { top: calc(58px + var(--safe-top)); }
  #toast { top: calc(56px + var(--safe-top)); }
  #hint { max-width: none; right: 10px; bottom: calc(96px + var(--safe-bottom)); }
}

/* Phone held sideways: one compact row of scores at the top left, the power
   bar at the top right (away from the finger pulling back), banners kept
   small, and cards get compact. */
@media (max-height: 500px) and (orientation: landscape) {
  #hud { right: auto; left: calc(10px + env(safe-area-inset-left, 0px)); }
  #hud .row { flex-wrap: nowrap; gap: 4px; }
  .chip { height: 32px; padding: 0 9px; font-size: 13.5px; }
  #hud .chip.icon { width: 36px; height: 36px; font-size: 17px; }
  #hud-name { display: none; }
  #power { top: calc(12px + var(--safe-top)); left: auto; right: calc(10px + env(safe-area-inset-right, 0px)); transform: none; width: min(220px, 30vw); }
  #cam-controls { right: calc(10px + env(safe-area-inset-right, 0px)); bottom: calc(24px + var(--safe-bottom)); gap: 8px; }
  #toast { top: calc(52px + var(--safe-top)); max-width: min(300px, 42vw); font-size: 14px; padding: 8px 12px; }
  #toast small { font-size: 13px; }
  #hint { bottom: calc(14px + var(--safe-bottom)); right: 240px; max-width: none; }
  #overlay { padding: 8px; }
  .card { width: min(640px, 100%); padding: 14px 18px; }
  .card h1 { font-size: 30px; }
  .card h2 { font-size: 24px; }
  .card .big { font-size: 34px; }
  .card p { margin: 3px 0; font-size: 15px; }
  .card .buttons { flex-direction: row; flex-wrap: wrap; margin-top: 10px; }
  .card .btn { flex: 1 1 160px; height: 44px; font-size: 16px; }
  .card .how { display: none; }
  .scorecard { margin-top: 6px; font-size: 13px; }
  .scorecard th, .scorecard td { padding: 2px; }
}

/* Labels over the signposts when choosing which bridge to cross. */
#paths { position: fixed; inset: 0; pointer-events: none; }
.path-choice {
  position: fixed;
  left: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 140px;
  padding: 10px 16px;
  border: 3px solid #fff;
  border-radius: 18px;
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
  pointer-events: auto;
  white-space: nowrap;
  animation: path-bob 1.6s ease-in-out infinite;
}
.path-choice b { font-size: 17px; }
.path-choice span { font-size: 13px; opacity: 0.85; }
.path-choice.gold { background: #b07d0c; border-color: #ffe08a; }
.path-choice:focus-visible { outline: 3px solid #fff; outline-offset: 3px; box-shadow: 0 0 0 6px var(--ink); }
.paths-title {
  position: fixed;
  top: calc(64px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 16px;
  background: var(--chip);
  box-shadow: var(--shadow);
  font-weight: 600;
  white-space: nowrap;
}
.path-leaders { position: fixed; inset: 0; width: 100%; height: 100%; overflow: visible; }
.path-leaders line { stroke: #fff; stroke-width: 3; stroke-linecap: round; filter: drop-shadow(0 1px 2px rgba(20, 50, 80, 0.5)); }
.path-leaders circle { fill: #fff; stroke: var(--ink); stroke-width: 2; }
@keyframes path-bob { 50% { margin-top: -6px; } }
@media (prefers-reduced-motion: reduce) { .path-choice { animation: none; } }

/* A white-out while crossing a bridge between islands. */
#fade {
  position: fixed;
  inset: 0;
  background: #f4f9ff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s;
}
#fade.on { opacity: 1; }

/* The course map. */
.map { display: block; width: 100%; max-width: 360px; margin: 8px auto 0; overflow: visible; }
.map .bridge { fill: none; stroke: #b49a72; stroke-width: 2.5; stroke-dasharray: 5 4; opacity: 0.55; }
.map .bridge.taken { stroke: var(--ink); stroke-dasharray: none; opacity: 0.85; stroke-width: 3; }
.map .bridge.gold { stroke: #e0a800; opacity: 0.6; }
.map .bridge.gold.open { opacity: 1; stroke-width: 3.5; stroke-dasharray: 7 4; }
.map .island .halo { fill: none; stroke: none; }
.map .island .name { font-size: 12.5px; font-weight: 600; text-anchor: middle; fill: var(--ink); paint-order: stroke; stroke: #fff; stroke-width: 3px; }
.map .island .par { font-size: 11px; text-anchor: middle; fill: var(--ink); opacity: 0.8; }
.map .island .score { font-size: 13px; font-weight: 700; text-anchor: middle; fill: #fff; paint-order: stroke; stroke: rgba(31, 53, 80, 0.7); stroke-width: 3px; }
.map .island .lock { font-size: 12px; text-anchor: middle; }
.map .island:not(.visited):not(.choice) { opacity: 0.55; }
.map .island.locked { opacity: 0.45; }
.map .island.here .halo { stroke: var(--ink); stroke-width: 2.5; }
.map .island.choice { cursor: pointer; }
.map .island.choice .halo { fill: rgba(255, 210, 63, 0.35); stroke: #e0a800; stroke-width: 3; animation: map-pulse 1.4s ease-in-out infinite; }
.map .island.choice:focus { outline: none; }
.map .island.choice:focus .halo { stroke: var(--ink); stroke-width: 4; }
.map .island.under .score { fill: #b8ffd9; }
.map .island.pale .score { fill: var(--ink); stroke: rgba(255, 255, 255, 0.85); }
.map .island.over .score { fill: #ffd1dc; }
@keyframes map-pulse { 50% { fill: rgba(255, 210, 63, 0.1); } }
@media (prefers-reduced-motion: reduce) { .map .island.choice .halo { animation: none; } }
.card .legend { font-size: 13px; opacity: 0.8; margin-top: 6px; }
.card .legend .key { display: inline-block; width: 18px; height: 0; border-top: 3px dashed #e0a800; vertical-align: middle; margin-right: 4px; }
@media (max-height: 500px) and (orientation: landscape) {
  .map { max-width: 320px; }
}

[hidden] { display: none !important; }
