:root {
  --felt: #14532d;
  --felt-dark: #0b3b1e;
  --gold: #d4af37;
  --paper: #f7f1e3;
  --ink: #1a1a1a;
  --red: #c41e3a;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html {
  touch-action: manipulation;
}
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  background:
    radial-gradient(1200px 600px at 50% -10%, #1d7a42 0%, transparent 55%),
    repeating-linear-gradient(90deg, rgba(255,255,255,.03) 0 2px, transparent 2px 7px),
    var(--felt);
  color: var(--paper);
  -webkit-tap-highlight-color: transparent;
}

#app { min-height: 100dvh; padding: calc(12px + var(--safe-t)) 12px calc(16px + var(--safe-b)); }

h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; letter-spacing: .02em; margin: 0 0 .4em; }
p { margin: 0 0 .8em; line-height: 1.4; }

.screen { max-width: 760px; margin: 0 auto; }

.brand {
  text-align: center;
  margin-bottom: 1.2rem;
}
.brand h1 { font-size: clamp(1.8rem, 6vw, 2.6rem); }
.brand .sub { opacity: .85; font-size: .95rem; }

.panel {
  background: rgba(8, 28, 16, .55);
  border: 1px solid rgba(212, 175, 55, .35);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 12px 40px rgba(0,0,0,.28);
  backdrop-filter: blur(8px);
}

label { display: block; font-size: .85rem; opacity: .9; margin: 10px 0 6px; }
input, select {
  width: 100%;
  font: inherit;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(0,0,0,.25);
  color: white;
}
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }

