:root {
  color-scheme: dark;
  --bg: #17142a;
  --bg-2: #231d40;
  --panel: #2c2552;
  --line: #443b72;
  --text: #f4f0fc;
  --muted: #aca4ca;
  --accent: #ffb454;
  --accent-ink: #2b1a02;
  --danger: #ff7a8a;
  --paper: #fbf5e9;
  --back-a: #6f50d8;
  --back-b: #3a2985;
  --vh: 100vh;
}
@supports (height: 100dvh) {
  :root { --vh: 100dvh; }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: var(--vh);
  background: radial-gradient(120% 70% at 50% 0%, #2e2558 0%, var(--bg) 62%) fixed, var(--bg);
  color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input { font: inherit; color: inherit; }
h1, h2, p, ul { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- Bausteine ----------------------------------------------------------- */

.screen { min-height: var(--vh); display: flex; flex-direction: column; }
.column {
  margin: auto;
  width: min(100% - 32px, 400px);
  padding: 28px 0 calc(28px + env(safe-area-inset-bottom));
  display: grid;
  gap: 14px;
}
.stack { display: grid; gap: 8px; }
.row { display: flex; gap: 8px; }
.row > .field, .grow { flex: 1; min-width: 0; }
.center { text-align: center; }
.muted { color: var(--muted); font-size: .9rem; }
.label { font-size: .78rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

.btn {
  appearance: none;
  border: 0;
  border-radius: 14px;
  padding: 14px 18px;
  font-weight: 700;
  font-size: 1rem;
  background: var(--panel);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line);
  cursor: pointer;
  transition: transform .1s ease, filter .15s ease;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: none; }
.btn.danger { background: color-mix(in srgb, var(--danger) 22%, var(--panel)); box-shadow: inset 0 0 0 1px var(--danger); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
@media (hover: hover) { .btn:not(:disabled):hover { filter: brightness(1.08); } }

.link {
  appearance: none; border: 0; background: none; padding: 8px;
  color: var(--muted); text-decoration: underline; text-underline-offset: 3px;
  cursor: pointer; justify-self: center; font-size: .92rem;
}

.field {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #1b1733;
  color: var(--text);
  font-size: 1rem;
}
.field::placeholder { color: #7d75a0; }
.field.code { text-transform: uppercase; letter-spacing: .3em; font-weight: 800; text-align: center; }
.field.code::placeholder { letter-spacing: .3em; font-weight: 600; }

.note {
  padding: 12px 14px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 45%, transparent);
  font-size: .92rem;
}
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .8rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.hint { font-size: .8rem; color: var(--muted); }
.inline-link {
  appearance: none; border: 0; background: none; padding: 0;
  font: inherit; font-weight: 700; color: var(--accent);
  text-decoration: underline; text-underline-offset: 2px; cursor: pointer;
}
.error { font-size: .88rem; color: #ffb3bd; }
.error.fine { color: #9fe3c8; }

/* --- Startseite und Raum ------------------------------------------------- */

.brand { text-align: center; margin-bottom: 4px; }
.brand-cards { --cw: 58px; display: flex; justify-content: center; margin-bottom: 16px; }
.brand-cards .card:nth-child(1) { transform: rotate(-13deg) translate(16px, 8px); }
.brand-cards .card:nth-child(2) { z-index: 1; }
.brand-cards .card:nth-child(3) { transform: rotate(13deg) translate(-16px, 8px); }
.brand h1 { font-size: 2.7rem; line-height: 1.1; letter-spacing: -.035em; }
.brand p { margin-top: 4px; color: var(--muted); }

.bigcode {
  text-align: center;
  font-size: 3.2rem;
  font-weight: 800;
  letter-spacing: .22em;
  padding-left: .22em;
  line-height: 1.1;
  color: var(--accent);
}
.players { list-style: none; padding: 0; display: grid; gap: 8px; }
.players li {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px; border-radius: 14px;
  background: var(--panel);
}
.players .pname { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tag {
  flex: none;
  font-size: .68rem; font-weight: 700;
  padding: 2px 8px; border-radius: 99px;
  background: rgba(255, 255, 255, .1); color: var(--text);
  white-space: nowrap;
}
.tag.warn { background: color-mix(in srgb, var(--danger) 26%, transparent); color: #ffd3d9; }
.tag.hot { background: color-mix(in srgb, var(--accent) 26%, transparent); color: #ffe4bd; }

/* --- Karten -------------------------------------------------------------- */

.card {
  position: relative;
  flex: none;
  width: var(--cw);
  height: calc(var(--cw) / .72);
  border: 0; padding: 0; margin: 0;
  border-radius: calc(var(--cw) * .14);
  display: grid; place-items: center;
  font: inherit; color: inherit; background: none;
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
  transition: transform .14s ease, box-shadow .14s ease;
}
.card.down {
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, .2) 0 14%, transparent 15%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .075) 0 2px, transparent 2px 8px),
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, .075) 0 2px, transparent 2px 8px),
    linear-gradient(160deg, var(--back-a), var(--back-b));
  box-shadow: inset 0 0 0 max(2px, calc(var(--cw) * .055)) rgba(255, 255, 255, .16), 0 2px 5px rgba(0, 0, 0, .4);
}
.card.up {
  background: color-mix(in oklch, var(--tone) 26%, var(--paper));
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .1), 0 2px 5px rgba(0, 0, 0, .4);
}
.card.up::after {
  content: "";
  position: absolute; left: 20%; right: 20%; bottom: 10%;
  height: max(2px, 5%);
  border-radius: 99px;
  background: var(--tone);
}
.card .num {
  font-size: calc(var(--cw) * .54);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.04em;
  font-variant-numeric: tabular-nums;
  transform: translateY(-4%);
}
.card.empty { box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .13); }
.card.gone { outline: 1.5px dashed rgba(255, 255, 255, .13); outline-offset: -3px; }

.card.can {
  cursor: pointer;
  box-shadow: 0 0 0 2.5px var(--accent), 0 5px 14px rgba(0, 0, 0, .5);
}
.card.can:active { transform: scale(.95); }
@media (hover: hover) { .card.can:hover { transform: translateY(-4%); } }
.card.lifted { transform: translateY(-12%) scale(1.06); box-shadow: 0 0 0 3px var(--accent), 0 12px 22px rgba(0, 0, 0, .55); }
.card.last::before {
  content: "";
  position: absolute; top: -3px; right: -3px;
  width: max(7px, calc(var(--cw) * .15)); aspect-ratio: 1;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--bg);
}

@keyframes flip { from { transform: rotateY(90deg) scale(1.06); } to { transform: none; } }
@keyframes deal { from { opacity: 0; transform: translateY(-10%) scale(.94); } to { opacity: 1; transform: none; } }
@keyframes drop { from { transform: translateY(-16%) scale(1.08); } to { transform: none; } }
@keyframes vanish { to { transform: scale(.55) rotate(10deg); opacity: 0; } }
.anim-flip { animation: flip .34s ease-out; }
.anim-deal { animation: deal .3s ease-out; }
.anim-drop { animation: drop .26s ease-out; }
.vanish { animation: vanish .42s ease-in forwards; }

/* --- Spieltisch ---------------------------------------------------------- */

#game {
  --n-opp: 1;
  --opp-scale: .62;
  --card-h: max(46px, min(calc((var(--vh) - 252px) / (4 + 3 * var(--opp-scale))), calc((100vw - 32px) / 3.1), 150px));
  --card-w: calc(var(--card-h) * .72);
  --gap: max(4px, calc(var(--card-w) * .09));
  --opp-w: min(calc(var(--card-w) * var(--opp-scale)), calc((100vw - 32px - (var(--n-opp) - 1) * 18px) / (4.4 * var(--n-opp))));
  display: grid;
  grid-template-rows: auto auto minmax(min-content, 1fr) auto auto;
  gap: 6px;
  padding: env(safe-area-inset-top) 16px calc(12px + env(safe-area-inset-bottom));
}
#game[data-opp="2"] { --n-opp: 2; --opp-scale: .5; }
#game[data-opp="3"] { --n-opp: 3; --opp-scale: .42; }
#game.hotseat[data-opp="1"] { --opp-scale: 1; }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 44px; }
.bar-title { display: flex; align-items: baseline; gap: 8px; min-width: 0; white-space: nowrap; }
.bar-title strong { font-size: 1.08rem; letter-spacing: -.02em; }
.bar-title span { font-size: .78rem; color: var(--muted); }
.bar nav { display: flex; gap: 6px; }
.pill {
  appearance: none; border: 0; cursor: pointer;
  font-size: .75rem; font-weight: 600;
  padding: 7px 11px; border-radius: 99px;
  background: rgba(255, 255, 255, .09); color: var(--text);
}

