:root {
  color-scheme: dark;
  --bg: #0b3d24;
  --bg2: #0e2f1f;
  --panel: #123a2a;
  --panel-light: #1a4c36;
  --accent: #e0b13a;
  --accent-dark: #b9862a;
  --text: #f0ece0;
  --card-bg: #fdfdfa;
  --card-border: #333;
  /* Im Querformat ist die Bildschirmhöhe die knappe Ressource (Breite reicht meist,
     die Handkartenreihe scrollt bei Bedarf horizontal) - Kartengrösse daher direkt
     an vh koppeln. Default = "gross"; überschrieben je nach Einstellung (siehe unten). */
  --card-w: clamp(48px, 16vh, 100px);
  --card-h: clamp(68px, 23vh, 145px);
  /* Pinselschrift braucht mehr Fläche zur Wirkung als eine normale Schrift - deutlich
     grösser als eine "normale" Kartenbeschriftung, bewusst so gewünscht. */
  --card-rank-size: clamp(1.7rem, 17.4vh, 3rem);
  --card-suit-size: clamp(1.2rem, 9.2vh, 1.8rem);
}

/* Kartengrösse-Presets (umschaltbar im Einstellungen-Modal, siehe app.js) */
body.card-size-klein {
  --card-w: 42px;
  --card-h: 60px;
  --card-rank-size: 1.7rem;
  --card-suit-size: 1.2rem;
}
body.card-size-mittel {
  --card-w: clamp(44px, 11vh, 85px);
  --card-h: clamp(64px, 16vh, 122px);
  --card-rank-size: clamp(1.6rem, 12vh, 2.4rem);
  --card-suit-size: clamp(1.2rem, 6.4vh, 1.56rem);
}
body.card-size-gross {
  --card-w: clamp(48px, 16vh, 100px);
  --card-h: clamp(68px, 23vh, 145px);
  --card-rank-size: clamp(1.7rem, 17.4vh, 3rem);
  --card-suit-size: clamp(1.2rem, 9.2vh, 1.8rem);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  overscroll-behavior: none;
  background: radial-gradient(ellipse at 50% 35%, var(--bg2) 0%, var(--bg) 70%);
  color: var(--text);
  font-family: system-ui, sans-serif;
  touch-action: manipulation;
}

#portrait-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  color: var(--text);
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  text-align: center;
  padding: 2rem;
}

@media (orientation: portrait) {
  #portrait-overlay { display: flex; }
  #join-screen, #game-screen { visibility: hidden; }
}

.screen { height: 100dvh; width: 100vw; }
.hidden { display: none !important; }

#join-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}
#join-screen h1 {
  margin: 0;
  letter-spacing: 0.03em;
  text-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
#join-screen input, #join-screen button {
  font-size: 1.1rem;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--card-border);
}
#join-screen button {
  background: linear-gradient(160deg, var(--accent), var(--accent-dark));
  color: #241a04;
  font-weight: 700;
  border: none;
  box-shadow: 0 2px 5px rgba(0,0,0,0.35);
}
.error { color: #ff6b6b; min-height: 1.2em; }

#team-panels {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}
.team-panel {
  background: linear-gradient(160deg, var(--panel-light), var(--panel));
  border-radius: 12px;
  padding: 0.9rem 1.1rem;
  width: 220px;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  box-shadow: 0 3px 10px rgba(0,0,0,0.3);
}
.team-panel input {
  font-size: 1rem;
  padding: 0.4rem;
  border-radius: 6px;
  border: 1px solid var(--card-border);
}
.team-members { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }
.team-member-slot { padding: 0.3rem 0.5rem; border-radius: 6px; background: rgba(255,255,255,0.08); }
.team-member-slot.empty { opacity: 0.5; font-style: italic; }
.team-panel button:disabled { opacity: 0.4; box-shadow: none; }

#game-screen {
  display: flex;
  flex-direction: row;
  height: 100dvh;
}

#game-main {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  /* Bewusst keine explizite Hoehe (100%/100dvh) - manche Browser (v.a. WebKit)
     loesen prozentuale Hoehen auf Flex-Kindern unzuverlaessig auf. #game-screen
     ist eine Row ohne eigenes align-items, also strecken sich beide Spalten
     (hier und #action-bar) per Default-"stretch" zuverlaessig auf volle Hoehe. */
}

