* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root {
  --sky-1: #ff9b5e;
  --sky-2: #ff5e87;
  --sky-3: #6a3d9b;
  --sky-4: #2a1d4f;
  --sand: #ecc88a;
  --grass: #4cb96b;
  --grass-deep: #2d7d4a;
  --wood: #8a5a32;
  --wood-light: #c08552;
  --gold: #ffd86b;
  --text: #fff5e6;
  --muted: #f0c8a0;
  --danger: #ff5e7e;
  --p1: #ff7b3d;
  --p2: #9bff7a;
  --p3: #ff4d8a;
  --p4: #7ad7ff;
}
html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: linear-gradient(180deg, #ff9b5e 0%, #ff5e87 30%, #6a3d9b 70%, #2a1d4f 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  user-select: none; -webkit-user-select: none;
  touch-action: none; overscroll-behavior: none;
}
#app {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
}
#game {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
}

.screen {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 10;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background:
    radial-gradient(ellipse at 50% 25%, rgba(255,200,140,0.35), transparent 60%),
    linear-gradient(180deg, rgba(40,20,60,0.65) 0%, rgba(20,10,30,0.92) 80%);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fadein 0.25s ease-out;
}
.screen.hidden { display: none; }

@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { 0% { transform: scale(0.7); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes splashpop { 0% { transform: scale(0.5); opacity: 0; } 30% { transform: scale(1.08); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }
@keyframes slideup { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes turnpop { 0% { transform: translateX(-50%) translateY(-30px); opacity: 0; } 30% { transform: translateX(-50%) translateY(0); opacity: 1; } 100% { transform: translateX(-50%) translateY(0); opacity: 1; } }
@keyframes pulseRing { 0%,100% { box-shadow: 0 0 0 0 rgba(255,123,61,0.4); } 50% { box-shadow: 0 0 0 8px rgba(255,123,61,0); } }

.menu-inner, .card-inner, .splash-inner {
  width: min(94vw, 460px);
  text-align: center;
  display: flex; flex-direction: column; align-items: center;
  gap: 14px;
  animation: pop 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}
.card-inner.wide { width: min(94vw, 540px); }

.title {
  font-size: clamp(46px, 13vw, 76px);
  line-height: 1; font-weight: 800;
  letter-spacing: -0.02em;
  text-shadow: 0 0 40px rgba(255,155,94,0.5), 0 4px 0 rgba(0,0,0,0.2);
}
.title-accent {
  background: linear-gradient(90deg, var(--gold), var(--p1) 40%, var(--p3) 80%);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
}
.subtitle {
  color: var(--muted);
  letter-spacing: 0.25em; font-size: 12px;
  text-transform: uppercase;
  margin-bottom: 20px;
}
h2 {
  font-size: 26px; font-weight: 800;
  background: linear-gradient(90deg, var(--gold), var(--p1));
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  margin-bottom: 6px;
}
.muted { color: var(--muted); }
.small { font-size: 12px; letter-spacing: 0.05em; }

.big-btn {
  background: linear-gradient(135deg, var(--p1), var(--p3));
  color: #1f0a0a; border: none;
  font-size: 22px; font-weight: 800;
  letter-spacing: 0.1em; padding: 16px 38px;
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(255,123,61,0.4), 0 0 0 1px rgba(255,255,255,0.18) inset;
  cursor: pointer;
  transition: transform 0.1s ease;
}
.big-btn:active { transform: scale(0.95); }
.big-btn:disabled { opacity: 0.5; cursor: default; box-shadow: none; }

.ghost-btn {
  background: rgba(255,255,255,0.08);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.16);
  font-size: 15px; font-weight: 600;
  padding: 12px 26px; border-radius: 999px;
  cursor: pointer; letter-spacing: 0.05em;
  transition: background 0.15s;
}
.ghost-btn:active { background: rgba(255,255,255,0.18); }

.text-input {
  width: 100%; max-width: 360px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: var(--text);
  font-size: 22px; font-weight: 700;
  padding: 14px 18px;
  border-radius: 14px;
  outline: none;
  text-align: center;
  letter-spacing: 0.08em;
  transition: border-color 0.15s, background 0.15s;
}
.text-input::placeholder { color: rgba(255,245,230,0.4); }
.text-input:focus { border-color: var(--gold); background: rgba(255,255,255,0.16); }
.code-input {
  font-size: 36px; font-weight: 800;
  letter-spacing: 0.4em; text-transform: uppercase;
  color: var(--gold);
}

.lobby-code {
  font-size: 56px; font-weight: 900;
  letter-spacing: 0.15em;
  background: linear-gradient(135deg, var(--gold), var(--p1));
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  text-shadow: 0 0 40px rgba(255,216,107,0.4);
  margin: 4px 0;
  font-variant-numeric: tabular-nums;
}
.lobby-players {
  display: flex; flex-direction: column; gap: 10px;
  width: 100%; margin: 18px 0 14px;
}
.lobby-player {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 14px;
  font-weight: 700;
  animation: slideup 0.3s ease-out;
}
.lobby-player.empty {
  background: transparent;
  border: 1px dashed rgba(255,255,255,0.18);
  opacity: 0.55;
}
.lobby-player .lp-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 10px currentColor;
  flex-shrink: 0;
}
.lobby-player .lp-name { flex: 1; text-align: left; color: var(--text); }
.lobby-player .lp-tag {
  font-size: 11px; padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255,255,255,0.16);
  color: rgba(255,255,255,0.9);
}
.lobby-player .lp-tag.host { background: rgba(255,216,107,0.25); color: var(--gold); }
.lobby-player .lp-tag.you  { background: rgba(255,123,61,0.3); color: var(--p1); }
.lobby-player .lp-tag.discon { background: rgba(255,94,126,0.25); color: var(--danger); }

/* HUD */
#hud {
  position: absolute; top: 0; left: 0; right: 0;
  padding: calc(env(safe-area-inset-top) + 8px) 10px 6px;
  z-index: 5; pointer-events: none;
}
#hud.hidden { display: none; }
.hud-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.hud-btn {
  pointer-events: auto;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(20, 10, 30, 0.7);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.14);
  font-size: 19px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.hud-btn:active { transform: scale(0.92); }
