:root {
  --ink: #17323a;
  --cream: #fffaf0;
  --accent: #ff6b5b;
  --accent-dark: #e14e3f;
  --green: #4fb544;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  overflow: hidden; position: fixed; inset: 0;
  overscroll-behavior: none; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  background: #16525a;
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }

/* HUD */
#hud {
  position: fixed; left: 0; right: 0; top: 0;
  padding: calc(8px + var(--safe-t)) 10px 0;
  pointer-events: none; z-index: 5;
}
.hud-row { display: flex; gap: 6px; align-items: stretch; }
.pill {
  background: rgba(255, 250, 240, 0.94); border-radius: 12px;
  padding: 4px 9px 5px; min-width: 0; flex: 1 1 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: 0 2px 0 rgba(0,0,0,.18);
  line-height: 1;
}
.pill.hole { flex-direction: row; align-items: baseline; gap: 2px; flex-wrap: wrap; justify-content: center; }
.pill.hole .lbl { width: 100%; text-align: center; }
.pill .lbl { font-size: 9px; letter-spacing: .08em; text-transform: uppercase; color: #5b7178; font-weight: 700; margin-bottom: 3px; }
.pill b { font-size: 19px; font-weight: 800; font-variant-numeric: tabular-nums; }
.pill .dim { font-size: 12px; color: #7b8d92; font-weight: 700; }
.hud-btns { display: flex; gap: 6px; pointer-events: auto; }
.icon-btn {
  width: 40px; border: 0; border-radius: 12px; padding: 0;
  background: rgba(255, 250, 240, 0.94); color: var(--ink);
  box-shadow: 0 2px 0 rgba(0,0,0,.18); cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn svg { width: 22px; height: 22px; }
.back-btn {
  width: auto; padding: 0 11px; text-decoration: none;
  font-size: 13px; font-weight: 800; white-space: nowrap;
}
.icon-btn:active { transform: translateY(1px); box-shadow: 0 1px 0 rgba(0,0,0,.18); }
.hole-name {
  margin-top: 6px; text-align: center; color: rgba(255,255,255,.85);
  font-size: 12px; font-weight: 700; letter-spacing: .04em; text-shadow: 0 1px 2px rgba(0,0,0,.35);
}

.hint {
  position: fixed; left: 50%; bottom: calc(14px + var(--safe-b)); transform: translateX(-50%);
  background: rgba(10, 40, 45, .72); color: #fff; font-size: 13px; font-weight: 600;
  padding: 8px 14px; border-radius: 999px; white-space: nowrap; max-width: calc(100% - 20px); overflow: hidden; text-overflow: ellipsis; pointer-events: none;
  transition: opacity .4s; z-index: 4;
}
.hint.off { opacity: 0; }

.toast {
  position: fixed; left: 50%; top: 42%; transform: translate(-50%, -50%) scale(.6);
  font-size: 40px; font-weight: 900; color: #fff; letter-spacing: .01em;
  text-shadow: 0 3px 0 rgba(0,0,0,.25), 0 0 18px rgba(0,0,0,.25);
  opacity: 0; pointer-events: none; z-index: 6; white-space: nowrap;
  transition: opacity .25s, transform .35s cubic-bezier(.2,1.6,.4,1);
}
.toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.toast.small { font-size: 24px; }

.fade { position: fixed; inset: 0; background: #16525a; opacity: 0; pointer-events: none; transition: opacity .28s; z-index: 7; }
.fade.on { opacity: 1; }

/* Modals */
.modal {
  position: fixed; inset: 0; z-index: 10; display: none;
  align-items: center; justify-content: center;
  background: rgba(8, 35, 40, .55); padding: 18px;
  padding-top: calc(18px + var(--safe-t)); padding-bottom: calc(18px + var(--safe-b));
  touch-action: manipulation;
}
.modal.show { display: flex; animation: pop .25s ease-out; }
@keyframes pop { from { opacity: 0; } to { opacity: 1; } }
.card {
  background: var(--cream); border-radius: 22px; padding: 22px 20px 18px;
  width: 100%; max-width: 340px; text-align: center;
  box-shadow: 0 6px 0 rgba(0,0,0,.2), 0 20px 50px rgba(0,0,0,.3);
  max-height: 100%; overflow: auto;
}
.card.wide { max-width: 440px; }
h1 { margin: 6px 0 2px; font-size: 34px; font-weight: 900; letter-spacing: -.01em; }
h2 { margin: 0 0 4px; font-size: 24px; font-weight: 900; }
.sub { margin: 0 0 14px; color: #5b7178; font-size: 14px; font-weight: 600; }
.logo svg { width: 92px; height: 92px; display: block; margin: 0 auto; }
.how { text-align: left; margin: 4px 0 16px; display: grid; gap: 8px; font-size: 14px; font-weight: 600; }
.how div { display: flex; align-items: center; gap: 10px; }
.step { flex: 0 0 24px; height: 24px; border-radius: 50%; background: var(--green); color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 800; }
.btn {
  display: block; width: 100%; border: 0; margin: 8px 0 0; cursor: pointer;
  font: inherit; font-size: 17px; font-weight: 800; padding: 13px 16px; border-radius: 14px;
  background: #e8e2d4; color: var(--ink); box-shadow: 0 3px 0 rgba(0,0,0,.15);
}
.btn.primary { background: var(--accent); color: #fff; box-shadow: 0 3px 0 var(--accent-dark); }
.btn.ghost { background: transparent; box-shadow: none; color: #5b7178; font-size: 15px; padding: 10px; }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.15); }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }
.best { margin: 10px 0 0; font-size: 13px; color: #5b7178; font-weight: 700; min-height: 1em; }

/* Scorecard */
.table-wrap { overflow-x: auto; margin: 0 -8px; }
@media (max-width: 380px) { #scTable th, #scTable td { font-size: 12px; } #scTable tr.score td { font-size: 13px; } .modal { padding-left: 10px; padding-right: 10px; } .card { padding-left: 14px; padding-right: 14px; } }
#scTable { border-collapse: separate; border-spacing: 1.5px; table-layout: fixed; width: 100%; font-variant-numeric: tabular-nums; }
#scTable th, #scTable td { font-size: 13px; padding: 6px 0; text-align: center; border-radius: 6px; }
#scTable th.rowlbl { width: 52px; }
#scTable th:last-child { width: 30px; }
#scTable th { color: #5b7178; font-weight: 800; font-size: 11px; text-transform: uppercase; }
#scTable tr td.rowlbl, #scTable tr th.rowlbl { text-align: left; padding-left: 4px; color: #5b7178; font-size: 10px !important; letter-spacing: .02em; background: transparent !important; font-weight: 800; text-transform: uppercase; }
#scTable tr.par td { background: #efe9dc; font-weight: 700; }
#scTable tr.score td { background: #fff; font-weight: 800; font-size: 15px; }
#scTable td.under { background: #d8f2d1 !important; color: #23772f; }
#scTable td.over { background: #ffe0dc !important; color: #c0392b; }
#scTable td.cur { outline: 2px solid var(--accent); }
#scTable td.tot { background: #17323a !important; color: #fff; }
.sc-total { margin-top: 12px; font-size: 18px; font-weight: 900; }

@media (min-width: 700px) and (min-height: 600px) {
  .pill b { font-size: 22px; }
  .hud-row { max-width: 520px; margin: 0 auto; }
}

@media (max-width: 360px) {
  .hud-row { gap: 4px; }
  .pill { padding: 4px 3px 5px; }
  .pill .lbl { font-size: 8px; letter-spacing: .02em; }
  .pill b { font-size: 17px; }
  .icon-btn { width: 34px; }
  .back-btn { width: auto; font-size: 12px; padding: 0 8px; }
  .hint { font-size: 12px; }
}