.opponents { display: flex; justify-content: center; align-items: flex-start; gap: 18px; }
.opponents .seat { --cw: var(--opp-w); --g: max(3px, calc(var(--opp-w) * .09)); }
.mine .seat { --cw: var(--card-w); --g: var(--gap); }
.center-row {
  --cw: var(--card-w);
  display: flex; align-items: center; justify-content: center;
  gap: calc(var(--card-w) * .42);
  padding: 4px 0;
}

.seat { display: grid; justify-items: center; gap: 5px; min-width: 0; }
.grid { display: grid; grid-template-columns: repeat(4, var(--cw)); gap: var(--g); }
.seat-head {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 22px; max-width: 100%;
  font-size: .78rem; color: var(--muted);
  white-space: nowrap;
}
.seat-head .who { font-weight: 700; font-size: .86rem; color: var(--text); overflow: hidden; text-overflow: ellipsis; }
.seat-head .nums { font-variant-numeric: tabular-nums; }
.seat.active .who { color: var(--accent); }
.seat.active .who::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: var(--accent); vertical-align: middle; transform: translateY(-1px); }
.seat.away .grid { opacity: .55; }
#game:not([data-opp="1"]) .opponents .open { display: none; }

.pile { display: grid; justify-items: center; gap: 5px; }
.cap { font-size: .68rem; color: var(--muted); white-space: nowrap; max-width: calc(var(--cw) * 1.5); overflow: hidden; text-overflow: ellipsis; }
#deck {
  box-shadow:
    inset 0 0 0 max(2px, calc(var(--cw) * .055)) rgba(255, 255, 255, .16),
    0 2px 0 #2f2272, 0 4px 0 #281c63, 0 7px 10px rgba(0, 0, 0, .45);
}
#deck.can {
  box-shadow:
    inset 0 0 0 max(2px, calc(var(--cw) * .055)) rgba(255, 255, 255, .16),
    0 0 0 2.5px var(--accent), 0 7px 14px rgba(0, 0, 0, .5);
}

