/* Timatch Tisch — Farben und Formen wie in der App: Orange als Akzent, Tinte als Grundton,
   große runde Karten, große Zahlen. Mobil zuerst; auf breiten Bildschirmen bleibt alles mittig. */

:root {
  --orange: #ffa749;
  --orange-deep: #f28c1e;
  --ink: #272727;
  --bg: #f4f4f6;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #6b6b70;
  --line: rgba(0, 0, 0, 0.08);
  --danger: #ff3b30;
  --success: #34c759;
  --radius: 22px;
  --radius-s: 14px;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --card: #1e1e21;
    --text: #f2f2f5;
    --muted: #9a9aa2;
    --line: rgba(255, 255, 255, 0.1);
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.35;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
input, select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
}
input:focus, select:focus { border-color: var(--orange); }
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 30px; }
h2 { font-size: 22px; }
h3 { font-size: 15px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; }

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 24px);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Kopfzeile */
.topbar { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.topbar .spacer { flex: 1; }
.topbar h1, .topbar h2 { flex: 1; text-align: center; font-size: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--card); box-shadow: var(--shadow);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--orange-deep); font-weight: 700; font-size: 18px;
}
.icon-btn:disabled { opacity: 0.35; }
.pill-btn {
  padding: 10px 16px; border-radius: 999px; background: var(--card); box-shadow: var(--shadow);
  color: var(--orange-deep); font-weight: 600;
}

/* Karten und Listen */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 0; }
.list { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 12px; }
.row .grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.section-title { margin: 6px 4px 0; }
.hint { font-size: 14px; color: var(--muted); margin: 0 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 18px; border-radius: 16px;
  font-weight: 600; background: var(--card); color: var(--orange-deep); box-shadow: var(--shadow);
  width: 100%;
}
.btn.primary { background: var(--orange); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.subtle { box-shadow: none; background: transparent; min-height: 40px; font-size: 15px; font-weight: 500; }
.btn:disabled { opacity: 0.4; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

.segmented { display: flex; background: var(--bg); border-radius: 12px; padding: 4px; gap: 4px; }
.segmented button { flex: 1; padding: 9px 6px; border-radius: 9px; font-weight: 600; color: var(--muted); font-size: 15px; }
.segmented button.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; }
.switch input { width: 51px; height: 31px; appearance: none; -webkit-appearance: none; border-radius: 16px; background: #c9c9ce; position: relative; transition: background 0.2s; padding: 0; border: 0; flex: none; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,0.25); transition: transform 0.2s; }
.switch input:checked { background: var(--orange); }
.switch input:checked::after { transform: translateX(20px); }

/* Personen-Zeile in der Einrichtung */
.player-row { display: flex; align-items: center; gap: 8px; }
.color-dot { width: 32px; height: 32px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,0.25); flex: none; }
.player-row input { flex: 1; }
.player-row .icon-btn { width: 36px; height: 36px; box-shadow: none; background: var(--bg); font-size: 15px; }

/* Tisch */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border-radius: var(--radius-s); padding: 12px 14px; box-shadow: var(--shadow); }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 32px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat.over .value { color: var(--danger); }

