/* Gravity Golf. A printed board game: paper, four inks, and a plate that never quite lines up. */
:root {
  --paper: #EFE5CD;
  --board: #F8F1DE;
  --surface: #FFF9EA;
  --ink: #25304A;
  --ink-soft: #5B6276;
  --plate: rgba(240, 139, 166, .58);
  --plate-solid: #F2A4B8;
  --cream: #FFF9EA;
  --rock: #CDC2A8;
  --grid: rgba(37, 48, 74, .17);
  --orange: #EE5A2C;
  --teal: #1F8F8A;
  --mustard: #F2B533;
  --pink: #F08BA6;
  --btn: #C2411A;
  --on-btn: #FFF8EA;
  --under: #18776F;
  --focus-halo: #EFE5CD;
  --deep: #25304A;
  --is-dark: 0;
  --ui: "Avenir Next", "Nunito Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --display: Rockwell, "Roboto Slab", "Rockwell Nova", Georgia, "Times New Roman", serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --spring: cubic-bezier(.3, 1.5, .5, 1);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0E1322;
    --board: #161D33;
    --surface: #1D2644;
    --ink: #F2E8D2;
    --ink-soft: #A9AFC3;
    --plate: rgba(245, 155, 180, .38);
    --plate-solid: #7B3A55;
    --cream: #FFF4DC;
    --rock: #3A4361;
    --grid: rgba(242, 232, 210, .13);
    --orange: #FF7A4A;
    --teal: #3FBDB2;
    --mustard: #F6C453;
    --pink: #F59BB4;
    --btn: #FF7A4A;
    --on-btn: #141A2B;
    --under: #5ED3C6;
    --focus-halo: #0E1322;
    --deep: #05070E;
    --is-dark: 1;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  height: 100vh; height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui);
  line-height: 1.35;
  overflow: hidden;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; box-shadow: 0 0 0 6px var(--focus-halo); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.nojs { padding: 24px; font-size: 18px; }

