/* King of Jewel – fühlt sich an wie eine App: kein Zoomen, kein Seiten-Scrollen. */

:root {
  --bg-1: #0f0820;
  --bg-2: #24104a;
  --card: rgba(28, 16, 54, 0.88);
  --card-2: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f6efff;
  --muted: #b3a3d6;
  --gold: #ffd76a;
  --gold-2: #ff9f43;
  --accent: #b77dff;
  --green: #7dff9a;
  --error: #ff7a8a;
  --radius: 18px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg-1);
}

#bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse at 15% 0%, rgba(183, 125, 255, 0.35), transparent 55%),
    radial-gradient(ellipse at 90% 100%, rgba(79, 195, 255, 0.22), transparent 55%),
    linear-gradient(160deg, var(--bg-2), var(--bg-1));
}

.hidden { display: none !important; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 0.82rem; }
.center { text-align: center; }
.error { color: var(--error); margin: 0; min-height: 1.1em; text-align: center; font-size: 0.9rem; }

/* Nur ausgewiesene Listen dürfen scrollen – innerhalb ihrer Karte, nie die ganze Seite */
.scroll { overflow-y: auto; touch-action: pan-y; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }

/* ---------- Bildschirme & Karten ---------- */

.screen {
  position: relative;
  z-index: 1;
  display: none;
  height: 100%;
  height: 100dvh;
  align-items: center;
  justify-content: center;
  padding: max(12px, var(--safe-t)) max(12px, var(--safe-r)) max(12px, var(--safe-b)) max(12px, var(--safe-l));
}
.screen.active { display: flex; }

.card {
  width: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
  border-radius: 24px;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(10px);
  overflow-y: auto;
  touch-action: pan-y;
  overscroll-behavior: contain;
}

h1, h2, h3 { margin: 0; }

input {
  font: inherit;
  font-size: 16px; /* ab 16px zoomt iOS beim Antippen nicht */
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.32);
  color: var(--text);
  outline: none;
  width: 100%;
  -webkit-user-select: text;
  user-select: text;
  touch-action: manipulation;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(183, 125, 255, 0.25); }

button {
  font: inherit;
  font-size: 1rem;
  font-weight: bold;
  padding: 11px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s, background 0.2s, opacity 0.2s;
}
button:active:not(:disabled) { transform: scale(0.96); }
button:disabled { opacity: 0.4; cursor: default; }
button.primary {
  background: linear-gradient(180deg, #ffe58f, var(--gold) 40%, var(--gold-2));
  color: #3a1d00;
  border: none;
  box-shadow: 0 6px 20px rgba(255, 160, 60, 0.35);
}
button.big { font-size: 1.15rem; padding: 14px; }
button.ghost { background: transparent; }
button.danger { color: var(--error); }
.chip { font-size: 0.8rem; padding: 6px 12px; border-radius: 999px; }
.pill {
  justify-self: end;
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 215, 106, 0.15);
  color: var(--gold);
  white-space: nowrap;
}

.page-head { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 8px; min-height: 44px; }
.page-head h2 { text-align: center; color: var(--gold); font-size: 1.25rem; }
.page-head > span:first-child { width: 44px; }
.back { width: 44px; height: 44px; padding: 0; font-size: 1.5rem; border-radius: 50%; }

.segmented { display: flex; gap: 4px; padding: 4px; border-radius: 16px; background: rgba(0, 0, 0, 0.3); }
.segmented button {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 4px;
  font-size: 1.1rem;
  border: none;
  background: transparent;
  border-radius: 12px;
}
.segmented button span { font-size: 0.72rem; color: var(--muted); }
.segmented button.active { background: linear-gradient(180deg, rgba(255, 215, 106, 0.3), rgba(255, 159, 67, 0.2)); box-shadow: inset 0 0 0 1px rgba(255, 215, 106, 0.6); }
.segmented button.active span { color: var(--gold); }
.segmented button:disabled { opacity: 1; }
.segmented button:disabled:not(.active) { opacity: 0.45; }

