/* Mini Golf Scorecard — phone-first, no page scroll on the play screen */
@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 600 700;
  font-display: swap;
  src: url("fonts/fraunces.woff2") format("woff2");
}
@font-face {
  font-family: "Plus Jakarta Sans";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("fonts/plus-jakarta-sans.woff2") format("woff2");
}

:root {
  --ink: #163027;
  --ink-soft: #4A675A;
  --ink-faint: #7A9488;
  --sea: #1F6F56;
  --sea-deep: #155544;
  --leaf: #2C9A70;
  --mint: #E7F5EE;
  --foam: #F7F4EE;
  --card: #FFFFFF;
  --line: #D7E5DC;
  --flag: #E4572E;
  --gold: #C9A227;
  --gold-soft: #F6E7B8;
  --lead-bg: #FFF8E8;
  --sky: #E4F1F2;
  --danger: #B42318;
  --shadow: 0 8px 24px rgba(22, 48, 39, 0.08);
  --shadow-sm: 0 2px 8px rgba(22, 48, 39, 0.06);
  --radius: 18px;
  --sans: "Plus Jakarta Sans", "Segoe UI", sans-serif;
  --serif: "Fraunces", "Times New Roman", serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  max-width: 100%;
  overflow: hidden;
  position: fixed;
  inset: 0;
  background: var(--sky);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.3;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
input, textarea { user-select: text; -webkit-user-select: text; }
button, input { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

#app {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  overflow: hidden;
  background:
    radial-gradient(120% 70% at 80% -10%, #FFF6D4 0%, transparent 50%),
    radial-gradient(90% 50% at 0% 0%, #D8EEF3 0%, transparent 55%),
    linear-gradient(180deg, #E8F3F0 0%, #F4F1E8 48%, #D8EBDC 100%);
}

.view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-top: var(--safe-t);
  padding-bottom: var(--safe-b);
}

/* ===== Buttons ===== */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  transition: transform .12s ease, background .12s ease, box-shadow .12s ease;
}
.btn:active { transform: scale(.98); }
.btn.primary {
  background: var(--sea);
  color: #F7FBF8;
  box-shadow: 0 8px 18px rgba(31, 111, 86, 0.28);
}
.btn.primary:active { background: var(--sea-deep); }
.btn.ghost {
  background: rgba(255,255,255,.7);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line);
}
.btn.danger-fill { background: var(--flag); box-shadow: 0 8px 18px rgba(228, 87, 46, 0.28); }
.btn.nav { flex: 1; min-height: 52px; font-size: 16px; }
.btn.add { width: 100%; margin-top: 8px; color: var(--sea-deep); }
.btn.add svg { width: 18px; height: 18px; }
.btn.start { width: 100%; margin-top: 20px; min-height: 54px; font-size: 17px; }
.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 12px;
  color: var(--ink);
  flex-shrink: 0;
}
.icon-btn:active { background: rgba(22, 48, 39, .06); }
.icon-btn svg { width: 22px; height: 22px; }
.text-btn {
  height: 44px;
  padding: 0 10px;
  font-weight: 650;
  color: var(--sea);
  font-size: 15px;
}

.step-btn {
  display: grid; place-items: center;
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--mint);
  color: var(--sea-deep);
  font-size: 24px;
  font-weight: 500;
  line-height: 1;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(31, 111, 86, 0.12);
}
.step-btn:active { background: #D3EBDD; }
.step-btn.sm { width: 36px; height: 36px; font-size: 20px; }
.step-btn.lg { width: 56px; height: 56px; font-size: 30px; }
.step-btn:disabled { opacity: .35; }

/* ===== Top bar ===== */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 8px;
  flex-shrink: 0;
}
.hole-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 20px;
  letter-spacing: -0.02em;
  text-align: center;
}
.hole-title i {
  font-style: normal;
  font-family: var(--sans);
  font-weight: 500;
  font-size: 13px;
  color: var(--ink-soft);
  margin-left: 4px;
}

