/* ---------------------------------------------------------------
   Design-Paket: Karten (Bildkarten, Glanz), Tisch-Atmosphaere,
   Chip-Stapel, Austeilen/Mischen, lebendige Lobby, Profilkarte,
   Ansichts-Uebergaenge, Tipp-Feedback und Querformat am Handy.
   Wird nach allen anderen Stylesheets geladen und ergaenzt sie nur.
   --------------------------------------------------------------- */

:root {
  --tilt-x: 0;
  --tilt-y: 0;
  /* Feines Filz-Rauschen als SVG - keine Bilddatei, von der CSP (img-src data:) gedeckt. */
  --felt-noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --spotlight: radial-gradient(ellipse 75% 55% at 50% -4%, rgba(255, 244, 214, 0.16), rgba(255, 244, 214, 0.05) 45%, transparent 72%);
}

/* ================================================================ Karten */

/* Glanz: wandert mit dem Kippen (tilt.js). Ohne Sensor bleibt ein ruhiger
   Glanzstreifen oben links - wie Licht auf lackiertem Karton. */
.fcard:not(.fcard--back)::before,
.card:not(.card--back)::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 4;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(118deg,
    transparent 28%,
    rgba(255, 255, 255, 0.5) 42%,
    rgba(255, 255, 255, 0.08) 50%,
    transparent 58%);
  background-size: 260% 260%;
  background-position:
    calc(18% + var(--tilt-x) * 45%)
    calc(18% + var(--tilt-y) * 45%);
  mix-blend-mode: soft-light;
  opacity: 0.8;
}

/* Frisch ausgeteilt: einmal ein Glanz-Wisch ueber die Karte (auch ohne Sensor). */
.fcard--deal::before,
.card--pop::before {
  animation: sheen-sweep 1.1s ease-out 0.35s backwards;
}
@keyframes sheen-sweep {
  from { background-position: -80% -80%; opacity: 1; }
  to { background-position: calc(18% + var(--tilt-x) * 45%) calc(18% + var(--tilt-y) * 45%); opacity: 0.8; }
}

/* Leicht schraeg abgelegt (Wert je Karte stabil, siehe --lay in den Renderern). */
.fcard, .discard .card { rotate: var(--lay, 0deg); }

/* Bildkarten */
.fcard__court {
  position: absolute;
  inset: calc(var(--card-w) * 0.16) calc(var(--card-w) * 0.2);
  display: grid;
  place-items: center;
}
.fcard__court svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.15)); }
.fcard--court .fcard__rank {
  z-index: 2;
  font-size: calc(var(--card-w) * 0.22);
  /* Kartenweiss hinter dem Index - wie beim echten Blatt liegt er ueber dem Rahmen */
  background: #fdfdfd;
  border-radius: 3px;
  padding: 0 1px 1px;
}
.fcard--court .fcard__rank span { font-size: calc(var(--card-w) * 0.19); }
.fcard--sm .fcard__court { inset: calc(var(--card-w) * 0.2) calc(var(--card-w) * 0.14); }

/* Ass: grosses Zeichen mit Zierrahmen */
.fcard--ace .fcard__pip { font-size: calc(var(--card-w) * 0.78); }
.table--blackjack .fcard--ace .fcard__pip svg { width: calc(var(--card-w) * 0.56); height: calc(var(--card-w) * 0.56); }
.fcard--ace::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: calc(var(--card-w) * 0.74);
  height: calc(var(--card-w) * 0.74);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 1px solid currentColor;
  opacity: 0.18;
  box-shadow: 0 0 0 calc(var(--card-w) * 0.04) rgba(0, 0, 0, 0.02) inset;
}

/* Weichere, zweistufige Schatten - Karten liegen "auf" dem Filz. */
.table .fcard:not(.fcard--back),
.table .card {
  box-shadow:
    0 1px 1px rgba(0, 0, 0, 0.25),
    0 6px 10px -4px rgba(0, 0, 0, 0.45),
    0 18px 28px -16px rgba(0, 0, 0, 0.7),
    inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}