/* ---------- Startseite ---------- */

.home { max-width: 400px; align-items: stretch; }
.logo {
  text-align: center;
  font-size: clamp(2rem, 8vmin, 2.8rem);
  letter-spacing: 1px;
  background: linear-gradient(180deg, #fff6c8, var(--gold) 45%, var(--gold-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 10px rgba(255, 180, 60, 0.45));
}
.logo span { font-size: 0.6em; }
.tagline { margin: -6px 0 4px; text-align: center; color: var(--muted); font-size: 0.9rem; }
.join { display: flex; gap: 8px; }
#code { text-transform: uppercase; letter-spacing: 6px; text-align: center; flex: 1; min-width: 0; }
.menu-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.menu-grid button { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 4px; font-size: 0.85rem; }
.menu-grid button span { font-size: 1.6rem; }

/* ---------- Seiten mit Listen (Level, Bestenliste) ---------- */

.page { max-width: 620px; height: min(100%, 760px); overflow: hidden; }
.page .scroll { flex: 1; min-height: 0; }

.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; align-content: start; padding: 2px; }
.level { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 6px; font-weight: normal; font-size: 0.78rem; line-height: 1.2; }
.level .num { font-size: 1.5rem; font-weight: bold; color: var(--gold); }
.level .lstars { color: var(--gold); letter-spacing: 1px; }
.level .shape { font-size: 0.65rem; color: var(--muted); }
.level.done { border-color: rgba(255, 215, 106, 0.5); background: rgba(255, 215, 106, 0.07); }

