/* ============================================================
   Tennis Schwauna ABO - Design-System
   Mobil zuerst, Licht/Dunkel automatisch + manuell umschaltbar,
   iOS-Safe-Areas beruecksichtigt (Notch / Dynamic Island / Home-Indikator).
   ============================================================ */

:root {
  --green-900: #08261a;
  --green-800: #0d3d27;
  --green-700: #145335;
  --green-600: #1f6f43;
  --green-500: #2e8b57;
  --green-400: #4caf72;
  --green-200: #a8dcbd;
  --green-100: #d9f0e3;

  --accent: #e8c547;
  --danger: #d9534f;
  --danger-soft: #fde8e7;

  --bg: #f4f7f5;
  --bg-elevated: #ffffff;
  --bg-sunken: #eaefec;
  --surface-border: #dde5e0;
  --text: #12211a;
  --text-muted: #5f7168;
  --text-faint: #93a39a;

  --brand: var(--green-600);
  --brand-contrast: #ffffff;
  --ring: color-mix(in srgb, var(--brand) 35%, transparent);

  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;

  --shadow-sm: 0 1px 2px rgba(8, 38, 26, .06), 0 1px 3px rgba(8, 38, 26, .05);
  --shadow: 0 4px 14px rgba(8, 38, 26, .08), 0 1px 3px rgba(8, 38, 26, .05);
  --shadow-lg: 0 14px 40px rgba(8, 38, 26, .14);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-num: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  --header-h: 58px;
  --tabbar-h: 62px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1410;
    --bg-elevated: #141f1a;
    --bg-sunken: #0e1813;
    --surface-border: #23332b;
    --text: #e7f0ea;
    --text-muted: #9bb0a4;
    --text-faint: #6d8377;
    --brand: var(--green-400);
    --brand-contrast: #06170f;
    --danger-soft: #3a1f1e;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 6px 18px rgba(0, 0, 0, .45);
    --shadow-lg: 0 16px 44px rgba(0, 0, 0, .55);
  }
}

:root[data-theme="dark"] {
  --bg: #0b1410;
  --bg-elevated: #141f1a;
  --bg-sunken: #0e1813;
  --surface-border: #23332b;
  --text: #e7f0ea;
  --text-muted: #9bb0a4;
  --text-faint: #6d8377;
  --brand: var(--green-400);
  --brand-contrast: #06170f;
  --danger-soft: #3a1f1e;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 6px 18px rgba(0, 0, 0, .45);
  --shadow-lg: 0 16px 44px rgba(0, 0, 0, .55);
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

/* Auf dem iPhone soll sich nichts wie eine Webseite anfuehlen:
   kein Text-Callout beim Halten, keine Auswahl beim Tippen. */
body.standalone {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
body.standalone input, body.standalone textarea {
  -webkit-user-select: text;
  user-select: text;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; letter-spacing: -.015em; }
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 650; }

/* ------------------------------------------------------------ Kopfzeile */

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--surface-border);
  padding-top: var(--safe-top);
}

.app-header__inner {
  height: var(--header-h);
  max-width: 780px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-header__brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -.01em;
}
.app-header__brand:hover { text-decoration: none; }
.app-header__brand img { width: 27px; height: 27px; }
.app-header__spacer { flex: 1; }

.icon-btn {
  width: 38px; height: 38px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--surface-border);
  border-radius: 50%;
  background: var(--bg-elevated);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.05rem;
  line-height: 1;
  text-decoration: none;
  flex: 0 0 auto;
  transition: background .15s, color .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover, .icon-btn:focus-visible { color: var(--brand); background: var(--bg-sunken); text-decoration: none; }
.icon-btn:active { transform: scale(.93); }

/* ------------------------------------------------------------ Layout */

.page {
  max-width: 780px;
  margin: 0 auto;
  padding: 18px 16px calc(26px + var(--tabbar-h) + var(--safe-bottom));
}
.page--narrow { max-width: 430px; }

.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: .85rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