.app {
  height: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: "top" "bar" "stage" "foot";
  gap: 8px;
}
.top { grid-area: top; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.bar { grid-area: bar; }
.stage { grid-area: stage; }
.foot { grid-area: foot; }

/* ---------- wordmark ---------- */
.wm { margin: 0; line-height: 0; }
.wm svg { display: block; width: clamp(122px, 33vw, 150px); height: auto; overflow: visible; }
.wm-ink { stroke: var(--ink); }
.wm-orange { stroke: var(--orange); }
.wm-plate { stroke: var(--plate); }
.wm-plate-fill { fill: var(--plate); }
.wm-planet { fill: var(--mustard); stroke: var(--ink); stroke-width: 4.5; }
.wm-dots { fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; stroke-dasharray: 0.1 6; opacity: .6; }
.wm-ring-back { fill: none; stroke: var(--ink); stroke-width: 7; }
.wm-ring-front { fill: none; stroke: var(--ink); stroke-width: 7; stroke-linecap: butt; }
.wm-ball { fill: var(--cream); stroke: var(--ink); stroke-width: 3.5; }
.wm-trail { fill: none; stroke: var(--ink); stroke-width: 4; stroke-linecap: round; stroke-dasharray: .1 9; }
.wm-cup { fill: var(--ink); }
.wm-pole { stroke: var(--ink); stroke-width: 3.5; stroke-linecap: round; }
.wm-flag { fill: var(--orange); stroke: var(--ink); stroke-width: 3; stroke-linejoin: round; }

.tools { display: flex; align-items: center; gap: 8px; }
.chip {
  margin: 0; min-height: 36px; display: inline-flex; align-items: center; gap: 7px;
  padding: 0 12px; border: 2px solid var(--ink); border-radius: 99px; background: var(--surface);
  font-size: 13px; font-weight: 700; letter-spacing: .02em; white-space: nowrap;
}
.chip i { width: 11px; height: 11px; border-radius: 50%; background: var(--orange); border: 2px solid var(--ink); display: inline-block; flex: none; }
.chip.on i { background: var(--mustard); }
.icon-btn {
  width: 44px; height: 44px; padding: 0; display: grid; place-items: center; cursor: pointer;
  border: 2px solid var(--ink); border-radius: 14px; background: var(--surface);
  box-shadow: 3px 3px 0 var(--ink);
  transition: transform .12s var(--ease), box-shadow .12s var(--ease);
}
.icon-btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn .spk { fill: var(--ink); }
.icon-btn[aria-pressed="false"] .waves { display: none; }
.icon-btn[aria-pressed="true"] .slash { display: none; }

/* ---------- the bar: round, numbers, pips ---------- */
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.modes { display: inline-flex; border: 2px solid var(--ink); border-radius: 14px; overflow: hidden; background: var(--surface); }
.modes button {
  min-height: 44px; padding: 0 14px; border: 0; background: none; cursor: pointer; font-weight: 700; font-size: 14px;
  display: inline-flex; align-items: center; gap: 6px;
}
.modes button + button { border-left: 2px solid var(--ink); }
.modes button small { font-weight: 600; color: var(--ink-soft); font-size: 12px; }
.modes button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.modes button[aria-pressed="true"] small { color: inherit; opacity: .85; }
.modes button:focus-visible { outline-offset: -5px; box-shadow: none; }
.hud { display: flex; gap: 14px; margin-left: auto; }
.stat { display: flex; flex-direction: column; align-items: flex-start; line-height: 1; }
.stat .k { font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-soft); font-weight: 700; margin-bottom: 3px; }
.stat .v { font-family: var(--display); font-weight: 700; font-size: 25px; }
.stat .v small { font-size: 13px; color: var(--ink-soft); font-family: var(--ui); font-weight: 700; margin-left: 1px; }
.stat b { font-variant-numeric: tabular-nums; }
.hole-name { margin: 0; font-family: var(--display); font-style: italic; font-size: 15px; color: var(--ink-soft); flex-basis: 100%; order: 5; display: none; }
.pips { list-style: none; margin: 0; padding: 0; display: flex; gap: 5px; flex-basis: 100%; order: 6; }
.pips li { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--ink); display: grid; place-items: center; font-size: 11px; line-height: 1; font-weight: 800; color: var(--ink); background: var(--surface); position: relative; }
.pips li.now { background: var(--mustard); }
.pips li.under { background: var(--under); color: var(--paper); }
.pips li.par { background: var(--ink); color: var(--paper); }
.pips li.over { background: var(--orange); color: var(--paper); border-style: dashed; }
@media (prefers-color-scheme: dark) { .pips li.now { color: #141A2B; } .pips li.over { color: #141A2B; } }

/* ---------- the stage ---------- */
.stage { position: relative; display: flex; align-items: center; justify-content: center; min-height: 0; min-width: 0; }
#board {
  display: block; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  border-radius: 14px; background: var(--paper);
  box-shadow: 5px 5px 0 var(--ink);
  cursor: crosshair;
  -webkit-tap-highlight-color: transparent;
}
#board:focus-visible { outline: 3px solid var(--ink); outline-offset: 5px; }
.hint {
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%); margin: 0; z-index: 2;
  padding: 7px 15px; border: 2px solid var(--ink); border-radius: 99px; background: var(--surface);
  font-weight: 700; font-size: 14px; white-space: nowrap; pointer-events: none; box-shadow: 3px 3px 0 var(--ink);
  animation: fadein .5s var(--ease) both;
}
.banner {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 3;
  width: min(94%, 380px); text-align: center; padding: 14px 18px 16px;
  background: var(--surface); border: 3px solid var(--ink); border-radius: 20px; box-shadow: 6px 6px 0 var(--orange);
  animation: pop .5s var(--spring) both;
}
.banner[hidden], .hint[hidden] { display: none; }
.banner .word {
  margin: 0; font-family: var(--display); font-weight: 800; font-style: italic; text-transform: uppercase;
  font-size: clamp(28px, 7.4vw, 40px); line-height: 1; letter-spacing: .01em;
  text-shadow: 3px 3px 0 var(--plate-solid);
}
.banner .sub { margin: 7px 0 12px; font-weight: 700; color: var(--ink-soft); font-size: 14px; }
@keyframes pop { from { opacity: 0; transform: translateX(-50%) scale(.7) translateY(14px); } to { opacity: 1; transform: translateX(-50%); } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ---------- buttons ---------- */
.btn {
  min-height: 44px; padding: 0 18px; border: 2px solid var(--ink); border-radius: 14px; background: var(--surface);
  font-weight: 800; font-size: 15px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  box-shadow: 3px 3px 0 var(--ink);
  transition: transform .12s var(--ease), box-shadow .12s var(--ease), background-color .12s;
}
.btn small { font-weight: 700; color: var(--ink-soft); font-size: 12px; }
.btn:hover:not(:disabled) { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.btn:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.btn:disabled { opacity: .45; cursor: default; box-shadow: none; }
.btn.primary { background: var(--btn); color: var(--on-btn); }
.btn.primary small { color: inherit; }
.btn[hidden] { display: none; }

.foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 14px; }
.how { margin: 0; font-size: 14px; color: var(--ink-soft); font-weight: 600; flex: 1 1 220px; }
.how kbd {
  display: inline-block; min-width: 22px; padding: 0 5px; margin: 0 1px; text-align: center;
  border: 1.5px solid var(--ink-soft); border-radius: 6px; font: 700 12px/18px var(--mono); color: var(--ink);
}
.acts { display: flex; gap: 8px; }
@media (pointer: coarse) { .keys { display: none; } }

/* ---------- the results card ---------- */
dialog { border: 0; padding: 0; background: transparent; color: var(--ink); max-width: min(94vw, 440px); width: 100%; overflow: visible; }
dialog::backdrop { background: rgba(14, 19, 34, .6); }
dialog[open] .card { animation: pop2 .45s var(--spring) both; }
@keyframes pop2 { from { opacity: 0; transform: scale(.85) translateY(16px); } to { opacity: 1; transform: none; } }
.card {
  position: relative; margin: 0; padding: 22px 22px 20px; background: var(--surface); border: 3px solid var(--ink);
  border-radius: 24px; box-shadow: 7px 7px 0 var(--orange); max-height: 92dvh; overflow: auto;
}
.eyebrow { margin: 0; font-size: 12px; letter-spacing: .14em; text-transform: uppercase; font-weight: 800; color: var(--ink-soft); }
.card h2 { margin: 2px 0 0; font-family: var(--display); font-style: italic; font-size: 28px; line-height: 1.1; }
.total { margin: 6px 0 12px; display: flex; align-items: baseline; gap: 10px; }
.total b { font-family: var(--display); font-size: 68px; line-height: .9; text-shadow: 4px 4px 0 var(--plate-solid); }
.total span { font-weight: 800; font-size: 16px; }
.card-holes { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 4px; }
.card-holes li { display: grid; grid-template-columns: 24px 1fr auto auto; gap: 10px; align-items: center; padding: 5px 8px; border-radius: 10px; background: var(--board); font-size: 14px; }
.card-holes .g { font-size: 17px; text-align: center; }
.card-holes .n { font-weight: 700; }
.card-holes .s { font-family: var(--display); font-weight: 700; font-variant-numeric: tabular-nums; }
.card-holes .w { color: var(--ink-soft); font-weight: 700; font-size: 12px; min-width: 76px; text-align: right; }
.streak-line { margin: 0 0 14px; font-weight: 700; font-size: 14px; color: var(--ink-soft); }
.card .row { display: flex; flex-wrap: wrap; gap: 8px; }
.card .row .btn { flex: 1 1 auto; }
.toast { min-height: 20px; margin: 10px 0 0; font-weight: 800; font-size: 14px; color: var(--under); }
.share-text { width: 100%; margin-top: 8px; font: 600 14px/1.4 var(--mono); border: 2px solid var(--ink); border-radius: 10px; padding: 8px; background: var(--board); color: var(--ink); resize: none; }
.card .close {
  position: absolute; top: 12px; right: 14px; min-height: 44px; min-width: 44px; padding: 0 6px; border: 0; background: none; cursor: pointer;
  font-weight: 800; font-size: 13px; text-decoration: underline; color: var(--ink-soft);
}

/* ---------- wide screens and landscape phones: the numbers move to a side column ---------- */
@media (orientation: landscape) and (min-width: 700px) {
  .app {
    grid-template-columns: clamp(206px, 25vw, 300px) minmax(0, 1fr);
    grid-template-rows: auto auto 1fr;
    grid-template-areas: "top stage" "bar stage" "foot stage";
    column-gap: 18px;
    align-content: start;
  }
  .top { flex-direction: column; align-items: flex-start; gap: 10px; }
  .wm svg { width: clamp(130px, 17vw, 220px); }
  .bar { flex-direction: column; align-items: stretch; gap: 10px; }
  .modes { display: grid; grid-template-columns: 1fr 1fr; }
  .modes button { justify-content: center; padding: 0 6px; }
  .hud { margin-left: 0; justify-content: space-between; gap: 8px; }
  .stat .v { font-size: 30px; }
  .hole-name { display: block; font-size: 17px; flex-basis: auto; order: 4; }
  .pips { flex-basis: auto; order: 5; }
  .foot { flex-direction: column; align-items: stretch; align-self: end; }
  .acts { flex-wrap: wrap; }
  .acts .btn { flex: 1 1 auto; }
  .how { flex: none; }
}
/* very short landscape phones */
@media (orientation: landscape) and (max-height: 480px) {
  .app { padding-top: 6px; padding-bottom: 6px; row-gap: 6px; }
  .wm svg { width: 112px; }
  .how { font-size: 12px; }
  .keys { display: none; }
  .stat .v { font-size: 22px; }
  .hole-name { display: none; }
  .btn { min-height: 44px; }
  .banner { bottom: 8px; padding: 10px 14px 12px; }
  .banner .word { font-size: 28px; }
  .banner .sub { margin: 4px 0 8px; }
}
/* phones held upright: modes on top, then the pips beside the numbers */
@media (orientation: portrait), (max-width: 699px) {
  .bar { display: grid; grid-template-columns: auto 1fr; grid-template-areas: "modes modes" "pips hud"; align-items: center; gap: 8px 10px; }
  .modes { grid-area: modes; justify-self: start; }
  .hud { grid-area: hud; justify-self: end; }
  .pips { grid-area: pips; }
  .hole-name { display: none; }
  .hint { display: none; }
}
@media (orientation: portrait) and (min-height: 760px) { .hint { display: block; } }
@media (max-width: 380px) {
  .chip { padding: 0 9px; font-size: 12px; }
  .modes button { padding: 0 10px; }
  .hud { gap: 11px; }
  .stat .v { font-size: 22px; }
  .btn { padding: 0 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .banner, dialog[open] .card, .hint { animation: none; }
  .btn, .icon-btn { transition: none; }
}
