:root {
  --bg: #311c2e;
  --panel: rgba(52, 28, 46, 0.88);
  --panel-2: rgba(88, 41, 67, 0.82);
  --felt: #17624d;
  --felt-dark: #0e4e3e;
  --accent: #ffca5c;
  --accent-2: #ff7db8;
  --text: #fff7ea;
  --muted: #e8d9c3;
  --danger: #ff6161;
  --ok: #89ffb0;
  --shadow: 0 12px 30px rgba(0,0,0,.28);
  --radius: 18px;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(circle at top, #5b3753, #1c1321 55%);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

body {
  overflow-x: hidden;
  overflow-y: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

.hidden { display: none !important; }

.glassy {
  backdrop-filter: blur(12px);
  background: linear-gradient(180deg, rgba(92,45,71,.9), rgba(52,28,46,.84));
  box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,.12);
}

#app {
  display: grid;
  grid-template-columns: 320px 1fr;
  grid-template-rows: 72px 1fr;
  height: 100vh;
  min-height: 100vh;
  background-image:
    radial-gradient(circle at 50% 10%, rgba(255,255,255,.05), transparent 30%),
    linear-gradient(180deg, rgba(255,202,92,.06), transparent 30%);
}

.topbar {
  grid-column: 1 / 3;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  z-index: 25;
}

.brand {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: .06em;
}

.status-line {
  font-size: .9rem;
  color: var(--muted);
}

.brand-wrap {
  flex: 1;
  min-width: 0;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.icon-btn,
.action-btn {
  border: 0;
  border-radius: 14px;
  padding: 10px 14px;
  background: linear-gradient(180deg, #815071, #5b3753);
  color: var(--text);
  box-shadow: 0 8px 18px rgba(0,0,0,.24);
  cursor: pointer;
  transition: transform .15s ease, filter .2s ease, box-shadow .25s ease;
}

.icon-btn:hover,
.action-btn:hover {
  transform: translateY(-1px) scale(1.01);
  filter: brightness(1.06);
}

.icon-btn:active,
.action-btn:active {
  transform: translateY(1px) scale(.99);
}

.action-btn.primary {
  background: linear-gradient(180deg, #d98e3d, #b5691b);
}

.action-btn.warn {
  background: linear-gradient(180deg, #bc678a, #8a3f60);
}

.action-btn.danger {
  background: linear-gradient(180deg, #d05c5c, #9e3232);
}

.side-panel {
  overflow-y: auto;
  padding: 14px;
  transition: transform .3s ease;
}

.side-panel:not(.open) {
  transform: translateX(-100%);
}

.panel-block {
  margin-bottom: 14px;
  padding: 14px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.02));
  border: 1px solid rgba(255,255,255,.08);
}

.panel-block h2 {
  margin: 0 0 10px;
  font-size: 1.05rem;
}

.profile-summary {
  min-height: 68px;
  padding: 10px;
  border-radius: 14px;
  background: rgba(0,0,0,.18);
  margin-bottom: 10px;
}

.main-stage {
  position: relative;
  display: grid;
  grid-template-rows: 1fr 220px;
  min-width: 0;
  min-height: 0;
}

.game-room {
  position: relative;
  margin: 14px 14px 8px 0;
  border-radius: 28px;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,.09);
  box-shadow: var(--shadow);
  background: radial-gradient(circle at center, #238668, var(--felt) 45%, var(--felt-dark) 100%);
}

.table-backdrop {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 50% 45%, rgba(255,255,255,.06), transparent 35%),
    radial-gradient(circle at 15% 15%, rgba(255,202,92,.08), transparent 22%),
    radial-gradient(circle at 85% 20%, rgba(255,125,184,.08), transparent 22%),
    linear-gradient(180deg, rgba(0,0,0,.06), rgba(0,0,0,.16));
  pointer-events: none;
}

.room-title {
  position: absolute;
  left: 18px;
  top: 16px;
  z-index: 3;
  padding: 8px 12px;
  background: rgba(49, 28, 46, .7);
  border-radius: 999px;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: .04em;
}

.play-area {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  padding: 58px 16px 16px;
  min-width: 0;
  min-height: 0;
}

.bottom-hud {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  padding: 0 14px calc(14px + env(safe-area-inset-bottom, 0px)) 0;
}

.hud-card {
  min-width: 0;
  overflow: hidden;
  border-radius: var(--radius);
  padding: 12px;
}

.hud-card h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.log-content {
  height: 145px;
  overflow: auto;
  white-space: pre-wrap;
  font-size: .92rem;
}

.field-label {
  display: block;
  margin: 10px 0 6px;
  color: var(--muted);
  font-size: .92rem;
}

.field-input {
  width: 100%;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.22);
  color: var(--text);
  border-radius: 14px;
  padding: 10px 12px;
}

.field-input.tall {
  min-height: 90px;
  resize: vertical;
}

.btn-row {
  display: flex;
  gap: 8px;
}

.btn-row.wrap {
  flex-wrap: wrap;
}

.toggle-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

.modal {
  border: 0;
  padding: 0;
  background: transparent;
}

.modal::backdrop {
  background: rgba(15, 9, 17, .72);
  backdrop-filter: blur(4px);
}

.modal-card {
  width: min(92vw, 900px);
  background: linear-gradient(180deg, rgba(72,39,58,.98), rgba(40,22,35,.98));
  border-radius: 24px;
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.1);
}

.modal-card.wide {
  width: min(96vw, 1160px);
}

.modal-card.slim {
  width: min(92vw, 560px);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.02));
}

