:root {
  --blue: #0d5f7a;
  --blue-dark: #073f52;
  --red: #d22f32;
  --green: #2c8c57;
  --green-dark: #17683d;
  --cream: #f6f2e8;
  --paper: #fffdf8;
  --ink: #17313a;
  --muted: #687b82;
  --line: #d9e1df;
  --gold: #e2b13c;
  --shadow: 0 18px 45px rgba(15, 55, 69, .16);
  --radius: 24px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: #eaf2f2; }
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: Inter, ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(circle at 15% 10%, rgba(255,255,255,.9), transparent 28rem),
    linear-gradient(155deg, #e7f2f3 0%, #f7f3e9 54%, #e7efe9 100%);
}
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  background: rgba(255,255,255,.54);
  backdrop-filter: blur(16px);
  box-shadow: 0 0 60px rgba(9, 61, 78, .12);
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(12px + env(safe-area-inset-top)) 18px 12px;
  background: rgba(248,252,250,.88);
  border-bottom: 1px solid rgba(13,95,122,.12);
  backdrop-filter: blur(20px);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.crest { width: 42px; height: 48px; object-fit: contain; filter: drop-shadow(0 5px 8px rgba(0,0,0,.12)); }
.eyebrow { font-size: 10px; letter-spacing: .16em; font-weight: 900; color: var(--red); }
h1 { margin: 1px 0 0; font-size: 24px; line-height: 1; letter-spacing: -.03em; color: var(--blue-dark); }
.top-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 42px; height: 42px; border: 0; border-radius: 14px;
  background: #fff; color: var(--blue-dark); font-weight: 900; font-size: 20px;
  box-shadow: 0 7px 18px rgba(13,95,122,.13); cursor: pointer;
}
.icon-btn:active { transform: translateY(1px) scale(.98); }
.hidden { display: none !important; }

.main-content { flex: 1; padding: 18px; }
.footer {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  padding: 14px 18px calc(14px + env(safe-area-inset-bottom));
  font-size: 12px; color: var(--muted);
}
.offline-badge { color: var(--green-dark); font-weight: 800; }

