/* ===== Kendal's Golf Cards Scoring — Golf Course theme ===== */
:root {
  --fairway: #1B4332;   /* primary / header / nav */
  --turf: #52796F;      /* secondary surfaces, buttons */
  --sand: #E8DCC4;      /* cards, table rows, backgrounds */
  --sand-dark: #d8c8a8;
  --sky: #8FBCBB;       /* subtle accents, links */
  --cream: #FAF7F0;     /* page background */
  --gold: #C9A227;      /* winner highlight, primary CTA */
  --gold-dark: #a9871a;
  --ink: #1C2B1F;       /* body text */
  --danger: #9b3a2f;
  --shadow: 0 2px 6px rgba(28, 43, 31, 0.18);
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

/* ===== Header ===== */
.app-header {
  background: var(--fairway);
  color: #fff;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 20;
}
.header-home {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 0;
  width: 100%;
  text-align: left;
}
.header-home .flag { font-size: 1.5rem; line-height: 1; }
.app-title { font-size: 1.15rem; font-weight: 700; letter-spacing: 0.2px; }

.app-main {
  max-width: 860px;
  margin: 0 auto;
  padding: 16px 14px calc(env(safe-area-inset-bottom, 0px) + 28px);
}

/* ===== Typography & sections ===== */
h1, h2, h3 { color: var(--fairway); margin: 0 0 0.5em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
.muted { color: #4a5c4d; font-size: 0.92rem; }
.center { text-align: center; }
a, .link { color: #2f6d68; }

.card {
  background: var(--sand);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

/* ===== Buttons ===== */
button {
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 12px 18px;
  border: none;
  border-radius: var(--radius);
  background: var(--turf);
  color: #fff;
  font-weight: 600;
  box-shadow: var(--shadow);
  width: 100%;
  transition: transform 0.05s ease, filter 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn:hover { filter: brightness(1.05); }
.btn + .btn { margin-top: 12px; }
.btn-primary { background: var(--gold); color: #2a2200; }
.btn-primary:hover { filter: brightness(1.04); }
.btn-fairway { background: var(--fairway); }
.btn-ghost {
  background: transparent;
  color: var(--fairway);
  border: 2px solid var(--turf);
  box-shadow: none;
}
.btn-danger { background: var(--danger); }
.btn-sm { min-height: 40px; padding: 8px 12px; font-size: 0.92rem; width: auto; }
.btn-row { display: flex; gap: 12px; }
.btn-row .btn { margin-top: 0; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Home ===== */
.home-hero { text-align: center; padding: 8px 0 4px; }
.home-hero .big-flag { font-size: 3rem; }

/* ===== Player setup ===== */
.player-list { list-style: none; margin: 0; padding: 0; }
.player-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--cream);
  border: 1px solid var(--sand-dark);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin-bottom: 8px;
}
.player-row.dragging { opacity: 0.5; }
.player-row.drag-over { border-color: var(--gold); border-style: dashed; }
.player-name { flex: 1; font-weight: 600; font-size: 1.05rem; }
.drag-handle {
  cursor: grab;
  font-size: 1.3rem;
  color: var(--turf);
  padding: 0 4px;
  user-select: none;
  touch-action: none;
}
.reorder-btns { display: flex; flex-direction: column; gap: 2px; }
.reorder-btns button {
  background: var(--turf);
  color: #fff;
  border: none;
  border-radius: 6px;
  width: 34px;
  height: 22px;
  line-height: 1;
  font-size: 0.85rem;
}
.icon-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  padding: 6px;
  color: var(--turf);
}
.icon-btn.remove { color: var(--danger); }
.dealer-badge {
  background: var(--gold);
  color: #2a2200;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
.set-dealer {
  background: transparent;
  border: 1px dashed var(--turf);
  color: var(--turf);
  font-size: 0.68rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.field { margin-bottom: 12px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; }
input[type="text"], input[type="number"] {
  font-family: inherit;
  font-size: 1.1rem;
  padding: 12px;
  border: 2px solid var(--sand-dark);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  width: 100%;
}
input:focus { outline: none; border-color: var(--turf); }
.inline-add { display: flex; gap: 8px; }
.inline-add input { flex: 1; }
.inline-add .btn { width: auto; }
.error-msg {
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 600;
  margin-top: 6px;
  min-height: 1.1em;
}

.roster-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip {
  background: var(--sky);
  color: #14332f;
  border: none;
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 0.95rem;
}
.chip:disabled { opacity: 0.4; }

/* ===== Scoring ===== */
.hole-header { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.hole-title { font-size: 1.5rem; font-weight: 800; color: var(--fairway); }
.dealer-line { font-size: 0.95rem; }
.dealer-line .dealer-badge { margin-left: 4px; }

.score-input-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--cream);
  border: 1px solid var(--sand-dark);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 10px;
}
.score-input-row .who { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; }
.score-input-row input {
  width: 96px;
  text-align: center;
  font-size: 1.4rem;
  font-weight: 700;
  padding: 10px;
}
.nav-btns { display: flex; gap: 12px; margin-top: 8px; }
.nav-btns .btn { margin-top: 0; }

/* ===== Scorecard ===== */
.scorecard-toggle {
  width: 100%;
  background: var(--turf);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 12px;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.scorecard-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-bottom: 16px; }
table.scorecard {
  border-collapse: collapse;
  width: 100%;
  min-width: 340px;
  background: var(--sand);
  border-radius: var(--radius);
  overflow: hidden;
}
table.scorecard th, table.scorecard td {
  padding: 8px 10px;
  text-align: center;
  border-bottom: 1px solid var(--sand-dark);
  white-space: nowrap;
}
table.scorecard thead th {
  background: var(--fairway);
  color: #fff;
  position: sticky;
  top: 0;
}
table.scorecard th.player-col, table.scorecard td.player-col {
  text-align: left;
  font-weight: 700;
  position: sticky;
  left: 0;
  background: var(--sand);
  z-index: 1;
}
table.scorecard thead th.player-col { background: var(--fairway); }
table.scorecard td.total-col { font-weight: 800; background: var(--sand-dark); }
table.scorecard tr.leader td { color: var(--fairway); }
table.scorecard tr.leader td.total-col { background: var(--gold); color: #2a2200; }
.leader-star { color: var(--gold); }
.cur-hole { background: rgba(201,162,39,0.18); }

/* ===== End of round ===== */
.winner-banner {
  text-align: center;
  background: var(--gold);
  color: #2a2200;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.winner-banner .trophy { font-size: 2.6rem; }
.winner-banner .winner-names { font-size: 1.5rem; font-weight: 800; margin-top: 4px; }
.tie-actions .btn { margin-top: 10px; }

/* ===== History ===== */
.history-entry {
  background: var(--sand);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  overflow: hidden;
}
.history-summary {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--ink);
}
.history-summary .h-players { font-weight: 700; font-size: 1.05rem; }
.history-summary .h-winner { color: var(--fairway); font-weight: 700; }
.history-summary .h-date { font-size: 0.85rem; color: #4a5c4d; }
.history-detail { padding: 0 16px 16px; }
.history-detail .btn-danger { margin-top: 12px; }

.badge-win { color: var(--gold); }

.stats-table { width: 100%; border-collapse: collapse; }
.stats-table th, .stats-table td { padding: 8px; text-align: center; border-bottom: 1px solid var(--sand-dark); }
.stats-table th:first-child, .stats-table td:first-child { text-align: left; }

.empty-state { text-align: center; padding: 30px 10px; color: #4a5c4d; }
.empty-state .big { font-size: 2.4rem; }

/* ===== Small utilities (kept as classes so a strict CSP style-src can
   forbid inline style attributes) ===== */
.hidden { display: none; }
.resume-sub { margin-top: 10px; }
.form-label { font-weight: 600; display: block; margin-bottom: 6px; }
.quick-add-label { margin: 10px 0 4px; }
.group-card {
  background: var(--sand);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}

.back-link {
  background: none;
  border: none;
  color: var(--fairway);
  font-weight: 700;
  padding: 6px 0;
  margin-bottom: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.section-links { display: flex; justify-content: center; margin-top: 12px; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  transform: translateX(-50%) translateY(20px);
  background: var(--fairway);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== Responsive ===== */
@media (min-width: 640px) {
  .app-title { font-size: 1.3rem; }
  .score-input-row input { width: 120px; }
}
@media (max-width: 380px) {
  html, body { font-size: 16px; }
  .app-title { font-size: 1rem; }
}