/* Bestenliste */
.board-content { display: flex; flex-direction: column; gap: 10px; }
.podium { display: grid; grid-template-columns: 1fr 1.15fr 1fr; align-items: end; gap: 8px; padding-top: 8px; }
.podium .place { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.podium .medal { font-size: 1.6rem; }
.podium .ava { width: 52px; height: 52px; font-size: 1.6rem; display: flex; align-items: center; justify-content: center; border-radius: 50%; background: rgba(0, 0, 0, 0.35); border: 2px solid var(--line); }
.podium .first .ava { width: 64px; height: 64px; font-size: 2rem; border-color: var(--gold); box-shadow: 0 0 18px rgba(255, 215, 106, 0.5); }
.podium .pname { font-size: 0.85rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.podium .pscore { font-weight: bold; color: var(--gold); }
.podium .step { width: 100%; border-radius: 12px 12px 0 0; background: linear-gradient(180deg, rgba(255, 215, 106, 0.25), rgba(255, 215, 106, 0.05)); text-align: center; font-weight: bold; color: var(--gold); padding-top: 6px; }
.podium .first .step { height: 60px; }
.podium .second .step { height: 42px; background: linear-gradient(180deg, rgba(200, 210, 230, 0.25), rgba(200, 210, 230, 0.05)); color: #dde3f0; }
.podium .third .step { height: 30px; background: linear-gradient(180deg, rgba(220, 140, 80, 0.25), rgba(220, 140, 80, 0.05)); color: #f0b080; }

.rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.rows li { display: grid; grid-template-columns: 28px 32px 1fr auto; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 12px; background: rgba(0, 0, 0, 0.25); }
.rows .rank { color: var(--muted); font-weight: bold; text-align: center; }
.rows .ava { font-size: 1.2rem; text-align: center; }
.rows .who { min-width: 0; display: flex; flex-direction: column; }
.rows .who b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: normal; }
.rows .who small { color: var(--muted); font-size: 0.7rem; }
.rows .score { font-weight: bold; color: var(--gold); }
.empty-note { text-align: center; color: var(--muted); padding: 30px 10px; }
.empty-note span { display: block; font-size: 2.4rem; margin-bottom: 6px; }

.records { display: grid; grid-template-columns: repeat(auto-fill, minmax(135px, 1fr)); gap: 10px; }
.record { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 14px 8px; border-radius: 16px; background: rgba(0, 0, 0, 0.25); border: 1px solid var(--line); text-align: center; }
.record .icon { font-size: 1.8rem; }
.record .label { font-size: 0.75rem; color: var(--muted); }
.record .value { font-size: 1.4rem; font-weight: bold; color: var(--gold); }
.record .holder { font-size: 0.8rem; }

.level-pick { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.level-pick button { width: 40px; height: 40px; padding: 0; border-radius: 50%; }
.level-pick b { text-align: center; flex: 1; }
.bosses { letter-spacing: 1px; }
.bosses .off { opacity: 0.25; filter: grayscale(1); }

/* ---------- Lobby ---------- */

.lobby { max-width: 460px; }
.lobby-code { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.lobby-code b { font-size: 2.4rem; letter-spacing: 10px; color: var(--gold); line-height: 1.1; }
.slots { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.slots li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 14px; background: rgba(0, 0, 0, 0.25); min-width: 0; font-size: 0.9rem; }
.slots li .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slots li.empty { color: var(--muted); font-style: italic; justify-content: center; border: 1px dashed var(--line); background: transparent; }
.slots li.gone { opacity: 0.5; }
.pickers { display: flex; flex-direction: column; gap: 8px; }
.picker { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.picker.colors { grid-template-columns: repeat(6, 1fr); }
.pick { aspect-ratio: 1; padding: 0; font-size: 1.25rem; border-radius: 12px; display: flex; align-items: center; justify-content: center; }
.pick.selected { outline: 3px solid var(--gold); outline-offset: 1px; }
.pick.swatch { border: 2px solid rgba(255, 255, 255, 0.3); aspect-ratio: 2 / 1; }
.pick.swatch:disabled { opacity: 0.15; }
.actions { display: flex; gap: 8px; }
.lobby .actions button { flex: 1; }

.avatar {
  flex: none;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: rgba(0, 0, 0, 0.3);
  font-size: 1rem;
  line-height: 1;
}

/* ---------- Spiel ----------
   Hochformat: Gegner oben, Brett, Bedienleiste unten.
   Querformat: Brett mit Bedienleiste links, Gegner rechts. */

#screen-game.active {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: "opp" "top" "arena" "bar";
  align-items: stretch;
  justify-items: center;
}
#opponents { grid-area: opp; display: flex; gap: 8px; justify-content: center; max-width: 100%; min-width: 0; }
#opponents:empty { display: none; }
#top { grid-area: top; width: 100%; display: flex; justify-content: center; }
#top:has(> .hidden:only-child) { display: none; }
#arena { grid-area: arena; width: 100%; min-height: 0; min-width: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
#bar { grid-area: bar; width: 100%; }

@media (min-aspect-ratio: 6/5) {
  #screen-game.active {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "top opp" "arena opp" "bar opp";
  }
  #opponents { flex-direction: column; justify-content: center; align-self: center; }
}

/* Brett */
#board-area { display: flex; gap: 10px; align-items: stretch; flex: none; }
#board-wrap { position: relative; flex: none; }
#board {
  display: block;
  border-radius: 20px;
  background: rgba(10, 4, 24, 0.5);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.55), 0 12px 40px rgba(0, 0, 0, 0.45);
  border: 1px solid var(--line);
  transition: filter 0.3s;
}
#board-wrap.waiting #board { filter: saturate(0.8) brightness(0.88); }
#float-layer { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.float {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: bold;
  font-size: clamp(1rem, 3.5vmin, 1.6rem);
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8), 0 0 14px var(--gold);
  animation: floatUp 1.1s ease-out forwards;
  white-space: nowrap;
}
.float.combo { font-size: clamp(1.2rem, 4.5vmin, 2.1rem); color: var(--gold); }
@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -160%) scale(1); }
}

