/* The table is a fixed 1280x720 stage scaled to fit; all positions below are stage pixels. */

body.table-page { overflow: hidden; height: 100vh; }

.table-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  height: 100vh;
  background: #050307;
}
.table-layout.side-closed { grid-template-columns: 1fr 0; }
.table-layout.side-closed .side { display: none; }

.stage-area { position: relative; overflow: hidden; }
.stage {
  position: absolute;
  left: 0;
  top: 0;
  width: 1280px;
  height: 720px;
  transform-origin: 0 0;
  overflow: hidden;
  background: #000;
}

.backdrop {
  position: absolute;
  inset: 0;
  background: url("../img/backdrop.png") center / cover no-repeat;
  image-rendering: pixelated;
  filter: brightness(0.75) saturate(1.05);
}
.vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 55%, transparent 35%, rgba(0, 0, 0, 0.75) 100%);
  pointer-events: none;
}

/* ------------------------------------------------------------------ HUD */

.hud {
  position: absolute;
  left: 10px;
  right: 10px;
  top: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 40;
}
.hud .btn.small { font-size: 14px; padding: 3px 8px 5px; }
.hud .btn kbd { font-size: 13px; }
.hud-item { padding: 2px 10px; background: rgba(10, 6, 14, 0.75); box-shadow: 0 0 0 2px #000; font-size: 18px; }
.hud-spacer { flex: 1; }

/* -------------------------------------------------------------- seating */

.seats-back, .seats-front { position: absolute; inset: 0; pointer-events: none; }
.seats-back { z-index: 5; }
.seats-front { z-index: 30; }

.avatar {
  position: absolute;
  width: 156px;
  height: 200px;
  background: center bottom / contain no-repeat;
  image-rendering: pixelated;
  filter: drop-shadow(0 0 10px rgba(0, 0, 0, 0.8));
  transition: filter 300ms;
}
.avatar.slot-2 { left: 562px; top: 52px; }
.avatar.slot-1 { left: 22px; top: 196px; }
.avatar.slot-3 { left: 1102px; top: 196px; transform: scaleX(-1); }
.avatar.dead { filter: grayscale(1) brightness(0.45) drop-shadow(0 0 6px #000); }
.avatar.current { filter: drop-shadow(0 0 4px #f2b84b) drop-shadow(0 0 18px rgba(242, 184, 75, 0.6)); }
.avatar.awaiting { animation: breathe 1.6s ease-in-out infinite; }
.avatar.shake { animation: shake 420ms steps(6) 1; }
.avatar.empty { opacity: 0.28; filter: grayscale(1) brightness(0.6); }
@keyframes breathe { 50% { translate: 0 -4px; } }
@keyframes shake {
  0%, 100% { translate: 0 0; }
  20% { translate: -8px 0; }
  40% { translate: 8px 0; }
  60% { translate: -6px 0; }
  80% { translate: 6px 0; }
}

.plate {
  position: absolute;
  min-width: 150px;
  max-width: 200px;
  padding: 4px 8px 5px;
  background: rgba(16, 10, 22, 0.88);
  box-shadow: 0 0 0 2px #000, 0 0 0 4px var(--edge);
  pointer-events: auto;
  font-size: 17px;
}
.plate.slot-2 { left: 730px; top: 70px; }
.plate.slot-1 { left: 20px; top: 404px; }
.plate.slot-3 { right: 20px; top: 404px; }
.plate.current { box-shadow: 0 0 0 2px #000, 0 0 0 4px var(--amber); }
.plate.target { cursor: pointer; box-shadow: 0 0 0 2px #000, 0 0 0 4px var(--teal), 0 0 18px var(--teal); }
.plate.target:hover { background: rgba(40, 80, 72, 0.95); }
.plate .pname { font-family: var(--font-ui); font-weight: 700; color: var(--bone); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plate .pname .tag { color: var(--bone-dim); font-weight: 400; font-size: 14px; margin-left: 4px; }
.plate .pmeta { display: flex; align-items: center; gap: 6px; color: var(--bone-dim); min-height: 20px; }
.plate .timer { margin-left: auto; color: var(--amber); }
.plate .timer.low { color: var(--blood); }
.plate .seat-actions { display: flex; gap: 6px; margin-top: 4px; }
.pips { display: inline-flex; gap: 3px; }
.pip { width: 9px; height: 9px; background: #000; box-shadow: 0 0 0 1px var(--edge-hi); }
.pip.on { background: var(--amber); box-shadow: 0 0 0 1px #000, 0 0 6px var(--amber); }

.tokens { display: inline-flex; gap: 3px; flex-wrap: wrap; }
.tok {
  width: 18px;
  height: 18px;
  display: inline-grid;
  place-items: center;
  font-size: 13px;
  line-height: 1;
  color: #1a0f05;
  font-family: var(--font-ui);
  font-weight: 700;
  box-shadow: 0 0 0 2px #000;
}
.tok.extra { background: radial-gradient(circle at 35% 30%, #ffe8a3, #e3a23a 60%, #8a5414); border-radius: 50%; }
.tok.extra.fresh { filter: saturate(0.3) brightness(0.8); }
.tok.death { background: #d9d2c0; color: #000; }
.tok.lovers { background: #e2546b; color: #fff; border-radius: 50% 50% 4px 4px; }
.tok.skip { background: #3a4a9a; color: #fff; }
.tok.link { background: transparent; color: #e2546b; box-shadow: none; font-size: 15px; }

/* ----------------------------------------------------------------- table */

.table3d {
  position: absolute;
  left: 150px;
  top: 222px;
  width: 980px;
  height: 430px;
  perspective: 1050px;
  perspective-origin: 50% 0%;
  z-index: 10;
}
.felt {
  position: absolute;
  inset: 0;
  background: url("../img/table.png") center / 100% 100% no-repeat;
  image-rendering: pixelated;
  transform: rotateX(30deg);
  transform-origin: 50% 100%;
  box-shadow: 0 30px 40px rgba(0, 0, 0, 0.7);
}
.pile { position: absolute; width: 84px; height: 126px; }
.deck-pile { left: 372px; top: 132px; }
.discard-pile { left: 520px; top: 132px; cursor: pointer; }
.pile .card { position: absolute; left: 0; top: 0; --cw: 84px; }
.pile-count {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: -26px;
  transform: translateX(-50%);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 20px;
  color: var(--amber);
  text-shadow: 0 2px 0 #000;
}
.discard-pile:empty::after, .deck-pile.empty::after {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 3px rgba(234, 223, 201, 0.25);
}
.felt-hands { position: absolute; inset: 0; pointer-events: none; }
.opp-hand { position: absolute; display: flex; }
.opp-hand .card { --cw: 50px; margin-left: -20px; }
.opp-hand .card:first-child { margin-left: 0; }
.opp-hand .card.fortune { margin-left: 14px; box-shadow: 0 0 0 1px #000, 0 0 10px rgba(154, 102, 224, 0.9); }
.opp-hand.slot-2 { left: 420px; top: 18px; }
.opp-hand.slot-1 { left: 40px; top: 150px; transform: rotate(90deg); transform-origin: 0 0; translate: 80px 0; }
.opp-hand.slot-3 { right: 40px; top: 150px; transform: rotate(-90deg); transform-origin: 100% 0; translate: -80px 0; }
.supply { position: absolute; left: 680px; top: 170px; display: flex; gap: 4px; }

.play-spot {
  position: absolute;
  left: 640px;
  top: 300px;
  width: 0;
  height: 0;
  z-index: 35;
}
.play-spot .card { position: absolute; --cw: 120px; transform: translate(-50%, -50%); }

/* --------------------------------------------------------------- arms/fx */

.arms { position: absolute; inset: 0; z-index: 28; pointer-events: none; }
.arm {
  position: absolute;
  width: 46px;
  height: 144px;
  margin-left: -23px;
  margin-top: -144px;
  background: center top / 100% 100% no-repeat;
  image-rendering: pixelated;
  transform-origin: 50% 100%;
  filter: drop-shadow(0 6px 4px rgba(0, 0, 0, 0.6));
  -webkit-mask-image: linear-gradient(to top, transparent 0, #000 36px);
  mask-image: linear-gradient(to top, transparent 0, #000 36px);
  opacity: 0;
}
.fx { position: absolute; inset: 0; z-index: 60; pointer-events: none; }
.fx .card { position: absolute; left: 0; top: 0; }
.float-text {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 28px;
  color: var(--amber);
  text-shadow: 0 3px 0 #000, 0 0 12px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
}
.float-text.bad { color: #ff6a6a; }
.float-text.good { color: #8fe08f; }
.float-text.cool { color: #9fd6ff; }
.flash { position: absolute; inset: 0; background: #fff; mix-blend-mode: screen; }

.banner {
  position: absolute;
  left: 50%;
  top: 300px;
  transform: translate(-50%, -50%);
  z-index: 70;
  padding: 10px 36px 14px;
  font-size: 42px;
  color: var(--amber);
  background: linear-gradient(90deg, transparent, rgba(8, 4, 12, 0.92) 18%, rgba(8, 4, 12, 0.92) 82%, transparent);
  text-shadow: 0 4px 0 #000;
  white-space: nowrap;
  pointer-events: none;
}

/* --------------------------------------------------------------- my side */

.me-panel {
  position: absolute;
  left: 14px;
  bottom: 14px;
  width: 200px;
  z-index: 32;
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 8px;
  align-items: end;
}
.me-panel .mini-avatar { width: 76px; height: 96px; background: center bottom / contain no-repeat; image-rendering: pixelated; }
.me-panel .plate { position: static; min-width: 0; }

.my-fortune { position: absolute; right: 24px; bottom: 22px; z-index: 32; text-align: center; }
.my-fortune .card { --cw: 78px; box-shadow: 0 0 0 2px #000, 0 0 16px rgba(154, 102, 224, 0.9), inset 0 0 0 2px #b98a3a; }
.my-fortune .label { font-family: var(--font-ui); font-size: 14px; color: var(--violet); margin-bottom: 6px; text-shadow: 0 2px 0 #000; }

.hand {
  position: absolute;
  left: 250px;
  right: 130px;
  bottom: 8px;
  height: 200px;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  z-index: 34;
}
.hand .slot { position: relative; transition: transform 120ms, margin 120ms; margin: 0 -6px; }
.hand .slot .card { --cw: 116px; transition: transform 120ms, box-shadow 120ms, filter 120ms; }
.hand .slot:hover { z-index: 5; }
.hand .slot:hover .card { transform: translateY(-26px) scale(1.04); }
.hand .slot .key {
  position: absolute;
  left: 50%;
  top: -24px;
  transform: translateX(-50%);
  font-family: var(--font-text);
  font-size: 16px;
  color: var(--amber);
  background: #000a;
  padding: 0 5px;
  box-shadow: 0 0 0 1px #000;
  z-index: 2;
}
.hand.many .slot { margin: 0 -24px; }
.hand .slot.selectable .card { cursor: pointer; box-shadow: 0 0 0 2px #000, 0 0 0 4px var(--teal), 0 0 16px rgba(72, 194, 173, 0.7); }
.hand .slot.unselectable .card { filter: brightness(0.5) grayscale(0.5); }
.hand .slot.chosen .card { transform: translateY(-34px); box-shadow: 0 0 0 2px #000, 0 0 0 5px var(--amber), 0 0 22px rgba(242, 184, 75, 0.8); }

.prompt-bar {
  position: absolute;
  left: 50%;
  bottom: 226px;
  transform: translateX(-50%);
  z-index: 45;
  min-width: 380px;
  max-width: 900px;
  padding: 10px 16px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: rgba(22, 14, 30, 0.95);
}
.prompt-title { font-family: var(--font-ui); font-weight: 700; font-size: 20px; color: var(--amber); text-align: center; }
.prompt-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.prompt-bar.waiting .prompt-title { color: var(--bone-dim); font-weight: 400; }

/* ------------------------------------------------------- lobby & coach */

.lobby-panel {
  position: absolute;
  left: 50%;
  top: 330px;
  transform: translate(-50%, -50%);
  z-index: 50;
  width: 560px;
  padding: 18px 22px;
  background: rgba(22, 14, 30, 0.96);
}
.stage:has(.minigames:not([hidden]):not(.is-min)) .lobby-panel {
  left: 200px;
  width: 500px;
  transform: translateY(-50%);
}
.minigames {
  position: absolute;
  top: 330px;
  left: calc(50% + 292px);
  transform: translateY(-50%);
  z-index: 48;
  width: auto;
  padding: 8px;
}
.minigames:not(.is-min) {
  left: 716px;
  width: 400px;
  height: 480px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
}
.minigames-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.minigames.is-min .minigames-title,
.minigames.is-min iframe { display: none; }
.minigames iframe {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: 0;
  background: var(--night);
  box-shadow: inset 0 0 0 2px #000;
}
.lobby-panel h2 { margin: 0 0 8px; color: var(--amber); }
.lobby-panel .row label { min-width: 120px; }
.lobby-panel .invite { display: flex; gap: 8px; align-items: center; }
.lobby-panel .invite input { flex: 1; font-size: 16px; }
.seat-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.seat-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: var(--ink); box-shadow: 0 0 0 2px #000; }
.seat-row .face { width: 34px; height: 42px; background: center bottom / contain no-repeat; image-rendering: pixelated; }
.seat-row .who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-row .who.empty { color: var(--bone-dim); }

.coach {
  position: absolute;
  left: 18px;
  top: 58px;
  z-index: 55;
  width: 470px;
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 12px;
  padding: 10px 14px;
  background: rgba(16, 26, 26, 0.95);
  box-shadow: 0 0 0 2px #000, 0 0 0 4px var(--teal), 0 0 0 6px #000;
}
.coach-face { width: 64px; height: 80px; background: url("../img/avatars/doctor.png") center bottom / contain no-repeat; image-rendering: pixelated; }
.coach-title { color: var(--teal); font-size: 16px; }
.coach-text { font-size: 20px; }
.coach-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* ------------------------------------------------------ overlays/modals */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  background: rgba(4, 2, 6, 0.72);
}
.overlay .sheet { width: 900px; padding: 20px 26px; text-align: center; background: rgba(22, 14, 30, 0.97); }
.overlay h2 { margin: 0 0 6px; font-size: 38px; color: var(--amber); }
.overlay .reason { color: var(--bone-dim); margin-bottom: 14px; }
.results { display: flex; justify-content: center; gap: 18px; flex-wrap: wrap; margin: 10px 0 18px; }
.result { padding: 10px; min-width: 190px; background: var(--ink); box-shadow: 0 0 0 2px #000, 0 0 0 4px var(--edge); }
.result.win { box-shadow: 0 0 0 2px #000, 0 0 0 4px var(--amber), 0 0 22px rgba(242, 184, 75, 0.5); }
.result.dead { opacity: 0.55; }
.result .rname { font-family: var(--font-ui); font-weight: 700; margin-bottom: 6px; }
.result .rcards { display: flex; justify-content: center; gap: 4px; min-height: 76px; }
.result .rcards .card { --cw: 52px; }
.result .rtotal { margin-top: 6px; color: var(--amber); font-size: 22px; }
.overlay .actions { display: flex; justify-content: center; gap: 12px; }

.modal-wrap {
  position: absolute;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  background: rgba(4, 2, 6, 0.78);
}
.modal { width: 1080px; max-height: 640px; display: flex; flex-direction: column; padding: 14px 18px; background: rgba(20, 13, 27, 0.98); }
.modal-head { display: flex; align-items: baseline; gap: 14px; }
.modal-head h2 { margin: 0; color: var(--amber); font-size: 26px; }
.modal-sub { flex: 1; color: var(--bone-dim); }
.modal-body { overflow-y: auto; padding: 18px 6px 10px; display: flex; flex-wrap: wrap; gap: 18px 14px; justify-content: center; }
.modal-body .card { --cw: 112px; }
.modal-body .pick { position: relative; cursor: pointer; }
.modal-body .pick .key { position: absolute; top: -18px; left: 50%; transform: translateX(-50%); color: var(--amber); font-size: 15px; }
.modal-body .pick.chosen .card { box-shadow: 0 0 0 2px #000, 0 0 0 5px var(--amber), 0 0 22px rgba(242, 184, 75, 0.8); transform: translateY(-8px); }
.modal-body .pick:hover .card { transform: translateY(-6px); }
.modal-body.compendium-view { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; justify-content: stretch; }
.modal-foot { display: flex; justify-content: center; gap: 12px; padding-top: 8px; }
.modal-foot:empty { display: none; }
.comp-row { display: grid; grid-template-columns: 80px 1fr; gap: 12px; padding: 8px; background: var(--ink); box-shadow: 0 0 0 2px #000; text-align: left; }
.comp-row .card { --cw: 80px; }
.comp-row h3 { margin: 0 0 4px; font-size: 17px; color: var(--amber); }
.comp-row p { margin: 0; font-size: 17px; }
.comp-row.gone { opacity: 0.45; }
.dist-table { width: 100%; border-collapse: collapse; }
.dist-table td { padding: 6px 8px; border-bottom: 2px solid #000; }
.dist-table .seat-pick { display: flex; gap: 6px; flex-wrap: wrap; }
.dist-table .btn.on { background: linear-gradient(#d68a2a, #a35a16); }
.help-grid { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; font-size: 20px; text-align: left; }

/* ------------------------------------------------------------- sidebar */

.side {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #120c18;
  box-shadow: inset 2px 0 0 #000, inset 4px 0 0 var(--edge);
}
.side-tabs { display: flex; padding: 8px 8px 0 12px; gap: 4px; }
.tab { font-family: var(--font-ui); font-size: 16px; color: var(--bone-dim); background: transparent; border: 0; padding: 6px 12px; cursor: pointer; }
.tab.active { color: var(--amber); background: var(--panel); box-shadow: 0 0 0 2px #000; }
#chat-badge { color: var(--ember); }
.side-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 8px 8px 8px 12px; }
.log, .chat { list-style: none; margin: 0; padding: 0 4px 0 0; overflow-y: auto; flex: 1; font-size: 17px; }
.log li { padding: 3px 0 4px; border-bottom: 1px solid #241a2c; color: var(--bone-dim); }
.log li.k-turn_start { color: var(--bone); margin-top: 6px; border-top: 2px solid #2f2238; }
.log li.k-kill { color: #ff8080; }
.log li.k-round_end, .log li.k-match_end { color: var(--amber); }
.log li.k-token, .log li.k-extra_turn { color: #f5d38a; }
.log li.private { color: #b7e6ff; }
.chat li { padding: 3px 0; }
.chat li b { color: var(--amber); font-family: var(--font-ui); font-size: 15px; }
.chat-form input { width: 100%; margin-top: 8px; font-size: 17px; }
.side-foot { padding: 8px 12px 12px; font-size: 15px; color: var(--bone-dim); border-top: 2px solid #000; }

@media (max-width: 900px) {
  .table-layout { grid-template-columns: 1fr 0; }
  .table-layout .side { display: none; }
  .table-layout.side-open { grid-template-columns: 1fr 260px; }
  .table-layout.side-open .side { display: flex; }
}
