/* Koran-Wettbewerb – ISO Stuttgart
   Ruhig, klar, große Tippflächen. Farben aus dem Vereinslogo. */
:root {
  --teal: #009E96;
  --teal-strong: #00776F;   /* für weiße Schrift (Kontrast ≥ 4.5:1) */
  --teal-soft: #E3F4F3;
  --orange: #F39200;
  --purple: #8B1A6B;
  --green: #4E9A2E;
  --blue: #0088CC;
  --red: #E2001A;
  --red-strong: #B80016;

  --bg: #F5F7F7;
  --surface: #FFFFFF;
  --text: #1E2828;
  --muted: #5E6969;
  --line: #E1E7E7;
  --shadow: 0 1px 2px rgba(20, 40, 40, .06), 0 4px 16px rgba(20, 40, 40, .06);

  --radius: 14px;
  --tap: 56px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 var(--font);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- Kopfzeile ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 8px 8px;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-logo { width: 34px; height: 34px; object-fit: contain; margin-left: 6px; }
.topbar-title {
  flex: 1; margin: 0; font-size: 18px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 12px; background: transparent;
}
.icon-btn:active { background: var(--teal-soft); }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: var(--text); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
#btn-menu svg { fill: var(--text); stroke: none; }

.offline-banner {
  background: #FFF4E0; color: #7A4A00; text-align: center;
  padding: 10px 16px; font-size: 15px; border-bottom: 1px solid #F6DDB0;
}

/* ---------- Grundlayout ---------- */
.app {
  max-width: 560px; margin: 0 auto;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 112px);
}
.section-title {
  margin: 22px 4px 10px; font-size: 14px; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase; color: var(--muted);
}
.hint { color: var(--muted); font-size: 15px; margin: 6px 4px; }
.center { text-align: center; }
.stack > * + * { margin-top: 12px; }

/* ---------- Anmeldung ---------- */
.login {
  min-height: calc(100dvh - 40px);
  display: flex; flex-direction: column; justify-content: center;
  max-width: 400px; margin: 0 auto;
}
.login-logo { width: min(78%, 300px); margin: 0 auto 8px; display: block; }
.login h2 { text-align: center; margin: 18px 0 4px; font-size: 24px; }
.login p { text-align: center; color: var(--muted); margin: 0 0 20px; }

/* ---------- Eingabefelder ---------- */
.field { display: block; }
.field-label { display: block; font-size: 15px; font-weight: 600; margin: 0 0 6px 2px; }
.input, .select {
  width: 100%; min-height: var(--tap);
  padding: 12px 16px;
  border: 1.5px solid var(--line); border-radius: 12px;
  background: var(--surface); font-size: 18px;
  appearance: none; -webkit-appearance: none;
}
.input:focus, .select:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-soft); }
.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6' fill='none' stroke='%235E6969' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; background-size: 20px;
  padding-right: 44px;
}
.search { position: relative; }
.search .input { padding-left: 46px; }
.search svg {
  position: absolute; left: 15px; top: 50%; transform: translateY(-50%);
  width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 2.2; stroke-linecap: round;
}
.error-text { color: var(--red-strong); font-size: 15px; font-weight: 600; margin: 8px 2px 0; min-height: 0; }