.hero-card, .card {
  background: rgba(255,253,248,.95);
  border: 1px solid rgba(13,95,122,.12);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.hero-card { overflow: hidden; }
.hero-visual {
  min-height: 170px;
  padding: 26px;
  color: #fff;
  background:
    linear-gradient(140deg, rgba(7,63,82,.98), rgba(13,95,122,.86)),
    repeating-linear-gradient(90deg, transparent 0 34px, rgba(255,255,255,.05) 34px 68px);
  position: relative;
}
.hero-visual::after {
  content: "";
  position: absolute; right: -28px; bottom: -44px;
  width: 180px; height: 180px; border-radius: 50%;
  border: 28px solid rgba(255,255,255,.08);
}
.hero-visual h2 { margin: 0 0 8px; font-size: clamp(28px, 7vw, 42px); line-height: 1; letter-spacing: -.04em; max-width: 450px; }
.hero-visual p { margin: 0; max-width: 480px; color: rgba(255,255,255,.82); }
.mini-green {
  position: absolute; right: 28px; top: 28px; width: 76px; height: 76px;
  border-radius: 50%; background: #5dbb72; box-shadow: inset 0 -10px 20px rgba(0,0,0,.12);
}
.mini-green::before { content: ""; position: absolute; width: 4px; height: 50px; background: white; left: 38px; top: -8px; border-radius: 3px; }
.mini-green::after { content: ""; position: absolute; border-left: 30px solid var(--red); border-top: 10px solid transparent; border-bottom: 10px solid transparent; left: 40px; top: -7px; }
.hole-dot { position: absolute; width: 14px; height: 7px; border-radius: 50%; background: #1f5f37; left: 32px; top: 48px; box-shadow: 0 8px 16px rgba(0,0,0,.2); }

.setup-body { padding: 22px; }
.section-title-row { display:flex; align-items:flex-start; justify-content:space-between; gap:12px; margin-bottom:14px; }
.section-title-row h2, .section-title-row h3 { margin:0; }
.section-title-row p { margin:4px 0 0; color:var(--muted); font-size:14px; }
.player-count { font-weight:900; color:var(--blue); background:#e8f2f4; border-radius:999px; padding:7px 10px; white-space:nowrap; }
.players-list { display:grid; gap:10px; }
.player-row { display:grid; grid-template-columns:40px 1fr 42px; gap:9px; align-items:center; }
.player-number { width:40px; height:40px; display:grid; place-items:center; border-radius:13px; background:#e9f3ef; color:var(--green-dark); font-weight:900; }
.text-input {
  width:100%; min-height:48px; border:1px solid var(--line); border-radius:15px; background:#fff; color:var(--ink);
  padding:11px 13px; outline:none; transition:.2s border-color,.2s box-shadow;
}
.text-input:focus { border-color:var(--blue); box-shadow:0 0 0 4px rgba(13,95,122,.12); }
.remove-btn { width:42px; height:42px; border:0; border-radius:13px; background:#f8e7e7; color:var(--red); font-size:20px; font-weight:900; cursor:pointer; }
.action-row { display:flex; flex-wrap:wrap; gap:10px; margin-top:18px; }
.btn {
  min-height:50px; border:0; border-radius:16px; padding:12px 18px; font-weight:900; cursor:pointer;
  display:inline-flex; align-items:center; justify-content:center; gap:8px; text-align:center;
}
.btn-primary { background:linear-gradient(135deg,var(--green),var(--green-dark)); color:#fff; box-shadow:0 12px 24px rgba(23,104,61,.25); }
.btn-secondary { background:#e8f2f4; color:var(--blue-dark); }
.btn-danger { background:#f8e7e7; color:#a51e25; }
.btn-ghost { background:transparent; border:1px solid var(--line); color:var(--ink); }
.btn:disabled { opacity:.45; cursor:not-allowed; box-shadow:none; }
.btn-wide { width:100%; }

.game-grid { display:grid; gap:14px; }
.status-card { padding:16px; display:grid; gap:12px; }
.status-top { display:flex; align-items:center; justify-content:space-between; gap:12px; }
.progress-copy strong { font-size:20px; color:var(--blue-dark); }
.progress-copy span { display:block; font-size:13px; color:var(--muted); margin-top:2px; }
.progress-bar { height:9px; border-radius:999px; background:#dfe9e7; overflow:hidden; }
.progress-bar > span { display:block; height:100%; border-radius:inherit; background:linear-gradient(90deg,var(--green),#6fbf72); transition:width .25s ease; }

.timer-box { min-width:124px; text-align:right; }
.timer-value { font-variant-numeric:tabular-nums; font-weight:950; font-size:22px; color:var(--blue-dark); letter-spacing:-.04em; }
.timer-value.warning { color:#b64b19; }
.timer-controls { display:flex; justify-content:flex-end; gap:5px; margin-top:5px; }
.timer-controls button { border:0; border-radius:9px; padding:5px 8px; background:#e8f2f4; color:var(--blue-dark); font-size:11px; font-weight:900; cursor:pointer; }

.player-card { padding:22px; text-align:center; position:relative; overflow:hidden; }
.player-card::before { content:""; position:absolute; inset:0 0 auto; height:6px; background:linear-gradient(90deg,var(--red),var(--gold),var(--green)); }
.player-meta { color:var(--muted); font-size:13px; font-weight:800; text-transform:uppercase; letter-spacing:.08em; }
.player-name { margin:5px 0 3px; font-size:clamp(30px,8vw,44px); line-height:1; letter-spacing:-.045em; color:var(--blue-dark); overflow-wrap:anywhere; }
.current-total { color:var(--muted); font-size:14px; }
.current-total strong { color:var(--ink); }

.score-label { margin:20px 0 10px; font-weight:900; }
.score-buttons { display:grid; grid-template-columns:repeat(3,1fr); gap:10px; }
.score-btn {
  aspect-ratio:1.35; border:2px solid #dbe5e3; border-radius:18px; background:#fff; color:var(--blue-dark);
  font-size:30px; font-weight:950; cursor:pointer; box-shadow:0 7px 15px rgba(15,55,69,.07);
}
.score-btn.selected { border-color:var(--green); color:#fff; background:linear-gradient(145deg,var(--green),var(--green-dark)); transform:translateY(-1px); }
.score-btn.max { color:var(--red); }
.score-btn.max.selected { color:white; background:linear-gradient(145deg,#d84c4d,#aa2028); border-color:#aa2028; }

.penalty-panel { margin-top:14px; padding:14px; border-radius:18px; background:#f4efe4; display:flex; align-items:center; justify-content:space-between; gap:12px; }
.penalty-copy { text-align:left; }
.penalty-copy strong { display:block; }
.penalty-copy span { font-size:12px; color:var(--muted); }
.penalty-controls { display:flex; align-items:center; gap:8px; }
.penalty-count { min-width:34px; font-size:20px; font-weight:950; color:var(--red); text-align:center; }
.small-round { width:38px; height:38px; border:0; border-radius:12px; background:#fff; color:var(--red); font-weight:950; cursor:pointer; box-shadow:0 5px 12px rgba(0,0,0,.08); }

.hole-score-preview { margin-top:14px; padding:11px 14px; border-radius:14px; background:#eaf5ee; color:var(--green-dark); font-weight:900; }
.game-actions { display:grid; grid-template-columns:1fr 1.5fr; gap:10px; }
.secondary-actions { display:grid; grid-template-columns:1fr 1fr; gap:10px; }

.leader-strip { padding:14px 16px; display:flex; align-items:center; gap:10px; overflow:auto; scrollbar-width:none; }
.leader-strip::-webkit-scrollbar { display:none; }
.leader-pill { flex:0 0 auto; padding:8px 11px; border-radius:999px; background:#eff4f3; font-size:13px; white-space:nowrap; }
.leader-pill strong { color:var(--blue-dark); }
.leader-pill.current { background:#dcedf2; outline:2px solid rgba(13,95,122,.18); }

.results-card { overflow:hidden; }
.results-head { padding:26px 22px; background:linear-gradient(145deg,var(--blue-dark),var(--blue)); color:white; }
.results-head .trophy { font-size:38px; }
.results-head h2 { margin:6px 0 4px; font-size:32px; letter-spacing:-.04em; }
.results-head p { margin:0; color:rgba(255,255,255,.75); }
.results-list { padding:14px; display:grid; gap:9px; }
.result-row { display:grid; grid-template-columns:48px 1fr auto; align-items:center; gap:10px; padding:14px; border-radius:17px; background:#fff; border:1px solid var(--line); }
.result-row.winner { background:linear-gradient(120deg,#fff8df,#fff); border-color:#eed37c; }
.place { width:42px; height:42px; display:grid; place-items:center; border-radius:13px; background:#e9f3ef; color:var(--green-dark); font-weight:950; }
.result-row.winner .place { background:var(--gold); color:#5c4100; }
.result-name { font-weight:900; overflow-wrap:anywhere; }
.result-detail { color:var(--muted); font-size:12px; margin-top:2px; }
.result-total { font-size:24px; font-weight:950; color:var(--blue-dark); }
.results-actions { padding:0 14px 16px; display:grid; gap:9px; }

.dialog { width:min(calc(100% - 24px),700px); max-height:88vh; border:0; border-radius:24px; padding:0; color:var(--ink); box-shadow:0 28px 80px rgba(0,0,0,.28); }
.dialog::backdrop { background:rgba(4,28,36,.55); backdrop-filter:blur(5px); }
.dialog-head { position:sticky; top:0; z-index:2; display:flex; align-items:center; justify-content:space-between; gap:12px; padding:15px 17px; background:#f9fbfa; border-bottom:1px solid var(--line); }
.dialog-head h2 { margin:0; font-size:20px; }
.dialog-body { padding:17px; overflow:auto; }
.dialog-body h3 { margin:16px 0 6px; color:var(--blue-dark); }
.dialog-body h3:first-child { margin-top:0; }
.dialog-body p { margin:0 0 10px; line-height:1.5; color:#425a62; }

.score-table-wrap { overflow:auto; border:1px solid var(--line); border-radius:16px; }
.score-table { width:max-content; min-width:100%; border-collapse:separate; border-spacing:0; font-size:13px; }
.score-table th,.score-table td { padding:9px 10px; border-right:1px solid var(--line); border-bottom:1px solid var(--line); text-align:center; background:#fff; }
.score-table th { position:sticky; top:0; background:#eef5f5; color:var(--blue-dark); z-index:1; }
.score-table th:first-child,.score-table td:first-child { position:sticky; left:0; text-align:left; min-width:125px; z-index:2; }
.score-table th:first-child { z-index:3; }
.score-table tr:last-child td { border-bottom:0; }
.score-table th:last-child,.score-table td:last-child { border-right:0; font-weight:950; }
.score-cell-btn { width:34px; height:34px; border:0; border-radius:10px; background:#eef3f2; color:var(--ink); font-weight:900; cursor:pointer; }
.score-cell-btn.empty { color:#96a5aa; }
.score-cell-btn.active { background:#dceff3; color:var(--blue-dark); outline:2px solid var(--blue); }

.toast { position:fixed; left:50%; bottom:calc(20px + env(safe-area-inset-bottom)); z-index:50; transform:translate(-50%,20px); opacity:0; pointer-events:none; background:#153d49; color:#fff; padding:11px 15px; border-radius:14px; box-shadow:0 12px 30px rgba(0,0,0,.24); transition:.25s; max-width:calc(100% - 32px); text-align:center; font-weight:800; font-size:13px; }
.toast.show { transform:translate(-50%,0); opacity:1; }

@media (min-width: 680px) {
  .main-content { padding:26px; }
  .score-buttons { grid-template-columns:repeat(6,1fr); }
  .score-btn { aspect-ratio:1; }
  .setup-body { padding:28px; }
}

@media (max-width: 430px) {
  .mini-green { transform:scale(.82); transform-origin:top right; }
  .hero-visual { padding:24px 20px; }
  .status-top { align-items:flex-start; }
  .timer-box { min-width:112px; }
  .timer-value { font-size:20px; }
  .game-actions { grid-template-columns:1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *,*::before,*::after { scroll-behavior:auto !important; transition:none !important; }
}