.status { display: grid; align-content: center; gap: 2px; min-height: 60px; text-align: center; }
#status-main { font-weight: 700; font-size: .95rem; line-height: 1.25; text-wrap: balance; }
#status-sub { font-size: .76rem; color: var(--muted); min-height: 1.2em; line-height: 1.25; text-wrap: balance; }

/* Handy im Querformat: Gegner und Stapel links, eigene Karten rechts */
@media (orientation: landscape) and (max-height: 520px) {
  #game {
    --card-h: max(40px, min(calc((var(--vh) - 100px) / 3.3), calc((50vw - 32px) / 3.1)));
    --opp-w: min(calc(var(--card-w) * .5), calc((50vw - 32px - (var(--n-opp) - 1) * 14px) / (4.4 * var(--n-opp))));
    --cen: calc(var(--card-w) * .62);
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto minmax(0, 1fr);
    column-gap: 16px;
    row-gap: 2px;
  }
  .bar { grid-column: 1 / -1; height: 38px; }
  .opponents { grid-column: 1; grid-row: 2; }
  .center-row { grid-column: 1; grid-row: 3; --cw: var(--cen); }
  .cap { max-width: none; }
  .status { grid-column: 1; grid-row: 4; min-height: 0; }
  .mine { grid-column: 2; grid-row: 2 / -1; align-self: center; }
}

/* --- Ergebnis, Dialoge, Meldungen ---------------------------------------- */

.sheet {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: end center;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: rgba(12, 9, 26, .6);
  animation: fade .25s ease-out;
}
.sheet-inner {
  width: min(100%, 460px);
  max-height: calc(var(--vh) - 32px);
  overflow: auto;
  display: grid; gap: 12px;
  padding: 22px;
  border-radius: 22px;
  background: var(--bg-2);
  box-shadow: 0 0 0 1px var(--line), 0 24px 60px rgba(0, 0, 0, .6);
  animation: rise .3s ease-out;
}
@media (min-width: 700px) { .sheet { place-items: center; } }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
.sheet h2, .dlg h2 { font-size: 1.4rem; letter-spacing: -.02em; line-height: 1.2; }