.active-card {
  border-radius: 26px; padding: 22px 16px 18px; color: #fff; text-align: center; width: 100%;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; gap: 8px; min-height: 230px;
  transition: transform 0.08s;
}
.active-card:active { transform: scale(0.985); }
.active-card.over { box-shadow: 0 0 0 4px var(--danger), var(--shadow); }
.active-card .avatar { width: 84px; height: 84px; font-size: 30px; border: 3px solid #fff; box-shadow: 0 3px 10px rgba(0,0,0,0.3); }
.active-card .name { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.active-card .time { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.active-card .status { font-size: 13px; opacity: 0.85; font-weight: 500; }

.avatar {
  width: 44px; height: 44px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 16px; flex: none; text-transform: uppercase;
}

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tiles.two { grid-template-columns: repeat(2, 1fr); }
.tiles.four { grid-template-columns: repeat(4, 1fr); }
.tile {
  background: var(--card); border-radius: var(--radius-s); padding: 10px 8px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 4px; box-shadow: var(--shadow);
  position: relative; width: 100%;
}
.tile.next { outline: 2px solid var(--orange); }
.tile.passed { opacity: 0.5; }
.tile .avatar { width: 40px; height: 40px; font-size: 14px; }
.tile .tname { font-size: 14px; font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .ttime { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .tsub { font-size: 11px; color: var(--muted); }
.tile .badge { position: absolute; top: 6px; right: 6px; font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 999px; background: var(--orange); color: #fff; }
.tile .badge.passed { background: var(--muted); }

.controls { display: flex; flex-direction: column; gap: 10px; }
.bottombar { display: flex; gap: 10px; margin-top: auto; padding-top: 6px; }
.bottombar .btn { flex: 1; }

/* Blatt (Verlauf) */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; max-height: 88vh; border-radius: 22px 22px 0 0; padding: 12px 16px calc(var(--safe-bottom) + 16px); overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.sheet .handle { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 4px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.chip { padding: 7px 14px; border-radius: 999px; background: var(--card); font-size: 14px; font-weight: 600; white-space: nowrap; box-shadow: var(--shadow); color: var(--text); }
.chip.active { background: var(--orange); color: #fff; }

.event { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.event:last-child { border-bottom: 0; }
.event .ename { font-weight: 600; }
.event .esub { font-size: 13px; color: var(--muted); }
.event .edur { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.event.faded { opacity: 0.45; }
.event .tag { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: rgba(255,167,73,0.2); color: var(--orange-deep); margin-left: 6px; }
.event .tag.gray { background: var(--line); color: var(--muted); }
.event .tag.red { background: rgba(255,59,48,0.15); color: var(--danger); }

.bars { display: flex; flex-direction: column; gap: 8px; }
.bar { display: grid; grid-template-columns: 90px 1fr auto; align-items: center; gap: 10px; font-size: 14px; }
.bar .track { height: 12px; border-radius: 6px; background: var(--line); overflow: hidden; }
.bar .fill { height: 100%; border-radius: 6px; }

/* Punkte */
.score-row { display: grid; grid-template-columns: 44px 1fr 110px; align-items: center; gap: 12px; }
.score-row input { text-align: right; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Zusammenfassung */
.winner { text-align: center; padding: 22px 16px; border-radius: var(--radius); color: #fff; box-shadow: var(--shadow); }
.winner .avatar { width: 72px; height: 72px; font-size: 26px; margin: 0 auto 8px; border: 3px solid #fff; }
.winner .wname { font-size: 28px; font-weight: 800; }
.winner .wsub { opacity: 0.9; font-size: 14px; }
.rank { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.rank:last-child { border-bottom: 0; }
.rank .pos { width: 28px; font-weight: 700; color: var(--muted); }
.rank .score { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi { text-align: center; }
.kpi .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 12px; color: var(--muted); }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 20; }
.modal { background: var(--card); border-radius: 20px; padding: 20px; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.modal p { margin: 0; color: var(--muted); font-size: 15px; }

.toast { position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 28px); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600; z-index: 30; box-shadow: var(--shadow); animation: toast 2.6s forwards; }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, 10px);} 12% { opacity: 1; transform: translate(-50%, 0);} 80% { opacity: 1;} 100% { opacity: 0;} }

.footer { text-align: center; font-size: 13px; color: var(--muted); padding: 10px 0 0; }
.footer a { color: var(--orange-deep); text-decoration: none; font-weight: 600; }

.history-item { display: flex; align-items: center; gap: 12px; }
.history-item .grow { flex: 1; min-width: 0; }
.history-item .g { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item .s { font-size: 13px; color: var(--muted); }

@media (min-width: 700px) {
  .active-card { min-height: 280px; }
  .active-card .name { font-size: 42px; }
  .stat .value { font-size: 40px; }
}