/* Duell: wer ist dran? */
#turn-badge {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(15, 8, 32, 0.85);
  border: 2px solid var(--line);
  font-weight: bold;
  font-size: 0.9rem;
  white-space: nowrap;
  pointer-events: none;
  z-index: 3;
}
#turn-alert {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.8rem, 8vmin, 3.4rem);
  font-weight: bold;
  color: var(--green);
  text-shadow: 0 0 24px rgba(125, 255, 154, 0.8), 0 4px 10px rgba(0, 0, 0, 0.8);
  background: radial-gradient(circle, rgba(125, 255, 154, 0.18), transparent 65%);
  border-radius: 20px;
  pointer-events: none;
  z-index: 4;
  animation: turnAlert 1.4s ease-out forwards;
}
@keyframes turnAlert {
  0% { opacity: 0; transform: scale(0.6); }
  15% { opacity: 1; transform: scale(1.08); }
  25% { transform: scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; }
}

/* Ladungsleiste */
#charge { width: 54px; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding-top: 10px; }
#charge-track {
  position: relative;
  flex: 1;
  width: 22px;
  margin-left: 28px;
  border-radius: 999px;
  background: rgba(10, 4, 24, 0.6);
  border: 1px solid var(--line);
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.6);
}
#charge-track::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 30%;
  border-radius: 999px 999px 0 0;
  background: repeating-linear-gradient(135deg, rgba(255, 120, 60, 0.12) 0 6px, transparent 6px 12px);
}
#charge-fill {
  --fill: 0%;
  position: absolute;
  left: 2px; right: 2px; bottom: 2px;
  height: max(0px, calc(var(--fill) - 4px));
  border-radius: 999px;
  background: linear-gradient(0deg, #6a5cff, #b77dff 50%, #ffd76a);
  box-shadow: 0 0 12px rgba(183, 125, 255, 0.6);
  transition: height 0.15s ease-out;
}
#charge-fill.boom { background: linear-gradient(0deg, #ffd76a, #ff9f43 60%, #ff4d4d); box-shadow: 0 0 18px rgba(255, 110, 60, 0.9); animation: pulse 0.5s ease-in-out infinite alternate; }
#charge-fill.idle { opacity: 0.45; }
@keyframes pulse { from { filter: brightness(1); } to { filter: brightness(1.4); } }
.tick { position: absolute; bottom: var(--pos); left: -4px; right: -4px; height: 2px; background: rgba(255, 255, 255, 0.35); transform: translateY(50%); }
.tick span { position: absolute; right: 100%; margin-right: 3px; top: 50%; transform: translateY(-50%); font-size: 0.72rem; white-space: nowrap; color: var(--muted); }
.tick.reached { background: var(--gold); }
.tick.reached span { color: var(--text); }
.tick.boom { height: 3px; background: #ff7a4a; }
#charge-info { align-self: stretch; font-size: 0.7rem; text-align: center; color: var(--muted); min-height: 2.4em; line-height: 1.2; }
#charge-info b { color: #ffb36a; font-size: 0.82rem; }
body.compact #board-area { gap: 6px; }
body.compact #charge { width: 40px; }
body.compact #charge-track { margin-left: 20px; width: 16px; }
body.compact .tick span { font-size: 0.6rem; }
body.compact #charge-info { font-size: 0.58rem; }

/* Bedienleiste unter dem Brett */
#bar {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 10px;
  max-width: 1100px;
  padding: 6px 8px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--line);
}
.stats { display: flex; gap: 4px; }
.stat { display: flex; flex-direction: column; align-items: center; min-width: 54px; padding: 3px 6px; border-radius: 12px; background: rgba(0, 0, 0, 0.25); }
.stat span { font-size: 0.62rem; color: var(--muted); white-space: nowrap; text-transform: uppercase; letter-spacing: 0.5px; }
.stat b { font-size: 1.05rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
#hud-moves.low { color: var(--error); }

#objective {
  flex: 1 1 200px;
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 3px 8px;
  padding: 4px 12px;
  border-radius: 12px;
  background: rgba(255, 215, 106, 0.1);
  border: 1px solid rgba(255, 215, 106, 0.3);
  color: var(--gold);
  font-size: 0.8rem;
}
#objective-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#objective-text { grid-column: 1; grid-row: 1; }
#objective-progress { grid-column: 2; grid-row: 1; font-weight: bold; font-variant-numeric: tabular-nums; }
.obj-bar { grid-column: 1 / -1; grid-row: 2; height: 5px; border-radius: 999px; background: rgba(0, 0, 0, 0.35); overflow: hidden; }
#objective-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--gold), var(--gold-2)); transition: width 0.4s; }
#objective.done { background: rgba(125, 255, 154, 0.12); border-color: rgba(125, 255, 154, 0.45); color: var(--green); }
#objective.done #objective-fill { background: var(--green); }

