:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --bar: rgba(249, 249, 251, 0.88);
  --text: #111114;
  --muted: #6e6e76;
  --line: rgba(60, 60, 67, 0.14);
  --accent: #23874a;
  --accent-soft: rgba(35, 135, 74, 0.13);
  --danger: #e5383b;
  --eagle: #9b4de0;
  --birdie: #1f9d55;
  --par: #8e8e93;
  --bogey: #ec8c13;
  --double: #e5383b;
  --under: #1f9d55;
  --over: #e07b00;
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --bar: rgba(22, 22, 24, 0.88);
    --text: #f2f2f7;
    --muted: #98989f;
    --line: rgba(84, 84, 88, 0.55);
    --accent: #46c26c;
    --accent-soft: rgba(70, 194, 108, 0.18);
    --birdie: #34c463;
    --under: #46c26c;
    --over: #f5a524;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: 0.35; cursor: default; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
h4 { margin: 0 0 10px; font-size: 15px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.under { color: var(--under); }
.over { color: var(--over); }
.even { color: var(--muted); }

/* ---------- Leisten ---------- */

.topbar {
  flex: none;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: env(safe-area-inset-top) 8px 0;
  min-height: calc(48px + env(safe-area-inset-top));
  background: var(--bar);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--line);
  z-index: 2;
}
.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 56vw;
}
.tb-left { justify-self: start; }
.tb-right { justify-self: end; }
.tb-btn {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 44px;
  padding: 0 8px;
  color: var(--accent);
  font-size: 17px;
}
.tb-btn.back { padding-left: 0; }
.tb-btn.back svg { width: 26px; height: 26px; }

.content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 16px 16px 32px;
}

.tabbar, .summary {
  flex: none;
  display: flex;
  background: var(--bar);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 0 5px;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
}
.tabbar a.on { color: var(--accent); }
.tabbar svg { width: 25px; height: 25px; }

.summary > div {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 9px 0 8px;
}
.summary b { font-size: 17px; font-variant-numeric: tabular-nums; }
.summary small { font-size: 11px; color: var(--muted); }

/* ---------- Karten & Listen ---------- */

.card {
  background: var(--card);
  border-radius: var(--radius);
  margin-bottom: 14px;
}
.card.pad { padding: 14px 16px; }
.group { margin-bottom: 22px; }
.group > h3 {
  margin: 0 0 6px 16px;
  font-size: 13px;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--muted);
}
.group > .card { margin-bottom: 0; }
.foot { margin: 6px 16px 0; font-size: 13px; color: var(--muted); }
.sync-line { text-align: center; font-size: 12px; color: var(--muted); margin: 4px 16px 0; }

