:root {
  --bg: #1a1c22;
  --panel: #24272f;
  --panel-2: #2d313b;
  --text: #e8eaed;
  --muted: #9aa0ac;
  --accent: #f4a13c;
  --border: #3a3f4b;
  --p1: #e6564e;
  --p2: #4e8fe6;
  --p3: #5bbf6a;
  --p4: #e6c34e;
  --f-carrot: #c9772e;
  --f-lettuce: #3f8f4a;
  --f-hedgehog: #7a5a3a;
  --f-hare: #b58a2e;
  --f-position: #3a6ea5;
  --f-start: #4a4f5a;
  --f-finish: #b8963a;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 0.8rem 1.5rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
header h1 { margin: 0; font-size: 1.4rem; }
nav { display: flex; gap: 0.5rem; }

.nav-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
}
.nav-btn:hover { color: var(--text); background: var(--panel-2); }
.nav-btn.active { color: var(--text); background: var(--panel-2); border-color: var(--border); }

main { padding: 1.5rem; max-width: 1200px; margin: 0 auto; }
.screen { display: none; }
.screen.active { display: block; }

h2 { margin-top: 0; }
.hint { color: var(--muted); margin-top: -0.3rem; }
.error { color: #ff8080; min-height: 1.2em; }

button.primary, button.secondary {
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.2rem;
  font-size: 1rem;
  cursor: pointer;
  margin-top: 0.6rem;
}
button.primary { background: var(--accent); color: #1a1c22; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* --- Sitz-Konfiguration --- */
.seat-config { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 0.8rem; margin: 1rem 0; }
.seat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 5px solid var(--seat-color, var(--border));
  border-radius: 10px;
  padding: 0.9rem;
}
.seat-card h4 { margin: 0 0 0.5rem; }
.seat-card select { width: 100%; padding: 0.4rem; border-radius: 6px; background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }

/* --- Board (Felder absolut nach LAYOUT positioniert, wie auf dem Originalbrett) --- */
.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1024 / 768;
  background:
    radial-gradient(circle at 50% 45%, #6f9a52 0%, #5c8746 45%, #47693a 100%);
  border-radius: 12px;
  overflow: hidden;
}
.board-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.track-line { fill: none; stroke: rgba(255,255,255,0.30); stroke-width: 0.6; stroke-linejoin: round; stroke-linecap: round; }
.field {
  position: absolute;
  /* width wird in app.js aus FIELD_PCT gesetzt (== Zellabstand → Kantenberührung). */
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  border: 1px solid rgba(0,0,0,0.45);
  user-select: none;
}
.field .fnum { position: absolute; top: 1px; left: 3px; font-size: 0.5rem; opacity: 0.8; }
.field .ficon { font-size: 0.95rem; line-height: 1; font-weight: 700; }
@media (max-width: 640px) { .field .ficon { font-size: 0.7rem; } .field .fnum { font-size: 0.42rem; } }
.field.type-Carrot { background: var(--f-carrot); }
.field.type-Lettuce { background: var(--f-lettuce); }
.field.type-Hedgehog { background: var(--f-hedgehog); }
.field.type-Hare { background: var(--f-hare); }
.field.type-Position { background: var(--f-position); }
.field.type-Start { background: var(--f-start); }
.field.type-Finish { background: var(--f-finish); }
.field.selectable { cursor: pointer; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(244,161,60,0.35); }
.field.selectable:hover { filter: brightness(1.15); }
.field.recommend { border-color: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,0.5); }
.field.played { outline: 3px solid var(--accent); outline-offset: 1px; z-index: 1; }

.pawns { display: flex; flex-wrap: wrap; gap: 1px; justify-content: center; margin-top: 1px; max-width: 100%; }
.pawn { width: 9px; height: 9px; border-radius: 50%; border: 1px solid rgba(0,0,0,0.5); box-shadow: 0 0 2px rgba(0,0,0,0.6); }
.pawn.p1 { background: var(--p1); }
.pawn.p2 { background: var(--p2); }
.pawn.p3 { background: var(--p3); }
.pawn.p4 { background: var(--p4); }

/* --- Spiel-Layout --- */
.game-layout, .analyze-layout, .replay-layout { display: grid; grid-template-columns: 2fr 1fr; gap: 1.5rem; align-items: start; }
@media (max-width: 900px) { .game-layout, .analyze-layout, .replay-layout { grid-template-columns: 1fr; } }
.board-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; }
.side { display: flex; flex-direction: column; gap: 1rem; }

