:root {
  color-scheme: dark;
  --bg: #101511;
  --felt: #183427;
  --felt-dark: #0f251d;
  --panel: #17201b;
  --panel-2: #202a24;
  --line: rgba(226, 238, 220, 0.16);
  --line-strong: rgba(226, 238, 220, 0.34);
  --text: #f3f5eb;
  --muted: #aab6a6;
  --gold: #e5b85f;
  --red: #d75e54;
  --blue: #7db7d8;
  --green: #78c88c;
  --ink: #18211b;
  --shadow: 0 18px 54px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(125, 183, 216, 0.16), transparent 28rem),
    linear-gradient(135deg, #101511, #0c1210 48%, #16130f);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #26322b;
  color: var(--text);
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: rgba(229, 184, 95, 0.75);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101711;
  color: var(--text);
  padding: 0 12px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 420px);
  min-height: 100vh;
}

.table {
  display: grid;
  grid-template-rows: auto minmax(128px, 1fr) auto auto;
  gap: 18px;
  min-width: 0;
  padding: 20px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    radial-gradient(circle at 50% 45%, #25553e, var(--felt-dark) 68%);
  background-size: 42px 42px, 42px 42px, auto;
}

.top-bar,
.board-head,
.section-title,
.room-actions,
.join-row,
.demo-controls,
.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 8px;
  background: var(--gold);
  color: #1a170f;
  font-size: 1.55rem;
  font-weight: 900;
}

.brand p,
.zone-label,
.section-title span,
.player-card p,
.opponent-meta,
.connection,
.room-code + .room-actions,
.demo-section p,
.log-section li {
  color: var(--muted);
}

.brand p,
.brand h1,
.section-title h2,
.board-head h2,
.demo-section h3 {
  margin: 0;
}

.brand p {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand h1 {
  font-size: clamp(1.65rem, 4vw, 3.4rem);
  line-height: 1;
}

.connection {
  min-width: 92px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(13, 20, 16, 0.62);
  text-align: center;
  font-size: 0.82rem;
}

.connection.is-live {
  color: var(--green);
}

.opponents {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  align-content: start;
  gap: 12px;
}

.commentary-bubble {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 12px;
  width: min(620px, calc(100vw - 470px));
  max-width: 100%;
  justify-self: center;
  align-self: start;
  margin-top: -6px;
  padding: 14px 16px 16px;
  border: 1px solid rgba(229, 184, 95, 0.42);
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(255, 248, 222, 0.98), rgba(232, 219, 181, 0.98));
  color: #21180e;
  box-shadow:
    0 18px 42px rgba(0, 0, 0, 0.34),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.commentary-bubble[hidden] {
  display: none;
}

.commentary-bubble::after {
  content: "";
  position: absolute;
}

.commentary-bubble {
  position: relative;
}

.commentary-bubble::before {
  content: "";
  position: absolute;
  left: 42px;
  bottom: -13px;
  width: 24px;
  height: 24px;
  border-right: 1px solid rgba(229, 184, 95, 0.42);
  border-bottom: 1px solid rgba(229, 184, 95, 0.42);
  background: #e8dbb5;
  transform: rotate(45deg);
}

.commentary-avatar {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 999px;
  background: #173426;
  color: var(--gold);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.35rem;
  font-weight: 900;
}

.commentary-bubble p {
  margin: 0;
  font-size: clamp(1rem, 1.35vw, 1.25rem);
  font-weight: 850;
  line-height: 1.32;
}

.commentary-bubble.is-streaming p::after {
  content: "▋";
  display: inline-block;
  margin-left: 3px;
  animation: blink 0.85s steps(1) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.opponent {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(13, 20, 16, 0.62);
  box-shadow: var(--shadow);
}

.opponent.is-turn {
  border-color: var(--gold);
  box-shadow:
    0 0 0 1px rgba(229, 184, 95, 0.35),
    0 0 18px rgba(229, 184, 95, 0.28),
    var(--shadow);
  animation: turn-pulse 1.6s ease-in-out infinite;
}

.opponent.is-turn::before {
  content: "";
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--gold);
  box-shadow: 0 0 0 4px rgba(229, 184, 95, 0.22);
  animation: turn-dot 1.2s ease-in-out infinite;
  z-index: 2;
}

.opponent {
  position: relative;
}

.player-board.is-my-turn {
  border-color: var(--gold);
  box-shadow:
    0 0 0 1px rgba(229, 184, 95, 0.4),
    0 0 28px rgba(229, 184, 95, 0.32),
    var(--shadow);
  animation: turn-pulse 1.8s ease-in-out infinite;
}

.player-board.is-my-turn .board-head h2::after {
  content: "YOUR TURN";
  display: inline-block;
  margin-left: 10px;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--gold);
  color: #1d170c;
  font-size: 0.62rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  vertical-align: middle;
  animation: turn-dot 1.2s ease-in-out infinite;
}

