:root {
  --bg: #f7eef1;
  --surface: #ffffff;
  --surface-2: #fbf6f8;
  --text: #241a22;
  --muted: #7b6874;
  --line: #eadbe1;
  --accent: #a3721c;
  --accent-text: #ffffff;
  --accent-soft: #f5e7c9;
  --live: #c2185b;
  --ok: #2e7d4f;
  --err: #b3261e;
  --shadow: 0 1px 2px rgb(60 20 40 / 6%), 0 6px 20px rgb(60 20 40 / 6%);
  --radius: 18px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17111a;
    --surface: #221a25;
    --surface-2: #2a212d;
    --text: #f4ebf1;
    --muted: #a8969f;
    --line: #3a2e3d;
    --accent: #e0b55a;
    --accent-text: #1d1507;
    --accent-soft: #3b2f1b;
    --live: #f06292;
    --ok: #6fcf97;
    --err: #ff8a80;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 6px 20px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(32px + env(safe-area-inset-bottom));
}

main, .topbar {
  max-width: 560px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- Kopfzeile */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: calc(12px + env(safe-area-inset-top));
  padding-bottom: 12px;
}

.brand { font-weight: 800; letter-spacing: -0.02em; font-size: 20px; }
.top-actions { display: flex; align-items: center; gap: 4px; min-width: 0; }
/* Freiwilliger Name ohne Account: bewusst unauffällig */
.name-btn {
  min-width: 0;
  max-width: 110px;
  border: 0;
  background: none;
  padding: 6px 4px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand span { color: var(--accent); }

.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
}
.chip.user .user-name { font-weight: 600; color: var(--text); }
.chip.user a, .chip.user button {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  font-size: 14px;
  text-decoration: none;
}

.banner {
  background: var(--err);
  color: #fff;
  text-align: center;
  font-size: 14px;
  padding: 6px 16px;
}

/* -------------------------------------------------------------------- Karten */

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

.now { text-align: center; }
.now h1 {
  margin: 4px 0 0;
  font-size: clamp(28px, 8vw, 40px);
  line-height: 1.1;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}
