/* ─── CUSTOM PROPERTIES ────────────────────────────────────────────────────── */

:root {
  --paper:        #efe1be;
  --paper-strong: #e0ca93;
  --ink:          #2f2618;
  --ink-soft:     #5a4f3a;
  --ink-border:   rgba(107, 79, 44, 0.35);
  --pink:         #ea739a;
  --pink-dark:    #b2416f;
  --sky:          #d5e6ee;
  
  /* Thematic Backgrounds & Surfaces */
  --bg-gradient:    radial-gradient(circle at top left, rgba(255, 255, 255, 0.55), transparent 30%), linear-gradient(180deg, #f4e7c8 0%, #dbc08e 100%);
  --card:           rgba(255, 250, 236, 0.92);
  --card-solid:     #fffbe8;
  --card-soft:      rgba(255, 251, 242, 0.74);
  --btn-surface:    rgba(255, 252, 245, 0.72);
  --selection-card: linear-gradient(180deg, rgba(255, 252, 243, 0.95), rgba(237, 220, 180, 0.95));
  --qd-draw-btn:    linear-gradient(180deg, #faf2d0 0%, #ebddab 100%);
  --qd-draw-empty:  linear-gradient(180deg, #f6edc8 0%, #e7d8a5 100%);
  
  --border:       rgba(69, 48, 28, 0.22);
  --shadow:       0 24px 48px rgba(71, 44, 20, 0.16);
  
  /* Focus indicators */
  --focus-color:  #ef4102;
  --focus-outline: 3px solid var(--focus-color);
  --focus-offset: 2px;
  
  /* Motion */
  --transition-fast: 160ms;
  --transition-medium: 340ms;
  --transition-slow: 600ms;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  :root {
    --paper:        #2a241a;
    --paper-strong: #3b3224;
    --ink:          #e8dcc5;
    --ink-soft:     #a89f8d;
    --ink-border:   rgba(220, 200, 180, 0.35);
    
    /* Thematic Backgrounds & Surfaces */
    --bg-gradient:    radial-gradient(circle at top left, rgba(255, 255, 255, 0.05), transparent 30%), linear-gradient(180deg, #2a241a 0%, #1a1610 100%);
    --card:           rgba(30, 26, 20, 0.92);
    --card-solid:     #1e1a14;
    --card-soft:      rgba(40, 35, 28, 0.8);
    --btn-surface:    rgba(45, 40, 32, 0.8);
    --selection-card: linear-gradient(180deg, rgba(50, 45, 35, 0.95), rgba(30, 25, 20, 0.95));
    --qd-draw-btn:    linear-gradient(180deg, #3d3422 0%, #292316 100%);
    --qd-draw-empty:  linear-gradient(180deg, #2d261a 0%, #1f1a12 100%);
    
    --border:       rgba(220, 200, 180, 0.22);
    --shadow:       0 24px 48px rgba(0, 0, 0, 0.6);
  }
}

/* Respect user's motion preferences */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ─── PORTRAIT BLOCKER ─────────────────────────────────────────────────────── */

.portrait-blocker {
  display: none;
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #2f2618 0%, #1a1610 100%);
  z-index: 10000;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 20px;
  color: #efe1be;
}

.portrait-blocker-content {
  max-width: 300px;
  animation: fadeInUp 0.5s ease-out;
}

.portrait-blocker h2 {
  font-family: 'Arial Black', 'Arial Narrow', Arial, sans-serif;
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
  color: #ef4102;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.portrait-blocker p {
  font-size: 1.1rem;
  margin-bottom: 2rem;
  opacity: 0.9;
}

.rotate-animation {
  width: 80px;
  height: 140px;
  margin: 0 auto;
  position: relative;
}

.phone-icon {
  width: 60px;
  height: 100px;
  background: #ef4102;
  border-radius: 8px;
  margin: 20px auto;
  position: relative;
  animation: rotatePhone 3s ease-in-out infinite;
  box-shadow: 0 4px 20px rgba(239, 65, 2, 0.4);
}

.phone-icon::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 50px;
  height: 80px;
  background: #2f2618;
  border-radius: 4px;
}

.phone-icon::after {
  content: '';
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 4px;
  background: #efe1be;
  border-radius: 2px;
}

@keyframes rotatePhone {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(90deg); }
}

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

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

@media screen and (orientation: portrait) and (max-width: 1024px) {
  .portrait-blocker { display: flex; }
  .page-shell { display: none; }
  body { overflow: hidden; }
}

@media screen and (max-height: 500px) and (orientation: landscape) {
  .page-shell { display: flex; }
  .portrait-blocker { display: none; }
}

/* ─── GLOBAL RESET & BASE ──────────────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -moz-tab-size: 4;
  tab-size: 4;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: Georgia, "Palatino Linotype", "Book Antiqua", Palatino, serif;
  color: var(--ink);
  line-height: 1.5;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--bg-gradient);
}

body.in-game {
  overflow: hidden;
}

.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--ink);
  color: var(--paper);
  padding: 8px;
  text-decoration: none;
  z-index: 100;
  border-radius: 0 0 4px 0;
  font-weight: bold;
}

.skip-link:focus { top: 0; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: var(--focus-outline);
  outline-offset: var(--focus-offset);
}

button:focus-visible,
.character-card:focus-visible,
.cpu-card:focus-visible {
  outline: var(--focus-outline);
  outline-offset: var(--focus-offset);
  box-shadow: 0 0 0 4px rgba(239, 65, 2, 0.2);
}

button,
.character-card,
.cpu-card {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p { margin-top: 0; }

h1 {
  margin-bottom: 0.25rem;
  font-size: clamp(1.55rem, 2.4vw, 2.3rem);
  font-family: Impact, 'Arial Black', Arial, sans-serif;
  line-height: 1.2;
}

.hidden { display: none !important; }

.subtitle {
  margin-bottom: 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
  line-height: 1.4;
}

/* ─── PAGE SHELL & NAVIGATION ──────────────────────────────────────────────── */

.page-shell {
  height: 100dvh;
  padding: 8px 8px 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  contain: layout style;
}

.app-layout {
  display: grid;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  height: 100vh;
  max-height: 100vh;
  box-sizing: border-box;
  contain: layout;
}

/* ─── SHARED PANEL STYLES ──────────────────────────────────────────────────── */

.setup-panel,
.panel,
.choice-panel,
.rules-drawer {
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.panel {
  border-radius: 24px;
  padding: 10px;
  min-height: 0;
  contain: content;
}

/* ─── BUTTONS ──────────────────────────────────────────────────────────────── */

.ghost-button,
.primary-button,
.spinner-button,
.choice-button {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 13px;
  cursor: pointer;
  transition: transform var(--transition-fast) ease, 
              background-color var(--transition-fast) ease, 
              box-shadow var(--transition-fast) ease, 
              opacity var(--transition-fast) ease;
  font: inherit;
  line-height: 1.2;
}

.ghost-button,
.choice-button {
  background: var(--btn-surface);
  color: var(--ink);
}

.ghost-button:hover,
.primary-button:hover,
.spinner-button:hover,
.choice-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.12);
}

.ghost-button:active,
.primary-button:active,
.spinner-button:active,
.choice-button:active {
  transform: translateY(0);
}

.primary-button,
.spinner-button {
  background: linear-gradient(180deg, #ef4102 0%, #e05014 100%);
  color: #fff9f0;
  font-family: 'Arial Black', 'Arial Narrow', Arial, sans-serif;
  font-size: 1.1em;
  font-variant: normal;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1;
  font-weight: 900;
}

.primary-button:disabled,
.spinner-button:disabled,
.choice-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.spinner-button {
  padding: 10px 18px 9px;
  border: 2px solid #3b1f0e;
  border-radius: 16px 22px 18px 20px;
  color: #fff8dc;
  font-weight: 900;
  font-size: 1.08em;
  letter-spacing: 0.04em;
  text-shadow: none;
  box-shadow: 0 4px 0 #612210, 0 12px 16px rgba(0, 0, 0, 0.2);
}

.spinner-button:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 6px 0 #612210, 0 14px 20px rgba(0, 0, 0, 0.24);
}

.spinner-button:active:not(:disabled) {
  transform: translateY(2px) scale(0.99);
  box-shadow: 0 2px 0 #612210, 0 6px 10px rgba(0, 0, 0, 0.2);
}

/* ─── SETUP SCREEN ─────────────────────────────────────────────────────────── */

.setup-panel {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0;
  border-radius: 28px;
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
  contain: layout;
}

.setup-hero-container {
  position: relative;
  width: 100%;
  max-height: 28vh;
  background: linear-gradient(180deg, #ef4102 0%, #e05014 100%);
  border-radius: 28px 28px 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  contain: paint;
}

.setup-hero {
  display: block;
  max-width: 100%;
  max-height: 28vh;
  width: auto;
  height: auto;
  object-fit: contain;
}

.setup-start-btn {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  padding: 13px 40px;
  font-family: 'Arial Black', 'Arial Narrow', Arial, sans-serif;
  font-variant: normal;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 900;
  font-size: 1.1em;
  line-height: 1;
  text-shadow: none;
  background: linear-gradient(180deg, #ef4102 0%, #e05014 100%);
  border: 2px solid #6b0a04;
  box-shadow: 0 4px 18px rgba(180, 20, 10, 0.55);
  white-space: nowrap;
}

.setup-start-btn:hover,
.setup-start-btn:focus-visible {
  transform: translateX(-50%) translateY(-1px);
  box-shadow: 0 6px 24px rgba(180, 20, 10, 0.65);
}

.setup-content {
  padding: 28px;
  display: grid;
  gap: 28px;
  background: var(--card);
  border-radius: 0 0 28px 28px;
}

.character-select,
.cpu-select {
  display: grid;
  gap: 14px;
  border: none;
  padding: 0;
  margin: 0;
  min-width: 0;
}

.setup-heading {
  margin: 0;
  text-align: center;
  font-family: 'Arial Black', 'Arial Narrow', Arial, sans-serif;
  font-size: 1.1em;
  font-weight: 700;
}

.character-grid,
.cpu-grid {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.character-card,
.cpu-card {
  border-radius: 22px;
  border: 1px solid var(--border);
  background: var(--selection-card);
  padding: 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  cursor: pointer;
  align-items: center;
  transition: outline-offset var(--transition-fast) ease, 
              box-shadow var(--transition-fast) ease;
  position: relative;
}

.character-card { width: 140px; }
.cpu-card { width: 130px; }

.character-card[aria-checked="true"],
.cpu-card[aria-checked="true"],
.character-card.selected,
.cpu-card.selected {
  outline: 4px solid #ef4102;
  outline-offset: 2px;
  border-color: rgba(197, 72, 18, 0.65);
  box-shadow: 0 10px 18px rgba(239, 65, 2, 0.24);
}

.character-card .pawn {
  position: static;
  width: 96px;
  height: 120px;
  transform: none;
  margin: 0 auto;
  display: block;
}

.character-card .pawn-inner { width: 100%; height: 100%; }
.character-card .pawn-name { font-size: 13px !important; color: #111; } /* Keeping #111 as it's overlay on character image */

.character-card[data-character-id="blabber"]      .pawn-name { bottom: 13% !important; }
.character-card[data-character-id="snooper"]      .pawn-name { bottom: 14% !important; }
.character-card[data-character-id="doggie-daddy"] .pawn-name { bottom: 10% !important; }
.character-card[data-character-id="baba-looey"]   .pawn-name { bottom:  6% !important; }

.portrait {
  width: 96px;
  height: 120px;
  border-radius: 12px;
  overflow: hidden;
  background: transparent;
  flex-shrink: 0;
  border: none;
  box-shadow: none;
  contain: paint;
}

.portrait-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
}

/* ─── GAME SHELL & BOARD ───────────────────────────────────────────────────── */

.game-shell {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1.55fr) minmax(220px, 280px);
  gap: 0;
  align-items: start;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  contain: strict;
}

.board-column {
  display: grid;
  gap: 4px;
  grid-template-rows: 1fr auto;
  min-height: 0;
}

.board-stage {
  position: relative;
  border-radius: 30px;
  padding: 10px;
  border: none;
  min-height: 70vh;
  max-height: 94vh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  contain: layout style paint;
}

.board-surface {
  margin-top: 14px;
  position: relative;
  width: min(100%, calc(94vh * 0.919));
  aspect-ratio: 953 / 1037;
  contain: layout;
}

.board-image {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 20px;
  object-fit: fill;
  user-select: none;
  -webkit-user-drag: none;
}

.board-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  contain: layout;
}

.pile-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  contain: layout;
}

/* ─── PILES ────────────────────────────────────────────────────────────────── */

.pile-stack {
  position: absolute;
  width: 9.2%;
  min-width: 48px;
  max-width: 104px;
  aspect-ratio: 5 / 7;
  transform: translate(-50%, -50%) rotate(var(--pile-angle, 0deg));
  contain: layout;
}

.pile-layers { position: absolute; inset: 0; }

.pile-layer {
  position: absolute;
  inset: 0;
  border-radius: 4px;
  border: 1px solid rgba(77, 58, 36, 0.7);
  background: linear-gradient(180deg, #fff9e9 0%, #e7d6b0 100%);
  transform: translate(
    calc(var(--layer-index) * -0.4px),
    calc(var(--layer-index) * -1.3px)
  );
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.18);
  contain: paint;
}

.pile-count {
  position: absolute;
  top: -8px;
  right: -10px;
  min-width: 19px;
  height: 19px;
  border-radius: 999px;
  border: 1px solid rgba(77, 46, 21, 0.55);
  background: linear-gradient(180deg, #fff4d8, #e8c17a);
  color: #3e2915;
  font-size: clamp(9px, 0.88vw, 11px);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.28);
  z-index: 1;
}

.pile-stack.is-empty .pile-count {
  background: linear-gradient(180deg, #efe9de, #d5c9b5);
  color: rgba(64, 47, 29, 0.8);
}

/* ─── PAWNS ────────────────────────────────────────────────────────────────── */

.pawn {
  position: absolute;
  width: 11.25%;
  min-width: 54px;
  max-width: 120px;
  display: block;
  overflow: visible;
  background: transparent;
  transform: translate(-50%, -50%);
  will-change: left, top, transform;
  transition: left 220ms cubic-bezier(0.25, 0, 0.25, 1), 
              top 220ms cubic-bezier(0.25, 0, 0.25, 1), 
              transform 200ms cubic-bezier(0.25, 0, 0.25, 1);
  contain: layout;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .pawn { transition: none; }
}

.pawn[data-moving="true"] {
  transform: translate(-50%, calc(-50% - 10px)) scale(1.08);
}

.pawn-inner { position: relative; width: 100%; }

.pawn-img {
  width: 100%;
  aspect-ratio: 1 / 1.25;
  object-fit: contain;
  object-position: center;
  background: transparent;
  display: block;
  position: relative;
  transform-origin: center center;
  transition: transform var(--transition-fast) ease;
  user-select: none;
  -webkit-user-drag: none;
}

.pawn--facing-left .pawn-img { transform: scaleX(-1); }

.pawn-name {
  position: absolute;
  bottom: 9%;
  left: 0;
  right: 0;
  text-align: center;
  font-family: 'Arial Black', Impact, 'Arial Narrow', Arial, sans-serif;
  font-size: clamp(6px, 1vw, 12px);
  font-weight: 800;
  color: #111;
  line-height: 1.25;
  white-space: nowrap;
  word-break: normal;
  hyphens: none;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  text-shadow: -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff, 0 0 4px rgba(255, 255, 255, 0.9);
  direction: ltr;
  pointer-events: none;
  user-select: none;
}

.pawn-name--double { bottom: 1.5%; line-height: 1.05; white-space: normal; }

/* ─── SPINNER ──────────────────────────────────────────────────────────────── */

.spinner-dock {
  position: absolute;
  width: min(340px, 48vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin-top: 32px;
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  transition: transform var(--transition-medium) ease, opacity var(--transition-medium) ease;
  z-index: 999;
  pointer-events: auto;
}

.spinner-dock--hidden { opacity: 0; pointer-events: none; }

.spinner-dock[data-side="bottom"],
.spinner-dock[data-side="right"] {
  right: 10px;
  bottom: 10px;
  transform: translate(120%, 0);
}

.spinner-dock[data-side="top"],
.spinner-dock[data-side="left"] {
  position: static;
  inset: unset;
  transform: none;
  z-index: auto;
  opacity: 1;
  transition: none;
  margin: 0 auto;
}

.spinner-dock.is-visible[data-side="bottom"],
.spinner-dock.is-visible[data-side="right"],
.spinner-dock.is-visible[data-side="top"],
.spinner-dock.is-visible[data-side="left"] {
  margin-top: 48px;
  opacity: 1;
}

.spinner-dock[data-side="center"] {
  left: 50% !important;
  top: 50% !important;
  right: auto !important;
  bottom: auto !important;
  max-width: 240px;
  max-height: 240px;
}

.spinner-dock[data-side="center"] .spinner-button {
  min-width: 260px;
  display: block;
}

.spinner-dock .spinner-assembly {
  margin-top: -30px;
  margin-bottom: 8px;
  max-width: 260px;
  max-height: 260px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  contain: layout;
}

.spinner-dock .spinner-wheel {
  max-width: 240px;
  max-height: 240px;
  width: 100%;
  height: auto;
}

.spinner-wheel {
  width: min(248px, 34vw);
  aspect-ratio: 1;
  position: relative;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #000;
  padding: 1px;
  overflow: hidden;
  contain: paint;
}

.spinner-assembly {
  position: relative;
  width: min(248px, 34vw);
  aspect-ratio: 1;
  left: 0;
}

.spinner-face {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  border-radius: 50%;
  user-select: none;
  pointer-events: none;
  -webkit-user-drag: none;
}

.spinner-pointer {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 96%;
  height: 96%;
  object-fit: contain;
  transform: translate(-50%, -50%) rotate(-135deg);
  transform-origin: 50% 50%;
  pointer-events: none;
  transition: transform 1.2s cubic-bezier(0.18, 0.89, 0.22, 1);
  user-select: none;
  -webkit-user-drag: none;
}

@media (prefers-reduced-motion: reduce) {
  .spinner-pointer { transition: none; }
}

.spinner-value {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.spinner-card {
  background: var(--card-solid) !important;
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-width: 340px;
  min-height: 440px;
  padding: 8px 24px 32px;
  overflow: hidden;
  max-width: 96vw;
  max-height: 96vh;
  opacity: 1 !important;
  contain: layout;
}

.spinner-header,
.challenge-context {
  font-family: 'Arial Black', 'Arial Narrow', Arial, sans-serif;
  font-variant: small-caps;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 900;
  font-size: 1.13em;
  text-align: center;
  color: var(--ink);
  background: transparent;
  border: none;
  padding: 0;
}

.spinner-header {
  margin: 0 0 2px;
  padding: 16px 0 10px;
  width: 100%;
  font-size: 1.25em;
  z-index: 2;
  border-bottom: 2px solid transparent;
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  position: relative;
}

/* ─── SIDEBARS & PLAYER CARDS ──────────────────────────────────────────────── */

.sidebar-left,
.sidebar-right {
  display: grid;
  gap: 80px;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
}

.sidebar-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  min-height: 52px;
}

.sidebar-right-offset { min-height: 52px; }

.player-panel {
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player-card {
  border-radius: 18px;
  border: 1px solid var(--border);
  padding: 9px;
  margin: 8px;
  background: var(--card-soft);
  transition: outline var(--transition-fast) ease;
  contain: layout;
}

.player-card.current-turn {
  outline: 3px solid #ef4102;
  outline-offset: 0;
  box-shadow: 0 0 0 2px rgba(224, 80, 20, 0.32);
}

.player-card-header {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin-bottom: 8px;
}

.player-name {
  margin-bottom: 2px;
  font-size: 1rem;
  font-weight: 600;
}

.player-meta {
  margin-bottom: 0;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.hand-toggle-btn {
  background: none;
  border: none;
  border-bottom: 1px dotted var(--ink-border);
  padding: 0;
  cursor: pointer;
  text-align: left;
  color: var(--ink-soft);
  font-size: 0.85rem;
  line-height: inherit;
  transition: color 120ms ease, border-bottom-color 120ms ease;
  font-family: inherit;
}

.hand-toggle-btn:hover,
.hand-toggle-btn:focus-visible {
  color: var(--ink);
  border-bottom-color: var(--ink);
  transform: none;
  box-shadow: none;
}

.hand-reveal {
  display: none;
  grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
  gap: 4px;
  padding: 6px 0;
  margin-bottom: 6px;
  contain: layout;
}

.hand-reveal.is-open { display: grid; }

.hand-card {
  position: relative;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid rgba(71, 54, 30, 0.35);
  background: var(--card-swatch, #ccc);
  aspect-ratio: 5 / 7;
  contain: paint;
}

.hand-card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.hand-card--missing .hand-card-img { display: none; }

.hand-card-label {
  display: none;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  text-align: center;
  padding: 3px 2px;
  line-height: 1.2;
  pointer-events: none;
  user-select: none;
}

.hand-card--missing .hand-card-label { display: block; }

.hand-reveal-empty {
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-style: italic;
  margin: 0;
  padding: 2px 0;
  grid-column: 1 / -1;
}

.player-progress { display: grid; gap: 6px; }

.played-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  column-gap: 6px;
  row-gap: 1px;
}

.played-slot {
  min-height: 40px;
  aspect-ratio: 7 / 5;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 0;
  background: rgba(120, 120, 120, 0.15);
  contain: paint;
}

.played-slot--filled { background: var(--btn-surface); }

.played-slot-img {
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: fill;
  object-position: center;
  display: block;
  border-radius: 0;
  user-select: none;
  -webkit-user-drag: none;
}

/* ─── CHOICE PANEL & DIALOGS ───────────────────────────────────────────────── */

.choice-panel {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: min(300px, calc(100% - 24px));
  border-radius: 24px;
  padding: 14px;
  display: grid;
  gap: 10px;
  z-index: 2000;
  contain: layout;
}

.dialog-card {
  max-width: 370px;
  min-width: 0;
  margin: 0 auto;
  text-align: center;
  padding: 18px 12px 22px;
  background: var(--card-solid);
  border-radius: 18px;
  box-shadow: 0 6px 32px rgba(0, 0, 0, 0.4);
  position: relative;
  word-break: break-word;
  overflow-wrap: break-word;
  contain: content;
}

.dialog-card h3 {
  margin-top: 0;
  font-family: 'Arial Black', 'Arial Narrow', Arial, sans-serif;
  font-size: 1.2em;
  font-weight: 700;
}

.dialog-body {
  font-size: 1.08em;
  line-height: 1.5;
  margin-bottom: 1.2em;
  white-space: pre-line;
  word-break: break-word;
}

.dialog-footer { display: flex; justify-content: center; width: 100%; }
.dialog-footer .spinner-button { margin-top: 10px; }

.choice-actions { display: grid; gap: 10px; }

.choice-sublabel {
  display: block;
  font-size: 0.75rem;
  font-style: italic;
  opacity: 0.72;
  margin-top: 2px;
  pointer-events: none;
}

/* ─── QUICK DRAW CHOICE PANEL ──────────────────────────────────────────────── */

.qd-header h3 {
  margin-bottom: 10px;
  font-family: 'Arial Black', 'Arial Narrow', Arial, sans-serif;
}

.qd-draw-section { margin-bottom: 18px; }

.qd-draw-btn {
  width: 100%;
  margin-bottom: 0.5em;
  background: var(--qd-draw-btn);
  border: 1px solid var(--ink-border);
  color: var(--ink);
}

.qd-draw-btn--empty {
  background: var(--qd-draw-empty);
  border-color: var(--ink-border);
  opacity: 0.55;
  filter: saturate(0.72);
  pointer-events: none;
  cursor: not-allowed;
  box-shadow: none;
}

.qd-challenge-label {
  margin-bottom: 6px;
  font-weight: bold;
  font-family: 'Arial Black', 'Arial Narrow', Arial, sans-serif;
}

.qd-challenge-hint {
  margin-bottom: 8px;
  font-size: 0.92em;
  color: var(--ink-soft);
}

.qd-challenge-grid { display: grid; gap: 8px; }
.qd-pass-btn { width: 100%; background: var(--border); color: var(--ink); }

/* ─── WINNER BANNER ────────────────────────────────────────────────────────── */

.winner-banner {
  position: absolute;
  inset: 12px;
  border-radius: 26px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 18px;
  background: rgba(40, 20, 10, 0.92);
  color: #fff6e6;
  font-size: clamp(1.4rem, 2.5vw, 2.4rem);
  z-index: 2001;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.4);
  contain: layout;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.winner-body { display: flex; flex-direction: column; align-items: center; max-width: 100%; }

.winner-character-img {
  width: 110px;
  height: auto;
  margin-bottom: 10px;
  object-fit: contain;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.5));
}

.winner-banner h2 {
  margin: 0 0 10px;
  font-size: 2.2rem;
  font-family: 'Arial Black', 'Arial Narrow', Arial, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.winner-message { font-size: 1.1rem; margin-bottom: 8px; line-height: 1.4; }
.winner-result { font-size: 1.5rem; font-weight: 900; text-transform: uppercase; letter-spacing: 0.05em; }

.winner-banner .winner-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 4px;
  margin: 18px auto 0;
  max-width: 800px;
  width: 100%;
  justify-items: stretch;
  align-items: stretch;
}

.winner-banner .winner-card-img {
  width: 100%;
  height: auto;
  object-fit: fill;
  border-radius: 4px;
  display: block;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  user-select: none;
  -webkit-user-drag: none;
}

/* ─── RULES DRAWER ─────────────────────────────────────────────────────────── */

.rules-drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: min(560px, 100vw);
  height: 100vh;
  height: 100dvh;
  border-radius: 0;
  transform: translateX(-100%);
  transition: transform var(--transition-medium) ease;
  z-index: 1000;
  display: grid;
  grid-template-rows: auto 1fr;
  background: var(--card);
  box-shadow: var(--shadow);
  contain: strict;
}

.rules-drawer.is-open { transform: translateX(0); }

.rules-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 20px 0;
  align-items: start;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
  padding-bottom: 10px;
}

.rules-body {
  overflow: auto;
  padding: 20px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.rules-heading {
  display: block;
  font-weight: 700;
  margin: 18px 0 8px;
  font-family: 'Arial Black', 'Arial Narrow', Arial, sans-serif;
  font-size: 1.1em;
}

.rules-indent { text-indent: 1.6em; }

.house-rules {
  margin-top: 24px;
  padding: 16px;
  border-radius: 20px;
  background: rgba(234, 115, 154, 0.08);
  border: 1px solid rgba(234, 115, 154, 0.2);
}

/* ─── ANIMATIONS: FLYING CARDS ─────────────────────────────────────────────── */

.flying-draw-card {
  position: fixed;
  aspect-ratio: 5 / 7;
  border: 1px solid rgba(77, 58, 36, 0.7);
  border-radius: 4px;
  background: linear-gradient(180deg, #fff9e9 0%, #e7d6b0 100%);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.32);
  pointer-events: none;
  opacity: 1;
  z-index: 90;
  transform: translate(-50%, -50%) rotate(-3deg);
  will-change: left, top, transform, opacity;
  transition:
    left     var(--transition-slow) cubic-bezier(0.25, 0.1, 0.25, 1),
    top      var(--transition-slow) cubic-bezier(0.25, 0.1, 0.25, 1),
    transform var(--transition-slow) cubic-bezier(0.25, 0.1, 0.25, 1),
    opacity  var(--transition-slow) ease;
  contain: layout paint;
}

@media (prefers-reduced-motion: reduce) {
  .flying-draw-card { transition: opacity var(--transition-fast) ease; }
}

.flying-draw-card.is-flying {
  transform: translate(-50%, -50%) rotate(6deg) scale(0.42);
  opacity: 0;
}

.flying-discard-card {
  position: absolute;
  aspect-ratio: 5 / 7;
  border: 1.5px solid #ea739a;
  border-radius: 4px;
  background: linear-gradient(180deg, #fff9e9 0%, #e7d6b0 100%);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.32);
  pointer-events: none;
  z-index: 2002;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
  will-change: opacity, transform;
  contain: layout paint;
}

.flying-discard-card img {
  width: 100%;
  height: auto;
  border-radius: 4px;
  display: block;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  user-select: none;
  -webkit-user-drag: none;
}

.flying-discard-card .discard-x {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 1;
}

.flying-discard-card .discard-x svg {
  width: 90%;
  height: 90%;
  display: block;
  opacity: 0.5;
  filter: drop-shadow(0 0 2px #fff) drop-shadow(0 0 4px #fff6);
}

/* ─── COLOR LABEL CLASSES (challenge dialog) ───────────────────────────────── */

.card-color-white,
.card-color-gray,
.card-color-blue,
.card-color-green,
.card-color-yellow,
.card-color-pink {
  display: block;
  margin: 12px auto 8px;
  font-family: 'Arial Black', 'Arial Narrow', Arial, sans-serif;
  font-variant: small-caps;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 900;
  font-size: 2.1em;
  line-height: 1.08;
  text-align: center;
  border-radius: 5px;
  padding: 2px 8px;
  box-sizing: border-box;
  text-shadow: 0 1px 2px #000, 0 0 2px #fff8, 1px 0 2px #000, -1px 0 2px #000;
}

.card-color-white  { color: #fffdf4 !important; }
.card-color-gray   { color: #bcbcbc !important; }
.card-color-blue   { color: #2a6fd6 !important; }
.card-color-yellow { color: #ffe14a !important; }
.card-color-pink   { color: #ea739a !important; }

.card-color-green {
  color: #43d943 !important;
  text-shadow:
    0 1px 2px #000, 0 0 2px #fff8,
    1px 0 2px #000, -1px 0 2px #000,
    0 0 2px #fff, 0 1.5px 4px #fff;
}

/* ─── RESPONSIVE ───────────────────────────────────────────────────────────── */

@media (max-height: 820px) {
  .setup-hero-container { height: 28vh; align-items: flex-start; }
  .setup-hero { width: 100%; height: 100%; max-width: none; max-height: none; object-fit: cover; object-position: top center; }
}

@media (max-width: 1100px) {
  .game-shell { grid-template-columns: 1fr; height: auto; max-height: none; gap: 10px; padding: 10px; }
  .sidebar-left, .sidebar-right { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: none; gap: 10px; }
  .sidebar-controls, .sidebar-right-offset { min-height: 0; }
  .board-stage { min-height: 60vh; order: -1; }
}

@media (max-width: 760px) {
  .page-shell { padding: 10px 10px 0; overflow: auto; height: auto; }
  .breadcrumbs { font-size: 0.9rem; margin-bottom: 8px; }
  .sidebar-left, .sidebar-right, .cpu-grid { grid-template-columns: 1fr; }
  .board-stage { min-height: 50vh; padding: 10px; }
  .board-overlay { inset: 10px; }
  .choice-panel { left: 10px; right: 10px; bottom: 10px; width: auto; max-height: 80vh; overflow-y: auto; }
  .spinner-dock[data-side="center"] { min-width: auto; width: 90vw; }
  .spinner-card { min-width: auto; width: 100%; min-height: auto; }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .player-card.current-turn { outline: 4px solid CanvasText; }
  .character-card[aria-checked="true"], .cpu-card[aria-checked="true"] {
    outline: 4px solid CanvasText; outline-offset: 4px;
  }
}

/* ─── PLAYER SLOT SETUP GRID ──────────────────────────────────────────────── */

/* Update the character fieldset legend to reflect the new purpose */
.character-select legend {
  max-width: 420px;
}

/* Cards are slightly wider to accommodate the type badge */
.player-slot-card {
  width: 148px;
  gap: 8px;
  transition: outline-offset var(--transition-fast) ease,
              box-shadow var(--transition-fast) ease,
              opacity var(--transition-fast) ease;
}

/* Dim "Off" slots */
.player-slot-card--off {
  opacity: 0.42;
  filter: grayscale(0.6);
}

.player-slot-card--off:hover,
.player-slot-card--off:focus-visible {
  opacity: 0.7;
  filter: grayscale(0.3);
}

/* Badge strip at the bottom of each slot card */
.slot-type-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 100%;
  border-radius: 10px;
  padding: 5px 10px 4px;
  font-family: 'Arial Black', 'Arial Narrow', Arial, sans-serif;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border: 1px solid transparent;
  transition: background var(--transition-fast) ease,
              color var(--transition-fast) ease;
  user-select: none;
}

.slot-type-badge--human {
  background: linear-gradient(180deg, rgba(107, 158, 80, 0.25), rgba(107, 158, 80, 0.1));
  color: #3d6e24;
  border-color: rgba(107, 158, 80, 0.35);
}

@media (prefers-color-scheme: dark) {
  .slot-type-badge--human {
    color: #90cc6a;
    border-color: rgba(107, 158, 80, 0.4);
  }
}

.slot-type-badge--cpu {
  background: linear-gradient(180deg, rgba(91, 184, 243, 0.25), rgba(91, 184, 243, 0.1));
  color: #1a6ea0;
  border-color: rgba(91, 184, 243, 0.35);
}

@media (prefers-color-scheme: dark) {
  .slot-type-badge--cpu {
    color: #7acff7;
    border-color: rgba(91, 184, 243, 0.4);
  }
}

.slot-type-badge--none {
  background: rgba(120, 100, 80, 0.08);
  color: var(--ink-soft);
  border-color: var(--border);
}

.slot-type-icon {
  font-size: 0.9rem;
  line-height: 1;
}

.slot-type-label {
  line-height: 1;
}

/* ─── PLAYER TYPE TAG (in-game sidebar) ───────────────────────────────────── */

.player-type-tag {
  display: inline-block;
  font-family: 'Arial Black', 'Arial Narrow', Arial, sans-serif;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 6px;
  padding: 1px 5px 0;
  vertical-align: middle;
  margin-left: 4px;
  line-height: 1.5;
  user-select: none;
}

.player-type-tag--human {
  background: rgba(107, 158, 80, 0.2);
  color: #3d6e24;
  border: 1px solid rgba(107, 158, 80, 0.35);
}

@media (prefers-color-scheme: dark) {
  .player-type-tag--human {
    color: #90cc6a;
  }
}

.player-type-tag--cpu {
  background: rgba(91, 184, 243, 0.18);
  color: #1a6ea0;
  border: 1px solid rgba(91, 184, 243, 0.3);
}

@media (prefers-color-scheme: dark) {
  .player-type-tag--cpu {
    color: #7acff7;
  }
}


/* ─── ONLINE LOBBY ──────────────────────────────────────────────────────────── */

.lobby-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 2rem 1rem;
  background: var(--bg-gradient);
}

.lobby-inner {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 2.4rem 2.8rem;
  max-width: 480px;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.lobby-title {
  font-family: inherit;
  font-size: 1.55rem;
  color: var(--ink);
  margin: 0 0 .2rem;
  letter-spacing: .03em;
}

.lobby-subtitle {
  color: var(--ink-soft);
  margin: 0;
  line-height: 1.55;
  font-size: .98rem;
}

.lobby-hint {
  color: var(--ink-soft);
  font-size: .88rem;
  margin: .1rem 0;
}

.lobby-mode-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin: .8rem 0 .4rem;
  flex-wrap: wrap;
}

.lobby-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .9rem;
}

.lobby-room-code {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: .22em;
  color: var(--ink);
  background: var(--paper-strong);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: .45rem 1.4rem .45rem 1.6rem; /* offset for letter-spacing */
  line-height: 1;
  user-select: all;
}

.lobby-code-input {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: .18em;
  text-align: center;
  text-transform: uppercase;
  background: var(--paper-strong);
  border: 2px solid var(--border);
  border-radius: 10px;
  color: var(--ink);
  padding: .45rem 1rem;
  width: 11rem;
  outline: none;
}
.lobby-code-input:focus {
  border-color: var(--focus-color);
  box-shadow: 0 0 0 3px rgba(239,65,2,.18);
}

.lobby-player-list {
  display: flex;
  flex-direction: column;
  gap: .45rem;
  width: 100%;
  min-height: 2.5rem;
}

.lobby-player-entry {
  display: flex;
  align-items: center;
  gap: .7rem;
  background: var(--card-soft);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: .45rem .9rem;
  font-size: .95rem;
  color: var(--ink);
}

.lobby-player-entry .player-type-tag {
  margin-left: auto;
  font-size: .78rem;
}

.lobby-error {
  color: #c0392b;
  font-size: .9rem;
  font-weight: 600;
  background: rgba(192,57,43,.08);
  border: 1px solid rgba(192,57,43,.22);
  border-radius: 8px;
  padding: .45rem .9rem;
  width: 100%;
}

.lobby-back {
  margin-top: .2rem;
  font-size: .88rem;
}

/* Spinning wait indicator */
.lobby-spinner-wrap {
  padding: .8rem 0;
}
.lobby-spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--focus-color);
  border-radius: 50%;
  animation: lobby-spin 0.85s linear infinite;
  margin: 0 auto;
}
@keyframes lobby-spin {
  to { transform: rotate(360deg); }
}

/* Play Online button near hero */
.setup-online-btn {
  position: absolute;
  bottom: .9rem;
  right: .9rem;
  font-size: .88rem;
  padding: .38rem .85rem;
  border-radius: 8px;
  z-index: 2;
}

/* Remote player indicator in player cards */
.player-type-tag--remote {
  background: rgba(91,184,243,.18);
  color: #1a78a4;
  border: 1px solid rgba(91,184,243,.35);
}

/* "Waiting for remote player" overlay on spin button */
.spin-waiting-remote {
  opacity: .55;
  cursor: not-allowed;
}


/* ─── LOBBY IDENTITY STEP ──────────────────────────────────────────────────── */

.lobby-label {
  font-size: .88rem;
  font-weight: 600;
  color: var(--ink-soft);
  text-align: left;
  width: 100%;
}

.lobby-char-label {
  margin-top: .3rem;
}

.lobby-identity-row {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  width: 100%;
}

.lobby-name-input {
  font-size: 1.1rem;
  font-weight: 600;
  background: var(--paper-strong);
  border: 2px solid var(--border);
  border-radius: 10px;
  color: var(--ink);
  padding: .5rem .85rem;
  width: 100%;
  outline: none;
  box-sizing: border-box;
}
.lobby-name-input:focus {
  border-color: var(--focus-color);
  box-shadow: 0 0 0 3px rgba(239,65,2,.18);
}

.lobby-char-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .55rem;
  width: 100%;
}

.lobby-char-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .3rem;
  padding: .5rem .3rem .45rem;
  background: var(--card-soft);
  border: 2px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast), opacity var(--transition-fast);
  position: relative;
}
.lobby-char-card img {
  width: 44px; height: 44px;
  object-fit: contain;
  border-radius: 6px;
}
.lobby-char-name {
  font-size: .72rem;
  font-weight: 600;
  color: var(--ink);
  text-align: center;
  line-height: 1.2;
}
.lobby-char-card:hover:not([disabled]) {
  border-color: var(--focus-color);
  background: var(--btn-surface);
}
.lobby-char-card--selected {
  border-color: var(--focus-color);
  background: var(--selection-card);
  box-shadow: 0 0 0 3px rgba(239,65,2,.18);
}
.lobby-char-card--taken {
  opacity: .45;
  cursor: not-allowed;
}
.lobby-char-taken {
  font-size: .65rem;
  color: #c0392b;
  font-weight: 700;
  position: absolute;
  top: .25rem;
  right: .3rem;
}

.lobby-identity-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .55rem;
  width: 100%;
}