/* ------------------------------------------------------------ Karten */

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card__body { padding: 16px; }
.card__head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--surface-border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.card__head h2, .card__head h3 { margin: 0; }
.card__head .app-header__spacer { flex: 1; }

/* Hero: naechstes eigenes Spiel */
.hero {
  position: relative;
  border-radius: var(--radius-lg);
  padding: 20px;
  color: #fff;
  background: linear-gradient(145deg, var(--green-700), var(--green-900));
  box-shadow: var(--shadow);
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute;
  right: -48px; top: -48px;
  width: 190px; height: 190px;
  border: 2px solid rgba(255, 255, 255, .12);
  border-radius: 50%;
}
.hero__label {
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .09em;
  opacity: .8;
  font-weight: 650;
}
.hero__date { font-size: 1.65rem; font-weight: 700; margin: 4px 0 2px; letter-spacing: -.02em; }
.hero__time { opacity: .85; font-size: .95rem; }
.hero__mates { margin-top: 13px; display: flex; flex-wrap: wrap; gap: 6px; position: relative; }
.hero--empty { background: linear-gradient(145deg, #52635a, #333f39); }

/* ------------------------------------------------------------ Kennzahlen */

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat {
  background: var(--bg-elevated);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
  padding: 13px 10px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.stat__value { font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; }
.stat__label { font-size: .72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-top: 2px; }

/* ------------------------------------------------------------ Spielerchips */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 550;
  background: var(--bg-sunken);
  color: var(--text-muted);
  border: 1px solid transparent;
  white-space: nowrap;
}
.chip--me { background: var(--brand); color: var(--brand-contrast); font-weight: 700; }
.chip--on-dark { background: rgba(255, 255, 255, .16); color: #fff; }
.chip--muted { background: transparent; border-color: var(--surface-border); color: var(--text-faint); }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.badge--proposal { background: var(--accent); color: #4a3a00; }
.badge--final { background: var(--green-500); color: #fff; }
.badge--open { background: var(--bg-sunken); color: var(--text-muted); }

/* ------------------------------------------------------------ Spieltagsliste */

.matchlist { list-style: none; margin: 0; padding: 0; }

.match {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--surface-border);
  transition: background .15s;
}
.match:last-child { border-bottom: 0; }
.match--mine { background: color-mix(in srgb, var(--brand) 7%, transparent); }
.match--past { opacity: .45; }
.match--unavailable { background: var(--danger-soft); }

.match__date {
  flex: 0 0 52px;
  text-align: center;
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
  padding: 6px 0;
  line-height: 1.1;
}
.match--mine .match__date { background: var(--brand); color: var(--brand-contrast); }
.match__day { font-size: 1.2rem; font-weight: 700; display: block; }
.match__month { font-size: .66rem; text-transform: uppercase; letter-spacing: .06em; opacity: .8; }

.match__players { flex: 1; display: flex; flex-wrap: wrap; gap: 5px; min-width: 0; }
.match__actions { flex: 0 0 auto; }

.match__strike .chip { text-decoration: line-through; }

/* Filterleiste */
.segmented {
  display: inline-flex;
  background: var(--bg-sunken);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.segmented button {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: .85rem;
  font-weight: 600;
  padding: 6px 15px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s, color .15s;
  -webkit-tap-highlight-color: transparent;
}
.segmented button[aria-pressed="true"] {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ------------------------------------------------------------ Formulare */

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], textarea, select {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  font-size: 1rem; /* unter 16px zoomt iOS beim Fokus hinein */
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
  appearance: none;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--ring);
}
textarea { resize: vertical; min-height: 78px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  font: inherit;
  font-weight: 650;
  font-size: .95rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: var(--brand-contrast);
  cursor: pointer;
  transition: filter .15s, transform .1s;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { filter: brightness(1.07); text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--block { width: 100%; }
.btn--ghost { background: transparent; color: var(--text-muted); border-color: var(--surface-border); }
.btn--ghost:hover { color: var(--brand); border-color: var(--brand); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--sm { padding: 7px 13px; font-size: .82rem; }

/* ------------------------------------------------------------ Hinweise */

.alert {
  padding: 12px 15px;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  border: 1px solid transparent;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.alert--error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.alert--ok { background: var(--green-100); color: var(--green-700); border-color: var(--green-200); }
.alert--info { background: var(--bg-sunken); color: var(--text-muted); border-color: var(--surface-border); }
.alert--warn { background: #fdf4d9; color: #8a6100; border-color: #f0dca4; }
:root[data-theme="dark"] .alert--ok { background: #10301f; color: var(--green-200); }
:root[data-theme="dark"] .alert--warn { background: #33280c; color: #f0dca4; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .alert--ok { background: #10301f; color: var(--green-200); }
  :root:not([data-theme="light"]) .alert--warn { background: #33280c; color: #f0dca4; }
}

/* ------------------------------------------------------------ Tabellen */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.grid { border-collapse: collapse; width: 100%; font-size: .88rem; }
table.grid th, table.grid td {
  padding: 8px 10px;
  text-align: center;
  border-bottom: 1px solid var(--surface-border);
  white-space: nowrap;
}
table.grid th { font-weight: 650; color: var(--text-muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
table.grid td:first-child, table.grid th:first-child { text-align: left; position: sticky; left: 0; background: var(--bg-elevated); }
table.grid tbody tr:hover td { background: var(--bg-sunken); }
table.grid td.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
table.grid .self { background: var(--bg-sunken); color: var(--text-faint); }
table.grid .hot { color: var(--brand); font-weight: 700; }

/* ------------------------------------------------------------ Fusszeile / Tabs */

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 60;
  display: flex;
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid var(--surface-border);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}
.tabbar a {
  flex: 1;
  height: var(--tabbar-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-faint);
  font-size: .68rem;
  font-weight: 600;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.tabbar a .ic { font-size: 1.2rem; line-height: 1; }
.tabbar a.is-active { color: var(--brand); }

/* ------------------------------------------------------------ Sonstiges */

.empty {
  text-align: center;
  padding: 38px 20px;
  color: var(--text-muted);
}
.empty .ic { font-size: 2.4rem; display: block; margin-bottom: 10px; opacity: .5; }

.install-hint {
  display: none;
  gap: 10px;
  align-items: flex-start;
  font-size: .85rem;
}
.install-hint.show { display: flex; }

.feedback-item {
  padding: 11px 0;
  border-bottom: 1px solid var(--surface-border);
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.feedback-item:last-child { border-bottom: 0; }
.feedback-item__body { flex: 1; min-width: 0; }

.skeleton {
  background: linear-gradient(90deg, var(--bg-sunken) 25%, var(--surface-border) 50%, var(--bg-sunken) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (min-width: 640px) {
  h1 { font-size: 1.75rem; }
  .page { padding-top: 26px; }
  .stats { grid-template-columns: repeat(4, 1fr); }
}


/* ------------------------------------------------------------ Tauschboerse */

.card--swap { border-color: color-mix(in srgb, var(--accent) 55%, var(--surface-border)); }
.hero--swap-done { background: linear-gradient(145deg, #1f6f43, #0d3d27); }
.swap-status { text-transform: none; letter-spacing: 0; font-weight: 500; opacity: .9; }

.chip--swapped { background: color-mix(in srgb, var(--accent) 35%, var(--bg-sunken)); color: var(--text); cursor: pointer; list-style: none; }
.chip--swapped::-webkit-details-marker { display: none; }
.chip--offered { background: var(--accent); color: #4a3a00; font-weight: 700; text-decoration: none; }
.chip--take { background: var(--green-100); color: var(--green-700); }
.chip--exchange { background: #e3edff; color: #1f3f8a; }
:root[data-theme="dark"] .chip--take { background: #10301f; color: var(--green-200); }
:root[data-theme="dark"] .chip--exchange { background: #16233d; color: #a9c1ff; }

details.swapinfo { position: relative; display: inline-block; }
details.swapinfo > summary { display: inline-flex; }
.swapinfo__pop {
  position: absolute; z-index: 30; left: 0; top: calc(100% + 6px);
  min-width: 240px; max-width: 320px;
  background: var(--bg-elevated); color: var(--text);
  border: 1px solid var(--surface-border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); padding: 10px 12px; font-size: .85rem; line-height: 1.45;
  white-space: normal;
}
.swapinfo__pop a { display: block; margin-top: 6px; font-weight: 600; }

.offers { display: grid; gap: 10px; }
.offer {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px; border: 1px solid var(--surface-border); border-radius: var(--radius);
  background: var(--bg-elevated); transition: border-color .15s, box-shadow .15s;
}
.offer--mine { border-style: dashed; }
.offer--accepted { border-color: var(--green-500); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green-500) 25%, transparent); background: color-mix(in srgb, var(--green-500) 8%, var(--bg-elevated)); }
.offer--declined { opacity: .5; }
.offer__avatar {
  flex: 0 0 40px; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700;
  background: var(--brand); color: var(--brand-contrast);
}
.offer__body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.offer__title { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.offer__note { font-style: italic; }
.offer__actions { flex: 0 0 auto; display: flex; flex-direction: column; gap: 6px; }

.timeline { display: flex; flex-direction: column; gap: 8px; }
.tl-event {
  display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap;
  font-size: .85rem; color: var(--text-muted); padding: 4px 0;
}
.tl-event--done { color: var(--green-600); font-weight: 600; }
.tl-event__icon { flex: 0 0 auto; }
.msg { display: flex; flex-direction: column; align-items: flex-start; max-width: 85%; }
.msg--mine { align-self: flex-end; align-items: flex-end; }
.msg__meta { font-size: .72rem; color: var(--text-faint); margin: 0 6px 2px; }
.msg__bubble {
  background: var(--bg-sunken); padding: 8px 12px; border-radius: 14px; border-top-left-radius: 4px;
}
.msg--mine .msg__bubble { background: var(--brand); color: var(--brand-contrast); border-top-left-radius: 14px; border-top-right-radius: 4px; }

/* ------------------------------------------------------------ Anleitung */
ol.guide { margin: 0 0 12px; padding-left: 0; list-style: none; counter-reset: step; display: flex; flex-direction: column; gap: 10px; }
ol.guide li { position: relative; padding-left: 38px; line-height: 1.45; }
ol.guide li::before {
  counter-increment: step; content: counter(step);
  position: absolute; left: 0; top: 0; width: 26px; height: 26px; border-radius: 50%;
  background: var(--brand); color: var(--brand-contrast); font-weight: 700; font-size: .85rem;
  display: grid; place-items: center;
}

/* ------------------------------------------------------------ Tausch: Ablauf + Rahmen */
.steps {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
  background: var(--bg-elevated); border: 1px solid var(--surface-border); border-radius: var(--radius);
  padding: 12px 10px;
}
.step { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; font-size: .72rem; color: var(--text-faint); line-height: 1.2; }
.step__n {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: .8rem; background: var(--bg-sunken); color: var(--text-faint);
  border: 2px solid transparent;
}
.step--done { color: var(--text-muted); }
.step--done .step__n { background: var(--green-500); color: #fff; }
.step--now { color: var(--text); font-weight: 650; }
.step--now .step__n { background: var(--accent); color: #4a3a00; border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 30%, transparent); }

.swap-frame { border-color: color-mix(in srgb, var(--brand) 45%, var(--surface-border)); border-width: 2px; }
.swap-frame__section { padding: 16px; border-bottom: 1px solid var(--surface-border); }
.swap-frame__section:last-child { border-bottom: 0; }
.swap-frame__section > h3 { margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.swap-frame__section--danger { background: color-mix(in srgb, var(--danger) 6%, var(--bg-elevated)); }

/* Inline-Icons in runden Knoepfen: erben die Textfarbe, keine Font-Abhaengigkeit */
.icon-btn .ic-svg { display: block; }