.fab {
  position: fixed; z-index: 20;
  left: 50%; bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .6);
}
.fab:active { transform: translateX(-50%) scale(.98); }

.table-wrap { overflow-x: auto; }
.scores { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.scores th, .scores td { padding: 9px 8px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.scores th:first-child, .scores td:first-child { text-align: left; }
.scores th { font-size: .74rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.scores td.name { font-weight: 700; max-width: 9em; overflow: hidden; text-overflow: ellipsis; }
.scores td.total { font-weight: 800; }
.scores tr.lead td.total { color: var(--accent); }
.scores tfoot td { font-weight: 800; border-bottom: 0; border-top: 2px solid var(--line); }
.scores small { color: var(--muted); font-weight: 500; }
.scores .none { color: var(--muted); text-align: left; }

dialog.dlg {
  width: min(100vw - 32px, 460px);
  max-height: calc(var(--vh) - 32px);
  padding: 22px;
  border: 0; border-radius: 22px;
  background: var(--bg-2); color: var(--text);
  box-shadow: 0 0 0 1px var(--line), 0 24px 60px rgba(0, 0, 0, .6);
}
dialog.dlg[open] { display: grid; gap: 14px; }
dialog.dlg::backdrop { background: rgba(12, 9, 26, .7); }
.rules { display: grid; gap: 10px; font-size: .93rem; }
.rules ul { padding-left: 1.2em; display: grid; gap: 6px; }
.rules strong { color: var(--accent); }

.offline {
  position: fixed; z-index: 40; top: calc(8px + env(safe-area-inset-top)); left: 50%;
  transform: translateX(-50%);
  width: max-content; max-width: calc(100vw - 24px);
  padding: 8px 14px; border-radius: 99px;
  background: #5a1f2c; color: #ffd3d9;
  font-size: .82rem; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
}
.toast {
  position: fixed; z-index: 50; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: max-content; max-width: calc(100vw - 32px);
  padding: 11px 16px; border-radius: 14px;
  background: #f4f0fc; color: #1d1836;
  font-size: .9rem; font-weight: 600; text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .55);
  animation: rise .2s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

.tags { display: inline-flex; gap: 4px; }
.tags:empty { display: none; }

/* --- Konto und Statistik -------------------------------------------------- */

.userbox {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; border-radius: 14px;
  background: var(--panel); box-shadow: inset 0 0 0 1px var(--line);
}
.userbox-who { min-width: 0; display: grid; gap: 1px; }
.userbox-who strong { font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.userbox-actions { display: flex; gap: 6px; flex: none; }

.column.wide { width: min(100% - 32px, 560px); margin: 0 auto; }
.sections { display: grid; gap: 22px; }
.page-head { display: flex; align-items: center; gap: 12px; }
.page-head h2 { font-size: 1.45rem; letter-spacing: -.02em; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: auto auto auto; gap: 8px; }
/* subgrid: Name, Zahl und Zusatz stehen in allen Kacheln auf gleicher Höhe, auch wenn ein Name umbricht */
.tile {
  display: grid; grid-row: span 3; grid-template-rows: subgrid; row-gap: 2px;
  padding: 14px 12px; border-radius: 14px; background: var(--panel);
}
.tile-name { align-self: end; }
.tile-name { font-size: .78rem; color: var(--muted); }
.tile-value { font-size: 1.9rem; font-weight: 700; line-height: 1.15; letter-spacing: -.02em; }
.tile-sub { font-size: .74rem; color: var(--muted); }

.scores.details td:last-child { font-weight: 700; }
.recent { list-style: none; padding: 0; display: grid; gap: 8px; }
.recent li { display: grid; gap: 6px; padding: 12px 14px; border-radius: 14px; background: var(--panel); }
.recent-head { display: flex; align-items: center; gap: 8px; font-size: .8rem; color: var(--muted); }
.recent-players { display: flex; flex-wrap: wrap; gap: 2px 16px; font-variant-numeric: tabular-nums; }
.recent-players .me { font-weight: 700; }
.recent-players .points { margin-left: 6px; color: var(--muted); }