#opponent-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.4rem 0.7rem;
  background: linear-gradient(to bottom, var(--panel-light), var(--panel));
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  font-size: 0.8rem;
  flex: 0 0 auto;
  z-index: 5;
}
#opponents-list {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  flex: 1 1 auto;
  min-width: 0;
}
.opponent {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.25rem 0.7rem;
  border-radius: 8px;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}
.opponent.current-turn { background: rgba(224, 177, 58, 0.18); box-shadow: 0 0 0 2px var(--accent); }
.opponent.ghost { opacity: 0.6; cursor: pointer; border: 1px dashed #ff6b6b; }
.opponent .badge { color: var(--accent); font-weight: bold; }
.schupf-gift-chip {
  margin-top: 0.2rem;
  padding: 0.05rem 0.5rem;
  border-radius: 6px;
  background: var(--accent);
  color: #222;
  font-weight: bold;
  font-size: 0.8rem;
  cursor: pointer;
}
.opponent .discon { color: #ff6b6b; }

#table-area {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  padding-bottom: 1.2rem;
  min-height: 0;
  position: relative;
}
/* Stich und "Am Zug"-Hinweis nebeneinander statt uebereinander: der Stich sitzt
   links am unteren Tischrand, der Hinweis rechts daneben - so verdeckt der Text
   die gespielten Karten nicht mehr und beides ist auf einen Blick lesbar. */
#trick-row {
  align-self: stretch;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 1.5rem;
}
#center-pile {
  position: relative;
  min-height: 80px;
  min-width: 220px;
  max-width: 90vw;
  padding: 0.5rem;
  cursor: pointer;
}
.trick-layer {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.trick-layer-cards {
  display: flex;
  gap: 0.2rem;
}
/* Die oberste Kombination liegt klar sichtbar oben, der Rest liegt nur angedeutet
   dahinter - Stapel antippen zeigt alle Spielzuege dieses Stichs. */
.trick-layer.second { opacity: 0.75 !important; }

#center-pile.expanded {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  align-items: center;
  min-height: auto;
  max-height: 60vh;
  overflow-y: auto;
  background: rgba(0,0,0,0.25);
  border-radius: 10px;
}
.trick-expanded-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.15rem 0.4rem;
}
.trick-expanded-row.top { background: rgba(224, 177, 58, 0.18); border-radius: 6px; }
.trick-expanded-label {
  min-width: 70px;
  font-size: 0.8rem;
  font-weight: bold;
  color: var(--accent);
  text-align: right;
}
#phase-banner, #wish-banner, #dragon-banner {
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(2px);
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  font-size: 0.9rem;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
#dragon-banner { color: var(--accent); font-weight: 600; }

#schupf-area {
  flex: 0 0 auto;
  padding: 0.4rem;
  background: var(--panel);
}
#schupf-slots {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
}
.schupf-slot {
  width: var(--card-w);
  height: var(--card-h);
  border: 2px dashed var(--accent);
  border-radius: clamp(6px, 1vmin, 12px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  text-align: center;
}
.schupf-slot.filled { border-style: solid; }

#hand-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: stretch;
  padding: 0.15rem 0.6rem;
  background: linear-gradient(to bottom, var(--panel-light), var(--panel));
  box-shadow: 0 -2px 8px rgba(0,0,0,0.25);
}
#hand-row {
  flex: 1 1 auto;
  display: flex;
  align-items: flex-end;
  gap: clamp(2px, 0.6vmin, 8px);
  overflow-x: auto;
  overflow-y: visible;
  min-height: calc(var(--card-h) + 14px);
  padding-top: 14px;
}
/* Eigene, ueber die volle Hoehe reichende Spalte rechts (neben Statuszeile,
   Tisch und Handkarten) - so bleiben Buttons immer an fester Position, ganz
   ohne Scrollen und ohne die Handkartenzeile zu verengen. */
#action-bar {
  flex: 0 0 96px;
  width: 96px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  gap: 0.4rem;
  padding: 0.6rem;
  background: linear-gradient(to bottom, var(--panel-light), var(--panel));
  box-shadow: -2px 0 8px rgba(0,0,0,0.25);
  z-index: 5;
}
#action-bar button {
  min-height: 34px;
  width: 100%;
  flex: 0 0 auto;
  border-radius: 10px;
  border: none;
  background: linear-gradient(160deg, var(--accent), var(--accent-dark));
  color: #241a04;
  font-weight: 700;
  font-size: 0.85rem;
  box-shadow: 0 2px 5px rgba(0,0,0,0.35);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
