/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green-dark:   #1a4a1c;
  --green-mid:    #2d7a2d;
  --green-light:  #4caf50;
  --sand:         #d4b87a;
  --water:        #1565c0;
  --navy:         #0f1923;
  --panel:        #1a1f2e;
  --panel-border: #2a3040;
  --text:         #e8f0e8;
  --text-dim:     #8a9e8a;
  --accent:       #f0c040;
  --accent2:      #4caf50;
  --red:          #e74c3c;
  --white:        #ffffff;
  --btn-h:        52px;
  --radius:       12px;
}

html, body {
  height: 100%;
  background: var(--navy);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== SHARED COMPONENTS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--btn-h);
  padding: 0 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s, opacity 0.1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}
.btn:active { transform: scale(0.94); opacity: 0.85; }

.btn-primary   { background: var(--accent); color: #111; }
.btn-secondary { background: var(--panel-border); color: var(--text); }
.btn-danger    { background: var(--red); color: #fff; }
.btn-green     { background: var(--green-mid); color: #fff; }
.btn-full      { width: 100%; }

input[type="text"] {
  width: 100%;
  height: var(--btn-h);
  padding: 0 16px;
  background: var(--panel-border);
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 18px;
  outline: none;
  transition: border-color 0.2s;
}
input[type="text"]:focus { border-color: var(--accent); }
input[type="text"]::placeholder { color: var(--text-dim); }

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== WELCOME SCREEN ===== */
#screen-welcome {
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 0;
  background: linear-gradient(160deg, #0f2a10 0%, #0f1923 60%);
}

.welcome-logo {
  font-size: 64px;
  line-height: 1;
  margin-bottom: 8px;
}

.welcome-title {
  font-size: 32px;
  font-weight: 900;
  letter-spacing: -0.5px;
  color: var(--accent);
  margin-bottom: 4px;
  text-align: center;
}

.welcome-sub {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 36px;
  text-align: center;
}

.welcome-form {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mode-btn {
  height: 56px;
  background: var(--panel-border);
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.mode-btn.selected {
  background: rgba(240, 192, 64, 0.15);
  border-color: var(--accent);
  color: var(--accent);
}

/* ===== OPPONENT SELECT SCREEN ===== */
#screen-opponent {
  background: var(--navy);
}

.screen-header {
  padding: 16px 20px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.screen-header h2 {
  font-size: 18px;
  font-weight: 800;
  color: var(--accent);
  flex: 1;
}

.btn-back {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
  -webkit-tap-highlight-color: transparent;
}

.opponent-list {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.opponent-card {
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.opponent-card:active { transform: scale(0.97); }
.opponent-card.selected {
  border-color: var(--accent);
  background: rgba(240, 192, 64, 0.08);
}

.avatar-wrap {
  flex-shrink: 0;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  overflow: hidden;
  position: relative;
}

.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.avatar-fallback {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 900;
  color: #fff;
}

.opp-info { flex: 1; min-width: 0; }
.opp-name { font-size: 17px; font-weight: 800; margin-bottom: 2px; }

.diff-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 20px;
  margin-bottom: 5px;
}
.diff-hard   { background: rgba(231,76,60,0.25); color: #e74c3c; }
.diff-medium { background: rgba(243,156,18,0.25); color: #f39c12; }
.diff-easy   { background: rgba(76,175,80,0.25);  color: #4caf50; }

.opp-tagline {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.4;
  /* Wrap the full bio onto as many lines as needed (no truncation) */
  white-space: normal;
  overflow-wrap: break-word;
}

.opp-check {
  font-size: 22px;
  opacity: 0;
  transition: opacity 0.15s;
}
.opponent-card.selected .opp-check { opacity: 1; }

.opponent-footer {
  padding: 12px 14px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--panel-border);
}

/* ===== GAME SCREEN ===== */
#screen-game {
  background: var(--green-dark);
}

.game-hud {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-border);
  padding: 0 8px;
  height: 44px;
  flex-shrink: 0;
  overflow: hidden;
}

.hud-seg {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--panel-border);
  height: 100%;
  padding: 2px 4px;
  min-width: 0;
}
.hud-seg:last-child { border-right: none; }

.hud-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  line-height: 1;
}

.hud-val {
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.hud-val.val-green  { color: var(--green-light); }
.hud-val.val-yellow { color: var(--accent); }
.hud-val.val-red    { color: var(--red); }

#game-canvas {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.controls-panel {
  background: var(--panel);
  border-top: 1px solid var(--panel-border);
  padding: 8px 10px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

/* Club row — all 7 clubs share the width so nothing is hidden off-screen */
.club-row {
  display: flex;
  gap: 5px;
  padding-bottom: 2px;
}

.club-btn {
  flex: 1 1 0;
  min-width: 0;
  height: 36px;
  padding: 0 4px;
  background: var(--panel-border);
  border: 2px solid transparent;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.12s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.club-btn.selected {
  background: rgba(76,175,80,0.2);
  border-color: var(--green-light);
  color: var(--green-light);
}
.club-btn.disabled {
  opacity: 0.3;
  pointer-events: none;
}

/* Aim row */
.aim-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-aim {
  flex: 1;
  height: 42px;
  background: var(--panel-border);
  border: none;
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background 0.1s;
}
.btn-aim:active { background: #3a4255; }

.aim-display {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  min-width: 46px;
  text-align: center;
  flex-shrink: 0;
}

/* Power strength selector (levels 1–6) */
.power-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.power-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  width: 40px;
  flex-shrink: 0;
}

.power-adj {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  background: var(--panel-border);
  border: none;
  border-radius: 8px;
  color: var(--text);
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background 0.1s, opacity 0.1s;
}
.power-adj:active { background: #3a4255; }
.power-adj:disabled { opacity: 0.3; pointer-events: none; }

.power-bar-track {
  position: relative;
  flex: 1;
  height: 18px;
  background: #222a35;
  border-radius: 9px;
  overflow: hidden;
  border: 1px solid var(--panel-border);
}

.power-bar-fill {
  height: 100%;
  width: 83.3%;
  border-radius: 9px;
  background: linear-gradient(90deg, #4caf50 0%, #8bc34a 45%, #f0c040 75%, #e67e22 100%);
  transition: width 0.12s ease, background 0.12s;
}
/* Overswing fill turns hot */
.power-bar-fill.over {
  background: linear-gradient(90deg, #f0c040 0%, #e67e22 55%, #e74c3c 100%);
}

/* Marker showing the 100% (full clean power) point — anything past it is overswing */
.power-bar-mark {
  position: absolute;
  top: -1px;
  bottom: -1px;
  left: 83.3%;       /* 100 / 120 */
  width: 2px;
  background: rgba(255,255,255,0.55);
}

.power-dist {
  font-size: 13px;
  font-weight: 800;
  color: var(--accent);
  width: 52px;
  text-align: right;
  flex-shrink: 0;
}

/* ===== INTRO OVERLAY ===== */
.intro-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  background: rgba(8, 14, 10, 0.82);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.intro-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 20px;
}

.intro-title {
  font-size: 22px;
  font-weight: 900;
  color: var(--accent);
  text-align: center;
  margin-bottom: 14px;
}

.intro-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 11px;
  margin-bottom: 18px;
}

.intro-list li {
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  padding-left: 22px;
  position: relative;
}
.intro-list li::before {
  content: '⛳';
  position: absolute;
  left: 0;
  top: 0;
  font-size: 13px;
}
.intro-list b { color: var(--accent); font-weight: 800; }

/* ===== CART GIRL EVENT MODAL ===== */
.cart-overlay {
  position: absolute;
  inset: 0;
  z-index: 60;
  background: rgba(8, 14, 10, 0.85);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: cartIn 0.25s ease;
}

@keyframes cartIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.cart-card {
  width: 100%;
  max-width: 340px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 22px 20px;
  text-align: center;
}

.cart-avatar {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  overflow: hidden;
  margin: 0 auto 14px;
  border: 3px solid var(--accent);
}
.cart-avatar img { width: 100%; height: 100%; object-fit: cover; }
.cart-avatar .avatar-fallback { font-size: 38px; }

.cart-title {
  font-size: 22px;
  font-weight: 900;
  color: var(--accent);
  margin-bottom: 8px;
}

.cart-text {
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  margin-bottom: 18px;
}
.cart-text b { color: var(--accent); font-weight: 800; }

.cart-actions {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.av-cart { background: #b8336a; }

/* Swing button */
.btn-swing {
  width: 100%;
  height: 48px;
  background: linear-gradient(135deg, #2d7a2d, #4caf50);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 1px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 0.08s, opacity 0.1s;
}
.btn-swing:active { transform: scale(0.96); opacity: 0.85; }
.btn-swing:disabled {
  opacity: 0.35;
  pointer-events: none;
}

/* Penalty notice */
.penalty-toast {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(231, 76, 60, 0.92);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  padding: 10px 20px;
  border-radius: 10px;
  pointer-events: none;
  z-index: 10;
  text-align: center;
  animation: toastFade 2s ease forwards;
}

@keyframes toastFade {
  0%   { opacity: 0; transform: translate(-50%, -60%); }
  15%  { opacity: 1; transform: translate(-50%, -50%); }
  75%  { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%); }
}

/* ===== HOLE SUMMARY SCREEN ===== */
#screen-hole-summary {
  align-items: stretch;
  justify-content: flex-start;
  background: linear-gradient(160deg, #0f2a10 0%, #0f1923 70%);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.summary-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 20px;
  gap: 20px;
}

.summary-hole-label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-dim);
}

.summary-score-label {
  font-size: 48px;
  font-weight: 900;
  text-align: center;
  line-height: 1;
}
.label-eagle   { color: #9b59b6; }
.label-birdie  { color: #f39c12; }
.label-par     { color: var(--green-light); }
.label-bogey   { color: #e67e22; }
.label-double  { color: var(--red); }
.label-triple  { color: #c0392b; }
.label-other   { color: #e74c3c; }

.summary-strokes {
  font-size: 18px;
  color: var(--text-dim);
  text-align: center;
}

/* AI reveal section */
.ai-reveal {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.ai-reveal-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
}

.ai-reveal-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
}

.ai-avatar-sm {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
}
.ai-avatar-sm img { width: 100%; height: 100%; object-fit: cover; }
.ai-avatar-sm .avatar-fallback { font-size: 18px; }

.ai-reveal-info { flex: 1; }
.ai-reveal-name { font-size: 16px; font-weight: 800; margin-bottom: 2px; }
.ai-reveal-score { font-size: 15px; color: var(--text-dim); }
.ai-reveal-score span { font-weight: 800; color: var(--text); }

/* Running scoreboard in summary */
.scorecard {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.scorecard table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.scorecard th {
  background: var(--panel-border);
  padding: 8px 10px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
}

.scorecard td {
  padding: 9px 10px;
  text-align: center;
  border-top: 1px solid var(--panel-border);
  font-weight: 600;
}

.scorecard td:first-child { text-align: left; color: var(--text-dim); font-size: 12px; }
.scorecard .total-row td  { font-weight: 800; background: rgba(240,192,64,0.07); }

.cell-under { color: #9b59b6; font-weight: 800; }
.cell-even  { color: var(--green-light); }
.cell-over1 { color: #e67e22; }
.cell-over2 { color: var(--red); }

.summary-footer {
  padding: 12px 20px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--panel-border);
  flex-shrink: 0;
}

/* ===== FINAL SCORE SCREEN ===== */
#screen-final {
  background: linear-gradient(160deg, #0a1f0b 0%, #0f1923 70%);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.final-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 20px;
  gap: 22px;
}

.final-trophy { font-size: 72px; line-height: 1; text-align: center; }

.final-headline {
  font-size: 26px;
  font-weight: 900;
  text-align: center;
  line-height: 1.2;
  color: var(--accent);
}

.final-msg {
  font-size: 15px;
  color: var(--text-dim);
  text-align: center;
  font-style: italic;
  max-width: 300px;
}

.final-vs {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 16px;
}

.final-player-card {
  flex: 1;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
}
.final-player-card.winner-card { border-color: var(--accent); }

.fp-name { font-size: 13px; font-weight: 700; color: var(--text-dim); margin-bottom: 6px; }
.fp-score {
  font-size: 42px;
  font-weight: 900;
  line-height: 1;
  margin-bottom: 4px;
}
.fp-vs { color: var(--text-dim); font-size: 14px; }

.final-vs-sep { font-size: 22px; font-weight: 900; color: var(--text-dim); flex-shrink: 0; }

.final-footer {
  padding: 12px 20px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

/* ===== SCORE DELTA COLORS ===== */
.delta-under { color: #9b59b6; }
.delta-even  { color: var(--green-light); }
.delta-over  { color: #e67e22; }

/* ===== AVATAR COLORS ===== */
.av-shane  { background: #2c3e50; }
.av-dan    { background: #1a5276; }
.av-dante  { background: #641e16; }
.av-ryan   { background: #1d4a1a; }
.av-logan  { background: #4a2060; }
