:root {
  --felt: #0b6b46;
  --felt-dark: #084d33;
  --cream: #fdf6e3;
  --ink: #1b1b1b;
  --accent: #e8b23c;
  --accent-dark: #c98f1e;
  --danger: #c1442c;
  --card-w: 64px;
  --card-h: 92px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--felt-dark);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  /* Verhindert, dass mobile Browser (v.a. iOS Safari) die Schrift in engen
     Containern automatisch vergrößern - sonst passen die festen Höhen
     (z.B. beim Logbuch) nicht mehr und Zeilen werden abgeschnitten. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

#app { min-height: 100vh; }

.view { min-height: 100vh; display: flex; flex-direction: column; }
.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }
.btn {
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 1rem;
  font-weight: 600;
  transition: transform .05s ease, opacity .15s ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #2a1d02; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }
.btn-ghost { background: rgba(255,255,255,0.12); color: #fff; }
.btn-small { padding: 8px 12px; font-size: .85rem; }
.btn-danger-ghost {
  background: rgba(193,68,44,.22);
  color: #ffd9d0;
  border: 1px solid rgba(193,68,44,.55);
  margin-top: 14px;
}
.btn-danger-ghost:hover:not(:disabled) { background: rgba(193,68,44,.35); }

/* ---------- Join screen ---------- */
#view-join {
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, var(--felt), var(--felt-dark));
  padding: 24px;
}
.join-card {
  background: var(--cream);
  border-radius: 18px;
  padding: 28px 26px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 20px 50px rgba(0,0,0,.35);
}
.join-card h1 { margin: 0 0 6px; font-size: 1.8rem; }
.join-card h1 .accent { color: var(--felt); }
.sub { color: #555; margin: 0 0 18px; font-size: .95rem; }
#name-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  border-radius: 10px;
  border: 1px solid #ccc;
  margin-bottom: 14px;
}
.join-buttons { display: flex; flex-direction: column; gap: 10px; }
.join-buttons .btn-primary { background: var(--felt); color: #fff; }
.join-buttons .btn-primary:hover { background: var(--felt-dark); }
.join-buttons .btn-ghost { background: #eee; color: #333; }
.bot-checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 12px;
  font-size: .82rem;
  color: #666;
  line-height: 1.35;
  cursor: pointer;
}
.bot-checkbox-label input { margin-top: 3px; flex-shrink: 0; }
.error-text { color: var(--danger); min-height: 1.2em; margin: 10px 0 0; font-size: .9rem; }
.lobby-list { margin-top: 20px; border-top: 1px solid #ddd; padding-top: 14px; }
.lobby-list h2 { font-size: .95rem; text-transform: uppercase; letter-spacing: .04em; color: #777; margin: 0 0 8px; }
#lobby-players { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
#lobby-players li {
  background: var(--felt); color: #fff; padding: 4px 10px; border-radius: 20px; font-size: .85rem;
}
#lobby-players li.offline { background: #999; }
.maumaster-line { font-size: .85rem; color: #555; margin: 8px 0 0; }
.hint { font-size: .8rem; color: #888; margin: 6px 0 0; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  background: rgba(0,0,0,.25);
  color: #fff;
  flex-wrap: wrap;
}
.round-info { font-weight: 600; font-size: .95rem; }
.topbar-buttons { display: flex; align-items: center; gap: 8px; }
.turn-indicator {
  flex: 1;
  text-align: center;
  font-weight: 700;
  font-size: 1.05rem;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(255,255,255,.08);
}
.turn-indicator.your-turn { background: var(--accent); color: #2a1d02; animation: pulse 1.4s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(232,178,60,.6);} 50% { box-shadow: 0 0 0 8px rgba(232,178,60,0);} }

.score-panel {
  background: rgba(0,0,0,.3);
  color: #fff;
  padding: 10px 16px;
  font-size: .9rem;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.score-panel .score-item { background: rgba(255,255,255,.1); padding: 4px 10px; border-radius: 8px; }
.score-panel .score-item.leader { background: var(--accent); color: #2a1d02; font-weight: 700; }

/* ---------- Waiting room ---------- */
.waiting-room {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  padding: 24px;
  text-align: center;
  background: radial-gradient(circle at top, var(--felt), var(--felt-dark));
}
.waiting-room ul { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 14px 0; }
.waiting-room li { background: rgba(255,255,255,.15); padding: 6px 14px; border-radius: 20px; }

.waiting-room .waiting-list {
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  max-width: 360px;
  margin: 14px auto;
  gap: 8px;
}
.waiting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(255,255,255,.15);
  padding: 6px 8px 6px 16px;
  border-radius: 24px;
  text-align: left;
}
.wp-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reorder-buttons { display: flex; gap: 4px; flex-shrink: 0; }
.reorder-btn {
  border: none;
  background: rgba(0,0,0,.25);
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: .9rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.reorder-btn:disabled { opacity: .3; cursor: not-allowed; }
.reorder-btn:active:not(:disabled) { transform: scale(.92); }

/* ---------- Board (player view) ---------- */
.board {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: radial-gradient(ellipse at center, var(--felt) 0%, var(--felt-dark) 100%);
  min-height: 0;
}
.table-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 18px;
  min-height: 160px;
}
.pile { display: flex; flex-direction: column; align-items: center; gap: 4px; position: relative; }
.pile-count { color: #fff; font-weight: 700; font-size: .85rem; margin-top: -6px; }
.pile-label { color: rgba(255,255,255,.7); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; }
/* Die letzten 3 abgelegten Karten deutlich gefächert, damit Wert/Farbe
   jeder einzelnen Karte über ihre kleinen Ecken-Indizes erkennbar bleiben
   (wichtig, damit sichtbar bleibt, welchen Wert ein zuvor gelegter Joker
   von der darunterliegenden Karte übernommen hat). translate() bezieht
   sich auf die Kartenbreite/-höhe selbst und bleibt damit über alle
   responsiven --card-w-Stufen hinweg proportional. */
.discard-pile {
  position: relative;
  width: calc(var(--card-w) * 1.85);
  height: calc(var(--card-h) * 1.35);
}
.discard-pile .card { position: absolute; top: 0; left: 0; }
.discard-pile .card:nth-child(1) { transform: translate(0%, 12%) rotate(-13deg); z-index: 1; }
.discard-pile .card:nth-child(2) { transform: translate(42%, 0%) rotate(5deg); z-index: 2; }
.discard-pile .card:nth-child(3) { transform: translate(85%, 8%) rotate(-3deg); z-index: 3; }

.card {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 8px;
  background: var(--cream);
  border: 1px solid rgba(0,0,0,.15);
  box-shadow: 0 3px 6px rgba(0,0,0,.35);
  font-weight: 700;
  font-size: 1.1rem;
  user-select: none;
  flex-shrink: 0;
}
/* Großes Symbol mittig (volle Ansicht der jeweils obersten/einzigen
   sichtbaren Karte, z.B. auf der eigenen Hand). */
.card-center {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
/* Kleine Werte/Farben-Indizes oben-links und unten-rechts wie bei echten
   Spielkarten - bleiben auch dann erkennbar, wenn die Karte im
   Ablagestapel größtenteils von einer neueren Karte verdeckt wird. */
.corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  font-weight: 700;
  pointer-events: none;
}
.corner-rank { font-size: .58rem; }
.corner-suit { font-size: .64rem; }
.corner-tl { top: 3px; left: 3px; }
.corner-br { bottom: 3px; right: 3px; transform: rotate(180deg); }
.card.joker .corner-rank { font-size: .5rem; }
.wish-badge {
  position: absolute;
  bottom: 3px;
  left: 3px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: #fff;
  border: 1.5px solid rgba(0,0,0,.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .72rem;
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0,0,0,.35);
}
.wish-badge.red { color: #b71c1c; }
.wish-badge.black { color: #1b1b1b; }
.card .rank { font-size: 1.15rem; line-height: 1; }
.card .suit { font-size: 1.4rem; line-height: 1; }
.card.red { color: #b71c1c; }
.card.black { color: #1b1b1b; }
.card.joker { color: #6a1b9a; }
.card.joker .card-center { font-size: .8rem; text-align: center; }
.card-back {
  background: repeating-linear-gradient(45deg, var(--felt) 0 6px, var(--felt-dark) 6px 12px);
  border: 2px solid var(--accent);
  transition: background .5s ease, border-color .5s ease;
}
/* Der Nachziehstapel selbst ist bei Spielern (nicht beim MauMaster, der
   nur zuschaut) antippbar und ersetzt damit den früheren "Karte
   ziehen"-Button - dezentes Pulsieren + Zeigefinger-Cursor signalisieren
   das. */
.draw-pile.clickable { cursor: pointer; }
.draw-pile.clickable .card-back { animation: draw-pile-pulse 1.8s ease-in-out infinite; }
@keyframes draw-pile-pulse {
  0%, 100% { box-shadow: 0 3px 6px rgba(0,0,0,.35); }
  50% { box-shadow: 0 3px 6px rgba(0,0,0,.35), 0 0 0 4px rgba(232,178,60,.35); }
}
/* Kurzes Aufhellen beim tatsächlichen Ziehen einer Karte - für ALLE
   Teilnehmer sichtbar (wird beim Polling über neue Logbuch-Einträge vom
   Typ "draw" ausgelöst, siehe flashDrawPile() in app.js), nicht nur für
   die ziehende Person. */
.card-back.flash {
  background: repeating-linear-gradient(45deg, #3fae7c 0 6px, var(--felt) 6px 12px);
  border-color: #fff3d6;
}

.action-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 46px;
  padding: 4px 12px;
}
.action-bar .btn { box-shadow: 0 4px 10px rgba(0,0,0,.3); }
.action-bar .penalty-btn { background: var(--danger); color: #fff; }

.hand-wrap {
  padding: 10px 10px 14px;
  background: rgba(0,0,0,.18);
  flex-shrink: 0;
}
.hand {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 6px 4px 8px;
  scroll-snap-type: x proximity;
}
.hand .card {
  cursor: pointer;
  scroll-snap-align: center;
  transition: transform .1s ease, opacity .15s ease;
}
.hand .card.legal { outline: 3px solid var(--accent); transform: translateY(-6px); }
.hand .card.illegal { opacity: .4; cursor: not-allowed; }
.hand .card:active.legal { transform: translateY(-2px) scale(.97); }

.log {
  /* Fest auf 5 Zeilen ausgelegt (siehe .log div) und bewusst NICHT
     schrumpfbar (flex-shrink: 0), damit auf kleinen/mobilen Bildschirmen
     nicht ausgerechnet die letzten Logzeilen aus dem sichtbaren Bereich
     herausgequetscht werden - stattdessen weicht die Tischfläche
     (.table-area) zuerst aus. */
  height: 130px;
  flex-shrink: 0;
  box-sizing: border-box;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: rgba(0,0,0,.25);
  color: #eee;
  font-size: .78rem;
  padding: 6px 12px;
  line-height: 1.5;
}
.log-mm { height: 158px; font-size: .85rem; }
.log div { border-bottom: 1px solid rgba(255,255,255,.06); padding: 2px 0; }

/* ---------- Rundenende-Panel ----------
   Wird bewusst NICHT mehr als eigener Vollbild-Screen dargestellt, sondern
   direkt im Tisch-Bereich eingeblendet (ersetzt dort nur Hand und
   Aktionsleiste) - so bleiben Tisch, Sitzplätze und der zuletzt abgelegte
   Stich sichtbar, was z.B. bei einer 7er-Straf-Kette oder einer
   Bube/Joker-Verdopplung der Miesen nachvollziehbar bleiben muss. */
.roundover-panel {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  text-align: center;
  padding: 14px 16px;
  gap: 10px;
  background: rgba(0,0,0,.32);
}
.roundover-panel h2 { font-size: 1.15rem; margin: 0; }
#p-roundover-scores, #m-roundover-scores {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 480px;
}
.score-pill { background: rgba(255,255,255,.12); padding: 8px 14px; border-radius: 10px; }
.roundover-panel .btn { margin-top: 2px; }
/* Läuft während der Auszähl-Animation (siehe runRoundOverAnimation() in
   app.js): zeigt, wessen Handkarten gerade aufgedeckt werden und die dabei
   simultan mitgezählten Miese. */
.count-status {
  font-size: .95rem;
  font-weight: 700;
  background: rgba(232,178,60,.18);
  border: 1px solid rgba(232,178,60,.4);
  padding: 6px 14px;
  border-radius: 10px;
  min-width: 180px;
}

/* ---------- Sound-Ein/Aus (pro Endgerät, siehe localStorage) ---------- */
.btn.muted { opacity: .55; }

/* ---------- MauMaster view ---------- */
.topbar-mm { justify-content: space-between; }
.mm-title { font-size: 1.1rem; margin: 0; color: #fff; }
.mm-controls { display: flex; gap: 8px; flex-wrap: wrap; }

.mm-table-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 0;
}
/* Breite/Höhe werden bewusst NICHT hier fest vorgegeben, sondern von
   sizeRoundTable() in app.js anhand des tatsächlich verfügbaren Platzes im
   Wrapper (.mm-table-wrap, dank "flex: 1" oben bereits auf die volle
   Resthöhe zwischen Kopfbereich und unterem Bereich gewachsen) als Pixel-
   Maße gesetzt. So füllt der Tisch auf jedem Gerät wirklich den gesamten
   übrigen Platz aus, statt an feste vw/vh-Obergrenzen gebunden zu sein. */
.mm-table {
  position: relative;
  margin: 0 auto;
  border-radius: 50%;
  background: radial-gradient(circle, var(--felt) 55%, var(--felt-dark) 100%);
  border: 10px solid #5a3a1e;
  box-shadow: inset 0 0 40px rgba(0,0,0,.5), 0 10px 30px rgba(0,0,0,.5);
}
.mm-center {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  display: flex;
  gap: 22px;
  align-items: center;
}

/* Dieselbe Tisch-Darstellung, aber kompakter in die Spieler-Ansicht
   eingebettet (dort muss darunter noch Platz für Hand, Aktions-Button und
   Logbuch bleiben). */
.p-table-wrap {
  flex-shrink: 1;
  min-height: 150px;
}
.p-table-wrap .mm-table {
  border-width: 6px;
}
.p-table-wrap .mm-center { gap: 10px; }
.p-table-wrap .mm-center .pile { transform: scale(0.8); }
.p-table-wrap .seat { min-width: 60px; }
.p-table-wrap .seat .seat-name { font-size: .7rem; padding: 3px 8px; }
.p-table-wrap .seat .seat-meta { font-size: .6rem; }
.p-table-wrap .seat .mini-card { width: 13px; height: 19px; margin-left: -7px; }
.seat {
  position: absolute;
  transform: translate(-50%, -50%);
  text-align: center;
  color: #fff;
  min-width: 92px;
}
.seat .seat-name {
  background: rgba(0,0,0,.4);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: .82rem;
  font-weight: 600;
  white-space: nowrap;
}
.seat.current .seat-name { background: var(--accent); color: #2a1d02; box-shadow: 0 0 0 4px rgba(232,178,60,.35); }
.seat .seat-meta { font-size: .72rem; color: rgba(255,255,255,.85); margin-top: 3px; }
.seat .seat-hand { display: flex; justify-content: center; margin-top: 4px; }
.seat .mini-card {
  width: 20px; height: 28px; margin-left: -10px; border-radius: 3px;
  background: repeating-linear-gradient(45deg, var(--felt) 0 3px, var(--felt-dark) 3px 6px);
  border: 1px solid var(--accent);
}
.seat .mini-card:first-child { margin-left: 0; }
.seat.offline .seat-name { opacity: .5; }

/* ---------- Suit picker modal ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-box {
  background: var(--cream);
  border-radius: 16px;
  padding: 22px;
  text-align: center;
  max-width: 320px;
  width: 100%;
}
.modal-box h3 { margin: 0 0 14px; }
.modal-box .btn-ghost { background: #eee; color: #333; }
.suit-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.suit-btn {
  border: none; border-radius: 12px; padding: 16px 8px;
  background: #222; color: #fff; font-size: 1.8rem;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.suit-btn span { font-size: .8rem; }
.suit-btn.suit-red { background: #7a1f1f; }

/* ---------- Bestätigungsdialog ---------- */
.confirm-message { color: #444; font-size: .95rem; margin: 0 0 18px; line-height: 1.4; }
.confirm-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.confirm-actions .btn-primary { background: var(--danger); color: #fff; }
.confirm-actions .btn-primary:hover { background: #9c3520; }

/* ---------- Historie ---------- */
.history-card { max-width: 560px; text-align: left; }
.history-card h1 { font-size: 1.4rem; }
.history-card .btn { margin-top: 6px; }
.history-card .btn-ghost { background: #eee; color: #333; }
.history-list { max-height: 55vh; overflow-y: auto; margin: 10px 0 18px; display: flex; flex-direction: column; gap: 8px; }
.history-entry { background: #f3ead1; border-radius: 10px; padding: 10px 14px; font-size: .88rem; }
.history-date { font-weight: 700; color: var(--felt); margin-bottom: 2px; }
.history-players { color: #444; }
.history-rounds { color: #888; font-size: .8rem; margin-top: 2px; }

/* ---------- Toasts ---------- */
#toast-container {
  position: fixed;
  top: 12px; left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px;
  z-index: 100;
  width: min(92vw, 420px);
}
.toast {
  background: #222; color: #fff;
  padding: 10px 16px; border-radius: 10px;
  font-size: .9rem;
  box-shadow: 0 6px 18px rgba(0,0,0,.4);
  animation: fadeInOut 3.2s ease forwards;
  text-align: center;
}
.toast.win { background: var(--accent); color: #2a1d02; font-weight: 700; font-size: 1.05rem; }
.toast.error { background: var(--danger); }
.toast.info { background: #2c5f8a; }
@keyframes fadeInOut {
  0% { opacity: 0; transform: translateY(-8px); }
  10%, 85% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; }
}

/* ---------- Responsive tweaks ---------- */
@media (min-width: 720px) {
  :root { --card-w: 78px; --card-h: 112px; }
  .join-card { padding: 36px 34px; }
}
@media (max-width: 420px) {
  :root { --card-w: 54px; --card-h: 78px; }
  .card .rank { font-size: .95rem; }
  .card .suit { font-size: 1.1rem; }
}
@media (max-height: 700px) {
  /* Auf niedrigen Bildschirmen (v.a. Smartphones im Querformat oder mit
     Browser-Leiste) gibt zuerst die Tischfläche Platz ab, damit Hand und
     Logbuch (siehe .log / .hand-wrap, flex-shrink: 0) immer vollständig
     sichtbar bleiben. */
  .table-area { min-height: 100px; padding: 10px; gap: 16px; }
  .p-table-wrap { min-height: 100px; }
  .log { height: 112px; }
  .log-mm { height: 130px; }
}