button, .btn {
  font: inherit;
  font-weight: 700;
  border: 0;
  border-radius: 14px;
  padding: 14px 16px;
  background: var(--gold);
  color: #1a1204;
  cursor: pointer;
  min-height: 48px;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
button.ghost {
  background: transparent;
  color: var(--paper);
  border: 1px solid rgba(247,241,227,.35);
}
button.danger { background: #8b1e1e; color: #fff; }
button:disabled { opacity: .45; cursor: not-allowed; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.choices.four { grid-template-columns: 1fr 1fr; }
.choices button { font-size: 1.15rem; }

.suit-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.suit-btn.red { color: var(--red); background: #fff; }
.suit-btn.black { color: #111; background: #fff; }

.error { color: #ffb4b4; min-height: 1.2em; margin-top: 8px; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.code-pill {
  background: #0b3b1e;
  border: 1px dashed var(--gold);
  padding: 6px 10px;
  border-radius: 999px;
  letter-spacing: .18em;
  font-weight: 800;
}

.players-layout { margin: 12px 0; display: flex; flex-direction: column; gap: 12px; }
.my-seat, .other-seat {
  background: rgba(0,0,0,.22);
  border-radius: 14px;
  padding: 10px;
  border: 1px solid transparent;
}
.my-seat.turn, .other-seat.turn { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(212,175,55,.35); }
.my-seat.offline, .other-seat.offline { opacity: .55; }
.my-hand {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-top: 8px;
  max-width: 440px;
}
.playing-card.fluid {
  width: 100%;
  height: auto;
  aspect-ratio: 2 / 3;
}
.others-title {
  font-size: .85rem;
  font-weight: 700;
  margin: 0 0 8px;
  opacity: .85;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.other-toggle {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
  background: transparent;
  color: inherit;
  border: 0;
  padding: 4px 2px;
  min-height: 48px;
  font-weight: 600;
  border-radius: 10px;
}
.other-name { font-weight: 800; }
.other-meta { font-size: .78rem; opacity: .85; font-weight: 500; }
.other-action { font-size: .8rem; color: var(--gold); margin-top: 2px; }
.other-hand { justify-content: flex-start; flex-wrap: wrap; }

.players {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin: 12px 0;
}
.seat {
  background: rgba(0,0,0,.22);
  border-radius: 14px;
  padding: 10px;
  border: 1px solid transparent;
}
.seat.turn { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(212,175,55,.35); }
.seat.offline { opacity: .55; }
.seat-name { font-weight: 800; display: flex; justify-content: space-between; }
.hand { display: flex; gap: 4px; margin-top: 8px; justify-content: center; min-height: 72px; }
.stats { font-size: .78rem; opacity: .85; margin-top: 6px; }

.playing-card {
  position: relative;
  width: 118px;
  height: auto;
  aspect-ratio: 2 / 3;
  border-radius: 10px;
  background: #fff;
  color: #111;
  box-shadow: 0 10px 20px rgba(0,0,0,.32);
  overflow: hidden;
  flex: 0 0 auto;
}
.playing-card.small { width: 48px; height: auto; aspect-ratio: 2 / 3; border-radius: 5px; }
.playing-card.red { color: var(--red); }
.playing-card.black { color: #161616; }
.playing-card .corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-weight: 800;
  line-height: 1;
  z-index: 2;
}
.playing-card .corner.tl { top: 6px; left: 6px; }
.playing-card .corner.br { bottom: 6px; right: 6px; transform: rotate(180deg); }
.playing-card .idx { font-family: Georgia, serif; font-size: 1.05rem; }
.playing-card.small .idx { font-size: .55rem; }
.playing-card .s { font-size: .9rem; }
.playing-card.small .s { font-size: .5rem; }
.playing-card.small .corner.tl { top: 2px; left: 3px; }
.playing-card.small .corner.br { bottom: 2px; right: 3px; }
.pip-field, .ace-suit, .court { position: absolute; inset: 18px 16px; }
.playing-card.small .pip-field, .playing-card.small .ace-suit, .playing-card.small .court { display: none; }
.pip {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 1.35rem;
}
.pip.flip { transform: translate(-50%, -50%) rotate(180deg); }
.ace-suit {
  display: grid;
  place-items: center;
  font-size: 4.4rem;
}
.court svg { width: 100%; height: 100%; }
.court-suit { position: absolute; font-size: 1.1rem; }
.court-suit.top { top: 4px; right: 6px; }
.court-suit.bot { bottom: 4px; left: 6px; transform: rotate(180deg); }
.court-letter { display: none; }
.card-sheen {
  pointer-events: none;
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent 40%, rgba(255,255,255,.28) 48%, transparent 56%);
}

.playing-card.photo {
  background: #fff;
  padding: 0;
  box-shadow: 0 10px 20px rgba(0,0,0,.35);
}
.playing-card.photo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
  background: #fff;
}

.drink-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(80, 0, 12, .82);
  animation: drinkPulse 1.1s ease-in-out infinite alternate;
}
@keyframes drinkPulse {
  from { background: rgba(90, 0, 10, .88); }
  to { background: rgba(140, 8, 18, .92); }
}
.drink-modal {
  width: min(420px, 100%);
  text-align: center;
  background: #1a0508;
  border: 3px solid #ffcc33;
  border-radius: 22px;
  padding: 22px 18px 18px;
  box-shadow: 0 0 40px rgba(255, 60, 60, .45);
}
.drink-kicker {
  text-transform: uppercase;
  letter-spacing: .18em;
  font-weight: 800;
  color: #ffd36a;
  margin: 0 0 4px;
}
.drink-count {
  font-size: clamp(4rem, 22vw, 7rem);
  font-weight: 900;
  line-height: .9;
  margin: 0;
  color: #fff;
  text-shadow: 0 6px 0 #7a0000;
}
.drink-unit {
  font-size: 1.4rem;
  font-weight: 800;
  margin: 6px 0 10px;
}
.drink-reason { opacity: .9; }
.drink-modal .flip, .drink-modal .playing-card { margin: 8px auto 16px; width: min(140px, 42vw); height: auto; aspect-ratio: 2 / 3; }
.drink-modal button { width: 100%; font-size: 1.25rem; min-height: 56px; }

.back-pattern {
  position: absolute;
  inset: 10px;
  border-radius: 4px;
  background:
    repeating-linear-gradient(45deg, #8a1a3c 0 6px, #6b1230 6px 12px),
    repeating-linear-gradient(-45deg, #9c2348 0 6px, #6b1230 6px 12px);
  opacity: .9;
}

.flip {
  width: 160px;
  aspect-ratio: 2 / 3;
  perspective: 1000px;
  margin: 0 auto;
}
.flip.fluid, .reveal .flip {
  width: min(160px, 46vw);
}
.flip-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform .7s cubic-bezier(.2, .7, .2, 1);
}
.flip.is-flipped .flip-inner { transform: rotateY(180deg); }
.flip-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.flip-face .playing-card {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
}
.flip-front { transform: rotateY(180deg); }

.reveal {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
}
.reveal .playing-card { width: min(160px, 46vw); height: auto; aspect-ratio: 2 / 3; }

.status {
  text-align: center;
  font-size: 1.05rem;
  margin: 8px 0 4px;
}

.log {
  max-height: 140px;
  overflow: auto;
  font-size: .82rem;
  opacity: .88;
  border-top: 1px solid rgba(255,255,255,.12);
  margin-top: 12px;
  padding-top: 8px;
}
.log div { padding: 2px 0; }

.assign-screen {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 24px - var(--safe-t) - var(--safe-b));
}
.assign-flow {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: rgba(8, 28, 16, .55);
  border: 1px solid rgba(212, 175, 55, .35);
  border-radius: 18px;
  padding: 14px;
  min-height: 0;
}
.assign-head {
  display: flex;
  align-items: center;
  gap: 12px;
}
.assign-head h2 { margin: 0; font-size: 1.2rem; }
.assign-left { margin: 0; font-size: 1.05rem; }
.assign-list { display: flex; flex-direction: column; gap: 8px; flex: 1; }
.assign-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0,0,0,.2);
  border-radius: 12px;
  padding: 12px 10px;
  min-height: 56px;
  font-size: 1.05rem;
}
.stepper { display: flex; align-items: center; gap: 8px; touch-action: manipulation; }
.stepper button { min-height: 48px; min-width: 48px; padding: 0; border-radius: 10px; touch-action: manipulation; }
.assign-submit { width: 100%; margin-top: auto; position: sticky; bottom: 0; }

.rules details { margin-top: 12px; }
.rules summary { cursor: pointer; color: var(--gold); }

.finale-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 0 12px;
}

@media (min-width: 720px) {
  .playing-card { width: 132px; height: auto; }
  .seat .playing-card.small { width: 54px; height: auto; }
}