.list > .row, .list > .field { border-bottom: 0.5px solid var(--line); }
.list > :last-child { border-bottom: 0; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  padding: 10px 16px;
  text-align: left;
}
.row.accent { color: var(--accent); }
.row .title { font-weight: 600; }
.row .sub { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin-top: 3px; }
.row .sub span:last-child { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.grow { flex: 1; min-width: 0; }
.score { display: flex; flex-direction: column; align-items: flex-end; font-variant-numeric: tabular-nums; }
.score b { font-size: 22px; line-height: 1.1; }
.score b.small { font-size: 15px; }
.score small { font-size: 12px; font-weight: 600; }
.chev { color: var(--muted); opacity: 0.6; display: flex; }
.chev svg { width: 18px; height: 18px; }
.play-icon { color: var(--accent); display: flex; }
.play-icon svg { width: 30px; height: 30px; }

.field { display: flex; align-items: center; gap: 12px; padding: 0 16px; min-height: 48px; }
.field > span { flex: none; width: 92px; }
.field input, .field select {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  outline: none;
  padding: 12px 0;
  font-size: 16px;
  text-align: right;
}
.field select { direction: rtl; }
textarea.notes {
  display: block;
  width: 100%;
  border: 0;
  background: none;
  resize: vertical;
  padding: 12px 16px;
  font-size: 16px;
  outline: none;
}

.empty-state { text-align: center; padding: 48px 20px; }
.empty-state .emoji { font-size: 52px; }
.empty-state h2 { margin: 10px 0 6px; font-size: 21px; }
.empty-state p { margin: 0 0 20px; color: var(--muted); }

/* ---------- Knöpfe ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 22px;
  border-radius: 12px;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: var(--card); color: var(--danger); }
.btn.block { display: flex; width: 100%; }
.btn.big { min-height: 54px; font-size: 17px; margin-top: 6px; }

.segmented {
  display: flex;
  background: rgba(118, 118, 128, 0.14);
  border-radius: 10px;
  padding: 2px;
  margin-bottom: 14px;
}
.segmented button {
  flex: 1;
  min-height: 32px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 6px;
}
.segmented button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14); font-weight: 600; }
@media (prefers-color-scheme: dark) { .segmented button.on { background: #636366; } }

/* ---------- Abschläge ---------- */

.tee {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
}
.tee-weiss { background: #f1f1f1; color: #111; }
.tee-gelb { background: #f8c933; color: #111; }

.tee-picker { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tee-option {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 4px;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
}
.tee-option small { font-size: 12px; opacity: 0.85; }
.tee-option input { position: absolute; opacity: 0; pointer-events: none; }
.tee-option:has(input:checked) { box-shadow: 0 0 0 3px var(--bg), 0 0 0 6px var(--accent); }

/* ---------- Score-Zellen (Scorecard-Stil) ---------- */

.sc {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  border-radius: 50%;
  flex: none;
}
.sc.sm { width: 25px; height: 25px; font-size: 13px; }
.sc.empty { color: var(--muted); opacity: 0.6; }
.sc.r-par { box-shadow: inset 0 0 0 1.5px var(--line); }
.sc.r-eagle { background: var(--eagle); color: #fff; box-shadow: 0 0 0 2px var(--card), 0 0 0 3.5px var(--eagle); }
.sc.r-birdie { background: var(--birdie); color: #fff; }
.sc.r-bogey { background: var(--bogey); color: #fff; border-radius: 6px; }
.sc.r-double { background: var(--double); color: #fff; border-radius: 6px; box-shadow: 0 0 0 2px var(--card), 0 0 0 3.5px var(--double); }
.sc.sm.r-bogey, .sc.sm.r-double { border-radius: 5px; }

.t-eagle { color: var(--eagle); }
.t-birdie { color: var(--birdie); }
.t-par { color: var(--muted); }
.t-bogey { color: var(--bogey); }
.t-double { color: var(--double); }

/* ---------- Spielen ---------- */

.strip {
  flex: none;
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 6px 8px;
  background: var(--bar);
  border-bottom: 0.5px solid var(--line);
}
.strip::-webkit-scrollbar { display: none; }
.strip button {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 3px 4px 5px;
  border-radius: 9px;
}
.strip button small { font-size: 11px; color: var(--muted); }
.strip button.on { background: var(--accent-soft); }
.strip button.on small { color: var(--text); font-weight: 700; }
.strip .sc.r-eagle, .strip .sc.r-double { box-shadow: none; }

.hole-head { text-align: center; margin-bottom: 18px; }
.hole-head h2 { margin: 0 0 8px; font-size: 34px; letter-spacing: -0.02em; }
.info3 { display: flex; }
.info3 > div { flex: 1; display: flex; flex-direction: column; align-items: center; }
.info3 b { font-size: 19px; font-variant-numeric: tabular-nums; }
.info3 small { font-size: 12px; color: var(--muted); }

.counter { display: flex; align-items: center; margin-bottom: 18px; }
.circle {
  flex: none;
  width: 78px;
  height: 78px;
  border-radius: 50%;
  font-size: 40px;
  font-weight: 500;
  line-height: 1;
  background: var(--accent-soft);
  color: var(--accent);
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.08s;
}
.circle.primary { background: var(--accent); color: #fff; }
.circle:active:not(:disabled) { transform: scale(0.92); }
.count { flex: 1; text-align: center; }
.count .num.muted { opacity: 0.35; }
.count .num { font-size: 96px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -0.03em; }
.count .label { font-weight: 600; margin-top: 4px; min-height: 21px; }
.bump { animation: bump 0.22s ease-out; }
@keyframes bump { 40% { transform: scale(1.12); } }

.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 18px; }
.quick button {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 2px;
  border-radius: 12px;
  background: rgba(118, 118, 128, 0.12);
}
.quick button b { font-size: 19px; }
.quick button small { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.quick button.on { background: var(--accent); color: #fff; }
.quick button.on small { color: rgba(255, 255, 255, 0.85); }

.drive > span { display: block; font-weight: 500; margin-bottom: 8px; }
.drive .segmented { margin-bottom: 0; }

.history .info3 { margin-bottom: 12px; }
.recent { display: flex; align-items: center; gap: 6px; }
.recent small { color: var(--muted); margin-right: 4px; }

/* ---------- Runde / Scorecard ---------- */

.round-head { display: flex; align-items: center; gap: 12px; }
.round-head .title { font-weight: 600; font-size: 17px; }
.round-head .sub { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin-top: 4px; }
.big-score { display: flex; flex-direction: column; align-items: flex-end; }
.big-score b { font-size: 46px; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.big-score span { font-weight: 600; }

.compare { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; font-size: 15px; }
.compare select {
  max-width: 60%;
  border: 0;
  border-radius: 8px;
  padding: 6px 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 15px;
}

.scorecard {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  margin-bottom: 14px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.scorecard th { width: 40px; text-align: left; font-weight: 400; font-size: 11px; color: var(--muted); }
.scorecard td { text-align: center; padding: 3px 0; }
.scorecard td.tot { width: 36px; font-weight: 600; }
.scorecard tr.tiny td { font-size: 9px; }
.scorecard tr.score-row td { padding: 6px 0; border-top: 0.5px solid var(--line); }
.scorecard tr.delta-row td { font-size: 9.5px; font-weight: 600; letter-spacing: -0.03em; white-space: nowrap; padding: 3px 1px; }
.sc-total { display: flex; align-items: baseline; gap: 10px; border-top: 0.5px solid var(--line); padding-top: 10px; }
.sc-total span { flex: 1; font-weight: 600; }
.sc-total b { font-size: 20px; }

.counts { display: flex; width: 100%; }
.counts > div { flex: 1; display: flex; flex-direction: column; align-items: center; }
.counts b { font-size: 20px; font-variant-numeric: tabular-nums; }
.counts small { font-size: 11px; color: var(--muted); }

/* ---------- Rekorde & Löcher ---------- */

.records { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.record {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px;
  background: var(--card);
  border-radius: var(--radius);
  min-width: 0;
}
.rec-head { display: flex; align-items: center; gap: 5px; }
.rec-head small { flex: 1; font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-head em { font-style: normal; font-size: 11px; color: var(--muted); }
.record b { font-size: 22px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.record small.muted { font-size: 12px; }

.chart { width: 100%; height: auto; display: block; overflow: visible; stroke: none; }
.chart .bar { stroke: none; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .rule { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; }
.chart .axis { fill: var(--muted); stroke: none; font-size: 11px; }
.chart .line { stroke: var(--accent); stroke-width: 2.5; fill: none; opacity: 0.55; }
.chart .dot { fill: var(--accent); stroke: var(--card); stroke-width: 2; }
.chart .dot.under, .chart .r-birdie { fill: var(--birdie); }
.chart .dot.over { fill: var(--over); }
.chart .dot.even, .chart .r-par { fill: var(--par); }
.chart .r-eagle { fill: var(--eagle); }
.chart .r-bogey { fill: var(--bogey); }
.chart .r-double { fill: var(--double); }

.hole-no {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}
.hole-title { display: flex; justify-content: space-between; margin-bottom: 12px; }
.tee-lengths { display: grid; grid-template-columns: repeat(2, 1fr); text-align: center; }
.tee-lengths small { display: block; margin-top: 4px; font-variant-numeric: tabular-nums; }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.tile { background: var(--card); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.tile small { display: block; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile b { font-size: 21px; font-variant-numeric: tabular-nums; }

.drive-row { margin-bottom: 12px; }
.drive-row:last-child { margin-bottom: 0; }
.drive-row > div:first-child { display: flex; justify-content: space-between; margin-bottom: 6px; }
.meter { height: 6px; background: rgba(118, 118, 128, 0.18); border-radius: 3px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

.course-table { overflow: hidden; }
.course-table table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.course-table th, .course-table td { text-align: center; padding: 8px 2px; }
.course-table th { font-size: 12px; font-weight: 600; color: var(--muted); }
.course-table th.tee-weiss, .course-table th.tee-gelb { color: inherit; }
.course-table tr:nth-child(even) td { background: rgba(118, 118, 128, 0.07); }
.course-table tr.split td { border-bottom: 2px solid var(--line); }
.course-table tr.foot-row td { border-top: 1px solid var(--line); }

/* ---------- Dialog & Hinweis ---------- */

.sheet-backdrop {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: flex-end;
  animation: fade 0.18s ease-out;
}
.sheet { width: 100%; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); animation: slide 0.22s ease-out; }
.sheet-card { background: var(--card); border-radius: var(--radius); overflow: hidden; margin-top: 8px; }
.sheet-title { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 14px 16px; text-align: center; border-bottom: 0.5px solid var(--line); }
.sheet-title b { font-size: 14px; color: var(--muted); }
.sheet-title small { font-size: 13px; color: var(--muted); }
.sheet button { display: block; width: 100%; min-height: 56px; font-size: 19px; color: var(--accent); border-bottom: 0.5px solid var(--line); }
.sheet button:last-child { border-bottom: 0; }
.sheet button.strong, .sheet button.cancel { font-weight: 600; }
.sheet button.destructive { color: var(--danger); }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateY(40px); opacity: 0; } }

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  background: rgba(30, 30, 32, 0.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 11;
  animation: fade 0.2s;
}

/* ---------- Anmeldung, Teams, Benutzer ---------- */

.login-head { text-align: center; padding: 28px 12px 20px; }
.login-head .emoji { font-size: 56px; }
.login-head h2 { margin: 8px 0 6px; font-size: 24px; }
.login-head p { margin: 0; color: var(--muted); }

.team-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  margin-bottom: 14px;
  padding: 6px 12px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.team-chip span { font-size: 11px; }
.team-pick { text-align: left; min-width: 0; }
.team-pick .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.info-btn { display: flex; align-items: center; justify-content: center; width: 40px; height: 40px; margin-right: -8px; color: var(--muted); }
.info-btn svg { width: 18px; height: 18px; }
.badge { display: inline-block; padding: 1px 6px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 600; vertical-align: 2px; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 18px; letter-spacing: 0.04em; user-select: all; -webkit-user-select: all; }
.row.danger-text { color: var(--danger); }
.field input[type=checkbox] { flex: none; width: 22px; height: 22px; accent-color: var(--accent); }
.field input::placeholder { color: var(--muted); opacity: 0.7; }
.field > span.grow { flex: 1; width: auto; }