.seats { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.seat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 5px solid var(--seat-color);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  font-size: 0.85rem;
}
.seat.current { box-shadow: 0 0 0 2px var(--accent); }
.seat .seat-name { font-weight: 600; }
.seat .seat-stats { color: var(--muted); font-size: 0.8rem; }
.seat .rank { float: right; color: var(--accent); font-weight: 600; }

.interaction { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 0.9rem; }
.interaction h3 { margin: 0 0 0.5rem; }
.move-option {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.5rem 0.7rem;
  margin-bottom: 0.4rem;
  cursor: pointer;
  font-size: 0.9rem;
}
.move-option:hover { border-color: var(--accent); }
.status-msg { color: var(--muted); }

.log-box { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 0.6rem 0.9rem; }
.log-box h3 { margin: 0.2rem 0 0.5rem; }
.log { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; font-size: 0.82rem; }
.log li { padding: 0.15rem 0; border-bottom: 1px solid var(--border); color: var(--muted); }
.log li:last-child { color: var(--text); }

/* --- Analyse --- */
.analyze-config { display: flex; flex-direction: column; gap: 0.5rem; }
.acfg-row {
  display: grid;
  grid-template-columns: auto 1fr 1fr 1fr auto;
  gap: 0.4rem;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 5px solid var(--seat-color);
  border-radius: 8px;
  padding: 0.4rem 0.5rem;
  font-size: 0.8rem;
}
.acfg-row input[type=number] { width: 100%; padding: 0.3rem; border-radius: 5px; background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.acfg-row label { display: flex; flex-direction: column; font-size: 0.68rem; color: var(--muted); gap: 2px; }
.acfg-head { font-weight: 600; }
.sims-row { display: flex; align-items: center; gap: 0.6rem; }
.sims-row input { flex: 1; }

.analyze-result { margin-top: 0.5rem; }
.seat-values { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.4rem; margin-bottom: 0.8rem; }
.sv { background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--seat-color); border-radius: 7px; padding: 0.4rem; text-align: center; font-size: 0.8rem; }
.sv .sv-val { font-weight: 600; font-size: 1rem; }
.amove { margin-bottom: 0.5rem; }
.amove .amove-top { display: flex; justify-content: space-between; font-size: 0.85rem; }
.amove.best .amove-top { color: var(--accent); font-weight: 600; }
.bar { height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; margin-top: 3px; }
.bar > span { display: block; height: 100%; background: var(--accent); }

/* --- Ereignis-Popups (Toasts) --- */
.toasts {
  position: fixed;
  top: 70px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 320px;
}
.toast {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 5px solid var(--seat-color, var(--accent));
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
  box-shadow: 0 6px 20px rgba(0,0,0,0.45);
  font-size: 0.85rem;
  animation: toast-in 0.25s ease-out;
}
.toast.out { opacity: 0; transform: translateX(20px); transition: opacity 0.4s, transform 0.4s; }
.toast-icon { font-size: 1.3rem; line-height: 1.2; }
.toast strong { color: var(--text); }
.toast div div { color: var(--muted); }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

/* --- Replay --- */
.replay-list { list-style: none; margin: 0 0 0.8rem; padding: 0; max-height: 320px; overflow-y: auto; }
.replay-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  margin-bottom: 0.4rem;
  cursor: pointer;
}
.replay-item:hover { border-color: var(--accent); }
.ri-name { font-weight: 600; font-size: 0.9rem; }
.ri-meta { color: var(--muted); font-size: 0.78rem; }
.upload-row { display: block; color: var(--muted); font-size: 0.85rem; margin-top: 0.4rem; }
.upload-row input { display: block; margin-top: 0.3rem; color: var(--text); font-size: 0.8rem; }

.replay-nav { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.6rem; }
.replay-nav button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  font-size: 0.95rem;
}
.replay-nav button:hover:not(:disabled) { border-color: var(--accent); }
.rp-pos { flex: 1; text-align: center; color: var(--muted); font-size: 0.85rem; }
.rp-info { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem 0.7rem; margin-bottom: 0.6rem; font-size: 0.85rem; }
.rp-move { margin-bottom: 0.2rem; }
.rp-ctx { color: var(--muted); font-size: 0.8rem; }
.amove.played-move .amove-top { color: var(--accent); }
.amove.played-move { border-left: 3px solid var(--accent); padding-left: 0.4rem; }