/* Beim Antippen hebt sich die Karte an - fuehlt sich "gegriffen" an. */
.card--playable:active,
.fcard--playable:active {
  transform: translateY(-16px) scale(1.06);
  transition-duration: 0.08s;
  z-index: 5;
}

/* Austeilen aus dem Schlitten: in der ersten Haelfte des Flugs sieht man die
   Rueckseite (Overlay), dann dreht sich die Karte auf. */
.table--blackjack .fcard--from-shoe { animation: none; }
.fcard--from-shoe::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 5;
  border-radius: inherit;
  background:
    repeating-linear-gradient(45deg, #2b3350 0 6px, #232a44 6px 12px);
  box-shadow: inset 0 0 0 4px #1b2138, inset 0 0 0 5px rgba(255, 255, 255, 0.2);
  animation: deal-back 0.58s var(--deal-delay, 0ms) both;
  pointer-events: none;
}
.fcard--from-shoe.fcard--ace::after { width: auto; height: auto; transform: none; left: 0; top: 0; border: 0; opacity: 1; border-radius: inherit; }
@keyframes deal-back {
  0%, 54% { opacity: 1; }
  56%, 100% { opacity: 0; }
}

/* Kartenrueckseite fuers Mischen (fx.js) */
.fx-cardback {
  width: 34px; height: 49px; border-radius: 5px;
  background: repeating-linear-gradient(45deg, #2b3350 0 5px, #232a44 5px 10px);
  box-shadow: inset 0 0 0 3px #1b2138, inset 0 0 0 4px rgba(255, 255, 255, 0.22), 0 4px 10px -3px #000;
}

/* UNO-Ablagestapel: fruehere Karten liegen schraeg darunter */
.discard { position: relative; display: grid; }
.discard > .card { grid-area: 1 / 1; }
.discard > .card:not(:last-child) { filter: brightness(0.82); }
.discard > .card:last-child { box-shadow: 0 2px 2px rgba(0, 0, 0, 0.3), 0 20px 30px -14px rgba(0, 0, 0, 0.85), inset 0 0 0 1px rgba(255, 255, 255, 0.2); }

/* ====================================================== Tisch-Atmosphaere */

.felt,
.table--blackjack .bj-felt {
  background-image:
    var(--felt-noise),
    var(--spotlight),
    radial-gradient(ellipse at 50% 38%, #235550, #16363a 58%, #0f252d);
  background-size: 180px 180px, 100% 100%, 100% 100%;
  box-shadow:
    inset 0 0 0 5px rgba(255, 255, 255, 0.015),
    inset 0 0 120px rgba(0, 0, 0, 0.5),
    inset 0 -40px 60px -30px rgba(0, 0, 0, 0.5),
    0 22px 40px -26px #000;
}
/* Busfahrer bleibt bei seinem eigenen (dunkleren) Ton, bekommt aber Struktur + Licht */
.table[data-game="busfahrer"] .felt {
  background-image: var(--felt-noise), var(--spotlight);
  background-size: 180px 180px, 100% 100%;
}

/* ------------------------------------------------------------- Chip-Stapel */
.chip-stack { display: inline-flex; align-items: flex-end; gap: 6px; }
.chip-stack__piles { display: flex; align-items: flex-end; gap: 2px; }
.chip-stack__col { position: relative; width: 22px; height: calc(8px + 7 * 3px + 12px); }
.chip-stack__disc {
  position: absolute;
  left: 0; bottom: calc(var(--i) * 3px);
  width: 22px; height: 12px;
  border-radius: 50%;
  background:
    radial-gradient(ellipse at 50% 42%, rgba(255, 255, 255, 0.35) 0 22%, transparent 24%),
    repeating-conic-gradient(from 8deg, var(--chip) 0 26deg, rgba(255, 255, 255, 0.85) 26deg 38deg);
  box-shadow:
    0 2px 0 color-mix(in srgb, var(--chip) 65%, #000),
    0 3px 3px rgba(0, 0, 0, 0.45);
}
.chip-stack__value {
  font-size: 0.66rem; font-weight: 800; color: #fde68a;
  padding: 2px 6px; border-radius: 999px; background: #0f2533cc; border: 1px solid #f0b42955;
  font-variant-numeric: tabular-nums;
}
.bj-empty-hand .chip-stack { flex-direction: column; align-items: center; gap: 4px; }

/* ============================================================ Lobby */

/* Schwebende Kartenzeichen im Hero */
.hero-suits { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.hero-suits span {
  position: absolute;
  left: calc(8% + var(--i) * 12%);
  bottom: -40px;
  font-size: calc(22px + (var(--i) * 7px) % 30px);
  color: rgba(var(--brand-rgb), 0.08);
  animation: suit-float calc(13s + var(--i) * 2.3s) linear calc(var(--i) * -3.1s) infinite;
}
.hero-suits span:nth-child(even) { color: rgba(239, 68, 68, 0.08); }
@keyframes suit-float {
  from { transform: translateY(0) rotate(0deg); opacity: 0; }
  10% { opacity: 1; }
  90% { opacity: 1; }
  to { transform: translateY(-420px) rotate(160deg); opacity: 0; }
}
.hub-hero > :not(.hero-suits) { position: relative; }

/* LIVE-Anzeige auf Spielkacheln und laufenden Tischen */
.live-badge {
  position: absolute; top: 16px; right: 56px;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px; border-radius: 999px;
  font-size: 0.66rem; font-weight: 800; letter-spacing: 0.08em;
  color: #fecaca; background: rgba(239, 68, 68, 0.14); border: 1px solid rgba(239, 68, 68, 0.45);
}
.live-badge i, .live-dot {
  width: 7px; height: 7px; border-radius: 50%; background: #ef4444; display: inline-block;
  box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
  animation: live-pulse 1.4s ease-out infinite;
}
.live-dot { margin-right: 4px; background: #f59e0b; }
@keyframes live-pulse { to { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); } }
.game-card__crowd .avatar { animation: crowd-bob 2.4s ease-in-out infinite; }
.game-card__crowd .avatar:nth-child(2) { animation-delay: -0.6s; }
.game-card__crowd .avatar:nth-child(3) { animation-delay: -1.2s; }
.game-card__crowd .avatar:nth-child(4) { animation-delay: -1.8s; }
@keyframes crowd-bob { 50% { transform: translateY(-3px); } }

/* Lobby-Figuren anderer: antippbar */
.lobby-floor__avatar { cursor: pointer; }

/* Tagesbonus-Truhe */
.daily { position: relative; overflow: hidden; border-color: rgba(240, 180, 41, 0.35); background: radial-gradient(ellipse at 10% 50%, rgba(240, 180, 41, 0.14), transparent 60%), var(--surface); }
.chest-btn { background: none; border: 0; padding: 4px; cursor: pointer; flex: none; }
.chest { position: relative; display: block; width: 64px; height: 56px; animation: chest-wiggle 2.8s ease-in-out infinite; transform-origin: 50% 100%; }
.chest__body {
  position: absolute; left: 4px; right: 4px; bottom: 0; height: 30px; border-radius: 4px 4px 7px 7px;
  background: linear-gradient(180deg, #a16207, #713f12);
  box-shadow: inset 0 0 0 3px #f0b429, inset 0 -8px 0 rgba(0, 0, 0, 0.18), 0 6px 12px -6px #000;
}
.chest__lid {
  position: absolute; left: 2px; right: 2px; top: 6px; height: 22px; border-radius: 14px 14px 3px 3px;
  background: linear-gradient(180deg, #ca8a04, #854d0e);
  box-shadow: inset 0 0 0 3px #f0b429;
  transform-origin: 50% 100%;
  transition: transform 0.45s cubic-bezier(.3,1.6,.5,1);
  z-index: 2;
}
.chest__lock { position: absolute; left: 50%; top: 24px; width: 10px; height: 12px; margin-left: -5px; border-radius: 2px; background: #fde68a; box-shadow: 0 0 0 2px #854d0e; z-index: 3; transition: opacity 0.2s; }
.chest__glow { position: absolute; left: 50%; top: 26px; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; background: #fde68a; opacity: 0; box-shadow: 0 0 30px 18px #fbbf24; transition: opacity 0.3s; }
.chest--open { animation: none; }
.chest--open .chest__lid { transform: translateY(-4px) rotateX(0) rotate(-24deg) translateX(-10px); }
.chest--open .chest__lock { opacity: 0; }
.chest--open .chest__glow { opacity: 1; }
@keyframes chest-wiggle {
  0%, 70%, 100% { transform: rotate(0); }
  74% { transform: rotate(-6deg); }
  78% { transform: rotate(5deg); }
  82% { transform: rotate(-3deg); }
  86% { transform: rotate(2deg); }
}

/* Bestenliste: Zeilen antippbar */
.score-row--button { width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer; background: transparent; border: 0; }
.score-row--button:hover { background: rgba(255, 255, 255, 0.04); }

/* ============================================================ Profilkarte */
.pcard {
  position: relative; display: grid; gap: 16px; padding: 18px; border-radius: 22px; overflow: hidden;
  background:
    radial-gradient(ellipse at 0% 0%, color-mix(in srgb, var(--pcard) 32%, transparent), transparent 60%),
    linear-gradient(160deg, #1c2736, #111925);
  border: 1px solid color-mix(in srgb, var(--pcard) 45%, transparent);
  box-shadow: 0 20px 40px -24px #000, inset 0 1px 0 rgba(255, 255, 255, 0.06);
  animation: pcard-in 0.4s cubic-bezier(.2,.8,.2,1);
}
@keyframes pcard-in { from { opacity: 0; transform: translateY(12px) scale(0.98); } }
.pcard__head { display: flex; align-items: center; gap: 14px; }
.pcard__avatar { padding: 3px; border-radius: 19px; background: conic-gradient(from 200deg, var(--pcard), #fde68a, var(--pcard)); box-shadow: 0 0 24px -4px var(--pcard); }
.pcard__avatar .avatar { box-shadow: 0 0 0 3px #111925; }
.pcard__name { font: 700 1.35rem/1.1 var(--font-hero); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard__since { font-size: 0.76rem; color: var(--text-faint); }
.pcard__empty { color: var(--text-dim); font-size: 0.9rem; }
.pcard__tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pcard__tile {
  display: grid; gap: 2px; padding: 12px; border-radius: 14px;
  background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 255, 255, 0.07);
  animation: pcard-in 0.45s cubic-bezier(.2,.8,.2,1) backwards;
}
.pcard__tile:nth-child(2) { animation-delay: 0.05s; }
.pcard__tile:nth-child(3) { animation-delay: 0.1s; }
.pcard__tile:nth-child(4) { animation-delay: 0.15s; }
.pcard__tile-label { font-size: 0.66rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-faint); }
.pcard__tile-value { font: 700 1.15rem/1.2 var(--font-hero); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard__tile-sub { font-size: 0.72rem; color: var(--text-dim); }
.pcard__tile--gold { border-color: rgba(240, 180, 41, 0.45); background: linear-gradient(160deg, rgba(240, 180, 41, 0.14), rgba(240, 180, 41, 0.03)); }
.pcard__tile--gold .pcard__tile-value { color: #fde68a; }
.pcard__tile--hot { border-color: rgba(249, 115, 22, 0.45); background: linear-gradient(160deg, rgba(249, 115, 22, 0.14), transparent); }
.pcard__tile--hot .pcard__tile-value::after { content: " 🔥"; }
.pcard__games { display: grid; gap: 10px; }
.pcard__game { display: grid; gap: 5px; }
.pcard__bar { height: 6px; border-radius: 99px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.pcard__bar i { display: block; height: 100%; width: var(--w); border-radius: inherit; background: linear-gradient(90deg, var(--pcard), var(--brand-2)); animation: bar-grow 0.9s cubic-bezier(.2,.8,.2,1) 0.2s backwards; }
@keyframes bar-grow { from { width: 0; } }
.table [data-player-id] .avatar { cursor: pointer; }

/* ============================================= Uebergaenge zwischen Ansichten */
::view-transition-old(root) { animation: vt-out 0.2s ease-in both; }
::view-transition-new(root) { animation: vt-in 0.32s cubic-bezier(.2,.8,.2,1) both; }
@keyframes vt-out { to { opacity: 0; transform: scale(0.985); } }
@keyframes vt-in { from { opacity: 0; transform: translateY(14px) scale(0.99); } }

/* ============================================ Querformat am Handy */
@media (orientation: landscape) and (max-height: 540px) {
  /* UNO, Busfahrer, Mensch: Tisch links, Hand + Bedienung rechts */
  .table:not(.table--blackjack) {
    display: grid;
    grid-template: "head head" auto "body foot" minmax(0, 1fr) / minmax(0, 1fr) minmax(300px, 42%);
  }
  .table:not(.table--blackjack) > .table__head { grid-area: head; min-height: 0; padding-top: calc(var(--safe-t) + 4px); padding-bottom: 4px; }
  .table:not(.table--blackjack) > .table__body { grid-area: body; padding-bottom: calc(var(--safe-b) + 6px); }
  .table:not(.table--blackjack) > .table__foot {
    grid-area: foot;
    display: flex; flex-direction: column; justify-content: flex-end; gap: 6px;
    overflow-y: auto;
    background: linear-gradient(90deg, transparent, rgba(8, 11, 22, 0.7) 12%);
  }
  .table:not(.table--blackjack) .hand { flex-wrap: nowrap; min-height: 0; padding-top: 22px; }
  .table:not(.table--blackjack) .hand .card { --card-w: 62px; }
  .table:not(.table--blackjack) .card--lg { --card-w: 70px; }

  /* Blackjack: Filz links, Bedienleiste rechts */
  .bj-layout { grid-template-columns: minmax(0, 1fr) 280px; padding: 6px; gap: 6px; }
  .bj-board-wrap { grid-row: auto; }
  .bj-controls { order: 2; border-radius: 14px; min-height: 0; gap: 10px; padding: 12px; }
  .table--blackjack .bj-felt { min-height: calc(100dvh - 90px); border-radius: 14px; padding: 10px 8px; }
  .table--blackjack .dealer { min-height: 110px; }
  .bj-table-mark { margin: 2px 0 4px; }
  .bj-table-mark > span { font-size: 1.1rem; }
  .bj-seat__hands { min-height: 0; }
  .bj-table-mark, .table--blackjack .bj-felt::after { display: none; }
  .table--blackjack .bj-felt { min-height: 0; }
  .table--blackjack .dealer { min-height: 0; gap: 6px; }
  .bj-table-status { min-height: 0; margin: 2px 0; }
  .bj-seat { padding-top: calc(var(--seat-drop) * 0.25); gap: 6px; }
  .bj-seats { padding-bottom: 6px; }
  .bj-seats-scroll { padding-top: 4px; }
  .table--blackjack .bj-shoe { top: 10px; right: 14px; }
  .bj-shoe .fcard { --card-w: 34px; }
  .table--blackjack .hand-block__cards .fcard { --card-w: 48px; }
  .table--blackjack .dealer__cards .fcard { --card-w: 52px; }
  .bj-controls .actions { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .hero-suits span, .live-badge i, .live-dot, .game-card__crowd .avatar, .chest,
  .pcard, .pcard__tile, .pcard__bar i, .fcard--deal::before, .card--pop::before { animation: none; }
  .fcard--from-shoe::after { display: none; }
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
}