.eyebrow {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.now.flash { animation: flash 1.2s ease-out; }
@keyframes flash {
  0% { box-shadow: 0 0 0 4px var(--accent), var(--shadow); }
  100% { box-shadow: 0 0 0 0 transparent, var(--shadow); }
}

.stage-controls {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 10px;
  margin-top: 18px;
}

.btn {
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--surface-2);
  min-height: 48px;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.danger { background: var(--err); color: #fff; border-color: transparent; }
.btn:disabled { opacity: 0.4; cursor: default; }

.own { text-align: center; }
.own-emoji { font-size: 44px; }
.own p { margin: 4px 0 0; color: var(--muted); }
.own strong { color: var(--text); font-size: 18px; }

.late-banner {
  margin: -6px -6px 12px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--accent-soft);
  font-size: 14px;
  text-align: center;
}

.rate-nav {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin: -8px 0 8px;
}
.rate-nav button {
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  padding: 6px 4px;
  min-height: 36px;
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rate-nav #rateCurrent { margin-left: auto; }

.missed h2 { margin: 0; font-size: 18px; }
.missed .sub { margin-bottom: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips .chip { font-weight: 600; }


/* -------------------------------------------------------------------- Slider */

.score-display {
  text-align: center;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  margin: 4px 0 8px;
}
.score-display span { font-size: 72px; font-weight: 800; letter-spacing: -0.03em; color: var(--accent); }
.score-display small { font-size: 20px; color: var(--muted); margin-left: 4px; }

.slider-row {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 6px;
}

.step {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 22px;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}
.step:active { background: var(--accent-soft); }

.slider {
  position: relative;
  height: 60px;
  padding: 0 18px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  outline: none;
}
.slider-inner { position: relative; height: 100%; }
.slider .track, .slider .fill {
  position: absolute;
  top: 50%;
  left: 0;
  height: 10px;
  margin-top: -5px;
  border-radius: 999px;
}
.slider .track { right: 0; background: var(--line); }
.slider .fill { background: var(--accent); }
.slider .thumb {
  position: absolute;
  top: 50%;
  width: 36px;
  height: 36px;
  margin: -18px 0 0 -18px;
  border-radius: 50%;
  background: var(--surface);
  border: 3px solid var(--accent);
  box-shadow: 0 2px 8px rgb(0 0 0 / 20%);
  transition: transform 0.1s;
}
.slider.dragging .thumb, .slider:focus-visible .thumb { transform: scale(1.12); }
.slider.unset .thumb { border-style: dashed; border-color: var(--muted); box-shadow: none; }

.scale {
  display: flex;
  justify-content: space-between;
  padding: 0 68px;
  font-size: 12px;
  color: var(--muted);
  margin-top: -6px;
}

.status { min-height: 1.4em; margin: 8px 0 0; font-size: 14px; color: var(--muted); text-align: center; }
.status.ok { color: var(--ok); }
.status.err { color: var(--err); }

.note-label {
  display: block;
  margin-top: 18px;
  font-weight: 600;
}
.note-label small { font-weight: 400; color: var(--muted); margin-left: 4px; }

textarea, input, select {
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 16px; /* verhindert Auto-Zoom auf iOS */
}
textarea { resize: vertical; min-height: 96px; }
#note { height: 9.6rem; } /* etwas größer als 4 Zeilen, lässt sich weiter aufziehen */
textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ------------------------------------------------------------------ Rangliste */

.ranking { margin-top: 32px; }
.ranking h2 { margin: 0; font-size: 22px; }
.ranking h3 { margin: 24px 0 8px; font-size: 15px; color: var(--muted); font-weight: 600; }
.sub { margin: 2px 0 12px; font-size: 14px; color: var(--muted); }

.rank-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.rank-item {
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.rank-item.current { outline: 2px solid var(--live); }
.pending .rank-item { box-shadow: none; background: transparent; border: 1px dashed var(--line); }

.rank-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: none;
  border: 0;
  text-align: left;
}
.rank-head { cursor: pointer; }
.rank-head.static { cursor: default; }

.mini-edit {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--accent);
  border-radius: 999px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 600;
  line-height: 20px;
  vertical-align: 1px;
}

.rank-pos { width: 28px; flex: none; font-weight: 700; font-size: 18px; text-align: center; color: var(--muted); }
.rank-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rank-name { font-weight: 650; overflow-wrap: anywhere; }
.rank-meta { font-size: 13px; color: var(--muted); }
.rank-score { font-weight: 800; font-size: 20px; font-variant-numeric: tabular-nums; }
.chev { color: var(--muted); font-size: 22px; transition: transform 0.15s; }
.rank-item.open .chev { transform: rotate(90deg); }
.live { color: var(--live); font-weight: 700; }

.bar { height: 4px; background: var(--line); margin: 0 14px 12px 54px; border-radius: 999px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

.rank-details { padding: 0 10px 10px; }
.rank-details h4, .team-notes h4 { margin: 4px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.rank-details blockquote, .team-notes blockquote {
  margin: 0 0 8px;
  padding: 8px 12px;
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 15px;
}
.rank-details cite, .team-notes cite { display: block; font-style: normal; font-weight: 700; font-size: 13px; margin-bottom: 2px; }

.team-notes {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.empty { color: var(--muted); font-size: 15px; padding: 12px 0; }

/* -------------------------------------------------------------- Sortieren */

.sort-card h2 { margin: 0; font-size: 20px; }
.grip-hint { font-weight: 700; }
.sort-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 6px; }
.sort-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sort-item.has-details { cursor: pointer; }
.sort-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 0;
}
.sort-item .chev { color: var(--muted); font-size: 22px; transition: transform 0.15s; }
.sort-item.open .chev { transform: rotate(90deg); }
.sort-item .rank-details { padding: 0 8px 8px; }
.sort-item .rank-details blockquote { background: var(--surface); }
.sort-item.dragging {
  position: relative;
  z-index: 2;
  transition: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 14px 30px rgb(0 0 0 / 22%), 0 0 0 2px var(--accent);
}
.sort-item.dragging.dropping {
  transition: transform 0.18s ease-out, box-shadow 0.18s;
  box-shadow: none;
}
.sort-item {
  /* Langes Drücken soll ziehen, nicht Text markieren oder das iOS-Menü öffnen */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.sort-item.pressing {
  transform: scale(0.97);
  transition: transform 0.35s ease-out;
  background: var(--accent-soft);
}
.sort-list.is-dragging { user-select: none; -webkit-user-select: none; }
.sort-list.is-dragging .sort-item:not(.dragging) { opacity: 0.85; }
.drag-handle {
  flex: none;
  width: 44px;
  align-self: stretch;
  min-height: 44px;
  display: grid;
  place-items: center;
  font-size: 22px;
  color: var(--muted);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.sort-item.dragging .drag-handle { color: var(--accent); }
.sort-list.is-dragging .drag-handle { cursor: grabbing; }
.sort-pos { flex: none; width: 28px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.sort-name { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.sort-name small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.sort-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.sort-footer .status { text-align: left; flex: 1; }
.sort-footer .link-btn { flex: 0 1 auto; text-align: right; }
.link-btn { border: 0; background: none; color: var(--accent); font-size: 14px; font-weight: 600; padding: 8px 0; margin-top: 8px; }

.btn.wide { width: 100%; margin-top: 12px; }
.final-card { outline: 2px solid var(--accent); }
.final-card .eyebrow { color: var(--accent); }
.final-members { color: var(--text); font-weight: 600; }

.rank-score small { display: block; font-size: 11px; font-weight: 600; color: var(--muted); text-align: right; }

/* --------------------------------------------------------------------- Modal */

.modal {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: calc(60px + env(safe-area-inset-top)) 16px 16px;
  z-index: 10;
}
.modal-box {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.modal-box h2 { margin: 0; }
.modal-box label { display: block; margin-top: 12px; font-weight: 600; font-size: 14px; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }

/* ------------------------------------------------------------ Demo, Instanz */

.demo-banner {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 8px 16px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: repeating-linear-gradient(-45deg, #f2b705, #f2b705 14px, #e8a600 14px, #e8a600 28px);
  color: #2b1d00;
  font-size: 13px;
  text-align: center;
  line-height: 1.35;
}
.demo-banner + .topbar { padding-top: 12px; }

.brand small {
  display: block;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--muted);
  margin-top: -2px;
}

/* -------------------------------------------------------------------- Fotos */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
}

.photo-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.photo-btn {
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 12px;
  font-size: 15px;
  cursor: pointer;
}
/* Fotos belegen immer nur eine Zeile; bei vielen wird waagerecht gescrollt */
.photo-chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.photo-chips::-webkit-scrollbar { display: none; }
.photo-chips:empty { display: none; }
.photo-chips .photo-chip { flex: none; white-space: nowrap; }
.photo-row .photo-chips { flex: 1; }
/* Speicher-Status neben der Überschrift statt als eigene Zeile unter dem Notizfeld */
.note-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 18px; }
.note-head .note-label { margin-top: 0; }
.note-head .status { margin: 0; min-height: 0; font-size: 13px; text-align: right; white-space: nowrap; }
.note-hint { display: block; font-size: 13px; color: var(--muted); }
.photo-chip {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 600;
  min-height: 32px;
}
.photo-chip:active { background: var(--accent-soft); }
#photoStatus { text-align: left; }
#photoStatus:empty { display: none; }
.team-notes .photo-chips { margin-top: 4px; }
.rank-details .photo-chips { margin-bottom: 8px; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  background: rgb(0 0 0 / 92%);
  color: #fff;
}
.lightbox-img {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  /* feste Spuren, damit max-height: 100 % am Bild greift (sonst wird es im Querformat abgeschnitten) */
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
  padding: calc(12px + env(safe-area-inset-top)) 8px 8px;
  touch-action: none; /* Wischen übernimmt das Skript */
  overflow: hidden;
}
.lightbox-img img {
  grid-area: 1 / 1;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.lightbox-img p { grid-area: 1 / 1; }
.lightbox-nav {
  position: absolute;
  top: 50%;
  width: 44px;
  height: 64px;
  margin-top: -32px;
  border: 0;
  border-radius: 12px;
  background: rgb(0 0 0 / 35%);
  color: #fff;
  font-size: 34px;
  line-height: 1;
}
.lightbox-nav.prev { left: 6px; }
.lightbox-nav.next { right: 6px; }
.lightbox-img img:not([src]) { display: none; }
.lightbox-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgb(0 0 0 / 60%);
}
.lightbox-bar span { flex: 1; min-width: 0; font-size: 14px; overflow-wrap: anywhere; }
.lightbox-bar .btn { min-height: 40px; padding: 8px 14px; color: #fff; background: rgb(255 255 255 / 12%); border-color: transparent; }
.lightbox-bar .btn.danger { background: var(--err); }

/* ---------------------------------------------------------------- Startseite */

.home-card { text-align: center; margin-top: 24px; }
.home-card h1 { font-size: 24px; margin: 8px 0; }
.home-card p { color: var(--muted); margin: 0; }
.home-foot { text-align: center; font-size: 13px; }
.home-foot a { color: var(--muted); }
.modal-box label small.muted { font-weight: 400; color: var(--muted); }
/* Kopfzeile: Logo und Login brechen nie um, der Name wird bei Platzmangel gekürzt */
.topbar .brand { flex: none; white-space: nowrap; }
.top-actions .chip { flex: none; white-space: nowrap; }
.top-actions .name-btn { flex: 0 1 auto; }
@media (max-width: 360px) {
  .topbar { gap: 6px; }
  .top-actions .chip { padding: 6px 10px; }
}
.modal-box label.check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 14px;
  font-weight: 600;
  font-size: 15px;
}
.check-row input { width: 20px; height: 20px; margin: 1px 0 0; flex: none; }
.check-row input:disabled + span { opacity: 0.55; }
.check-row small { display: block; font-weight: 400; font-size: 13px; }
.muted-note { font-size: 13px; margin-top: 12px; }