.modal-body {
  padding: 16px;
  max-height: 78vh;
  overflow: auto;
}

.close-modal {
  border: 0;
  background: rgba(255,255,255,.08);
  color: white;
  border-radius: 12px;
  padding: 8px 12px;
  cursor: pointer;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.avatar-picker {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.avatar-option {
  width: 62px;
  height: 62px;
  border-radius: 18px;
  background: rgba(0,0,0,.2);
  border: 2px solid transparent;
  overflow: hidden;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.avatar-option.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255,202,92,.2);
}

.avatar-option img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-card {
  padding: 12px;
  border-radius: 18px;
  background: rgba(0,0,0,.18);
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.profile-card img {
  width: 62px;
  height: 62px;
  border-radius: 18px;
  object-fit: cover;
}

.profile-card .meta {
  flex: 1;
  min-width: 0;
}

.builder-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
}

.builder-controls {
  max-height: 74vh;
  overflow: auto;
  padding-right: 6px;
}

.builder-stage-wrap {
  min-width: 0;
}

.builder-stage {
  min-height: 580px;
  border-radius: 20px;
  background:
    radial-gradient(circle at center, rgba(255,255,255,.06), transparent 35%),
    linear-gradient(180deg, #1d7058, #125141);
  position: relative;
  border: 2px dashed rgba(255,255,255,.18);
  overflow: hidden;
}

.builder-token {
  position: absolute;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,.15);
  border: 2px solid rgba(255,255,255,.16);
  cursor: grab;
}

.builder-token img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.piece-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.palette-piece {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: rgba(0,0,0,.18);
  display: grid;
  place-items: center;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,.12);
}

.palette-piece span {
  font-size: 1.4rem;
}

.tooltip {
  position: fixed;
  z-index: 60;
  max-width: 240px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(26, 14, 22, .95);
  color: #fff;
  box-shadow: var(--shadow);
  font-size: .88rem;
  pointer-events: none;
}

.help-copy {
  color: var(--muted);
}

.game-shell {
  width: 100%;
  height: 100%;
  display: grid;
  gap: 10px;
}

.center-board {
  display: grid;
  place-items: center;
  min-height: 0;
}