@keyframes turn-pulse {
  0%, 100% {
    box-shadow:
      0 0 0 1px rgba(229, 184, 95, 0.4),
      0 0 18px rgba(229, 184, 95, 0.22),
      var(--shadow);
  }
  50% {
    box-shadow:
      0 0 0 1px rgba(229, 184, 95, 0.7),
      0 0 32px rgba(229, 184, 95, 0.45),
      var(--shadow);
  }
}

@keyframes turn-dot {
  50% { opacity: 0.55; }
}

.opponent.is-loser,
.player-board.is-loser,
.player-row.is-loser {
  position: relative;
  border-color: rgba(215, 94, 84, 0.9);
  animation: loser-wobble 0.62s ease-in-out 0s 4;
}

.opponent.is-loser::after,
.player-board.is-loser::after {
  content: "SHITHEAD";
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 5;
  padding: 8px 12px;
  border: 3px solid #5b120e;
  border-radius: 8px;
  background: rgba(215, 94, 84, 0.94);
  color: #fff7df;
  font-size: clamp(1rem, 2vw, 1.55rem);
  font-weight: 1000;
  letter-spacing: 0.08em;
  transform: rotate(-9deg) scale(0.86);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.34);
  animation: stamp-in 0.48s cubic-bezier(0.17, 0.89, 0.32, 1.38) forwards;
}

.player-row.is-loser {
  background: rgba(215, 94, 84, 0.14);
}

.is-loser .avatar {
  animation: loser-pulse 0.72s ease-in-out 0s 5;
}

@keyframes stamp-in {
  0% {
    opacity: 0;
    transform: rotate(-18deg) scale(2.2);
  }
  70% {
    opacity: 1;
    transform: rotate(-8deg) scale(0.92);
  }
  100% {
    opacity: 1;
    transform: rotate(-9deg) scale(1);
  }
}

@keyframes loser-wobble {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-3px) rotate(-0.3deg);
  }
  75% {
    transform: translateX(3px) rotate(0.3deg);
  }
}

@keyframes loser-pulse {
  50% {
    filter: saturate(1.4) brightness(1.12);
    transform: scale(1.08);
  }
}

.opponent-head,
.player-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.avatar {
  position: relative;
  display: grid;
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 12px;
  border: 0;
  background: transparent;
  color: #fff;
  font-weight: 900;
  overflow: hidden;
  isolation: isolate;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.28);
}

.avatar::before {
  content: none;
}

.avatar::after {
  content: none;
}

.avatar-svg {
  display: block;
  width: 100%;
  height: 100%;
}

.avatar-initials {
  position: absolute;
  left: 7px;
  bottom: 5px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.5rem;
  letter-spacing: 0.08em;
}