#bar .actions { display: flex; align-items: center; gap: 6px; }
.round {
  position: relative;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.round i {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  font-style: normal;
  font-size: 0.7rem;
  line-height: 18px;
  background: var(--gold);
  color: #3a1d00;
}
#btn-shuffle:disabled i { background: var(--muted); }
.badge { padding: 4px 10px; border-radius: 999px; font-weight: bold; font-size: 0.82rem; white-space: nowrap; }
.badge.fire { color: #ffb36a; background: rgba(255, 110, 60, 0.18); border: 1px solid rgba(255, 140, 60, 0.6); animation: pulse 0.6s ease-in-out infinite alternate; }
.badge.rock { color: #e8dcd2; background: rgba(150, 130, 110, 0.25); border: 1px solid rgba(200, 180, 160, 0.5); }

/* Aufklappfelder: Emotes und Einstellungen */
.pop-wrap { position: relative; }
.popover {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  z-index: 30;
  padding: 8px;
  border-radius: 18px;
  background: rgba(30, 16, 58, 0.97);
  border: 1px solid var(--line);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  animation: popIn 0.15s ease-out;
}
@keyframes popIn { from { opacity: 0; transform: translateY(8px) scale(0.95); } to { opacity: 1; transform: none; } }
#emote-pop { display: grid; grid-template-columns: repeat(4, 48px); gap: 6px; }
#emote-pop button { width: 48px; height: 48px; padding: 0; font-size: 1.6rem; border-radius: 14px; }
.popover.menu { display: flex; flex-direction: column; gap: 6px; min-width: 200px; }
.popover.menu button { text-align: left; }
.popover.menu button.off { opacity: 0.55; }

/* Meldungen: liegen über der Bedienleiste, nie über dem Brett, und blenden sauber aus */
.toast {
  pointer-events: none;
  padding: 6px 14px;
  border-radius: 14px;
  background: rgba(40, 20, 74, 0.97);
  border: 1px solid rgba(255, 215, 106, 0.45);
  font-size: 0.88rem;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, visibility 0s linear 0.25s;
  z-index: 25;
}
.toast.show { opacity: 1; visibility: visible; transition: opacity 0.2s; }
#toast { position: fixed; top: max(12px, var(--safe-t)); left: 50%; transform: translateX(-50%); max-width: calc(100vw - 32px); border-radius: 999px; }
#game-toast { position: absolute; inset: 3px; display: flex; align-items: center; justify-content: center; }

/* Gegner */
.opp {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  padding: 6px;
  border-radius: 14px;
  background: var(--card);
  border: 2px solid var(--line);
}
.opp.gone { opacity: 0.4; }
.opp.turn { box-shadow: 0 0 0 3px var(--green), 0 0 18px rgba(125, 255, 154, 0.5); }
.opp header { display: flex; align-items: center; gap: 5px; font-size: 0.8rem; min-width: 0; }
.opp header .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.opp header .pts { color: var(--gold); font-weight: bold; }
.opp .avatar { width: 22px; height: 22px; font-size: 0.75rem; }
.opp .sub { font-size: 0.68rem; color: var(--muted); display: flex; justify-content: space-between; gap: 4px; }
.opp canvas { border-radius: 8px; background: rgba(0, 0, 0, 0.35); display: block; align-self: center; }

.emote-pop {
  position: absolute;
  left: 50%;
  top: 30%;
  font-size: clamp(2.2rem, 9vmin, 4rem);
  pointer-events: none;
  animation: emotePop 1.6s ease-out forwards;
  z-index: 5;
}
@keyframes emotePop {
  0% { opacity: 0; transform: translate(-50%, 0) scale(0.3); }
  15% { opacity: 1; transform: translate(-50%, -20%) scale(1.25); }
  70% { opacity: 1; transform: translate(-50%, -60%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -110%) scale(0.9); }
}

/* Koop-Boss */
#boss {
  width: min(560px, 100%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 12px;
  border-radius: 14px;
  background: rgba(120, 20, 40, 0.35);
  border: 1px solid rgba(255, 90, 90, 0.5);
}
#boss-emoji { font-size: 1.8rem; }
#boss.hit #boss-emoji { animation: bossHit 0.4s; }
@keyframes bossHit { 0%, 100% { transform: none; } 25% { transform: translateX(-6px) rotate(-8deg); } 75% { transform: translateX(6px) rotate(8deg); } }
.boss-body { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.boss-head { display: flex; justify-content: space-between; font-size: 0.82rem; }
.boss-bar { height: 10px; border-radius: 999px; background: rgba(0, 0, 0, 0.4); overflow: hidden; }
#boss-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #ff4d6d, #ff9f43); transition: width 0.4s; }

body[data-mode="level"] .pop-wrap:has(#btn-emote) { display: none; }

#net-status {
  position: fixed;
  top: max(10px, var(--safe-t));
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(255, 90, 90, 0.92);
  color: #fff;
  font-weight: bold;
  z-index: 40;
}

/* ---------- Fenster (Regeln, Ergebnisse) ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, var(--safe-t)) max(16px, var(--safe-r)) max(16px, var(--safe-b)) max(16px, var(--safe-l));
  background: rgba(8, 3, 18, 0.72);
  backdrop-filter: blur(4px);
}
.sheet { max-width: 560px; height: min(100%, 700px); overflow: hidden; }
.rules-text { flex: 1; min-height: 0; color: var(--muted); font-size: 0.92rem; line-height: 1.45; }
.rules-text h3 { color: var(--gold); font-size: 1rem; margin: 10px 0 4px; }
.rules-text ul { margin: 0; padding-left: 18px; }
.rules-text b { color: var(--text); }

.result { max-width: 420px; align-items: stretch; }
.result h2 { text-align: center; color: var(--gold); }
.result-actions { display: flex; flex-direction: column; gap: 8px; }
.ranking { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.ranking li { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 12px; background: rgba(0, 0, 0, 0.25); }
.ranking li .n { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking li .pts { margin-left: auto; font-weight: bold; color: var(--gold); }
.ranking li .bonus { font-size: 0.75rem; color: var(--green); }
.ranking li.first { background: linear-gradient(90deg, rgba(255, 215, 106, 0.25), rgba(0, 0, 0, 0.25)); }
.stars { text-align: center; font-size: 2.6rem; letter-spacing: 6px; }
.stars .off { opacity: 0.2; filter: grayscale(1); }

/* ---------- Kleine Bildschirme ---------- */

/* Schmal (Handy hochkant): Werte + Knöpfe in einer Zeile, Ziel darunter */
@media (max-width: 560px) {
  #bar { justify-content: space-between; }
  .stats { order: 1; }
  #bar .actions { order: 2; }
  #objective { order: 3; flex-basis: 100%; }
  .stat { min-width: 46px; padding: 2px 4px; }
  .stat b { font-size: 0.95rem; }
  .round { width: 38px; height: 38px; font-size: 1.05rem; }
  .card { padding: 16px; }
}
@media (max-width: 370px) {
  .stat { min-width: 40px; }
  .stat span { font-size: 0.55rem; }
  .stat b { font-size: 0.85rem; }
  .round { width: 34px; height: 34px; }
  .badge { font-size: 0.7rem; padding: 3px 6px; }
}

/* Wenig Höhe (Handy quer) */
@media (max-height: 520px) {
  .screen { padding-top: max(6px, var(--safe-t)); padding-bottom: max(6px, var(--safe-b)); }
  #screen-game.active { gap: 6px; }
  #bar { padding: 4px 6px; gap: 4px 8px; }
  .stat { padding: 1px 4px; }
  .stat span { font-size: 0.55rem; }
  .stat b { font-size: 0.9rem; }
  .round { width: 34px; height: 34px; font-size: 1rem; }
  #objective { padding: 2px 10px; font-size: 0.72rem; }
  #boss { padding: 2px 8px; }
  #boss-emoji { font-size: 1.3rem; }
  .boss-bar { height: 7px; }
  .card { padding: 14px; gap: 8px; }
  .logo { font-size: 1.8rem; }
  .lobby-code b { font-size: 1.8rem; }
  .menu-grid button { padding: 8px 4px; }
  .menu-grid button span { font-size: 1.2rem; }
  /* Startseite und Lobby nebeneinander statt untereinander */
  .home { max-width: 640px; display: grid; grid-template-columns: 1fr 1fr; align-items: center; }
  .home .logo, .home .tagline { grid-column: 1; }
  .home .menu-grid, .home .error { grid-column: 1 / -1; }
  .lobby { max-width: 760px; display: grid; grid-template-columns: 1fr 1fr; align-content: start; }
  .lobby .lobby-code, .lobby #pick-mode, .lobby #mode-desc { grid-column: 1; }
  .lobby .slots { grid-column: 1; }
  .lobby .pickers, .lobby #lobby-hint, .lobby .actions { grid-column: 2; }
  .lobby .pickers { grid-row: 1 / span 3; }
}

/* Ladungsleiste waagerecht unter dem Brett (Hochformat) */
body.charge-h #board-area { flex-direction: column; gap: 8px; }
body.charge-h #board-wrap { order: 1; }
body.charge-h #charge { order: 2; width: auto; flex-direction: row; align-items: center; gap: 10px; padding: 16px 4px 0; }
body.charge-h #charge-track { flex: 1; width: auto; height: 16px; margin: 0; }
body.charge-h #charge-track::before { left: auto; right: 0; top: 0; bottom: 0; width: 30%; height: auto; border-radius: 0 999px 999px 0; }
body.charge-h #charge-fill { left: 2px; top: 2px; bottom: 2px; right: auto; height: auto; width: max(0px, calc(var(--fill) - 4px)); }
body.charge-h .tick { left: var(--pos); bottom: auto; top: -4px; right: auto; width: 2px; height: auto; bottom: -4px; transform: translateX(-50%); }
body.charge-h .tick.boom { width: 3px; height: auto; }
body.charge-h .tick span { right: auto; left: 50%; top: auto; bottom: 100%; margin: 0 0 2px; transform: translateX(-50%); }
body.charge-h #charge-info { flex: none; width: 92px; min-height: 0; text-align: right; align-self: center; }
body.charge-h.compact #charge-track { height: 12px; }
body.charge-h.compact #charge-info { width: 74px; }

/* Einladung auf der Startseite */
.invite {
  padding: 10px 12px;
  border-radius: 14px;
  text-align: center;
  background: rgba(125, 255, 154, 0.12);
  border: 1px solid rgba(125, 255, 154, 0.45);
  color: var(--green);
  font-size: 0.95rem;
  line-height: 1.4;
}
.invite b { letter-spacing: 3px; }
.invite span { color: var(--muted); font-size: 0.82rem; }

/* Aufklappfelder links vom Knopf öffnen, wenn er links im Bild sitzt */
.popover.align-left { right: auto; left: 0; }