/* ---------- Knöpfe ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: var(--tap);
  padding: 12px 18px; border: 0; border-radius: 12px;
  font-size: 18px; font-weight: 700;
  background: var(--teal-strong); color: #fff;
}
.btn:active { filter: brightness(.92); }
.btn:disabled { opacity: .55; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1.5px solid var(--line); }
.btn-danger { background: var(--red-strong); }
.btn-ghost { background: transparent; color: var(--teal-strong); }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }
.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, .45); border-top-color: #fff;
  animation: spin .8s linear infinite;
}
.btn-secondary .spinner { border-color: var(--line); border-top-color: var(--teal); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Listen ---------- */
.list {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 64px; padding: 10px 14px 10px 16px;
  border: 0; border-top: 1px solid var(--line); background: transparent; text-align: left;
}
.row:first-child { border-top: 0; }
.row:active { background: var(--teal-soft); }
.row-main { flex: 1; min-width: 0; }
.row-title { display: block; font-weight: 600; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { display: block; font-size: 14px; color: var(--muted); }
.row-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.row.is-archived .row-title { color: var(--muted); text-decoration: line-through; }
.chev { width: 18px; height: 18px; flex: none; fill: none; stroke: #A5B0B0; stroke-width: 2.4; stroke-linecap: round; }

.score {
  min-width: 64px; padding: 6px 12px; border-radius: 999px;
  background: var(--teal-soft); color: var(--teal-strong);
  font-weight: 800; font-size: 18px; text-align: center;
  font-variant-numeric: tabular-nums;
}
.score.neg { background: #FDE8EA; color: var(--red-strong); }
.tag {
  font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  background: #EEF1F1; color: var(--muted); white-space: nowrap;
}

/* Klassen-Kacheln */
.class-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.class-card {
  position: relative; min-height: 72px; padding: 14px 16px 14px 20px;
  border: 0; border-radius: var(--radius); background: var(--surface);
  box-shadow: var(--shadow); text-align: left; overflow: hidden;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.class-card .class-name { flex: 1; min-width: 0; }
.class-card .class-count { flex: none; }
.class-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 6px; background: var(--accent, var(--teal)); }
.class-card:active { transform: scale(.98); }
.class-name { font-weight: 700; font-size: 17px; line-height: 1.25; word-break: break-word; }
.class-count { color: var(--muted); font-size: 14px; }

.empty {
  text-align: center; color: var(--muted); padding: 32px 16px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
}

/* Schwebender Knopf unten */
.fab-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px);
  background: linear-gradient(to top, var(--bg) 70%, rgba(245, 247, 247, 0));
}
.fab-bar .btn { max-width: 528px; margin: 0 auto; }

/* Admin-Reiter */
.tabs { display: flex; gap: 6px; background: #E9EEEE; padding: 4px; border-radius: 12px; }
.tab {
  flex: 1; min-height: 44px; border: 0; border-radius: 9px; background: transparent;
  font-weight: 700; font-size: 15px; color: var(--muted);
}
.tab.is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.admin-badge {
  display: inline-block; background: var(--purple); color: #fff;
  font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 6px; letter-spacing: .03em;
}

/* ---------- Bottom-Sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(15, 30, 30, .42); animation: fade .18s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-width: 560px; margin: 0 auto; max-height: 92dvh; overflow-y: auto; overflow-x: hidden;
  background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 10px 18px calc(env(safe-area-inset-bottom) + 18px);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .15);
  animation: up .22s cubic-bezier(.2, .8, .2, 1);
}
.sheet-grip { width: 44px; height: 5px; border-radius: 3px; background: #D5DCDC; margin: 0 auto 12px; }
.sheet h2 { margin: 0 0 2px; font-size: 22px; line-height: 1.25; }
.sheet .sub { color: var(--muted); margin: 0 0 16px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* Punkte-Eingabe */
.segmented { display: flex; background: #E9EEEE; border-radius: 12px; padding: 4px; gap: 4px; margin-bottom: 14px; }
.segmented button {
  flex: 1; min-height: 48px; border: 0; border-radius: 9px; background: transparent;
  font-weight: 700; font-size: 16px; color: var(--muted);
}
.segmented button.is-active { background: var(--surface); color: var(--teal-strong); box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
.segmented button.is-active.minus { color: var(--red-strong); }

.points-input-wrap { display: flex; align-items: center; gap: 10px; }
.points-sign { font-size: 40px; font-weight: 800; width: 34px; text-align: center; color: var(--teal-strong); }
.points-sign.minus { color: var(--red-strong); }
.points-input {
  flex: 1; min-width: 0; width: 100%; height: 76px; text-align: center;
  font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums;
  border: 2px solid var(--line); border-radius: 14px; background: var(--surface);
}
.points-input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-soft); }
.points-range { text-align: center; color: var(--muted); font-size: 14px; margin: 8px 0 14px; }

.confirm-box {
  text-align: center; padding: 18px 12px; margin: 4px 0 16px;
  border-radius: 16px; background: var(--teal-soft);
}
.confirm-box.minus { background: #FDE8EA; }
.confirm-delta { font-size: 22px; font-weight: 800; color: var(--teal-strong); }
.confirm-box.minus .confirm-delta { color: var(--red-strong); }
.confirm-calc { font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 4px; }
.confirm-calc .arrow { color: var(--muted); font-weight: 400; margin: 0 8px; }
.confirm-q { font-weight: 600; margin-top: 6px; }

/* Menü */
.menu-list .row { min-height: 58px; }
.menu-who { background: var(--teal-soft); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 12px; right: 12px; z-index: 30;
  bottom: calc(env(safe-area-inset-bottom) + 88px);
  max-width: 536px; margin: 0 auto;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 12px 12px 16px; border-radius: 14px;
  background: #1E2828; color: #fff; box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  overflow: hidden; animation: up .2s ease;
}
.toast-text { flex: 1; font-weight: 600; font-size: 16px; }
.toast-btn {
  min-height: 44px; padding: 0 14px; border: 0; border-radius: 10px;
  background: rgba(255, 255, 255, .14); color: #7FE3DC; font-weight: 800; font-size: 16px;
}
.toast-bar { position: absolute; left: 0; bottom: 0; height: 3px; background: #7FE3DC; transform-origin: left; }
.toast.is-error { background: var(--red-strong); }
/* Bei geöffnetem Bottom-Sheet oben anzeigen, damit der Hinweis keine Knöpfe verdeckt */
body.sheet-open .toast { top: calc(env(safe-area-inset-top) + 10px); bottom: auto; }

.loading { display: grid; place-items: center; padding: 60px 0; }
.loading .spinner { width: 32px; height: 32px; border-color: var(--line); border-top-color: var(--teal); }

@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}

/* ---------- Geschlecht/Alter und Ränge ---------- */
.feld-paar { display: grid; grid-template-columns: 1fr 112px; gap: 12px; }
.rang { font-weight: 700; color: var(--purple); }
.confirm-rang { margin-top: 8px; font-weight: 600; }
.confirm-rang b { color: var(--purple); }
.tabs .tab { flex: 1 1 auto; padding: 0 8px; font-size: 14px; }
.rang-zeile {
  display: grid; grid-template-columns: 1fr 1fr 44px; gap: 8px 10px; align-items: end;
  grid-template-areas: "name name name" "von bis weg" "anzahl anzahl anzahl";
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.rz-name { grid-area: name; }
.rz-von { grid-area: von; }
.rz-bis { grid-area: bis; }
.rz-weg { grid-area: weg; margin-bottom: 6px; font-size: 18px; color: var(--red-strong); }
.rz-anzahl { grid-area: anzahl; font-size: 13px; color: var(--muted); }