.avatar.a0 { background: linear-gradient(135deg, #245f55 0%, #4a9c8b 48%, #d8b665 100%); }
.avatar.a1 { background: linear-gradient(135deg, #733932 0%, #c6614e 54%, #e0ad57 100%); }
.avatar.a2 { background: linear-gradient(135deg, #243d70 0%, #5a72b2 52%, #d8d0a0 100%); }
.avatar.a3 { background: linear-gradient(135deg, #3b315f 0%, #8260a7 48%, #76c58f 100%); }
.avatar.a4 { background: linear-gradient(135deg, #1f5669 0%, #5aa4bb 50%, #d08e68 100%); }
.avatar.a5 { background: linear-gradient(135deg, #64452f 0%, #ad7552 52%, #b9c9a5 100%); }

.opponent strong,
.player-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.opponent-zones {
  display: grid;
  gap: 8px;
}

.tiny-row,
.card-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.center-board {
  display: grid;
  grid-template-columns: 118px minmax(0, 1fr) 118px;
  align-items: center;
  gap: 18px;
  max-width: 920px;
  width: 100%;
  margin: auto;
}

.draw-stack,
.burn-stack,
.pile-zone,
.player-board,
.panel-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(15, 22, 17, 0.82);
  box-shadow: var(--shadow);
}

.draw-stack,
.burn-stack {
  display: grid;
  min-height: 166px;
  place-items: center;
  padding: 12px;
  text-align: center;
}

.draw-stack span,
.burn-stack span {
  color: var(--muted);
  font-size: 0.76rem;
}

.burn-stack {
  position: relative;
}

.burn-pile {
  position: relative;
  width: 60px;
  height: 84px;
  margin: 0 auto;
}

.burn-card {
  position: absolute;
  inset: 0;
  border-radius: 5px;
  background:
    linear-gradient(135deg, rgba(40, 22, 18, 0.95), rgba(15, 8, 6, 0.95)),
    repeating-linear-gradient(45deg, transparent 0 3px, rgba(60, 30, 20, 0.4) 3px 4px);
  border: 1px solid rgba(80, 40, 24, 0.7);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

.burn-card::after {
  content: "";
  position: absolute;
  inset: 4px 6px 6px 4px;
  border-radius: 3px;
  background:
    radial-gradient(circle at 30% 70%, rgba(180, 120, 60, 0.18), transparent 60%),
    radial-gradient(circle at 70% 30%, rgba(140, 80, 40, 0.14), transparent 55%);
}

.burn-pile:empty::before {
  content: "·";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, 0.18);
  font-size: 1.4rem;
}

.burn-flame {
  --burn-scale: 1;
  --burn-intensity: 0.6;
  --burn-duration: 1100ms;
  position: absolute;
  left: 50%;
  bottom: 28px;
  width: 1px;
  height: 1px;
  pointer-events: none;
  opacity: 0;
  z-index: 5;
}

.burn-flame.is-burning {
  animation: burn-flash var(--burn-duration) ease-out forwards;
}

.burn-flame.is-burning::before,
.burn-flame.is-burning::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  width: calc(34px * var(--burn-scale));
  height: calc(72px * var(--burn-scale));
  margin-left: calc(-17px * var(--burn-scale));
  border-radius: 50% 50% 30% 30% / 60% 60% 30% 30%;
  background:
    radial-gradient(circle at 50% 88%, #fff3c0 0%, #ffd066 18%, #ff9a3c 42%, #d24a1a 70%, transparent 88%);
  filter: blur(calc(2px * var(--burn-scale))) drop-shadow(0 0 calc(18px * var(--burn-scale)) rgba(255, 130, 50, var(--burn-intensity)));
  animation: flame-flicker 0.16s ease-in-out infinite alternate;
  transform-origin: 50% 100%;
  opacity: var(--burn-intensity);
}

.burn-flame.is-burning::after {
  width: calc(54px * var(--burn-scale));
  height: calc(46px * var(--burn-scale));
  margin-left: calc(-27px * var(--burn-scale));
  background:
    radial-gradient(circle at 50% 90%, rgba(255, 220, 120, 0.7), rgba(210, 90, 30, 0.55) 55%, transparent 80%);
  animation-duration: 0.22s;
  opacity: calc(var(--burn-intensity) * 0.85);
}

.burn-spark {
  position: absolute;
  left: 50%;
  bottom: 4px;
  width: 4px;
  height: 4px;
  margin-left: -2px;
  border-radius: 999px;
  background: radial-gradient(circle, #fff2b2 0%, #ff9a3c 50%, transparent 80%);
  filter: blur(0.5px) drop-shadow(0 0 4px rgba(255, 180, 90, 0.9));
  opacity: 0;
}

.burn-flame.is-burning .burn-spark {
  animation: spark-fly var(--burn-duration) cubic-bezier(0.4, 0.05, 0.6, 1) forwards;
}

@keyframes burn-flash {
  0% { opacity: 0; }
  18% { opacity: 1; }
  72% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes flame-flicker {
  from { transform: scaleY(1) rotate(-2deg); }
  to { transform: scaleY(1.18) rotate(2deg); }
}

@keyframes spark-fly {
  0% {
    opacity: 1;
    transform: rotate(var(--spark-angle, 0deg)) translateY(0) scale(1);
  }
  90% { opacity: 0.8; }
  100% {
    opacity: 0;
    transform: rotate(var(--spark-angle, 0deg)) translateY(calc(-1 * var(--spark-dist, 60px))) scale(0.4);
  }
}

.pile-zone {
  display: grid;
  grid-template-columns: minmax(190px, 330px) minmax(0, 1fr);
  align-items: center;
  gap: 18px;
  min-height: 190px;
  padding: 18px;
}

.pile-cards {
  display: flex;
  min-height: 138px;
  align-items: center;
}

.pile-cards .card {
  margin-right: -50px;
}

.pile-card.is-flipping > .card {
  animation: pile-flip 520ms cubic-bezier(0.2, 0.8, 0.3, 1.1) both;
  transform-origin: center center;
  backface-visibility: hidden;
}

.pile-card.is-flipping > .card.is-flying {
  animation: pile-fly 720ms cubic-bezier(0.22, 0.7, 0.25, 1.05) both;
  z-index: 200;
}

@keyframes pile-flip {
  0% {
    transform: translateY(-30px) rotateY(180deg) scale(0.85);
    opacity: 0;
  }
  55% {
    transform: translateY(-4px) rotateY(0deg) scale(1.08);
    opacity: 1;
  }
  100% {
    transform: none;
    opacity: 1;
  }
}

@keyframes pile-fly {
  0% {
    transform: translate(var(--fly-x, 0), var(--fly-y, -30px)) rotateY(180deg) scale(0.55);
    opacity: 0;
    filter: drop-shadow(0 16px 24px rgba(0, 0, 0, 0.6));
  }
  20% {
    opacity: 1;
  }
  60% {
    transform: translate(0, -6px) rotateY(0deg) scale(1.1);
    opacity: 1;
    filter: drop-shadow(0 12px 22px rgba(0, 0, 0, 0.55));
  }
  100% {
    transform: none;
    opacity: 1;
    filter: none;
  }
}

.pile-zone p {
  margin: 0 0 8px;
  color: var(--gold);
  font-weight: 900;
}

.pile-zone strong {
  display: block;
  color: var(--text);
  font-size: clamp(1rem, 2.4vw, 1.45rem);
}

.player-board {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.board-head p {
  margin: 5px 0 0;
  color: var(--muted);
}

.actions button,
.demo-controls button {
  min-width: 96px;
}

.actions button:first-child,
.primary {
  background: var(--gold);
  color: #1d170c;
  border-color: transparent;
  font-weight: 900;
}

.tableau {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.tableau-stacks {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-start;
}

.card-stack {
  position: relative;
  flex: 0 0 auto;
  width: 92px;
  height: 142px;
}

.card-stack > .card {
  position: absolute;
  left: 0;
  margin: 0;
  width: 92px;
  height: 128px;
  min-height: 128px;
}

.card-stack > .stack-down {
  top: 0;
  z-index: 1;
}

.card-stack > .stack-up {
  top: 14px;
  z-index: 2;
}

.card-stack.mini {
  width: 38px;
  height: 60px;
}

.card-stack.mini > .card {
  width: 38px;
  height: 54px;
  min-height: 54px;
}

.card-stack.mini > .stack-up {
  top: 6px;
}

.zone-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.card {
  position: relative;
  display: block;
  width: 92px;
  height: 128px;
  flex: 0 0 auto;
  overflow: hidden;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  box-shadow:
    0 11px 22px rgba(0, 0, 0, 0.34),
    0 2px 0 rgba(255, 255, 255, 0.12);
  font-size: 1rem;
  font-weight: 900;
}

.card::before {
  content: none;
}

.card-svg {
  display: block;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.2));
}

/* card SVG fonts are now set inline (Refined Felt — Cormorant + Georgia) */

.card.red {
  color: #ad2d2d;
}

.card.black {
  color: #18211b;
}

.corner {
  position: absolute;
  display: grid;
  justify-items: center;
  min-width: 18px;
  line-height: 0.9;
  z-index: 2;
}

.corner b {
  font-size: 0.78rem;
}

.corner i {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.78rem;
  font-style: normal;
}

.corner.top {
  top: 8px;
  left: 8px;
}

.corner.bottom {
  right: 8px;
  bottom: 8px;
  transform: rotate(180deg);
}

.card-art {
  position: absolute;
  inset: 24px 15px;
  display: grid;
  place-items: center;
  font-family: Georgia, "Times New Roman", serif;
}

.card-art strong {
  font-size: 2.05rem;
  line-height: 1;
}

.card-art span {
  font-size: 0.88rem;
  line-height: 1;
}

.pips-2,
.pips-3,
.pips-4,
.pips-5,
.pips-6,
.pips-7,
.pips-8,
.pips-9,
.pips-10 {
  grid-template-columns: repeat(2, 1fr);
  align-content: space-between;
}

.pips-3 span:nth-child(3),
.pips-5 span:nth-child(5),
.pips-7 span:nth-child(7),
.pips-9 span:nth-child(9) {
  grid-column: 1 / -1;
}

.pips-10 span {
  font-size: 0.72rem;
}

.card.back {
  border-color: #d7bd76;
  background:
    radial-gradient(circle at 50% 50%, rgba(229, 184, 95, 0.28) 0 22%, transparent 23%),
    linear-gradient(45deg, rgba(255, 255, 255, 0.09) 25%, transparent 25% 50%, rgba(255, 255, 255, 0.09) 50% 75%, transparent 75%),
    linear-gradient(135deg, #254d3d, #13281f);
  background-size: 100% 100%, 14px 14px, auto;
  color: #f4d889;
}

.back-emblem {
  position: absolute;
  inset: 50% auto auto 50%;
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid rgba(244, 216, 137, 0.7);
  border-radius: 999px;
  background: rgba(16, 21, 17, 0.58);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.15rem;
  transform: translate(-50%, -50%);
}

.joker-art strong {
  max-width: 48px;
  color: #3b2424;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 0.95rem;
  text-align: center;
  overflow-wrap: anywhere;
}

.card.mini {
  width: 66px;
  height: 92px;
  min-height: 92px;
  font-size: 1rem;
}

.card.burned {
  background: #2f1917;
  color: #ffb28c;
  border-color: rgba(255, 178, 140, 0.5);
}

button.card {
  min-height: 128px;
  padding: 0;
}

button.card.is-playable {
  border-color: var(--green);
}

button.card:disabled {
  opacity: 0.64;
}

.hand-zone {
  display: grid;
  gap: 8px;
}

.hand-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 4px 0 2px;
}

.hand-actions button {
  min-width: 140px;
  min-height: 46px;
  border-radius: 10px;
  font-weight: 800;
  font-size: 0.95rem;
}

.hand-actions button#pickupButton {
  background: rgba(13, 20, 16, 0.7);
  color: var(--text);
  border-color: var(--line-strong);
  font-weight: 800;
}

.hand-actions button#playButton {
  background: var(--gold);
  color: #1d170c;
  border-color: transparent;
  font-weight: 900;
}

.hand-row {
  flex-wrap: nowrap;
  justify-content: center;
  align-items: flex-end;
  min-height: 156px;
  padding: 12px 4px 8px;
  overflow-x: auto;
  overflow-y: visible;
  scrollbar-width: none;
}

.hand-row::-webkit-scrollbar {
  display: none;
}

.hand-row .card {
  transform-origin: center bottom;
  transition: transform 180ms cubic-bezier(0.2, 0.7, 0.2, 1.1);
}

button.card.is-selected {
  outline: 3px solid var(--gold);
  transform: translateY(-16px) !important;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100vh;
  overflow: auto;
  padding: 16px;
  border-left: 1px solid var(--line);
  background: rgba(13, 18, 15, 0.94);
}

.panel-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  background: var(--panel);
}

.section-title h2 {
  font-size: 1rem;
}

.input-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 7px;
}

.avatar-choice {
  width: 100%;
  min-width: 0;
  height: 58px;
  min-height: 58px;
  padding: 0;
}

.avatar-choice.avatar {
  width: 100%;
  height: 58px;
}

.avatar-choice.is-selected {
  outline: 2px solid var(--gold);
}

.room-code {
  display: grid;
  min-height: 64px;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: #111812;
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: 0.18em;
}

.room-actions {
  align-items: stretch;
}

.room-actions > button {
  flex: 0 0 128px;
}

.join-row {
  flex: 1;
  align-items: stretch;
}

.join-row button {
  flex: 0 0 70px;
}

.join-row input {
  text-transform: uppercase;
}

.player-list {
  display: grid;
  gap: 8px;
}

.player-row {
  min-height: 48px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.player-row span:last-child {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.78rem;
}

.log-section ol {
  display: grid;
  gap: 8px;
  max-height: 190px;
  margin: 0;
  overflow: auto;
  padding-left: 20px;
}

.log-section li {
  padding-right: 4px;
  font-size: 0.88rem;
}

.llm-debug-section {
  border-color: rgba(125, 183, 216, 0.32);
}

.llm-debug-section details {
  display: grid;
  gap: 8px;
}

.llm-debug-section summary {
  cursor: pointer;
  color: var(--blue);
  font-size: 0.82rem;
  font-weight: 900;
}

.llm-debug-section pre {
  max-height: 220px;
  margin: 0;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b1110;
  color: #cfe6dc;
  font-size: 0.72rem;
  line-height: 1.4;
  white-space: pre-wrap;
}

.demo-table {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(54px, 1fr));
  gap: 7px;
  min-height: 100px;
  align-items: center;
}

.demo-table .card {
  width: 58px;
  height: 82px;
  min-height: 82px;
  margin: auto;
  font-size: 0.95rem;
}

.demo-section h3 {
  font-size: 1rem;
}

.demo-section p {
  min-height: 66px;
  margin: 0;
  line-height: 1.45;
}

/* ---------- Mobile redesign — Variant A (Refined Felt) ---------- */

.sheet-toggle {
  display: none;
}

.sheet-handle {
  display: none;
}

.sheet-scrim {
  display: none;
}

.sheet-tabs {
  display: none;
}

.side-panel[data-active-tab] .panel-section {
  /* desktop: tabs ignored, all sections visible */
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0 2px;
  color: var(--text);
  font-size: 0.88rem;
  cursor: pointer;
  user-select: none;
}

.toggle-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-height: 18px;
  margin: 0;
  accent-color: var(--gold);
  cursor: pointer;
}

body.urgent-turn .player-board.is-my-turn {
  animation: urgent-shake 0.4s ease-in-out 3;
  border-color: #ff7f4f;
  box-shadow:
    0 0 0 2px rgba(255, 127, 79, 0.65),
    0 0 36px rgba(255, 127, 79, 0.5);
}

body.urgent-turn::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: none;
  background: radial-gradient(circle at 50% 50%, transparent 50%, rgba(255, 90, 50, 0.18));
  animation: urgent-glow 0.6s ease-in-out;
}

@keyframes urgent-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

@keyframes urgent-glow {
  0%, 100% { opacity: 0; }
  50% { opacity: 1; }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  /* Top bar — brand + connection pill + hamburger */
  .top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  .brand {
    gap: 9px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
  }

  .brand h1 {
    font-size: 1.35rem;
  }

  .brand p {
    font-size: 0.66rem;
  }

  .connection {
    display: none;
  }

  .sheet-toggle {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 13px;
    min-height: 36px;
    border: 1px solid rgba(229, 184, 95, 0.35);
    border-radius: 999px;
    background: rgba(13, 20, 16, 0.7);
    color: var(--gold);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    cursor: pointer;
  }

  .sheet-toggle .dot {
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: #aab6a6;
  }

  .sheet-toggle .dot.live {
    background: #78c88c;
    box-shadow: 0 0 0 3px rgba(120, 200, 140, 0.18);
  }

  .sheet-toggle-label {
    color: rgba(243, 245, 235, 0.55);
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.16em;
    line-height: 1;
  }

  .sheet-toggle-code {
    line-height: 1;
    color: var(--gold);
    font-weight: 900;
    letter-spacing: 0.08em;
  }

  .sheet-toggle-icon {
    width: 14px;
    height: 14px;
    margin-left: 2px;
    color: var(--gold);
    opacity: 0.75;
  }

  /* Felt table — tighter padding on mobile */
  .table {
    gap: 12px;
    padding: 12px 12px 84px;
  }

  /* Opponents — 2-up grid with mini back fan */
  .opponents {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .opponent {
    padding: 7px 8px;
    border: 1px solid rgba(226, 238, 220, 0.14);
    border-radius: 10px;
    background: rgba(11, 17, 13, 0.55);
    box-shadow: none;
    display: grid;
    gap: 6px;
  }

  .opponent.is-turn {
    border-color: var(--gold);
    box-shadow: 0 0 0 1px rgba(230, 184, 94, 0.25), 0 8px 18px rgba(0, 0, 0, 0.3);
  }

  .opponent-head {
    display: flex;
    align-items: center;
    gap: 7px;
  }

  .opponent .avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
  }

  .opponent-meta-block {
    display: grid;
    line-height: 1.1;
    min-width: 0;
  }

  .opponent strong {
    font-size: 0.76rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .opponent-meta {
    color: rgba(243, 245, 235, 0.55);
    font-size: 0.6rem;
    letter-spacing: 0.04em;
  }

  .turn-chip {
    margin-left: auto;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--gold);
    color: #1d170c;
    font-size: 0.55rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
  }

  .opponent-mini {
    display: flex;
    padding-left: 4px;
    min-height: 30px;
  }

  .mini-back {
    width: 22px;
    height: 30px;
    border-radius: 4px;
    background: linear-gradient(135deg, #244b3a, #112619);
    border: 1px solid rgba(195, 155, 74, 0.4);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
  }

  .opponent-zones .zone-label {
    font-size: 0.55rem;
  }

  .opponent .tiny-row .card.mini {
    width: 24px;
    height: 34px;
    min-height: 34px;
    font-size: 0.6rem;
  }

  /* Center board — single column, draw/burn on a row */
  .center-board {
    grid-template-columns: 70px minmax(0, 1fr) 70px;
    gap: 8px;
    padding: 0;
  }

  .draw-stack,
  .burn-stack {
    min-height: 104px;
    padding: 8px 4px;
    border-radius: 10px;
  }

  .draw-stack span,
  .burn-stack span {
    font-size: 0.62rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
  }

  .pile-zone {
    grid-template-columns: 1fr;
    gap: 8px;
    min-height: 138px;
    padding: 10px;
    border-radius: 10px;
  }

  .pile-zone p {
    font-size: 0.86rem;
  }

  .pile-zone strong {
    font-size: 0.78rem;
  }

  .pile-cards {
    position: relative;
    justify-content: center;
    min-height: 84px;
  }

  .pile-cards .pile-card {
    position: relative;
  }

  .pile-cards .pile-card + .pile-card {
    margin-left: -38px;
  }

  .pile-cards .pile-card .card {
    margin-right: 0;
    width: 56px;
    height: 78px;
  }

  .pile-empty {
    color: rgba(255, 255, 255, 0.3);
    font-size: 0.78rem;
    letter-spacing: 0.08em;
  }

  /* Tableau — overlapping stacks in one row */
  .tableau {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .tableau-stacks {
    gap: 8px;
  }

  .card-stack {
    width: 56px;
    height: 88px;
  }

  .card-stack > .card {
    width: 56px;
    height: 78px;
    min-height: 78px;
  }

  .card-stack > .stack-up {
    top: 8px;
  }

  .player-board {
    padding: 12px;
    gap: 10px;
    border-radius: 12px;
  }

  .board-head {
    display: grid;
    gap: 8px;
  }

  .board-head h2 {
    font-size: 1rem;
  }

  /* Hide the in-card actions (replaced by sticky bar) */
  .board-head .actions {
    display: none;
  }

  /* Default cards — felt mini sizing for tableau / draw / pile */
  .card {
    width: 56px;
    height: 78px;
  }

  button.card {
    min-height: 78px;
  }

  .card.mini {
    width: 38px;
    height: 54px;
    min-height: 54px;
    font-size: 0.85rem;
  }

  /* Hand fan — overlapping, rotated, larger touch targets */
  .hand-row {
    justify-content: center;
    align-items: flex-end;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: visible;
    padding: 14px 6px 12px;
    min-height: 130px;
    scrollbar-width: none;
  }

  .hand-row::-webkit-scrollbar {
    display: none;
  }

  .hand-row .card {
    width: 68px;
    height: 96px;
    min-height: 96px;
    transform-origin: center bottom;
    transition: transform 180ms cubic-bezier(0.2, 0.7, 0.2, 1.1);
  }

  button.card.is-selected {
    transform: translateY(-18px) !important;
    outline: 2px solid var(--gold);
  }

  /* Avatar grid in profile sheet */
  .avatar-grid {
    grid-template-columns: repeat(6, 1fr);
  }

  /* ---------- Sticky thumb-zone action bar ---------- */
  .player-board {
    position: relative;
  }

  .player-board::after {
    content: "";
    display: block;
    height: 4px;
  }

  /* Floating action bar (uses existing buttons cloned into a fixed slot
     by re-using the .actions buttons; here we float them at bottom) */
  .actions {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    z-index: 60;
    display: grid !important;
    grid-template-columns: 1fr 1.4fr;
    gap: 8px;
    padding: 0;
  }

  .actions button {
    min-height: 50px;
    border-radius: 12px;
    font-size: 0.95rem;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.4);
  }

  /* Show floating action bar by re-mounting via duplicate? — instead make
     the in-board actions visible & fixed using the markup we already have. */

  /* ---------- Bottom sheet (side panel) ---------- */
  .sheet-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 70;
    background: rgba(0, 0, 0, 0.5);
    opacity: 1;
    transition: opacity 220ms;
  }

  .sheet-scrim[hidden] {
    display: block;
    opacity: 0;
    pointer-events: none;
  }

  .side-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 80;
    height: auto;
    max-height: 86vh;
    padding: 4px 14px 22px;
    border-left: 0;
    border-top: 1px solid rgba(229, 184, 95, 0.35);
    border-radius: 18px 18px 0 0;
    background: #14201a;
    box-shadow: 0 -20px 40px rgba(0, 0, 0, 0.5);
    transform: translateY(100%);
    transition: transform 280ms cubic-bezier(0.2, 0.7, 0.2, 1);
    overflow: auto;
  }

  .side-panel.is-half {
    transform: translateY(40%);
  }

  .side-panel.is-full {
    transform: translateY(0%);
  }

  .sheet-handle {
    position: sticky;
    top: 0;
    z-index: 1;
    display: grid;
    place-items: center;
    width: 100%;
    min-height: 22px;
    margin: 0 0 6px;
    padding: 8px 0 4px;
    border: 0;
    background: #14201a;
    cursor: pointer;
  }

  .sheet-handle span {
    display: block;
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.2);
  }

  .panel-section {
    border-radius: 12px;
  }

  /* Sheet tabs */
  .sheet-tabs {
    position: sticky;
    top: 26px;
    z-index: 1;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    padding: 6px 0 8px;
    margin: 0 0 8px;
    background: #14201a;
    border-bottom: 1px solid rgba(226, 238, 220, 0.1);
  }

  .sheet-tabs button {
    background: transparent;
    border: 0;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    color: rgba(243, 245, 235, 0.55);
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    font-size: 0.7rem;
    padding: 8px 0;
    min-height: 36px;
  }

  .sheet-tabs button.is-on {
    color: var(--gold);
    border-bottom-color: var(--gold);
  }

  /* Show only the active section */
  .side-panel[data-active-tab] .panel-section {
    display: none;
  }

  .side-panel[data-active-tab="profile"] .panel-section[data-tab="profile"],
  .side-panel[data-active-tab="room"] .panel-section[data-tab="room"],
  .side-panel[data-active-tab="log"] .panel-section[data-tab="log"],
  .side-panel[data-active-tab="demo"] .panel-section[data-tab="demo"] {
    display: grid;
  }

  .side-panel[data-active-tab="log"] .panel-section.llm-debug-section[hidden] {
    display: none;
  }

  /* Commentary — full width on mobile */
  .commentary-bubble {
    width: 100%;
    justify-self: stretch;
    margin-top: 0;
  }
}

@media (max-width: 420px) {
  .brand h1 {
    font-size: 1.2rem;
  }

  .center-board {
    grid-template-columns: 60px minmax(0, 1fr) 60px;
  }

  .hand-row .card {
    width: 62px;
    height: 88px;
    min-height: 88px;
  }
}

/* ---------- Share / QR ---------- */

.room-actions {
  flex-wrap: wrap;
}

.room-actions .share-room {
  flex: 1 0 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
}

.share-room svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.share-room:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Pulse the Join button when arriving via a shared link */
.pulse {
  animation: share-pulse 1.4s ease-in-out infinite;
}

@keyframes share-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229, 184, 95, 0.0); }
  50% { box-shadow: 0 0 0 4px rgba(229, 184, 95, 0.4); }
}

.share-modal {
  width: min(92vw, 360px);
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.share-modal::backdrop {
  background: rgba(8, 12, 10, 0.62);
  backdrop-filter: blur(2px);
}

.share-modal-inner {
  position: relative;
  display: grid;
  gap: 14px;
  padding: 22px 22px 24px;
  text-align: center;
}

.share-modal h2 {
  margin: 0;
  font-size: 1.2rem;
}

.share-sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.share-sub strong {
  color: var(--gold);
  letter-spacing: 0.14em;
}

.share-qr {
  display: grid;
  place-items: center;
  width: 220px;
  max-width: 100%;
  aspect-ratio: 1;
  margin: 0 auto;
  padding: 12px;
  border-radius: 12px;
  background: #ffffff;
}

.share-qr svg {
  display: block;
  width: 100%;
  height: 100%;
}

.share-url {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b1110;
  color: #cfe6dc;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.74rem;
  word-break: break-all;
  user-select: all;
}

.share-buttons {
  display: flex;
  gap: 10px;
}

.share-buttons button {
  flex: 1;
  min-height: 44px;
}

.share-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-size: 1.4rem;
  line-height: 1;
}

/* ---------- Quit / reset ---------- */

.leave-game {
  width: 100%;
  min-height: 42px;
  margin-top: 4px;
  border-color: rgba(215, 94, 84, 0.5);
  color: #f0a99f;
  background: rgba(60, 18, 14, 0.28);
}

.leave-game:hover {
  border-color: var(--red);
  color: #ffd9d2;
}

.leave-game.is-host {
  border-color: rgba(215, 94, 84, 0.7);
  color: #ffb3a8;
  background: rgba(80, 20, 16, 0.4);
}

.confirm-modal {
  width: min(90vw, 320px);
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.confirm-modal::backdrop {
  background: rgba(8, 12, 10, 0.62);
  backdrop-filter: blur(2px);
}

.confirm-inner {
  display: grid;
  gap: 16px;
  padding: 22px;
  text-align: center;
}

.confirm-inner p {
  margin: 0;
  font-size: 1rem;
  line-height: 1.45;
}

.confirm-buttons {
  display: flex;
  gap: 10px;
}

.confirm-buttons button {
  flex: 1;
  min-height: 44px;
}

.confirm-buttons .danger {
  border-color: var(--red);
  background: var(--red);
  color: #2a0f0c;
  font-weight: 800;
}

.confirm-buttons .danger:hover {
  background: #e0685e;
}