.hud-mid { flex: 1; text-align: center; min-width: 0; }
.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
#hole-label {
  font-size: 12px; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase;
  text-shadow: 0 1px 4px rgba(0,0,0,0.7);
}
#turn-row { display: flex; justify-content: center; gap: 4px; margin-top: 5px; flex-wrap: wrap; }
.pchip {
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(20, 10, 30, 0.6);
  border: 1px solid rgba(255,255,255,0.14);
  padding: 3px 7px; border-radius: 10px;
  font-size: 11px; font-weight: 700;
  transition: transform 0.2s, box-shadow 0.2s;
}
.pchip.active { transform: scale(1.12); border-color: rgba(255,255,255,0.5); box-shadow: 0 0 14px currentColor; }
.pchip.holed { opacity: 0.55; }
.pchip.discon { opacity: 0.4; text-decoration: line-through; }
.pdot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 6px currentColor;
}
.pname { color: rgba(255,245,230,0.95); }
.pscore { color: rgba(255,245,230,0.95); background: rgba(0,0,0,0.3); padding: 0 5px; border-radius: 6px; font-size: 10px; }
#stroke-counter, #timer {
  font-size: 11px; color: var(--muted);
  background: rgba(20, 10, 30, 0.5);
  padding: 4px 8px; border-radius: 10px;
  pointer-events: auto; font-weight: 600;
}
#timer { color: var(--gold); font-weight: 800; min-width: 36px; text-align: center; }
#timer.urgent { color: var(--danger); animation: pulseRing 0.8s infinite; }

/* Splash */
.splash-inner { gap: 8px; }
#splash-hole {
  font-size: 18px; letter-spacing: 0.3em;
  color: var(--muted); text-transform: uppercase;
  animation: splashpop 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}
#splash-name {
  font-size: clamp(40px, 11vw, 64px); font-weight: 800;
  background: linear-gradient(90deg, var(--gold), var(--p1));
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  animation: splashpop 0.6s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}
#splash-par { font-size: 16px; color: var(--gold); letter-spacing: 0.15em; font-weight: 700;
  animation: splashpop 0.7s cubic-bezier(0.2, 0.9, 0.3, 1.3); }

/* How-to */
.howto-list { display: flex; flex-direction: column; gap: 12px; text-align: left; margin: 16px 0 24px; width: 100%; }
.howto-item {
  display: flex; align-items: center; gap: 14px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14);
  padding: 11px 14px; border-radius: 14px;
  font-size: 14px; line-height: 1.4;
}
.howto-item .emoji-ish {
  font-size: 22px; width: 32px; text-align: center;
  color: var(--gold);
  text-shadow: 0 0 10px var(--gold);
}

/* Scorecards */
.score-rows {
  display: flex; flex-direction: column;
  width: 100%; gap: 8px; margin: 12px 0 18px;
}
.score-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 12px;
  animation: slideup 0.35s ease-out backwards;
}
.score-row .sr-dot { width: 12px; height: 12px; border-radius: 50%; background: currentColor; box-shadow: 0 0 8px currentColor; flex-shrink: 0; }
.score-row .sr-name { flex: 1; text-align: left; font-weight: 700; color: rgba(255,245,230,0.95); }
.score-row .sr-strokes { font-size: 22px; font-weight: 800; min-width: 28px; text-align: center; }
.score-row .sr-rel { font-size: 13px; font-weight: 600; padding: 2px 8px; border-radius: 999px; min-width: 50px; text-align: center; }
.score-row .sr-rel.under { background: rgba(155,255,122,0.22); color: var(--p2); }
.score-row .sr-rel.even  { background: rgba(255,255,255,0.14); color: rgba(255,245,230,0.7); }
.score-row .sr-rel.over  { background: rgba(255,77,138,0.25); color: var(--danger); }

