:root {
  --bg: #140a22;
  --panel: rgba(22, 10, 36, 0.76);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f8f4ff;
  --muted: #d6c8ee;
  --gold: #ffcf68;
  --gold-deep: #ff9f3c;
  --green: #1dd095;
  --green-deep: #0d715e;
  --pink: #ff6f94;
  --shadow: 0 24px 60px rgba(2, 0, 10, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(186, 89, 255, 0.22), transparent 30%),
    radial-gradient(circle at bottom, rgba(255, 153, 67, 0.18), transparent 24%),
    linear-gradient(180deg, #16071c 0%, #0d1327 50%, #150924 100%);
  overflow-x: hidden;
}

#table-bg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0.72;
  z-index: 0;
}

#app {
  position: relative;
  z-index: 1;
}

/* ── Layout: stacked vertically ── */
.screen {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Top Bar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 8px 16px;
  background: linear-gradient(180deg, rgba(40, 14, 56, 0.9), rgba(17, 15, 40, 0.85));
  border-bottom: 1px solid var(--line);
}

.brand-title {
  margin: 0;
  font-family: "Cinzel", serif;
  font-size: 1.3rem;
}

.brand-copy, .rule-note, .seat-note, .meta-text {
  margin: 4px 0 0;
  color: var(--muted);
  line-height: 1.4;
  font-size: 0.82rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.chip-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.82rem;
}

.chip-label input[type="number"] {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  color: var(--text);
  padding: 3px 5px;
  font: inherit;
  font-size: 0.82rem;
}

.setting-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.action-btn {
  padding: 8px 16px;
  border-radius: 999px;
  border: 0;
  outline: 0;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--text);
  cursor: pointer;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.action-btn.primary {
  color: #271203;
  background: linear-gradient(135deg, var(--gold), var(--gold-deep));
}

.action-btn.success {
  color: #04231c;
  background: linear-gradient(135deg, #7dffbc, #27cf8b);
}

.action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ── Table Area: fixed height, holds oval + seats + center ── */
.table-area {
  position: relative;
  width: 100%;
  height: 420px;
  flex-shrink: 0;
}

.oval-table {
  position: absolute;
  top: 30px;
  left: 50%;
  transform: translateX(-50%);
  width: min(700px, 88vw);
  height: 320px;
  border-radius: 999px;
  background:
    radial-gradient(circle at 50% 44%, rgba(63, 255, 190, 0.2), transparent 30%),
    linear-gradient(180deg, #1a8a82 0%, #17706a 55%, #135a56 100%);
  border: 14px solid #7c2a34;
  box-shadow:
    inset 0 0 0 5px rgba(255, 215, 143, 0.45),
    inset 0 0 70px rgba(4, 48, 48, 0.5),
    0 24px 60px rgba(0, 0, 0, 0.36);
}

.oval-table::after {
  content: "";
  position: absolute;
  inset: 14%;
  border-radius: 999px;
  border: 3px solid rgba(116, 255, 214, 0.14);
}

/* ── Seats around table ── */
.seat {
  position: absolute;
  width: 130px;
  transform: translate(-50%, -50%);
  text-align: center;
  z-index: 2;
}

.seat-card {
  padding: 6px 8px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(8, 26, 40, 0.92), rgba(19, 18, 48, 0.8));
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.3);
}

.seat.active .seat-card {
  box-shadow:
    0 0 0 2px rgba(255, 207, 104, 0.4),
    0 12px 28px rgba(0, 0, 0, 0.3);
}

.avatar {
  width: 42px;
  height: 42px;
  margin: 0 auto 4px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.9rem;
  color: #23140a;
  background: linear-gradient(135deg, #ffe49d, #ff9e5e);
  border: 2px solid rgba(255, 255, 255, 0.8);
}

.seat-name {
  font-size: 0.8rem;
  font-weight: 800;
}

.seat-pts {
  color: var(--gold);
  font-size: 0.75rem;
  font-weight: 700;
}

.mini-fan {
  position: relative;
  width: 72px;
  height: 38px;
  margin: 6px auto 0;
}

.mini-card {
  position: absolute;
  top: 0;
  left: 50%;
  width: 26px;
  height: 36px;
  border-radius: 6px;
  transform-origin: bottom center;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.28);
  font-size: 0.65rem;
}