#action-bar button:active { transform: translateY(1px); box-shadow: 0 1px 2px rgba(0,0,0,0.3); }
#action-bar button:disabled { opacity: 0.4; box-shadow: none; }

.card {
  overflow: hidden;
  width: var(--card-w);
  height: var(--card-h);
  min-width: var(--card-w);
  background: linear-gradient(160deg, #ffffff 0%, var(--card-bg) 55%, #ece8dd 100%);
  color: var(--card-border);
  border: 1px solid rgba(0,0,0,0.5);
  border-radius: clamp(6px, 1vmin, 12px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15em;
  cursor: pointer;
  user-select: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  flex-shrink: 0;
  box-shadow: 0 2px 4px rgba(0,0,0,0.35), 0 1px 0 rgba(255,255,255,0.5) inset;
}
.card-rank {
  font-family: "Ma Shan Zheng", cursive;
  font-size: var(--card-rank-size);
  font-weight: 400;
  line-height: 1;
}
.card-suit {
  font-family: "Ma Shan Zheng", cursive;
  font-size: var(--card-suit-size);
  font-weight: 400;
  opacity: 0.85;
  line-height: 1;
}
.card:hover { transform: translateY(-2px); }
.card.selected {
  transform: translateY(calc(-1 * clamp(8px, 2vmin, 18px)));
  box-shadow: 0 6px 14px rgba(0,0,0,0.45), 0 0 0 2px var(--accent);
}
.card.suggested { box-shadow: 0 2px 4px rgba(0,0,0,0.35), 0 0 0 3px rgba(224, 177, 58, 0.6) inset; }
.card.suit-schwarz { color: #111; }
.card.suit-pagode { color: #1a5fb4; }
.card.suit-jade { color: #1c8a54; }
.card.suit-stern { color: #c01c28; }
.card.special { color: #7a3fa0; }

#scoreboard {
  font-size: 0.8rem;
  font-weight: 600;
  background: rgba(0,0,0,0.3);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  white-space: nowrap;
  flex: 0 0 auto;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(1px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-content {
  background: linear-gradient(160deg, var(--panel-light), var(--panel));
  padding: 1.2rem 1.4rem;
  border-radius: 14px;
  max-width: 90vw;
  max-height: 90dvh;
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
}
#wish-options, #dragon-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  justify-content: center;
  margin: 0.5rem 0;
}
#wish-options button, #dragon-options button {
  padding: 0.45rem 0.7rem;
  border-radius: 8px;
  border: none;
  background: linear-gradient(160deg, var(--accent), var(--accent-dark));
  color: #241a04;
  font-weight: 700;
  box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}

#settings-button {
  position: fixed;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 60;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.35);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.settings-group {
  text-align: left;
  margin: 0.8rem 0;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid rgba(255,255,255,0.15);
}
.settings-group label {
  display: block;
  margin: 0.3rem 0;
  cursor: pointer;
}
.settings-group input[type="radio"]:disabled + label,
.settings-group input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.hint { font-size: 0.8rem; opacity: 0.7; margin: 0.2rem 0 0; }
#settings-modal h2, #review-modal h2 { margin-top: 0; }
#settings-close-button, #review-close-button, #review-open-button {
  margin-top: 0.5rem;
  padding: 0.5rem 1.1rem;
  border-radius: 8px;
  border: none;
  background: linear-gradient(160deg, var(--accent), var(--accent-dark));
  color: #241a04;
  font-weight: 700;
  box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}
.danger-button {
  margin: 0.3rem 0.3rem 0 0;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: 1px solid #c0392b;
  background: rgba(192, 57, 43, 0.18);
  color: #ff9a8c;
  font-weight: 600;
}

#review-modal .modal-content { max-width: 95vw; width: 480px; }
#review-list { text-align: left; }
#review-list h3 {
  margin: 0.8rem 0 0.3rem;
  font-size: 0.85rem;
  color: var(--accent);
  border-bottom: 1px solid rgba(255,255,255,0.15);
  padding-bottom: 0.2rem;
}
.review-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.15rem 0;
  font-size: 0.85rem;
  flex-wrap: wrap;
}
.review-cards { display: flex; gap: 0.2rem; }
.review-cards .card {
  width: 34px;
  height: 48px;
  min-width: 34px;
  cursor: default;
}
.review-cards .card-rank { font-size: 1.15rem; }
.review-cards .card-suit { font-size: 0.8rem; }
