:root {
  color-scheme: dark;
  --paper: #161719;
  --paper-2: #222327;
  --ink: #ebe9e3;
  --ink-2: #a3a099;
  --ink-3: #6c6a65;
  --line: #34363b;
  --card-ink: #1f1f1d;
  --felt: #264738;
  --felt-line: rgba(255, 255, 255, .09);
  --red: #b23a2e;
  --card: #fbfaf7;
  --card-edge: #cfc9bc;
  --back: #273239;
  --back-edge: #1a2227;
  --back-line: #3a4a53;
  --accent: #c8963e;
  --font: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-num: ui-rounded, "SF Pro Rounded", "Segoe UI", Roboto, Arial, sans-serif;
  --card-w: 36px;
  --me-card-w: 62px;
  --board-card-w: 54px;
  --sk: 1;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.4 var(--font);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button, input { font: inherit; color: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

/* Kopfzeile */
.bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  flex: none;
  white-space: nowrap;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: .01em; }
.brand-mark { width: 16px; height: 16px; fill: var(--ink); flex: none; }
.meta { color: var(--ink-2); font-size: 13px; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.bar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.short { display: none; }

.icon-btn {
  width: 34px; height: 34px; padding: 0;
  display: grid; place-items: center;
  border: 1px solid var(--line); background: transparent; border-radius: 6px; cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: var(--ink-2); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg .solid { fill: var(--ink-2); stroke: none; }
.icon-btn:hover svg { stroke: var(--ink); }
.icon-btn:hover svg .solid { fill: var(--ink); }
.icon-btn .off { display: none; }
.icon-btn[aria-pressed="false"] .on { display: none; }
.icon-btn[aria-pressed="false"] .off { display: inline; }

.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; color: var(--ink-2); user-select: none; -webkit-user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.track { width: 30px; height: 18px; border-radius: 9px; background: var(--line); position: relative; transition: background .2s; flex: none; }
.thumb { position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .2s var(--ease); box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .track { background: var(--felt); }
.switch input:checked + .track .thumb { transform: translateX(12px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Buttons */
.btn {
  border: 1px solid var(--ink);
  background: transparent;
  padding: 10px 18px;
  border-radius: 6px;
  cursor: pointer;
  min-width: 110px;
  min-height: 44px;
  font-weight: 500;
  transition: background .15s, color .15s, opacity .15s, transform .1s;
}
.btn:hover:not(:disabled) { background: var(--paper-2); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .35; cursor: default; }
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.primary:hover:not(:disabled) { background: #fff; }
.btn.ghost { border-color: var(--line); }
.btn.small { padding: 6px 12px; min-width: 0; min-height: 34px; font-size: 13px; }
.btn.wide { min-width: 240px; }
.btn:focus-visible, .chip-btn:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Bereich unter der Kopfzeile */
main { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; padding: 10px 16px 14px; gap: 10px; }
.table-wrap { width: 100%; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }

/* Tisch: Größe setzt ui.js passend zum freien Platz */
.table { position: relative; width: 100%; height: 100%; flex: none; }
.felt {
  position: absolute;
  inset: 13% 9%;
  background: var(--felt);
  border-radius: 50%;
  box-shadow: inset 0 0 0 calc(10px * var(--sk)) #1f3b2f, inset 0 0 0 calc(10px * var(--sk) + 1px) var(--felt-line);
}
.table.portrait .felt { inset: 12% 11%; }
.table.portrait .plate { min-width: 80px; padding: 4px 8px 3px; }
.table.portrait .seat:not(.me) { width: 96px; }
.center {
  position: absolute;
  left: 50%; top: 47%;
  transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: calc(10px * var(--sk));
}
.board { display: flex; gap: calc(var(--board-card-w) * .1); height: calc(var(--board-card-w) * 1.4); }
.board .slot {
  width: var(--board-card-w);
  height: calc(var(--board-card-w) * 1.4);
  border-radius: 5px;
  border: 1px dashed rgba(255,255,255,.14);
}
.board .card { --w: var(--board-card-w); }
.pot, .message { font-size: calc(14px * max(var(--sk), .85)); }
.pot { color: #e9e4d6; font-variant-numeric: tabular-nums; letter-spacing: .02em; min-height: 1.4em; }
.pot b { font-weight: 600; color: #fff; }
.message { color: #fff; text-align: center; min-height: 1.4em; max-width: 60vw; }
.message .line { animation: fadeUp .35s var(--ease) both; }
.message .line + .line { animation-delay: .08s; }

/* Karten */
.card {
  --w: var(--card-w);
  width: var(--w);
  height: calc(var(--w) * 1.4);
  perspective: 600px;
  flex: none;
}
.card-inner {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform .5s var(--ease);
  transform: rotateY(180deg);
}
.card.up .card-inner { transform: rotateY(0); }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.face svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 1px 1.5px rgba(0,0,0,.25)); }
.face.back { transform: rotateY(180deg); }
.card.deal { animation: dealIn .42s var(--ease) both; }
.card.dim { opacity: .4; transition: opacity .3s; }
.card.win .face svg { filter: drop-shadow(0 0 3px rgba(200,150,62,.9)); }
.card.win { transform: translateY(-4px); transition: transform .3s var(--ease); }

@keyframes dealIn {
  from { transform: translate(var(--dx, 0), var(--dy, 0)) rotate(-12deg) scale(.7); opacity: 0; }
  20% { opacity: 1; }
  to { transform: none; opacity: 1; }
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(200,150,62,.0); } 50% { box-shadow: 0 0 0 5px rgba(200,150,62,.35); } }

/* Plätze (werden mit dem Tisch skaliert) */
.seat {
  position: absolute;
  transform: translate(-50%, -50%) scale(var(--sk));
  display: flex; flex-direction: column; align-items: center;
  width: 110px;
  transition: opacity .3s;
}
.seat .hand { display: flex; gap: 3px; height: calc(var(--card-w) * 1.4); margin-bottom: -8px; position: relative; z-index: 1; }
.seat.me { width: 170px; }
.seat.me .hand { height: calc(var(--me-card-w) * 1.4); gap: 5px; margin-bottom: -10px; }
.seat.me .card { --w: var(--me-card-w); }
.plate {
  position: relative; z-index: 2;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 12px 4px;
  min-width: 92px;
  text-align: center;
  line-height: 1.2;
  transition: border-color .2s, background .2s;
}
.plate .name { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; }
.plate .stack { display: block; font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.seat.turn .plate { border-color: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.seat.folded .plate, .seat.out .plate { background: var(--paper-2); border-color: var(--paper-2); color: var(--ink-3); }
.seat.folded .plate .stack, .seat.out .plate .stack { color: var(--ink-3); }
.seat.folded .tag, .seat.out .tag { color: var(--ink-3); }
.seat.me.folded .hand { opacity: .5; }
.seat.winner .plate { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.seat.winner .plate .stack { color: #55534d; }
.tag {
  margin-top: 4px;
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ink-2);
  background: var(--paper-2);
  border-radius: 4px;
  padding: 1px 6px;
  min-height: 17px;
  white-space: nowrap;
}
.tag:empty { visibility: hidden; }
.tag.fresh { animation: fadeUp .3s var(--ease) both; }
.tag.hand-name { background: var(--accent); color: #fff; }
.badge { position: absolute; top: -6px; right: 6px; z-index: 3; width: 20px; height: 20px; }
.seat.me .badge { right: 22px; }
.badge svg { width: 100%; height: 100%; display: block; }

.bet {
  position: absolute;
  transform: translate(-50%, -50%) scale(max(var(--sk), .8));
  display: flex; align-items: center; gap: 4px;
  color: #f4efe3; font-size: 12px; font-variant-numeric: tabular-nums;
  pointer-events: none;
  transition: opacity .2s;
}
.bet svg { width: 16px; height: 16px; display: block; }
.bet.empty { opacity: 0; }

#fx { position: absolute; inset: 0; pointer-events: none; }
.fly { position: absolute; width: 16px; height: 16px; transform: translate(-50%, -50%); }
.fly svg { width: 100%; height: 100%; display: block; }

/* Bedienung */
.controls {
  width: 100%; max-width: 640px; flex: none;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  min-height: 122px;
}
.status { font-size: 13px; color: var(--ink-2); min-height: 18px; text-align: center; }
.action-row { display: flex; gap: 10px; justify-content: center; }
.raise-row { display: flex; align-items: center; gap: 10px; width: 100%; }
.presets { display: flex; gap: 4px; }
.chip-btn {
  border: 1px solid var(--line); background: transparent; border-radius: 14px;
  padding: 4px 10px; font-size: 12px; cursor: pointer; color: var(--ink-2); min-height: 30px;
}
.chip-btn:hover:not(:disabled) { border-color: var(--ink-3); color: var(--ink); }
.chip-btn:disabled { opacity: .35; cursor: default; }
#raiseSlider { flex: 1; accent-color: var(--ink); min-width: 80px; height: 30px; }
#raiseInput {
  width: 76px; padding: 5px 6px; border: 1px solid var(--line); border-radius: 6px; min-height: 32px;
  background: transparent; font-variant-numeric: tabular-nums; text-align: right;
}

/* Overlays */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, .6);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  animation: fadeIn .2s ease both;
}
.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 26px 28px 22px;
  width: 100%; max-width: 440px;
  max-height: 100%; overflow: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
  animation: fadeUp .3s var(--ease) both;
}
.panel h1 { margin: 0 0 4px; font-size: 22px; font-weight: 600; letter-spacing: -.01em; }
.panel .sub { margin: 0 0 22px; color: var(--ink-2); font-size: 14px; }
.field { margin-bottom: 24px; }
.field-label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 8px; }
.stepper { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.stepper button {
  border: 1px solid var(--line); background: transparent; border-radius: 6px;
  min-height: 40px; cursor: pointer; font-variant-numeric: tabular-nums;
}
.stepper button[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.panel-actions { display: flex; justify-content: flex-end; gap: 10px; }
.panel-actions .btn { min-width: 0; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Handy hochkant */
@media (max-width: 600px) {
  .bar { padding: 8px 12px; gap: 10px; }
  .brand-text, .meta .players { display: none; }
  .long { display: none; }
  .short { display: inline; }
  .bar-right { gap: 8px; }
  main { padding: 6px 12px 10px; gap: 6px; }
  .controls { gap: 8px; min-height: 0; }
  .btn { min-width: 0; flex: 1; padding: 10px 6px; }
  .btn.small { flex: none; }
  .action-row { width: 100%; gap: 8px; }
  .btn.wide { min-width: 0; }
  .raise-row { flex-wrap: wrap; gap: 8px; }
  .presets { width: 100%; }
  .chip-btn { flex: 1; }
  .stepper { grid-template-columns: repeat(5, 1fr); }
  .panel { padding: 22px 20px 18px; }
}
@media (max-width: 360px) {
  .meta { display: none; }
}

/* Handy quer: Bedienung rechts neben dem Tisch */
@media (orientation: landscape) and (max-height: 560px) {
  .bar { padding: 6px 14px; }
  .btn.small, .icon-btn { min-height: 30px; height: 30px; }
  .icon-btn { width: 30px; }
  main { flex-direction: row; align-items: stretch; padding: 6px 12px 8px; gap: 12px; }
  .table-wrap { width: auto; min-width: 0; }
  .controls { width: 220px; max-width: none; justify-content: center; gap: 8px; min-height: 0; }
  .action-row { flex-direction: column; width: 100%; gap: 6px; }
  .btn { min-width: 0; width: 100%; min-height: 38px; padding: 7px 10px; }
  .btn.wide { min-width: 0; }
  .raise-row { flex-wrap: wrap; gap: 6px; }
  .presets { display: grid; grid-template-columns: 1fr 1fr; width: 100%; gap: 4px; }
  #raiseSlider { flex: 1 1 100px; }
  #raiseInput { width: 64px; }
  .status { font-size: 12px; }
  .panel { padding: 16px 20px; }
  .panel .sub, .field { margin-bottom: 14px; }
}

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