.mini-card.back {
  background: linear-gradient(135deg, #ffcc73, #e35a6d 50%, #2b356f);
  border: 2px solid rgba(255, 255, 255, 0.75);
}

.mini-card.face {
  background: #f8f6fb;
  color: #0e1220;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.mini-card.face.red { color: #cb3158; }

.mini-card.joker {
  background: linear-gradient(135deg, #ffe88a, #ff6fc8) !important;
  color: #2d1050 !important;
}

.seat-timer {
  font-size: 0.65rem;
  color: var(--gold);
  font-weight: 700;
  animation: timer-pulse 0.8s ease-in-out infinite;
}

.seat-note {
  font-size: 0.7rem;
  margin: 2px 0 0;
  min-height: 16px;
  color: var(--muted);
}

/* ── Center Zone (deck + discard inside table) ── */
.center-zone {
  position: absolute;
  left: 50%;
  top: 52%;
  transform: translate(-50%, -50%);
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.2);
}

.center-status {
  margin: 0;
  padding: 6px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.9);
  color: #182234;
  font-weight: 700;
  font-size: 0.8rem;
  white-space: nowrap;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pile-row {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: center;
}

.pile-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.pile-label {
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.72rem;
  font-weight: 700;
}

.pile {
  position: relative;
  width: 60px;
  height: 84px;
  border-radius: 12px;
  cursor: pointer;
}

.pile.disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.stack-card {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, #ffce70, #ff707d 50%, #2b4476);
  border: 2px solid rgba(255, 255, 255, 0.72);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.28);
}

.stack-card:nth-child(2) {
  transform: translate(4px, -4px);
  opacity: 0.8;
}

.stack-card:nth-child(3) {
  transform: translate(8px, -8px);
  opacity: 0.6;
}

.deck-count {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #ffe28a, #ff9d4b);
  color: #351a00;
  font-weight: 800;
  font-size: 0.7rem;
}

.turn-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.turn-pill {
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.4);
  color: var(--gold);
  font-size: 0.75rem;
  font-weight: 800;
}

.table-timer {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 1rem;
  color: #fff;
  background: rgba(29, 208, 149, 0.3);
  border: 2px solid var(--green);
  animation: none;
}

.table-timer.timer-warn {
  background: rgba(255, 111, 148, 0.3);
  border-color: var(--pink);
  color: var(--pink);
  animation: timer-pulse 0.5s ease-in-out infinite;
}

/* Full card (in discard pile center + hand) */
.full-card {
  position: relative;
  width: 60px;
  height: 84px;
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(241, 241, 248, 0.96));
  color: #141a2c;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.28);
}

