:root {
  --card-w: 96px;   /* wird via leer.svg kalibriert */
  --card-h: 144px;

  /* Light */
  --bg: #f7f8fc;
  --panel: #ffffff;
  --panel-2: #f1f4fb;
  --text: #0f1b2e;
  --muted: #5c6c86;
  --line: #e3e8f5;
  --accent: #3b6ff6;
}

[data-theme="dark"] {
  --bg: #0e1420;
  --panel: #111827;
  --panel-2: #0b1220;
  --text: #e6eefc;
  --muted: #94a3b8;
  --line: #1f2a44;
  --accent: #6aa0ff;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
#app { max-width: 1100px; margin: 0 auto; padding: 24px; }

/* Header + Settings (Icon ohne Box) */
.app-header { position: relative; text-align: center; margin-bottom: 16px; }
.app-header h1 { margin: 0 0 6px; font-weight: 800; letter-spacing: -0.02em; }
.subtitle { margin: 0; color: var(--muted); }

.settings-fab {
  position: fixed; top: 16px; right: 16px;
  background: none; border: none; padding: 0;
  cursor: pointer; line-height: 0;
}
.settings-svg { width: 22px; height: 22px; color: #5b6b88; }
[data-theme="dark"] .settings-svg { color: #ffffff; }

/* Modal (zentriert, größer) */
.modal { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(15,27,46,.4); backdrop-filter: blur(2px); z-index: 1000; }
.modal.hidden { display: none; }
.modal-content {
  width: min(520px, 94vw);
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 16px 40px rgba(0,0,0,.18);
}
.modal-header, .modal-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.modal-footer { border-bottom: 0; border-top: 1px solid var(--line); }
.modal-body { padding: 14px 16px; display: grid; gap: 12px; }
.modal-header h2 { margin: 0; font-size: 18px; }
.modal-header .close { border: 0; background: transparent; font-size: 18px; cursor: pointer; color: var(--text); }

.row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
}
.label-text { font-weight: 600; color: var(--text); }

/* Switch rechts neben Text */
.switch { position: relative; display: inline-block; width: 50px; height: 28px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line);
  transition: .22s; border-radius: 999px;
}
.slider::before {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: .22s;
}
.switch input:checked + .slider { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(22px); }

/* Buttons */
button { border: 0; padding: 12px 16px; border-radius: 12px; cursor: pointer; font-weight: 600; }
button.primary { background: var(--accent); color: #fff; }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }

/* Deck & gezogene Karte */
.table { display: grid; grid-template-columns: 1fr; gap: 12px; align-items: center; margin: 10px 0 6px; }
.deck-area { display: flex; gap: 12px; align-items: center; }
.card-frame {
  width: var(--card-w); height: var(--card-h); border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); box-shadow: 0 6px 16px rgba(16,24,40,.08); display: grid; place-items: center;
  position: relative; overflow: hidden;
}
.card-frame .card-img { width: 100%; height: 100%; object-fit: contain; display: block; }
.card-frame.placeholder { border-style: dashed; opacity: .9; background: var(--panel-2); }

/* Flip animation */
.flip-in { animation: flipIn .35s ease-out both; transform-origin: center; }
@keyframes flipIn { from { transform: rotateY(90deg); opacity: 0; } 60% { opacity: 1; } to { transform: rotateY(0deg); opacity: 1; } }
.flip-reveal { animation: flipReveal .35s ease-out both; }
@keyframes flipReveal { from { transform: rotateY(90deg); opacity: 0; } to { transform: rotateY(0); opacity: 1; } }

/* Controls / Deck info */
.controls { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.deck-info { margin-left: auto; color: var(--muted); }

/* Status */
.status { display: flex; gap: 24px; align-items: center; background: var(--panel); padding: 12px 16px; border-radius: 12px; border: 1px solid var(--line); }
.status .last-card { font-weight: 600; }
.status .checkpoint-status { color: var(--muted); }

/* Rennstrecke */
.track { margin-top: 16px; }
.track-grid {
  display: grid; grid-template-columns: repeat(7, minmax(90px,1fr)); gap: 6px;
  background: var(--panel); padding: 12px; border-radius: 16px; border: 1px solid var(--line);
}
.track-grid .cell {
  background: var(--panel-2); border-radius: 10px; min-height: 64px; display: flex;
  align-items: center; justify-content: center; position: relative; overflow: hidden; color: var(--text);
}
.track-grid .label { font-weight: 700; color: var(--muted); }

/* Finish Light */
.cell.finish { background: linear-gradient(135deg, #eef2ff 60%, #e3e9ff 60%); }
.cell.finish::after {
  content: ""; position: absolute; right: 0; top: 0; bottom: 0; width: 18px;
  background: repeating-linear-gradient(90deg,#fff 0 6px,#000 6px 12px); opacity: .18;
}
/* Finish Dark */
[data-theme="dark"] .cell.finish {
  background: linear-gradient(135deg, #0b1324 60%, #080e1a 60%);
  border-color: #24304a;
}
[data-theme="dark"] .cell.finish::after { opacity: .35; filter: brightness(0.65); }

/* Bus-Token */
.bus-token {
  position: absolute; inset: 6px; border-radius: 10px; display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--panel);
}
.bus-token img { width: 22px; height: 22px; object-fit: contain; }

/* Checkpoints */
.checkpoints-under { margin-top: 8px; display: grid; grid-template-columns: repeat(7, minmax(90px,1fr)); gap: 6px; }
.checkpoints-under .spacer { height: var(--card-h); }
.checkpoint-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  display: grid; place-items: center; overflow: hidden; width: var(--card-w); height: var(--card-h); margin: 0 auto;
}
.checkpoint-card img, .checkpoint-back { width: 100%; height: 100%; }
.checkpoint-back { background: var(--panel); display: grid; place-items: center; }
.checkpoint-back img { width: 100%; height: 100%; object-fit: contain; }

/* Log */
.log { margin-top: 18px; }
#log {
  background: var(--panel); border-radius: 12px; padding: 12px; max-height: 220px; overflow: auto;
  border: 1px solid var(--line); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.log-entry { color: #243b6b; font-size: 14px; }
#log-section.hidden { display: none; }