/* ===== Play: hole meta ===== */
.hole-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 2px 16px 8px;
  flex-shrink: 0;
}
.par-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border-radius: 999px;
  padding: 4px 6px 4px 14px;
  box-shadow: var(--shadow-sm);
}
.par-lab {
  font-size: 12px;
  font-weight: 650;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.par-val {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 20px;
  width: 22px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.dots {
  display: flex;
  gap: 4px;
  width: 100%;
  max-width: 340px;
  height: 22px;
  align-items: center;
  justify-content: center;
}
.dot {
  flex: 1;
  height: 22px;
  border-radius: 99px;
  background: rgba(22, 48, 39, 0.12);
  background-clip: content-box;
  min-width: 0;
  padding: 8px 0;
}
.dot.done { background-color: var(--leaf); }
.dot.now { background-color: var(--flag); flex: 1.8; }
.dot.lead-done { /* reserved */ }

/* ===== Player rows ===== */
.rows {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 14px;
  min-height: 0;
  overflow: hidden;
  justify-content: center;
}
.prow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 10px 10px 10px 14px;
  box-shadow: var(--shadow-sm);
  flex: 1 1 0;
  min-height: 56px;
  max-height: 96px;
  position: relative;
}
.prow.is-lead {
  background: linear-gradient(180deg, #FFFBF0, var(--lead-bg));
  box-shadow: 0 0 0 1.5px rgba(201, 162, 39, 0.45), var(--shadow-sm);
}
.who { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.swatch {
  width: 10px; height: 10px; border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c, var(--leaf)) 22%, transparent);
  background: var(--c, var(--leaf));
}
.who-text { min-width: 0; }
.pname {
  font-weight: 650;
  font-size: 16px;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pmeta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 2px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 550;
}
.ptotal { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--ink); font-size: 15px; }
.prel { font-variant-numeric: tabular-nums; }
.prel.under { color: var(--leaf); }
.prel.over { color: var(--flag); }
.lead-pill {
  display: none;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: #8A6A10;
  background: var(--gold-soft);
  border-radius: 99px;
  padding: 2px 7px;
  margin-left: 6px;
}
.prow.is-lead .lead-pill { display: inline-flex; }
.lead-pill svg { width: 9px; height: 9px; }
.stepper { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.strokes {
  width: 36px;
  text-align: center;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 28px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

/* Compact rows when many players */
#view-play[data-count="5"] .prow,
#view-play[data-count="6"] .prow,
#view-play[data-count="7"] .prow,
#view-play[data-count="8"] .prow {
  max-height: 62px;
  padding: 6px 8px 6px 12px;
  border-radius: 14px;
}
#view-play[data-count="5"] .strokes,
#view-play[data-count="6"] .strokes,
#view-play[data-count="7"] .strokes,
#view-play[data-count="8"] .strokes { font-size: 24px; }
#view-play[data-count="5"] .lead-pill,
#view-play[data-count="6"] .lead-pill,
#view-play[data-count="7"] .lead-pill,
#view-play[data-count="8"] .lead-pill { display: none !important; }
#view-play[data-count="7"] .rows,
#view-play[data-count="8"] .rows { gap: 6px; }
#view-play[data-count="7"] .step-btn,
#view-play[data-count="8"] .step-btn { width: 44px; height: 44px; }

/* ===== Compact scorecard strip ===== */
.strip-wrap {
  flex-shrink: 0;
  padding: 6px 0 2px;
  min-height: 0;
  position: relative;
}
.strip-wrap::after {
  content: "";
  position: absolute;
  top: 6px;
  right: 0;
  bottom: 8px;
  width: 24px;
  background: linear-gradient(90deg, rgba(232, 243, 234, 0), rgba(232, 243, 234, .95));
  pointer-events: none;
}
.strip {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 0 14px 8px;
  overscroll-behavior: contain;
}
.strip table, .card-scroll table {
  border-collapse: separate;
  border-spacing: 0;
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  font-variant-numeric: tabular-nums;
  width: max-content;
}
.strip th, .strip td, .card-scroll th, .card-scroll td {
  width: 32px;
  min-width: 32px;
  height: 28px;
  text-align: center;
  font-size: 12px;
  font-weight: 550;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.strip th.name, .strip td.name,
.card-scroll th.name, .card-scroll td.name {
  position: sticky;
  left: 0;
  z-index: 2;
  width: 72px;
  min-width: 72px;
  max-width: 72px;
  text-align: left;
  padding: 0 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: var(--card);
  font-weight: 650;
}
.strip thead th, .card-scroll thead th {
  background: #F3F7F4;
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .02em;
  position: sticky;
  top: 0;
  z-index: 1;
}
.strip thead th.name, .card-scroll thead th.name { z-index: 3; }
.strip td.tot, .strip th.tot, .card-scroll td.tot, .card-scroll th.tot,
.strip td.sub, .strip th.sub, .card-scroll td.sub, .card-scroll th.sub {
  background: #F3F7F4;
  font-weight: 700;
  width: 36px;
  min-width: 36px;
}
.strip td.cell, .card-scroll td.cell { cursor: pointer; }
.strip td.cell:active, .card-scroll td.cell:active { background: var(--mint); }
.strip td.cell.is-now, .card-scroll td.cell.is-now { background: #FFF3D6; font-weight: 700; }
.strip td.cell.is-empty, .card-scroll td.cell.is-empty { color: var(--ink-faint); }
.strip tr:last-child td, .card-scroll tr:last-child td { border-bottom: 0; }
.strip tr td:last-child, .strip tr th:last-child,
.card-scroll tr td:last-child, .card-scroll tr th:last-child { border-right: 0; }
.strip table { overflow: hidden; }

.foot {
  display: flex;
  gap: 10px;
  padding: 8px 14px 10px;
  flex-shrink: 0;
}
#btn-prev:disabled { opacity: .4; }

/* ===== Setup ===== */
#view-setup { overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
.setup-inner {
  padding: 28px 22px 32px;
  max-width: 400px;
  margin: 0 auto;
  width: 100%;
}
.setup-hero { display: flex; justify-content: center; margin-bottom: 10px; }
.setup-mark {
  width: 88px; height: 88px;
  border-radius: 22px;
  box-shadow: 0 12px 28px rgba(22, 48, 39, 0.14);
}
#view-setup h1 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 34px;
  letter-spacing: -0.03em;
  text-align: center;
  margin: 8px 0 0;
}
.lede { text-align: center; color: var(--ink-soft); margin: 6px 0 22px; font-weight: 500; }
.field-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 8px;
}
.pfield {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.pfield .swatch { margin-left: 6px; }
.pfield input {
  flex: 1;
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  padding: 0 14px;
  background: var(--card);
  box-shadow: inset 0 0 0 1px var(--line);
  outline: none;
  font-size: 16px; /* prevent iOS zoom */
  font-weight: 550;
}
.pfield input:focus { box-shadow: inset 0 0 0 1.5px var(--sea); }
.rm {
  width: 44px; height: 44px;
  border-radius: 12px;
  color: var(--ink-faint);
  font-size: 22px;
  flex-shrink: 0;
}
.rm:active { background: rgba(22,48,39,.06); color: var(--danger); }
#add-player:disabled { opacity: .4; }

/* ===== Scorecard view ===== */
#view-scorecard { background: transparent; }
.card-scroll {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 14px 20px;
  overscroll-behavior: contain;
}
.card-scroll table {
  min-width: 100%;
  border-radius: 16px;
}
.card-scroll th, .card-scroll td { height: 36px; font-size: 13px; width: 36px; min-width: 36px; }
.card-scroll th.name, .card-scroll td.name { width: 86px; min-width: 86px; max-width: 86px; }

/* ===== Winner ===== */
#view-winner { overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
.win-inner {
  padding: 28px 22px 32px;
  max-width: 400px;
  margin: 0 auto;
  width: 100%;
  text-align: center;
}
.win-flag { width: 72px; height: 72px; margin: 8px auto 6px; }
.win-flag svg { width: 100%; height: 100%; filter: drop-shadow(0 6px 10px rgba(22,48,39,.15)); }
.win-kicker {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 4px 0 0;
}
#view-winner h1 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 34px;
  letter-spacing: -0.03em;
  margin: 6px 0 0;
  line-height: 1.1;
}
.win-sub { color: var(--ink-soft); margin: 8px 0 22px; font-weight: 550; }
.standings {
  list-style: none;
  margin: 0 0 24px;
  padding: 0;
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  text-align: left;
}
.standings li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.standings li:last-child { border-bottom: 0; }
.standings li.is-win { background: var(--lead-bg); }
.rank {
  width: 28px;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 18px;
  color: var(--ink-soft);
  text-align: center;
}
.standings li.is-win .rank { color: var(--gold); }
.s-name { flex: 1; font-weight: 650; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.s-score { font-variant-numeric: tabular-nums; font-weight: 700; }
.s-rel { font-variant-numeric: tabular-nums; color: var(--ink-soft); font-size: 13px; width: 36px; text-align: right; }
.s-rel.under { color: var(--leaf); }
.s-rel.over { color: var(--flag); }
.win-actions { display: flex; flex-direction: column; gap: 10px; }
.win-actions .btn { width: 100%; }

/* ===== Sheets ===== */
.sheet {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.sheet-bg {
  position: absolute;
  inset: 0;
  background: rgba(22, 48, 39, 0.35);
  width: 100%;
  height: 100%;
}
.sheet-card {
  position: relative;
  background: var(--foam);
  border-radius: 22px 22px 0 0;
  padding: 12px 14px calc(16px + var(--safe-b));
  box-shadow: 0 -8px 30px rgba(22, 48, 39, 0.18);
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
}
.sheet-item {
  width: 100%;
  min-height: 52px;
  text-align: left;
  padding: 0 16px;
  font-weight: 650;
  border-radius: 14px;
  font-size: 16px;
}
.sheet-item:active { background: rgba(22, 48, 39, .06); }
.sheet-item.danger { color: var(--danger); }
.confirm-copy {
  font-size: 16px;
  font-weight: 550;
  text-align: center;
  margin: 10px 8px 16px;
  line-height: 1.4;
}
.sheet-card .btn { width: 100%; margin-bottom: 8px; }
.editor-card { text-align: center; padding-top: 18px; }
.editor-label { font-weight: 650; margin: 0 0 16px; color: var(--ink-soft); }
.editor-step { display: flex; align-items: center; justify-content: center; gap: 16px; margin-bottom: 18px; }
.editor-val {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 56px;
  width: 80px;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

@media (min-height: 740px) {
  .prow { max-height: 110px; }
  .strokes { font-size: 32px; }
}