.board-grid {
  display: grid;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.board-cell {
  position: relative;
  width: min(10vw, 68px);
  height: min(10vw, 68px);
  display: grid;
  place-items: center;
  font-size: 2rem;
  cursor: pointer;
  user-select: none;
}

.board-cell.small {
  width: min(9vw, 58px);
  height: min(9vw, 58px);
  font-size: 1.5rem;
}

.board-cell.dark { background: #6a3f2a; }
.board-cell.light { background: #d6b691; }

.board-cell.highlight::after,
.card-slot.highlight::after,
.token-glow::after {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 14px;
  border: 3px solid rgba(255,202,92,.85);
  box-shadow: 0 0 18px rgba(255,202,92,.55);
  animation: popGlow .8s infinite alternate;
}

.board-cell.selected {
  box-shadow: inset 0 0 0 4px rgba(255,125,184,.76);
}

.piece {
  filter: drop-shadow(0 4px 5px rgba(0,0,0,.28));
}

.info-strip,
.player-strip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.chip {
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(0,0,0,.25);
}

.card-row,
.seat-row,
.token-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
}

.playing-card,
.card-slot {
  width: 72px;
  height: 102px;
  border-radius: 14px;
  background: linear-gradient(180deg, #fffef9, #ebdfca);
  color: #1b1620;
  border: 2px solid rgba(0,0,0,.12);
  box-shadow: 0 10px 18px rgba(0,0,0,.2);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 6px;
  position: relative;
  cursor: pointer;
}

.playing-card.back {
  background: linear-gradient(180deg, #7b3156, #3b2138);
  color: #fff;
}

.playing-card.tiny {
  width: 52px;
  height: 74px;
  font-size: .74rem;
}

.playing-card.selected {
  transform: translateY(-8px);
}

.soli-card.selected-card {
  transform: translateY(-8px);
  filter: drop-shadow(0 0 16px rgba(255,202,92,.55));
}

.soli-pile {
  min-height: 112px;
}

.card-corner {
  font-weight: 700;
  font-size: .92rem;
}

.card-center {
  font-size: 1.7rem;
  text-align: center;
  flex: 1;
  display: grid;
  place-items: center;
}

.seat {
  min-width: 140px;
  padding: 10px;
  border-radius: 18px;
  background: rgba(0,0,0,.18);
  border: 1px solid rgba(255,255,255,.08);
}

.seat.active {
  box-shadow: 0 0 0 3px rgba(255,202,92,.24), 0 0 26px rgba(255,202,92,.24);
}

.seat.folded {
  opacity: .55;
}

.market-board,
.stack-area {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
}

.fade-in { animation: fadeIn .28s ease; }
.glow-idle { animation: idleGlow 4s ease-in-out infinite; }
.pulse { animation: pulse 1.2s infinite; }
.big-win { animation: bigWin .95s ease; }
.arcade-spark { animation: arcadeSpark 1.5s ease-in-out infinite; }

.two-small-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.profiles-list {
  max-height: 50vh;
  overflow: auto;
}

.match-banner {
  padding: 10px 14px;
  border-radius: 16px;
  background: rgba(255,202,92,.13);
  color: var(--accent);
}

.mini-text {
  font-size: .84rem;
  color: var(--muted);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

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

@keyframes idleGlow {
  0%,100% {
    box-shadow: inset 0 0 0 rgba(255,255,255,0), 0 0 0 rgba(255,202,92,0);
  }
  50% {
    box-shadow: inset 0 0 42px rgba(255,255,255,.03), 0 0 24px rgba(255,202,92,.10);
  }
}

@keyframes popGlow {
  from { opacity: .55; }
  to { opacity: 1; }
}

@keyframes bigWin {
  0% { transform: scale(1); filter: brightness(1); }
  40% { transform: scale(1.05) rotate(-1deg); filter: brightness(1.28); }
  80% { transform: scale(1.02) rotate(1deg); }
  100% { transform: scale(1); }
}

@keyframes arcadeSpark {
  0%,100% { box-shadow: 0 0 0 rgba(255,125,184,.0); }
  25% { box-shadow: 0 0 18px rgba(255,125,184,.24); }
  60% { box-shadow: 0 0 28px rgba(255,202,92,.26); }
}

@media (max-width: 980px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: 72px auto 1fr;
  }

  .topbar {
    grid-column: 1;
  }

  .side-panel {
    position: fixed;
    top: 72px;
    bottom: 0;
    left: 0;
    width: min(90vw, 360px);
    z-index: 40;
  }

  .main-stage {
    grid-row: 3;
    grid-template-rows: 1fr 240px;
    padding-left: 0;
  }

  .game-room {
    margin: 10px;
  }

  .bottom-hud {
    grid-template-columns: 1fr;
    padding: 0 10px 10px;
  }

  .two-col,
  .builder-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  #app {
    grid-template-rows: 72px auto auto;
    height: auto;
    min-height: 100dvh;
    padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  }

  .brand {
    font-size: 1.06rem;
  }

  .toggle-grid {
    grid-template-columns: 1fr;
  }

  .main-stage {
    display: block;
    min-height: auto;
    padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  }

  .game-room {
    margin: 10px;
    height: auto;
    min-height: clamp(560px, 72svh, 920px);
  }

  .room-title {
    left: 14px;
    top: 12px;
  }

  .play-area {
    position: relative;
    inset: auto;
    display: block;
    padding: 58px 12px 14px;
    min-height: calc(clamp(560px, 72svh, 920px) - 58px);
  }

  .play-area > * {
    min-width: 0;
  }

  .game-shell {
    height: auto;
    min-height: 100%;
    align-content: start;
  }

  .center-board {
    min-height: 0;
    overflow: visible;
  }

  .bottom-hud {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 0 10px 10px;
  }

  .hud-card {
    overflow: visible;
  }

  .log-content {
    height: auto;
    max-height: 160px;
  }

  .board-cell {
    width: min(11vw, 48px);
    height: min(11vw, 48px);
    font-size: 1.5rem;
  }

  .board-cell.small {
    width: min(10vw, 42px);
    height: min(10vw, 42px);
    font-size: 1.1rem;
  }

  .playing-card {
    width: 58px;
    height: 86px;
  }

  .seat {
    min-width: 120px;
  }
}