/* Final scorecard table */
.ge-table {
  width: 100%; display: grid;
  grid-template-columns: 14px 70px repeat(18, minmax(18px, 1fr)) 50px;
  gap: 3px 2px; align-items: center;
  font-size: 11px; margin: 14px 0 20px;
  overflow-x: auto;
}
.ge-cell { text-align: center; padding: 4px 2px; font-weight: 600; color: rgba(255,245,230,0.92); }
.ge-cell.head { font-size: 9px; letter-spacing: 0.05em; color: var(--muted); border-bottom: 1px solid rgba(255,255,255,0.1); padding-bottom: 6px; }
.ge-cell.name { text-align: left; font-weight: 700; padding-left: 6px; }
.ge-cell.tot { font-size: 14px; font-weight: 800; }
.ge-cell.dot { width: 12px; height: 12px; border-radius: 50%; background: currentColor; box-shadow: 0 0 6px currentColor; justify-self: center; }
.ge-cell.winner-cell { background: rgba(255,216,107,0.18); border-radius: 6px; }

/* Turn banner */
.turn-banner {
  position: absolute; top: 100px; left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 10, 30, 0.92);
  border: 1px solid rgba(255,255,255,0.2);
  padding: 10px 18px; border-radius: 999px;
  z-index: 4;
  display: flex; align-items: center; gap: 10px;
  pointer-events: none;
  animation: turnpop 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.3);
  font-weight: 800; font-size: 16px; letter-spacing: 0.05em;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
}
.turn-banner.hidden { display: none; }
.tb-dot { width: 14px; height: 14px; border-radius: 50%; background: currentColor; box-shadow: 0 0 12px currentColor; }

/* Connection indicator */
.conn {
  position: absolute; top: calc(env(safe-area-inset-top) + 8px); right: 8px;
  font-size: 10px; padding: 4px 8px; border-radius: 999px;
  background: rgba(20,10,30,0.55);
  z-index: 50;
  pointer-events: none;
  font-weight: 800;
  border: 1px solid rgba(255,255,255,0.1);
}
.conn.hidden { display: none; }
.conn.online { color: var(--p2); }
.conn.offline { color: var(--danger); }

/* Toast */
.toast {
  position: absolute; top: 30%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(20, 10, 30, 0.9);
  color: var(--text);
  padding: 14px 22px; border-radius: 14px;
  font-weight: 700; font-size: 17px;
  z-index: 20; pointer-events: none;
  border: 1px solid rgba(255,255,255,0.15);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  animation: pop 0.3s ease-out;
}
.toast.hidden { display: none; }

.complete-buttons { display: flex; gap: 14px; margin-top: 14px; }

.solo-btn {
  border: 1px solid rgba(255,216,107,0.5) !important;
  color: var(--gold) !important;
}

/* Daily-end screen pieces */
.big-stars { display: flex; gap: 12px; font-size: 56px; margin: 8px 0 4px; }
.big-stars .bs { color: rgba(255,255,255,0.15); text-shadow: 0 1px 4px rgba(0,0,0,0.5); transform: scale(0); display: inline-block; }
.big-stars .bs.lit { color: var(--gold); text-shadow: 0 0 24px var(--gold); animation: starpop 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.4) forwards; }
.big-stars .bs.lit:nth-child(2) { animation-delay: 0.15s; }
.big-stars .bs.lit:nth-child(3) { animation-delay: 0.3s; }
@keyframes starpop { 0% { transform: scale(0); opacity: 0; } 60% { transform: scale(1.3); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }

.daily-summary {
  font-size: 18px;
  margin: 8px 0;
  color: var(--text);
}
.daily-summary .ds-strokes { font-size: 32px; font-weight: 800; color: var(--gold); }
.daily-summary .ds-rel { font-size: 14px; padding: 3px 10px; border-radius: 999px; font-weight: 700; margin-left: 8px; vertical-align: middle; }
.daily-summary .ds-rel.under { background: rgba(155,255,122,0.22); color: var(--p2); }
.daily-summary .ds-rel.even  { background: rgba(255,255,255,0.14); color: rgba(255,245,230,0.7); }
.daily-summary .ds-rel.over  { background: rgba(255,77,138,0.25); color: var(--danger); }

.daily-streak {
  display: flex; gap: 18px; justify-content: center;
  margin: 8px 0 12px;
  font-size: 13px; color: var(--muted);
  letter-spacing: 0.06em; text-transform: uppercase;
}
.daily-streak .ds-stat b { display: block; font-size: 22px; font-weight: 800; color: var(--text); margin-bottom: 2px; }
.daily-streak .ds-stat.fire b { color: var(--p1); }

.daily-history {
  display: flex; gap: 5px; justify-content: center;
  margin: 4px 0 14px;
}
.daily-history .dh-cell {
  width: 28px; height: 28px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 800;
  background: rgba(255,255,255,0.08);
  color: rgba(255,245,230,0.6);
  border: 1px solid rgba(255,255,255,0.08);
  position: relative;
}
.daily-history .dh-cell.played { background: rgba(255,216,107,0.22); border-color: rgba(255,216,107,0.4); color: var(--gold); }
.daily-history .dh-cell.today { outline: 2px solid var(--p1); }

.hidden { display: none !important; }
