:root {
  --grass: #3f7f36;
  --grass-dark: #2c5a26;
  --sky: #7fa9cf;
  --ink: #10180f;
  --paper: #f4f6ef;
  --panel: rgba(12, 22, 12, 0.82);
  --panel-line: rgba(226, 240, 214, 0.20);
  --accent: #f2c744;
  --accent-2: #e0533f;
  --text: #eaf2e2;
  --muted: #a9bda0;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--text);
  background: #0d1a0d;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#hud { position: absolute; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
.panel {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  backdrop-filter: blur(6px);
  padding: 10px 12px;
}
#topbar {
  position: absolute; top: 10px; left: 10px; right: 10px;
  display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap;
}
#scorecard-btn, #help-btn, #new-btn { cursor: pointer; }
h1 {
  font-size: 15px; margin: 0 0 2px; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--accent);
}
.sub { font-size: 11px; color: var(--muted); margin: 0; }
#holeinfo { min-width: 190px; }
.row { display: flex; gap: 14px; align-items: baseline; }
.big { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.lab { font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
#controls {
  position: absolute; left: 10px; right: 10px; bottom: 10px;
  display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap;
}
#clubbar { display: flex; gap: 4px; flex-wrap: wrap; }
button {
  font: inherit; font-size: 12px; color: var(--text);
  background: rgba(24, 44, 22, 0.9);
  border: 1px solid var(--panel-line); border-radius: 7px;
  padding: 6px 9px; cursor: pointer;
}
button:hover { background: rgba(44, 78, 40, 0.95); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.sel { background: var(--accent); color: #17200f; border-color: var(--accent); font-weight: 650; }
button.primary { background: var(--accent-2); border-color: var(--accent-2); font-weight: 650; }
button[disabled] { opacity: 0.45; cursor: default; }
label.ctl { display: block; font-size: 10px; text-transform: uppercase;
            letter-spacing: 0.1em; color: var(--muted); margin-bottom: 3px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.slider { min-width: 150px; flex: 1 1 150px; }
.val { font-variant-numeric: tabular-nums; color: var(--accent); font-size: 12px; }
#map { position: absolute; right: 10px; top: 96px; border-radius: 10px;
       border: 1px solid var(--panel-line); background: rgba(10, 20, 10, 0.8); }
#msg {
  position: absolute; left: 50%; top: 84px; transform: translateX(-50%);
  text-align: center; font-size: 13px; max-width: 78vw;
}
dialog {
  border: 1px solid var(--panel-line); border-radius: 12px; padding: 0;
  background: #131f12; color: var(--text); max-width: 760px; width: 92vw;
  max-height: 84vh;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.62); }
.dlg-body { padding: 18px 22px; overflow-y: auto; max-height: 72vh; }
.dlg-body h2 { font-size: 16px; margin: 0 0 10px; color: var(--accent); }
.dlg-body h3 { font-size: 12px; margin: 18px 0 6px; text-transform: uppercase;
               letter-spacing: 0.1em; color: var(--accent); }
.dlg-body p, .dlg-body li { font-size: 13px; line-height: 1.55; color: #dbe6d2; }
.dlg-body code { font-family: var(--mono); font-size: 12px; color: var(--accent); }
table { border-collapse: collapse; width: 100%; font-size: 12px;
        font-variant-numeric: tabular-nums; }
th, td { border-bottom: 1px solid var(--panel-line); padding: 4px 6px; text-align: right; }
th:first-child, td:first-child { text-align: left; }
.scroll-x { overflow-x: auto; }
.dlg-foot { padding: 10px 22px 16px; display: flex; justify-content: flex-end; gap: 8px; }
.hidden { display: none !important; }
#shape-panel.putting label[for=shape], #shape-panel.putting #shape { opacity: 0.35; }
#shape-panel.putting label[for=pace], #shape-panel.putting #pace { opacity: 1; }
/* Phones (portrait and landscape): the HUD becomes one flowing column so the
   stat panels, the message, the map and the controls never sit on each other. */
@media (max-width: 640px), (max-height: 520px) {
  #hud { display: flex; flex-direction: column; gap: 6px;
         padding: max(6px, env(safe-area-inset-top)) 6px max(6px, env(safe-area-inset-bottom)); }
  #topbar, #controls, #msg, #map { position: static; transform: none; }
  #topbar, #controls { pointer-events: none; gap: 6px; }
  #topbar > *, #controls > * { pointer-events: auto; }
  .panel { padding: 6px 8px; border-radius: 8px; }
  h1 { font-size: 12px; }
  .row { gap: 10px; }
  .big { font-size: 16px; }
  #lie { font-size: 13px !important; }
  #holeinfo { min-width: 0; }
  #holeinfo .row { margin-top: 2px !important; }
  button { font-size: 11px; padding: 5px 7px; }
  #msg { align-self: center; max-width: 100%; font-size: 12px; padding: 5px 10px; }
  #map { align-self: flex-end; width: 104px; height: 104px; flex: 0 0 auto; }
  #controls { margin-top: auto; }
  #controls > .panel:first-child { flex: 1 1 100% !important; min-width: 0; }
  #clubbar { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
             padding-bottom: 2px; }
  #clubbar button { flex: 0 0 auto; }
  .slider { min-width: 0; flex: 1 1 130px; }
  #controls > .panel:last-child { flex: 1 1 100% !important; flex-direction: row !important; }
  #controls > .panel:last-child button { flex: 1 1 0; padding: 8px 6px; }
  label.ctl { margin-bottom: 1px; }
  label.ctl[for=power], label.ctl[for=pace] { margin-top: 4px !important; }
}
@media (max-height: 520px) and (min-width: 641px) {
  #controls > .panel:first-child, #controls > .panel:last-child { flex: 0 1 auto !important; }
  #map { position: absolute; right: 6px; top: 88px; width: 96px; height: 96px; }
}
/* Very short portrait phones (iPhone SE 1st gen): the overhead map yields its
   row to the controls; the "To hole" readout and the 3D view still show the line. */
@media (max-width: 640px) and (max-height: 600px) {
  #map { display: none; }
}
