:root {
  --felt: #0f4a38;
  --felt-deep: #0a3226;
  --ink: #f2efe6;
  --muted: rgba(242, 239, 230, 0.72);
  --gold: #e0b35a;
  --danger: #e85d4c;
  --red: #c62828;
  --black: #1a1a1a;
  --card: #f7f4ec;
  --shadow: rgba(0, 0, 0, 0.35);
  --font-display: "Songti SC", "STSong", "Noto Serif SC", "Georgia", serif;
  --font-body: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(224, 179, 90, 0.22), transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 80%, rgba(20, 90, 70, 0.5), transparent 50%),
    linear-gradient(165deg, #145c45 0%, var(--felt-deep) 55%, #062018 100%);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#app {
  min-height: 100%;
  min-height: 100dvh;
}

.screen {
  min-height: 100dvh;
  padding:
    max(0.75rem, env(safe-area-inset-top))
    max(0.75rem, env(safe-area-inset-right))
    max(0.75rem, env(safe-area-inset-bottom))
    max(0.75rem, env(safe-area-inset-left));
}

.brand {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 10vw, 3.4rem);
  letter-spacing: 0.08em;
  color: var(--gold);
  text-shadow: 0 8px 28px var(--shadow);
}

.brand-sm { font-size: 1.35rem; letter-spacing: 0.12em; }

.headline {
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 5vw, 1.75rem);
  font-weight: 400;
  margin: 0.5rem 0 0.4rem;
  line-height: 1.35;
}

.lede { color: var(--muted); line-height: 1.55; font-size: 0.95rem; }