.full-card.red { color: #c63357; }

.full-card .corner {
  position: absolute;
  display: grid;
  gap: 1px;
  line-height: 1;
  font-weight: 800;
  font-size: 0.65rem;
}

.full-card .corner.top { top: 4px; left: 4px; }
.full-card .corner.bottom { right: 4px; bottom: 4px; transform: rotate(180deg); }

.full-card .center {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  font-weight: 800;
}

/* ── Joker Card ── */
.full-card.joker-card {
  background: linear-gradient(135deg, #ffe88a 0%, #ff6fc8 50%, #8b5cf6 100%);
  color: #2d1050;
}

.full-card.joker-card .center {
  font-size: 1.8rem;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* ── Money Card Badge ── */
.money-badge {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ffe28a, #ff9d4b);
  color: #351a00;
  font-weight: 800;
  font-size: 0.55rem;
  display: grid;
  place-items: center;
}

.empty-pile {
  width: 60px;
  height: 84px;
  border-radius: 12px;
  border: 2px dashed rgba(255, 255, 255, 0.25);
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.65rem;
}

/* ── Info bar between table and hand ── */
.info-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 6px 16px;
  background: linear-gradient(180deg, rgba(34, 16, 52, 0.8), rgba(8, 13, 31, 0.85));
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-size: 0.8rem;
}

.info-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
}

.info-chip strong {
  color: var(--gold);
}

.info-chip .green { color: var(--green); }

.status-chip {
  flex: 1;
  min-width: 0;
}

.status-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Timer ── */
.timer-chip {
  background: rgba(29, 208, 149, 0.15);
  border: 1px solid rgba(29, 208, 149, 0.3);
  min-width: 44px;
  justify-content: center;
}

.timer-chip strong {
  color: var(--green) !important;
  font-size: 0.95rem;
}

.timer-chip.timer-warn {
  background: rgba(255, 111, 148, 0.2);
  border-color: rgba(255, 111, 148, 0.4);
  animation: timer-pulse 0.6s ease-in-out infinite;
}

.timer-chip.timer-warn strong {
  color: var(--pink) !important;
}

@keyframes timer-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

/* ── Arrange Button ── */
.arrange-active {
  background: rgba(29, 208, 149, 0.2) !important;
  border: 1px solid rgba(29, 208, 149, 0.3);
  color: var(--green) !important;
}

/* ── Meld Group Colors ── */
.hand-card.meld-a { box-shadow: 0 -3px 0 0 #1dd095, 0 8px 16px rgba(0,0,0,0.2); }
.hand-card.meld-b { box-shadow: 0 -3px 0 0 #ffcf68, 0 8px 16px rgba(0,0,0,0.2); }
.hand-card.meld-c { box-shadow: 0 -3px 0 0 #ff6f94, 0 8px 16px rgba(0,0,0,0.2); }
.hand-card.meld-d { box-shadow: 0 -3px 0 0 #8b5cf6, 0 8px 16px rgba(0,0,0,0.2); }
.hand-card.meld-e { box-shadow: 0 -3px 0 0 #38bdf8, 0 8px 16px rgba(0,0,0,0.2); }

.hand-card.meld-a.money-card { box-shadow: 0 -3px 0 0 #1dd095, 0 0 0 2px var(--gold), 0 8px 16px rgba(0,0,0,0.2); }
.hand-card.meld-b.money-card { box-shadow: 0 -3px 0 0 #ffcf68, 0 0 0 2px var(--gold), 0 8px 16px rgba(0,0,0,0.2); }
.hand-card.meld-c.money-card { box-shadow: 0 -3px 0 0 #ff6f94, 0 0 0 2px var(--gold), 0 8px 16px rgba(0,0,0,0.2); }
.hand-card.meld-d.money-card { box-shadow: 0 -3px 0 0 #8b5cf6, 0 0 0 2px var(--gold), 0 8px 16px rgba(0,0,0,0.2); }
.hand-card.meld-e.money-card { box-shadow: 0 -3px 0 0 #38bdf8, 0 0 0 2px var(--gold), 0 8px 16px rgba(0,0,0,0.2); }

/* ── Player Hand Area (bottom) ── */
.hand-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 8px 12px 12px;
  background: linear-gradient(180deg, rgba(20, 10, 34, 0.9), rgba(10, 8, 24, 0.95));
  min-height: 220px;
}

.hand-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.hand-top h2 {
  margin: 0;
  font-family: "Cinzel", serif;
  font-size: 1.1rem;
}

.hand-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mini-btn {
  padding: 6px 12px;
  border-radius: 999px;
  border: 0;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

.hand-stage {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex: 1;
}

.hand-fan {
  position: relative;
  flex: 1;
  min-height: 160px;
}

.hand-card {
  position: absolute;
  bottom: 0;
  width: 72px;
  height: 100px;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transform-origin: bottom center;
  transition: transform 0.18s ease, bottom 0.18s ease, box-shadow 0.18s ease;
}

/* Scale up full-card inside hand */
.hand-card .full-card {
  width: 72px;
  height: 100px;
}

.hand-card .full-card .corner {
  font-size: 0.7rem;
}

.hand-card .full-card .corner.top { top: 5px; left: 5px; }
.hand-card .full-card .corner.bottom { right: 5px; bottom: 5px; }

.hand-card .full-card .center {
  font-size: 1.6rem;
}

.hand-card:hover {
  bottom: 12px;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.34);
  z-index: 10;
}

.hand-card.disabled { cursor: default; }

.hand-card.money-card {
  box-shadow: 0 0 0 2px var(--gold), 0 8px 16px rgba(0, 0, 0, 0.28);
}

.hold-slot {
  width: 90px;
  flex-shrink: 0;
  min-height: 130px;
  padding: 8px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px dashed rgba(255, 255, 255, 0.18);
  text-align: center;
}

.hold-slot strong {
  font-size: 0.78rem;
}

.hold-slot .rule-note {
  font-size: 0.7rem;
}

.hold-card {
  margin-top: 6px;
}

.hold-card .full-card {
  width: 72px;
  height: 100px;
  margin: 0 auto;
}

/* ── Results Overlay ── */
.results-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 20px;
}

.results-modal {
  width: min(520px, 95vw);
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px 20px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(40, 14, 56, 0.96), rgba(12, 15, 36, 0.98));
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.5);
}

.results-title {
  margin: 0 0 16px;
  font-family: "Cinzel", serif;
  font-size: 1.6rem;
  text-align: center;
  color: var(--gold);
}

.results-section {
  margin-bottom: 14px;
}

.results-section h3 {
  margin: 0 0 8px;
  font-size: 0.9rem;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
}

.results-grid { display: grid; gap: 6px; }

.result-player {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.88rem;
}

.result-player.winner {
  background: rgba(255, 207, 104, 0.12);
  border: 1px solid rgba(255, 207, 104, 0.25);
}

.net { font-weight: 800; }
.net.positive { color: var(--green); }
.net.negative { color: var(--pink); }

.flow-list {
  display: grid;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
}

.flow-item {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.8rem;
}

.flow-from { color: var(--pink); font-weight: 700; }
.flow-arrow { color: var(--muted); }
.flow-to { color: var(--green); font-weight: 700; }
.flow-reason { color: var(--muted); font-size: 0.72rem; margin-left: auto; }

.net-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 6px;
}

.net-item {
  padding: 8px 10px;
  border-radius: 12px;
  text-align: center;
  font-size: 0.85rem;
}

.net-item.positive { background: rgba(29, 208, 149, 0.12); color: var(--green); }
.net-item.negative { background: rgba(255, 111, 148, 0.12); color: var(--pink); }

/* ── Responsive ── */
@media (max-width: 820px) {
  .topbar {
    padding: 6px 10px;
  }

  .brand-title { font-size: 1rem; }

  .table-area { height: 360px; }

  .oval-table {
    width: min(95vw, 600px);
    height: 270px;
    top: 24px;
    border-width: 10px;
  }

  .seat { width: 100px; }
  .avatar { width: 32px; height: 32px; font-size: 0.75rem; }
  .seat-name { font-size: 0.7rem; }
  .mini-fan { width: 56px; height: 30px; }
  .mini-card { width: 20px; height: 28px; font-size: 0.55rem; }

  .pile { width: 48px; height: 68px; }
  .full-card { width: 48px; height: 68px; }
  .full-card .corner { font-size: 0.55rem; }
  .full-card .center { font-size: 1.2rem; }
  .stack-card { border-radius: 10px; }
  .deck-count { width: 20px; height: 20px; font-size: 0.6rem; }
  .empty-pile { width: 48px; height: 68px; }

  .hand-card { width: 60px; height: 84px; }
  .hand-card .full-card { width: 60px; height: 84px; }
  .hand-card .full-card .center { font-size: 1.3rem; }

  .hold-slot { width: 76px; }
  .hold-card .full-card { width: 60px; height: 84px; }
}