.join-panel, .over-panel {
  width: min(420px, 100%);
  margin: 12vh auto 0;
  animation: rise 0.45s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

.stack { display: grid; gap: 0.85rem; margin-top: 1.4rem; }
.stack label { display: grid; gap: 0.35rem; font-size: 0.85rem; color: var(--muted); }
.stack input {
  border: 1px solid rgba(242, 239, 230, 0.22);
  background: rgba(6, 32, 24, 0.55);
  color: var(--ink);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  font-size: 1.05rem;
}
.stack input:focus {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 10px;
  padding: 0.8rem 1.15rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.12s ease, filter 0.12s ease, background 0.12s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-primary {
  background: linear-gradient(180deg, #f0c56e, var(--gold));
  color: #2a1a05;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28);
}
.btn-ghost {
  background: rgba(242, 239, 230, 0.1);
  color: var(--ink);
  border: 1px solid rgba(242, 239, 230, 0.18);
}
.btn-sm { padding: 0.4rem 0.7rem; font-size: 0.85rem; }

.error { color: #ffb4a8; font-size: 0.9rem; margin-top: 0.5rem; }
.hint { color: var(--muted); font-size: 0.85rem; margin-top: 0.8rem; line-height: 1.45; }

.topbar, .table-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.room-tag { color: var(--muted); font-size: 0.9rem; }
.level-line { color: var(--muted); margin-bottom: 1rem; }

.seat-list {
  list-style: none;
  display: grid;
  gap: 0.55rem;
}
.seat-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: rgba(6, 32, 24, 0.45);
  border: 1px solid rgba(242, 239, 230, 0.1);
}
.seat-list .tag {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: rgba(224, 179, 90, 0.2);
  color: var(--gold);
}
.seat-list .tag.is-away { background: rgba(232, 93, 76, 0.2); color: #ffb4a8; }
.seat-list .tag.is-ready { background: rgba(80, 200, 140, 0.25); color: #9af0c4; }

.cta-row { display: flex; gap: 0.65rem; margin-top: 1.2rem; flex-wrap: wrap; }

.scoreboard {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 700;
  font-size: 0.95rem;
}
.team-a { color: #9ad7ff; }
.team-b { color: #ffc48a; }
.vs { color: var(--muted); font-size: 0.8rem; }

.table-meta {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
  font-size: 0.78rem;
}
.table-meta span {
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.25);
}
.turn-timer { color: var(--gold); font-variant-numeric: tabular-nums; }

#screen-table {
  display: none;
  flex-direction: column;
  height: 100dvh;
  padding-bottom: 0;
}
#screen-table.is-active { display: flex; }

.table-felt {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: 0 -0.25rem;
  border-radius: 18px;
  background:
    radial-gradient(ellipse 70% 60% at 50% 45%, #1a6b52 0%, var(--felt) 55%, #0c3d2e 100%);
  box-shadow: inset 0 0 0 2px rgba(224, 179, 90, 0.18), 0 16px 40px var(--shadow);
  overflow: hidden;
}

.seat {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  max-width: 42%;
}
.seat-top { top: 0.55rem; left: 50%; transform: translateX(-50%); }
.seat-left { left: 0.45rem; top: 38%; }
.seat-right { right: 0.45rem; top: 38%; align-items: flex-end; }
.seat-name {
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  white-space: nowrap;
  max-width: 9rem;
  overflow: hidden;
  text-overflow: ellipsis;
}
.seat.is-turn .seat-name {
  outline: 2px solid var(--gold);
  animation: pulse 1.1s ease infinite;
}
.seat.is-finished .seat-name { opacity: 0.55; }
@keyframes pulse {
  50% { box-shadow: 0 0 0 4px rgba(224, 179, 90, 0.25); }
}
.seat-count {
  font-size: 0.72rem;
  color: var(--muted);
}
.seat-play {
  display: flex;
  gap: 0.15rem;
  flex-wrap: wrap;
  justify-content: center;
  min-height: 2.2rem;
}

.center-pile {
  position: absolute;
  left: 50%;
  top: 48%;
  transform: translate(-50%, -50%);
  text-align: center;
  min-width: 8rem;
}
.center-kind {
  font-size: 0.8rem;
  color: var(--gold);
  margin-bottom: 0.35rem;
  min-height: 1.1em;
}
.center-cards {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.2rem;
  max-width: min(90vw, 360px);
}
.center-cards .card.is-bomb {
  animation: bombshake 0.35s ease;
}
@keyframes bombshake {
  0%, 100% { transform: translateY(0); }
  25% { transform: translateY(-6px) rotate(-3deg); }
  75% { transform: translateY(-2px) rotate(3deg); }
}

.tribute-banner, .settle-banner {
  position: absolute;
  left: 50%;
  top: 18%;
  transform: translateX(-50%);
  z-index: 3;
  padding: 0.65rem 1rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.62);
  color: var(--gold);
  font-size: 0.9rem;
  text-align: center;
  max-width: 90%;
  line-height: 1.4;
  animation: rise 0.3s ease both;
}

.hand-dock {
  flex-shrink: 0;
  padding: 0.45rem 0 max(0.5rem, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.35));
}
.hand-dock.is-my-turn {
  animation: dockPulse 1.4s ease infinite;
}
@keyframes dockPulse {
  50% { filter: brightness(1.08); }
}
.hand-scroll {
  overflow-x: auto;
  overflow-y: visible;
  padding: 1.1rem 0.25rem 0.35rem;
  -webkit-overflow-scrolling: touch;
}
.hand {
  display: flex;
  justify-content: center;
  min-width: min-content;
  padding: 0 0.5rem;
}

.card {
  --w: clamp(42px, 11vw, 58px);
  width: var(--w);
  height: calc(var(--w) * 1.4);
  border-radius: 7px;
  background: var(--card);
  color: var(--black);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.28);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  padding: 0.28rem 0.32rem;
  font-weight: 700;
  font-size: calc(var(--w) * 0.28);
  line-height: 1;
  user-select: none;
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
  margin-left: calc(var(--w) * -0.38);
  position: relative;
  border: 1px solid rgba(0, 0, 0, 0.08);
}
.hand .card:first-child { margin-left: 0; }
.card .suit { font-size: 1.15em; align-self: center; }
.card.is-red { color: var(--red); }
.card.is-wild {
  box-shadow: 0 0 0 2px var(--gold), 0 4px 10px rgba(0, 0, 0, 0.28);
}
.card.is-joker { color: #6a1b9a; }
.card.is-selected {
  transform: translateY(-16px);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.35);
  z-index: 2;
}
.card.is-mini {
  --w: 34px;
  cursor: default;
  margin-left: -10px;
  font-size: 0.65rem;
  pointer-events: none;
}
.card.is-mini:first-child { margin-left: 0; }
.center-cards .card {
  margin-left: -12px;
  cursor: default;
  animation: dealIn 0.22s ease both;
}
.center-cards .card:first-child { margin-left: 0; }
@keyframes dealIn {
  from { opacity: 0; transform: translateY(18px) scale(0.92); }
  to { opacity: 1; transform: none; }
}

.actions {
  display: flex;
  justify-content: center;
  gap: 0.55rem;
  padding: 0.35rem 0.5rem 0;
}
.action-error {
  text-align: center;
  color: #ffb4a8;
  font-size: 0.85rem;
  margin-top: 0.35rem;
}

.disconnect {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: #8a2e22;
  color: #fff;
  text-align: center;
  padding: 0.45rem;
  font-size: 0.85rem;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 22%;
  transform: translateX(-50%);
  z-index: 40;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  padding: 0.55rem 0.9rem;
  border-radius: 8px;
  font-size: 0.9rem;
  animation: rise 0.2s ease both;
}

@media (max-width: 420px) {
  .card { --w: 40px; }
  .seat-left .seat-play, .seat-right .seat-play { max-width: 5.5rem; }
}
