/* Extracted from index.html during the client module split. */
  :root {
    --bg: #0f0a08;
    --bg-2: #1a1410;
    --panel: #2a1f18;
    --panel-2: #38291f;
    --line: #5a4a3a;
    --wood: #6b4a2e;
    --ink: #f5ecd9;
    --ink-dim: #b8a98c;
    --pink: #ff5b8a;
    --pink-glow: #ff5b8acc;
    --teal: #4ad6c8;
    --gold: #f2c94c;
    --good: #6fcf97;
    --bad: #eb5757;
    --card-art-crop: 104%;
    --rail-width: clamp(252px, 18vw, 300px);
    --hand-card-width: clamp(150px, 11vw, 190px);
    /* Zoomed-park trailer tile size; park-view.js reads these for its oval
       layout math, so keep them in sync via the variables only. */
    --zoom-trailer-w: 80px;
    --zoom-trailer-h: 112px;
    --z-stage-card: 40;
    --z-preview: 210;
    --z-modal: 200;
    --z-toast: 225;
    --z-inspector: 230;
  }
  * { box-sizing: border-box; }
  html {
    /* Kill double-tap-to-zoom delays on touch screens without blocking
       pinch-zoom; stop mobile Safari inflating text in landscape. */
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
  }
  html, body {
    margin: 0; padding: 0; height: 100%;
    /* Small-viewport height tracks the collapsing mobile URL bar; older
       browsers ignore the unknown unit and keep 100%. */
    height: 100dvh;
    background: var(--bg);
    background-image:
      radial-gradient(circle at 20% 10%, rgba(255,91,138,0.05), transparent 40%),
      radial-gradient(circle at 80% 90%, rgba(74,214,200,0.04), transparent 40%);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    font-size: 14px;
    overflow: hidden;
  }
  body { display: flex; flex-direction: column; }

  header {
    background: linear-gradient(180deg, #1f1612 0%, #2a1f18 100%);
    border-bottom: 2px solid var(--pink);
    box-shadow: 0 2px 20px rgba(255,91,138,0.15);
    padding: 8px 20px;
    display: flex; align-items: center; gap: 20px;
    flex-wrap: wrap; z-index: 5;
  }
  header h1 {
    margin: 0; font-size: 20px; letter-spacing: 1px;
    color: var(--pink); text-shadow: 0 0 12px var(--pink-glow); font-weight: 800;
  }
  .stat { display: flex; flex-direction: column; line-height: 1.15; }
  .stat .label { font-size: 9px; text-transform: uppercase; color: var(--ink-dim); letter-spacing: 1px; }
  .stat .val { font-size: 16px; font-weight: 700; }
  .stat .val.pink { color: var(--pink); text-shadow: 0 0 8px var(--pink-glow); }
  .stat .val.teal { color: var(--teal); }
  header .spacer { flex: 1; }
  header button {
    background: var(--pink); color: white; border: none;
    padding: 6px 14px; border-radius: 4px; cursor: pointer;
    font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
    box-shadow: 0 0 12px var(--pink-glow);
  }
  header button:hover { filter: brightness(1.15); }
  .sound-toggle {
    background: var(--panel-2); color: var(--gold);
    border: 1px solid var(--gold); box-shadow: none;
    padding: 6px 10px; font-size: 13px;
  }
  .sound-toggle.muted { color: var(--ink-dim); border-color: var(--line); opacity: 0.75; }
  .rail-toggle { display: none; }

  main {
    flex: 1; display: grid;
    grid-template-columns: minmax(0, 1fr) var(--rail-width);
    gap: 8px; padding: 8px;
    min-height: 0;
  }
  .left { display: flex; flex-direction: column; gap: 8px; min-width: 0; min-height: 0; }
  .parks-and-zoom { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }
  .park-viewport { flex: 1; min-height: 0; overflow: hidden; }
  #overview-area { width: 100%; height: 100%; }
  .right { display: flex; flex-direction: column; gap: 6px; min-width: 0; min-height: 0; overflow-y: auto; }

  .panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    min-height: 0;
    box-shadow: inset 0 0 30px rgba(0,0,0,0.4);
  }
  .panel h2 {
    margin: 0 0 8px 0; font-size: 10px; text-transform: uppercase;
    letter-spacing: 1px; color: var(--ink-dim);
    border-bottom: 1px solid var(--line); padding-bottom: 4px;
    display: flex; justify-content: space-between; align-items: center;
  }
  .panel h2 .right-meta { color: var(--pink); font-weight: normal; }

  /* ── OVERVIEW: all parks visible ─────────── */
  #overview-area {
    width: 100%; height: 100%; display: grid; gap: 8px; overflow: hidden;
  }
  #overview-area.p2 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
  #overview-area.p3 { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr; }
  #overview-area.p4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
  #overview-area.p5 { grid-template-columns: repeat(6, 1fr); grid-template-rows: 1fr 1fr; }
  #overview-area.p5 > .mini-park { grid-column: span 2; }
  #overview-area.p5 > .mini-park:nth-child(4) { grid-column: 2 / span 2; }
  #overview-area.p5 > .mini-park:nth-child(5) { grid-column: 4 / span 2; }
  #overview-area.p6 { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr; }

  .mini-park {
    background:
      linear-gradient(135deg, rgba(255,255,255,0.025), transparent 34%),
      var(--panel);
    border: 2px solid var(--line);
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
  }
  .mini-park:hover {
    border-color: var(--pink);
    box-shadow: 0 0 16px rgba(255,91,138,0.25);
  }
  .mini-park.active-player {
    border-color: var(--gold);
    box-shadow: 0 0 0 1px rgba(242,201,76,0.18), 0 0 16px rgba(242,201,76,0.3);
  }
  .mini-park.self-park:not(.active-player) {
    border-color: rgba(74,214,200,0.75);
    box-shadow: 0 0 12px rgba(74,214,200,0.16);
  }
  .mini-park .park-bg {
    position: absolute; inset: 0;
    background-size: cover; background-position: center;
    opacity: 0.12; pointer-events: none;
  }
  .mini-park-header {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 9px;
    border: 1px solid rgba(184,169,140,0.28);
    border-radius: 5px;
    background: rgba(24,16,12,0.82);
    box-shadow: 0 2px 10px rgba(0,0,0,0.48), inset 0 1px rgba(255,255,255,0.04);
    z-index: 1;
  }
  /* 3D overview tiles: the park canvas fills the tile; the header floats on top
     of it. Clicks/drops fall through the canvas to the tile div. */
  .mini-park-3d .mini-park-canvas {
    position: absolute; inset: 0; width: 100%; height: 100%;
    display: block; object-fit: cover; pointer-events: none; z-index: 0;
  }
  .mini-park-3d .mini-park-header {
    position: absolute; top: 7px; left: 7px; right: 7px;
    pointer-events: none; z-index: 2;
  }
  .mini-park-header .name { font-weight: 700; font-size: 12px; }
  .park-chip {
    flex: 0 0 auto; padding: 2px 6px; border-radius: 9px;
    font-size: 8px; line-height: 1; font-weight: 900; letter-spacing: 0.7px;
    text-transform: uppercase;
  }
  .park-chip.you { color: #06201d; background: var(--teal); }
  .park-chip.turn { color: #2a1f08; background: var(--gold); }
  .mini-park-header .flam { margin-left: auto; color: var(--pink); font-weight: 700; font-size: 13px; }
  .mini-park-body {
    flex: 1; position: relative; z-index: 1;
    overflow: hidden;
  }
  .mini-park-oval {
    position: relative; width: 100%; height: 100%;
  }
  .mini-trailer {
    position: absolute;
    width: 42px; height: 58px;
    border: 1.5px dashed var(--wood);
    border-radius: 4px;
    background: var(--bg-2);
    overflow: hidden;
    background-size: cover; background-position: center;
    transition: all 0.15s;
  }
  .mini-trailer.occupied { border-style: solid; border-color: var(--line); }
  .mini-trailer .mini-tenant {
    position: absolute; inset: 2px;
    background-size: var(--card-art-crop); background-position: center top;
    border-radius: 2px;
  }
  /* Hitched couple in the mini view: split the tile */
  .mini-trailer .mini-tenant.duo-a { right: 50%; }
  .mini-trailer .mini-tenant.duo-b { left: 50%; }
  .mini-trailer .mini-pts {
    position: absolute; bottom: 1px; right: 1px;
    font-size: 8px; font-weight: 800;
    padding: 0 3px; border-radius: 2px;
    background: rgba(0,0,0,0.8);
  }
  .mini-trailer .mini-pts.pos { color: var(--good); }
  .mini-trailer .mini-pts.neg { color: var(--bad); }

  /* Amenity images in park center */
  .mini-park-center {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    display: flex; flex-wrap: wrap; gap: 5px;
    justify-content: center; align-items: center;
    max-width: 70%; z-index: 2;
  }
  .mini-amenity-card {
    width: 32px; height: 44px;
    border-radius: 3.2% / 2.3%;
    overflow: hidden;
    background-size: var(--card-art-crop); background-position: center;
    background-color: transparent;
    border: none;
    box-shadow: 0 2px 5px rgba(0,0,0,0.55), 0 0 5px rgba(242,201,76,0.22);
  }
  .mini-effect-card {
    width: 28px; height: 38px;
    border-radius: 3.2% / 2.3%;
    overflow: hidden;
    background-size: var(--card-art-crop); background-position: center;
    background-color: transparent;
    border: none;
    box-shadow: 0 2px 5px rgba(0,0,0,0.55), 0 0 5px rgba(235,87,87,0.22);
    opacity: 0.9;
  }

  /* Flamingo decorations in parks */
  .flamingo-deco {
    position: absolute;
    width: 24px; height: 24px;
    font-size: 18px;
    cursor: grab;
    user-select: none;
    z-index: 3;
    filter: drop-shadow(0 1px 3px rgba(0,0,0,0.5));
    transition: transform 0.1s;
  }
  .flamingo-deco:hover { transform: scale(1.3); }
  .flamingo-deco.dragging { cursor: grabbing; transform: scale(1.4); z-index: 10; }

  /* ── ZOOMED PARK — overlaid on top of full left column ── */
  #zoom-area {
    display: none; flex-direction: column;
    position: absolute; inset: 0;
    z-index: 20;
    background: rgba(15,10,8,0.97);
    border: 2px solid var(--pink);
    border-radius: 10px;
    box-shadow: 0 0 40px rgba(255,91,138,0.35), 0 8px 32px rgba(0,0,0,0.8);
    overflow: hidden;
  }
  #zoom-area.active { display: flex; }
  #zoom-back {
    position: absolute; top: 8px; left: 8px; z-index: 10;
    background: var(--panel-2); border: 1px solid var(--pink);
    color: var(--pink); padding: 4px 12px; border-radius: 4px;
    cursor: pointer; font-size: 11px; font-weight: 700;
  }
  #zoom-back:hover { background: var(--pink); color: white; }
  #view-toggle {
    position: absolute; top: 8px; right: 8px; z-index: 10;
    background: var(--panel-2); border: 1px solid var(--teal);
    color: var(--teal); padding: 4px 12px; border-radius: 4px;
    cursor: pointer; font-size: 11px; font-weight: 700; letter-spacing: 0.5px;
  }
  #view-toggle:hover { background: var(--teal); color: #06201d; }
  body.mode-3d #view-toggle { border-color: var(--gold); color: var(--gold); }
  body.mode-3d #view-toggle:hover { background: var(--gold); color: #2a1f08; }

  /* 3D park layer — overlays the oval area when 3D mode is active */
  #board3d-area {
    position: absolute; inset: 0; z-index: 2;
    display: none;
  }
  body.mode-3d #board3d-area { display: block; }
  body.mode-3d .zoom-oval-area { visibility: hidden; }
  #board3d-container { position: absolute; inset: 0; }
  #board3d-container canvas { display: block; }
  #board3d-loading {
    position: absolute; inset: 0; z-index: 3;
    display: none; flex-direction: column; align-items: center; justify-content: center;
    gap: 12px; color: var(--ink-dim); font-size: 12px; letter-spacing: 0.5px;
    background: rgba(15,10,8,0.55); pointer-events: none;
  }
  #board3d-loading.show { display: flex; }
  .b3d-spin {
    width: 34px; height: 34px; border-radius: 50%;
    border: 3px solid rgba(255,91,138,0.25); border-top-color: var(--pink);
    animation: b3dspin 0.9s linear infinite;
  }
  @keyframes b3dspin { to { transform: rotate(360deg); } }
  #board3d-hint {
    position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
    z-index: 3; pointer-events: none;
    background: rgba(0,0,0,0.45); color: var(--ink-dim);
    font-size: 10px; padding: 4px 10px; border-radius: 12px;
    border: 1px solid var(--line); white-space: nowrap;
  }

  #zoom-park {
    flex: 1; position: relative; overflow: hidden;
    display: flex; flex-direction: column;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
  }
  #zoom-park .park-bg {
    position: absolute; inset: 0;
    background-size: cover; background-position: center;
    opacity: 0.15; pointer-events: none;
  }
  .zoom-header {
    position: relative; z-index: 4; pointer-events: none;
    display: flex; align-items: center; gap: 12px;
    min-height: 38px; padding: 8px 126px;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(90deg, rgba(15,10,8,0.92), rgba(42,31,24,0.72), rgba(15,10,8,0.92));
    backdrop-filter: blur(5px);
  }
  .zoom-header .pname { font-size: 18px; font-weight: 700; }
  .zoom-header .pname.current { color: var(--gold); }
  .zoom-header .pflam { color: var(--pink); font-weight: 700; font-size: 16px; }
  .zoom-header .pscore { color: var(--ink-dim); font-size: 11px; margin-left: auto; }

  .zoom-oval-area {
    position: relative; z-index: 1;
    flex: 1; min-height: 0;
  }
  .zoom-trailer {
    position: absolute;
    width: var(--zoom-trailer-w); height: var(--zoom-trailer-h);
    border: 2px dashed var(--wood);
    border-radius: 6px;
    background: var(--bg-2);
    overflow: hidden;
    background-size: cover; background-position: center;
    transition: all 0.15s;
  }
  .zoom-trailer.occupied { border-style: solid; border-color: var(--line); }
  .zoom-trailer.hitched { border-color: var(--good); border-style: solid; }
  .zoom-trailer.vacant { }
  .zoom-trailer.drop-target {
    border: 2px solid var(--pink) !important;
    box-shadow: 0 0 16px var(--pink-glow), inset 0 0 16px rgba(255,91,138,0.2);
    animation: pulse 1.4s ease-in-out infinite;
  }
  @keyframes pulse {
    0%, 100% { box-shadow: 0 0 16px var(--pink-glow), inset 0 0 16px rgba(255,91,138,0.2); }
    50% { box-shadow: 0 0 24px var(--pink-glow), inset 0 0 24px rgba(255,91,138,0.35); }
  }
  .zoom-trailer .tnum {
    position: absolute; top: 2px; left: 4px;
    font-size: 8px; color: var(--ink-dim);
    background: rgba(0,0,0,0.6); padding: 1px 3px; border-radius: 2px;
    z-index: 2;
  }
  .zoom-trailer .tenant-card {
    position: absolute; inset: 3px;
    background-size: var(--card-art-crop); background-position: center top;
    border-radius: 3px;
    z-index: 1;
  }
  /* Hitched couple: the two tenants share the tile side by side */
  .zoom-trailer .tenant-card.duo-a { right: 50%; }
  .zoom-trailer .tenant-card.duo-b { left: 50%; border-left: 1px solid rgba(0,0,0,0.55); }
  .zoom-trailer.hitched::after {
    content: '💍'; position: absolute; top: 1px; right: 2px;
    font-size: 10px; z-index: 3; text-shadow: 0 0 4px rgba(0,0,0,0.9);
  }
  .zoom-trailer .tenant-pts {
    position: absolute; bottom: 2px; right: 3px;
    font-size: 11px; font-weight: 800;
    padding: 1px 5px; border-radius: 3px;
    background: rgba(0,0,0,0.8); z-index: 3;
  }
  .zoom-trailer .tenant-pts.pos { color: var(--good); }
  .zoom-trailer .tenant-pts.neg { color: var(--bad); }
  .zoom-trailer .tenant-pts.zero { color: var(--ink-dim); }
  .zoom-trailer .vacant-label {
    position: absolute; bottom: 6px; left: 0; right: 0;
    text-align: center; font-size: 8px; color: var(--ink-dim);
    font-style: italic; z-index: 1;
  }

  /* Zoomed park center amenity cards */
  .zoom-center {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    display: flex; flex-wrap: wrap; gap: 10px;
    justify-content: center; align-items: center;
    max-width: 340px; z-index: 2;
  }
  .zoom-center.drop-target-center {
    outline: 2px dashed var(--gold);
    outline-offset: 4px;
    border-radius: 8px;
    background: rgba(242,201,76,0.05);
  }
  .zoom-amenity-card {
    width: 52px; height: 72px;
    border-radius: 3.2% / 2.3%;
    overflow: hidden;
    background-size: var(--card-art-crop); background-position: center;
    background-color: transparent;
    border: none;
    box-shadow: 0 3px 9px rgba(0,0,0,0.6), 0 0 7px rgba(242,201,76,0.22);
    cursor: pointer;
    transition: transform 0.15s;
  }
  .zoom-amenity-card:hover { transform: scale(1.1); z-index: 5; }
  .zoom-effect-card {
    width: 44px; height: 62px;
    border-radius: 3.2% / 2.3%;
    overflow: hidden;
    background-size: var(--card-art-crop); background-position: center;
    background-color: transparent;
    border: none;
    box-shadow: 0 3px 8px rgba(0,0,0,0.6), 0 0 7px rgba(235,87,87,0.2);
    opacity: 0.85;
    cursor: pointer;
    transition: transform 0.15s;
  }
  .zoom-effect-card:hover { transform: scale(1.1); z-index: 5; }

  /* ── HAND AREA ───────────────────────────── */
  #handPanel {
    flex-shrink: 0; overflow: hidden;
    background:
      linear-gradient(180deg, rgba(107,74,46,0.22), transparent 24px),
      var(--panel);
  }
  .hand {
    display: flex; gap: 9px; max-width: 100%; min-width: 0;
    overflow-x: auto; overflow-y: hidden; padding: 10px 2px;
    min-height: clamp(222px, 15.5vw, 284px);
    scrollbar-color: var(--wood) rgba(15,10,8,0.35);
  }
  .hand-card {
    flex: 0 0 var(--hand-card-width);
    aspect-ratio: 5 / 7;
    border-radius: 3.2% / 2.3%;
    overflow: hidden;
    background-size: var(--card-art-crop); background-position: center;
    background-color: transparent;
    border: none;
    cursor: grab;
    position: relative;
    transition: transform 0.15s, box-shadow 0.15s, filter 0.15s;
    box-shadow: 0 5px 12px rgba(0,0,0,0.58);
  }
  .hand-card:hover {
    transform: translateY(-4px) scale(1.025);
    box-shadow: 0 10px 24px rgba(0,0,0,0.75), 0 0 0 2px rgba(245,236,217,0.18);
    z-index: 5;
  }
  .hand-card.selected {
    box-shadow: 0 0 0 3px rgba(255,91,138,0.7), 0 0 24px var(--pink-glow), 0 10px 24px rgba(0,0,0,0.75);
    transform: translateY(-4px) scale(1.025);
  }
  .hand-show-btn {
    position: absolute; top: 4px; right: 4px; z-index: 6;
    width: 30px; height: 30px; padding: 0;
    border-radius: 50%; border: 1px solid var(--gold);
    background: rgba(15,10,8,0.78); color: var(--gold);
    font-size: 13px; line-height: 1; cursor: pointer;
    opacity: 0; transition: opacity 0.12s, transform 0.12s;
  }
  .hand-card:hover .hand-show-btn,
  .hand-card:focus-within .hand-show-btn { opacity: 1; }
  .hand-show-btn:hover { transform: scale(1.15); background: var(--gold); color: #2a1f08; }
  .hand-card.illegal { opacity: 0.4; filter: grayscale(0.6); cursor: not-allowed; }
  .hand-card.dragging { opacity: 0.4; transform: scale(0.95); }
  .hand-card.drag-over-left { box-shadow: -5px 0 0 var(--pink), 0 5px 12px rgba(0,0,0,0.58); }
  .hand-card.drag-over-right { box-shadow: 5px 0 0 var(--pink), 0 5px 12px rgba(0,0,0,0.58); }
  .hand-card.fallback {
    display: flex; flex-direction: column; padding: 6px;
    background: linear-gradient(180deg, #3d2a1f 0%, #2a1f18 100%);
    background-color: #2a1f18;
    border: 2px solid var(--line);
    border-radius: 8px;
  }
  .hand-card.fallback:hover { border-color: var(--ink-dim); }
  .hand-card.fallback.selected { border-color: var(--pink); border-width: 3px; }
  .hand-card.fallback .htype {
    font-size: 8px; text-transform: uppercase;
    text-align: center; padding: 2px; border-radius: 3px;
    font-weight: 700; letter-spacing: 0.5px;
  }
  .hand-card.fallback .htype.tenant { background: #4a8fb8; }
  .hand-card.fallback .htype.amenity { background: #b88a4a; }
  .hand-card.fallback .htype.disaster { background: #b84a4a; }
  .hand-card.fallback .htype.action { background: #7a5ab8; }
  .hand-card.fallback .hname {
    font-size: 12px; font-weight: 700; text-align: center;
    margin-top: 6px; line-height: 1.2;
  }
  .hand-card.fallback .hsub {
    font-size: 9px; color: var(--ink-dim); text-align: center;
    font-style: italic; margin-top: 2px;
  }
  .hand-card.fallback .hpts {
    font-size: 24px; font-weight: 800; text-align: center;
    color: var(--pink); text-shadow: 0 0 8px var(--pink-glow);
    margin: auto 0;
  }
  .hand-card.fallback .hflavor {
    font-size: 8px; color: var(--ink-dim); font-style: italic;
    text-align: center; line-height: 1.2;
  }

  /* ── RIGHT SIDEBAR ───────────────────────── */
  #phasePanel { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }
  .phase-now {
    background: linear-gradient(135deg, var(--panel-2), var(--bg-2));
    border: 1px solid var(--pink); border-radius: 6px; padding: 8px; text-align: center;
    box-shadow: 0 0 12px rgba(255,91,138,0.2);
  }
  .phase-now .pname {
    font-weight: 800; color: var(--pink); text-transform: uppercase;
    font-size: 12px; letter-spacing: 1px; text-shadow: 0 0 8px var(--pink-glow);
  }
  .phase-now .phint { color: var(--ink-dim); font-size: 9px; margin-top: 3px; }
  body.card-limit-reached .phase-now {
    border-color: var(--gold);
    box-shadow: 0 0 18px rgba(242,201,76,0.36);
  }
  body.card-limit-reached .phase-now .pname,
  body.card-limit-reached .phase-now .phint { color: var(--gold); }
  .btn {
    background: var(--panel-2); color: var(--ink);
    border: 1px solid var(--line); border-radius: 4px;
    padding: 7px 10px; cursor: pointer; font-size: 11px;
    text-align: left; font-weight: 600; transition: all 0.1s;
  }
  .btn:hover:not(:disabled) {
    background: var(--wood); border-color: var(--pink); transform: translateX(2px);
  }
  .btn:disabled { opacity: 0.35; cursor: not-allowed; }
  .btn.primary {
    background: var(--pink); border-color: var(--pink); color: white;
    box-shadow: 0 0 12px var(--pink-glow);
  }
  .btn.primary:hover:not(:disabled) { filter: brightness(1.15); }
  .btn.card-limit-next:not(:disabled) {
    color: #2a1f08; background: var(--gold); border-color: var(--gold);
    box-shadow: 0 0 14px rgba(242,201,76,0.34);
  }

  .opps { display: flex; flex-direction: column; gap: 4px; }
  .opp {
    background: var(--panel-2); border: 1px solid var(--line);
    border-radius: 4px; padding: 6px; cursor: pointer; transition: all 0.15s;
  }
  .opp:hover { background: var(--wood); }
  .opp.viewing { border-color: var(--pink); box-shadow: 0 0 8px var(--pink-glow); }
  .opp.current::before { content: '▶'; color: var(--gold); margin-right: 4px; }
  .opp .top { display: flex; justify-content: space-between; align-items: center; }
  .opp .name { font-weight: 700; font-size: 12px; }
  .opp .flam { color: var(--pink); font-weight: 700; }
  .opp .small { font-size: 9px; color: var(--ink-dim); margin-top: 1px; }
  .opp .small.showing { color: var(--gold); font-weight: 700; }
  .opp .you-tag {
    font-size: 8px; text-transform: uppercase; letter-spacing: 0.5px;
    background: var(--teal); color: #06201d; padding: 1px 5px;
    border-radius: 8px; margin-left: 5px; vertical-align: middle;
  }

  .recent-card-panel { flex: 0 0 auto; }
  .recent-card {
    width: 100%; min-height: 58px; display: grid;
    grid-template-columns: 42px minmax(0, 1fr); align-items: center; gap: 9px;
    padding: 6px; border: 1px solid var(--line); border-radius: 6px;
    color: var(--ink); background: var(--panel-2); text-align: left; cursor: pointer;
  }
  .recent-card:hover:not(:disabled) { border-color: var(--teal); background: var(--wood); }
  .recent-card:disabled { cursor: default; opacity: 0.7; grid-template-columns: 1fr; }
  .recent-card-thumb {
    width: 42px; aspect-ratio: 5 / 7; border-radius: 3px;
    background-size: var(--card-art-crop); background-position: center;
    box-shadow: 0 2px 7px rgba(0,0,0,0.6);
  }
  .recent-card-copy { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
  .recent-card-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; color: var(--gold); }
  .recent-card-copy span { color: var(--ink-dim); font-size: 9px; line-height: 1.25; }
  .recent-card-empty { color: var(--ink-dim); font-size: 10px; text-align: center; }

  #logPanel { flex: 0 0 auto; min-height: 0; padding: 0; overflow: hidden; }
  #logPanel[open] {
    flex: 0 0 auto; min-height: 130px; max-height: 38vh; padding-bottom: 8px;
  }
  #logPanel summary {
    min-height: 34px; display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 9px 10px; cursor: pointer; list-style: none;
    color: var(--ink-dim); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px;
  }
  #logPanel summary::-webkit-details-marker { display: none; }
  #logPanel summary::after { content: 'Show'; margin-left: auto; color: var(--teal); font-size: 9px; letter-spacing: 0.4px; }
  #logPanel[open] summary::after { content: 'Hide'; }
  .log-badge {
    min-width: 18px; padding: 2px 5px; border-radius: 10px;
    color: #2a1f08; background: var(--gold); text-align: center; font-size: 8px;
  }
  .log {
    min-height: 0; height: auto;
    overflow-y: auto; overflow-x: hidden; scrollbar-gutter: stable;
    padding: 0 10px; font-size: 9px; line-height: 1.4;
    scrollbar-color: var(--wood) rgba(15,10,8,0.35);
  }
  /* Native <details> content has an internal wrapper, so percentage/flex
     heights do not reliably create a scroll range here. Give the open log a
     viewport-bounded height directly and let its own overflow do the work. */
  #logPanel[open] .log {
    height: clamp(96px, calc(32vh - 42px), 318px);
    max-height: calc(38vh - 42px);
  }
  .log::-webkit-scrollbar { width: 8px; }
  .log::-webkit-scrollbar-thumb { background: var(--wood); border-radius: 4px; }
  .log .entry { padding: 3px 0; border-bottom: 1px dotted var(--line); color: var(--ink-dim); overflow-wrap: anywhere; }
  .log .entry .ev { color: var(--pink); font-weight: 700; }
  .log .entry time { color: var(--ink-dim); font-variant-numeric: tabular-nums; margin-right: 3px; }
  .log .entry.expandable { cursor: pointer; }
  .log .entry.expandable:hover, .log .entry.expanded { color: var(--ink); }
  .log .entry .ev-full {
    margin: 4px 0 2px; padding: 6px 8px; max-height: 30vh; overflow: auto;
    white-space: pre-wrap; overflow-wrap: anywhere; font-size: 9px; line-height: 1.45;
    color: var(--ink); background: rgba(15,10,8,0.45);
    border: 1px solid var(--line); border-radius: 6px;
  }
  .log-tools { display: none; padding: 0 10px 6px; }
  #logPanel[open] .log-tools { display: flex; justify-content: flex-end; gap: 6px; }
  .log-tools button {
    padding: 3px 8px; cursor: pointer;
    color: var(--teal); background: transparent;
    border: 1px solid var(--line); border-radius: 6px;
    font-size: 9px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase;
  }
  .log-tools button:hover { border-color: var(--teal); }

  /* ── PREVIEW TOOLTIP ─────────────────────── */
  #preview {
    position: fixed;
    width: min(320px, calc(100vw - 28px), calc((100vh - 28px) * 5 / 7)); aspect-ratio: 5 / 7;
    background-size: var(--card-art-crop); background-position: center;
    background-color: transparent;
    border: none;
    border-radius: 3.2% / 2.3%;
    overflow: hidden;
    box-shadow: 0 0 36px rgba(255,91,138,0.32), 0 8px 24px rgba(0,0,0,0.7);
    pointer-events: none; z-index: var(--z-preview); display: none;
  }
  #preview.show { display: block; }
  #preview.fallback {
    display: flex; flex-direction: column; padding: 20px;
    background: linear-gradient(180deg, #3d2a1f 0%, #2a1f18 100%);
    border: 3px solid var(--pink);
    border-radius: 10px;
  }
  #preview.fallback .ftype {
    font-size: 15px; text-transform: uppercase; text-align: center;
    padding: 6px; border-radius: 3px; font-weight: 700; letter-spacing: 1px;
  }
  #preview.fallback .fname { font-size: 32px; font-weight: 800; text-align: center; margin-top: 18px; }
  #preview.fallback .fsub { font-size: 18px; color: var(--ink-dim); text-align: center; font-style: italic; }
  #preview.fallback .fpts { font-size: 74px; font-weight: 800; text-align: center; color: var(--pink); text-shadow: 0 0 12px var(--pink-glow); margin: 22px 0; }
  #preview.fallback .fflavor { font-size: 17px; color: var(--ink-dim); font-style: italic; text-align: center; }

  /* ── CARD INSPECTOR (click-to-flip) ─────────────────────── */
  #cardInspector {
    position: fixed; inset: 0; z-index: var(--z-inspector); display: none;
    align-items: center; justify-content: center;
    background: rgba(8,5,4,0.9);
  }
  #cardInspector.active { display: flex; }
  .ci-card {
    width: min(330px, 78vw); aspect-ratio: 5 / 7;
    perspective: 1400px; cursor: pointer;
    animation: ciPop 0.22s ease;
  }
  @keyframes ciPop { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
  .ci-inner {
    position: relative; width: 100%; height: 100%;
    transform-style: preserve-3d; transition: transform 0.55s cubic-bezier(.2,.8,.25,1);
  }
  #ciCard.flipped .ci-inner { transform: rotateY(180deg); }
  .ci-front, .ci-back {
    position: absolute; inset: 0; border-radius: 14px; overflow: hidden;
    -webkit-backface-visibility: hidden; backface-visibility: hidden;
    box-shadow: 0 0 40px var(--pink-glow), 0 12px 40px rgba(0,0,0,0.8);
  }
  .ci-front {
    background-size: var(--card-art-crop); background-position: center;
    background-color: transparent;
    border: none;
    border-radius: 3.2% / 2.3%;
  }
  .ci-front.fallback-front, .ci-back { border: 3px solid var(--pink); }
  .ci-back {
    transform: rotateY(180deg);
    background:
      radial-gradient(circle at 50% 0%, rgba(255,91,138,0.12), transparent 60%),
      linear-gradient(180deg, #3a2a20 0%, #241a14 100%);
    display: flex; flex-direction: column; padding: 18px 16px; color: var(--ink);
  }
  .cb-type {
    align-self: center; font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px;
    font-weight: 800; padding: 4px 14px; border-radius: 12px; color: #1a1206;
  }
  .cb-type.cb-amenity { background: #f2c94c; }
  .cb-type.cb-disaster { background: #eb5757; color: #fff; }
  .cb-type.cb-action { background: #b58cff; color: #1a1026; }
  .cb-name {
    text-align: center; font-size: 22px; font-weight: 800; line-height: 1.1;
    margin: 12px 6px 6px; color: var(--ink);
    text-shadow: 0 0 14px rgba(255,91,138,0.3);
  }
  .cb-tags { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; margin-bottom: 8px; }
  .cb-tags span {
    font-size: 9px; text-transform: uppercase; letter-spacing: 0.5px;
    background: var(--panel-2); border: 1px solid var(--line); color: var(--ink-dim);
    padding: 2px 8px; border-radius: 10px;
  }
  .cb-pts {
    align-self: center; font-size: 13px; font-weight: 800; margin-bottom: 10px;
    color: var(--gold);
  }
  .cb-pts.neg { color: var(--bad); }
  .cb-flavor {
    text-align: center; font-style: italic; font-size: 12px; color: var(--teal);
    margin-bottom: 12px; line-height: 1.35;
  }
  .cb-cond {
    font-size: 13px; line-height: 1.5; color: var(--ink); overflow-y: auto;
    border-top: 1px solid var(--line); padding-top: 10px; flex: 1; min-height: 0;
  }
  .cb-cond::-webkit-scrollbar { width: 6px; }
  .cb-cond::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
  .ci-hint {
    position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
    color: var(--ink-dim); font-size: 11px; letter-spacing: 0.5px;
    background: rgba(0,0,0,0.5); padding: 5px 14px; border-radius: 14px; border: 1px solid var(--line);
  }
  /* tiny flip button shown on non-tenant hand cards */
  .hand-flip-btn {
    position: absolute; top: 4px; left: 4px; z-index: 6;
    width: 30px; height: 30px; padding: 0;
    border-radius: 50%; border: 1px solid var(--teal);
    background: rgba(15,10,8,0.78); color: var(--teal);
    font-size: 14px; line-height: 1; cursor: pointer;
    opacity: 0; transition: opacity 0.12s, transform 0.12s;
  }
  .hand-card:hover .hand-flip-btn,
  .hand-card:focus-within .hand-flip-btn { opacity: 1; }
  .hand-flip-btn:hover { transform: scale(1.15) rotate(90deg); background: var(--teal); color: #06201d; }
  .can-inspect { cursor: pointer; }

  /* ── CARD PLAY REVEAL (bots / opponents) ────────────────── */
  #cardReveal {
    position: absolute; inset: 10px; z-index: var(--z-stage-card); display: none;
    align-items: center; justify-content: center; pointer-events: none;
    border-radius: 10px;
    background: radial-gradient(circle, rgba(15,10,8,0.52), rgba(15,10,8,0.08) 54%, transparent 74%);
  }
  #cardReveal.show { display: flex; }
  .cr-wrap {
    width: min(540px, calc(100% - 24px)); display: grid;
    grid-template-columns: minmax(150px, 210px) minmax(0, 1fr);
    align-items: center; gap: 16px; padding: 14px;
    border: 1px solid rgba(255,91,138,0.66); border-radius: 12px;
    background:
      linear-gradient(135deg, rgba(107,74,46,0.28), transparent 42%),
      rgba(26,20,16,0.96);
    box-shadow: 0 18px 60px rgba(0,0,0,0.86), 0 0 30px rgba(255,91,138,0.24);
    pointer-events: auto;
    animation: crIn 0.28s cubic-bezier(.2,.9,.3,1.15);
  }
  #cardReveal.out .cr-wrap { animation: crOut 0.35s ease forwards; }
  #cardReveal.local-play .cr-wrap { animation-name: crInFromHand; }
  @keyframes crIn { from { transform: scale(0.78) translateY(-18px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } }
  @keyframes crInFromHand { from { transform: scale(0.72) translateY(44px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } }
  @keyframes crOut { to { transform: scale(0.92) translateY(-14px); opacity: 0; } }
  .cr-card-button {
    position: absolute; inset: 0; z-index: 2; width: 100%; height: 100%;
    padding: 0; border: 0; border-radius: 3.2% / 2.3%; background: transparent; cursor: zoom-in;
  }
  .cr-who {
    color: var(--pink); font-size: 10px; font-weight: 900; letter-spacing: 1.1px; text-transform: uppercase;
  }
  .cr-card {
    position: relative; display: block; width: 100%; aspect-ratio: 5 / 7; border-radius: 3.2% / 2.3%;
    overflow: hidden;
    background-size: var(--card-art-crop); background-position: center; background-color: transparent;
    border: none;
    box-shadow: 0 0 44px rgba(255,91,138,0.42), 0 16px 50px rgba(0,0,0,0.85);
  }
  .cr-card.fallback-front { border: 3px solid var(--gold); border-radius: 12px; background-color: var(--panel-2); }
  /* Destroyed-amenity spotlight: red-glow card with a rubber-stamp slam */
  #cardReveal.destroyed .cr-wrap {
    border-color: rgba(235,87,87,0.85);
    box-shadow: 0 18px 60px rgba(0,0,0,0.86), 0 0 34px rgba(235,87,87,0.4);
  }
  #cardReveal.destroyed .cr-card {
    box-shadow: 0 0 44px rgba(235,87,87,0.6), 0 16px 50px rgba(0,0,0,0.85);
    filter: saturate(0.75);
  }
  #cardReveal.destroyed .cr-who { color: var(--bad, #eb5757); }
  .cr-stamp {
    position: absolute; top: 42%; left: -6%; right: -6%; z-index: 3;
    padding: 5px 0; text-align: center; pointer-events: none;
    transform: rotate(-16deg);
    font-size: 24px; font-weight: 900; letter-spacing: 4px; color: #fff;
    background: rgba(198,28,28,0.88);
    border-top: 2px solid rgba(255,255,255,0.85); border-bottom: 2px solid rgba(255,255,255,0.85);
    text-shadow: 0 2px 6px rgba(0,0,0,0.7);
    animation: crStampIn 0.3s cubic-bezier(.2,1.4,.4,1) 0.28s both;
  }
  @keyframes crStampIn {
    from { transform: rotate(-16deg) scale(2.4); opacity: 0; }
    to   { transform: rotate(-16deg) scale(1); opacity: 1; }
  }
  .cr-copy { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
  .cr-name { font-size: 22px; line-height: 1.05; font-weight: 900; color: var(--gold); text-shadow: 0 0 10px rgba(242,201,76,0.32); }
  .cr-target {
    width: 100%; padding: 7px 9px; border-left: 3px solid var(--teal);
    background: rgba(74,214,200,0.08); color: var(--ink);
    font-size: 12px; font-weight: 700; line-height: 1.35;
  }
  .cr-act { font-size: 12px; color: var(--ink-dim); line-height: 1.45; }
  .cr-hint { font-size: 9px; color: var(--teal); letter-spacing: 0.4px; }
  .cr-next {
    margin-top: 2px; padding: 6px 11px; border: 1px solid var(--pink); border-radius: 4px;
    color: var(--pink); background: rgba(15,10,8,0.62); cursor: pointer;
    font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.6px;
  }
  .cr-next:hover { color: white; background: var(--pink); }
  .cr-progress {
    width: 100%; height: 3px; margin-top: 2px; overflow: hidden; border-radius: 3px;
    background: rgba(184,169,140,0.2);
  }
  .cr-progress::after {
    content: ''; display: block; width: 100%; height: 100%; background: var(--pink);
    transform-origin: left; animation: crProgress var(--reveal-hold, 2800ms) linear forwards;
  }
  #cardReveal.paused .cr-progress::after { animation-play-state: paused; }
  @keyframes crProgress { to { transform: scaleX(0); } }

  /* ── MODAL ────────────────────────────────── */
  .modal-bg {
    position: fixed; inset: 0; background: rgba(0,0,0,0.85);
    display: none; align-items: center; justify-content: center; z-index: var(--z-modal);
    backdrop-filter: blur(4px);
  }
  .modal-bg.active { display: flex; }
  .modal {
    background: var(--panel); border: 2px solid var(--pink);
    border-radius: 10px; padding: 20px;
    max-width: 520px; min-width: 320px;
    box-shadow: 0 0 40px var(--pink-glow);
    /* Long option lists (trailer pickers, couple pickers) scroll inside the
       modal instead of clipping off the top/bottom of the screen. */
    max-height: min(84vh, 860px);
    display: flex; flex-direction: column;
  }
  .modal h3 { margin: 0 0 10px 0; color: var(--pink); font-size: 16px; flex: 0 0 auto; }
  .modal p { margin: 0 0 14px 0; color: var(--ink); font-size: 13px; flex: 0 0 auto; }
  .modal .opts {
    display: flex; flex-direction: column; gap: 6px;
    overflow-y: auto; min-height: 0; padding-right: 2px;
  }
  /* Navigation buttons (Back / Cancel) read differently from the choices. */
  .modal .opts .btn.nav {
    color: var(--ink-dim); border-style: dashed; background: transparent;
  }
  .modal .opts .btn.nav:hover { color: var(--ink); border-color: var(--teal); }

  /* ── TOAST NOTIFICATIONS ─────────────────────── */
  #toast-stack {
    position: fixed; top: 62px; right: calc(var(--rail-width) + 18px);
    display: flex; flex-direction: column; gap: 8px;
    z-index: var(--z-toast); pointer-events: none;
    max-width: 430px; width: min(430px, calc(100vw - var(--rail-width) - 36px));
  }
  .toast {
    background: var(--panel-2);
    border: 2px solid var(--pink);
    border-radius: 8px;
    padding: 10px 18px;
    color: var(--ink);
    font-size: 13px; font-weight: 600;
    box-shadow: 0 4px 20px rgba(0,0,0,0.7), 0 0 16px var(--pink-glow);
    opacity: 0; pointer-events: none;
    transition: opacity 0.35s, transform 0.35s;
    transform: translateY(10px);
    line-height: 1.45;
  }
  .toast.show { opacity: 1; transform: translateY(0); }
  .toast.warn { border-color: var(--bad); box-shadow: 0 4px 20px rgba(0,0,0,0.7), 0 0 16px rgba(235,87,87,0.4); }
  .toast.good { border-color: var(--good); box-shadow: 0 4px 20px rgba(0,0,0,0.7), 0 0 16px rgba(111,207,151,0.3); }
  .toast.gold { border-color: var(--gold); box-shadow: 0 4px 20px rgba(0,0,0,0.7), 0 0 16px rgba(242,201,76,0.3); }

  /* ── SETUP ────────────────────────────────── */
  #setup {
    position: fixed; inset: 0; background: var(--bg);
    background-image:
      linear-gradient(180deg, rgba(10,7,5,0.22), rgba(10,7,5,0.82)),
      url('./loading-screens/trailer-park-titans-loading-background.png');
    background-size: cover, cover;
    background-position: center, center;
    display: flex; align-items: center; justify-content: center; z-index: 200;
  }
  #setup .box {
    background: rgba(42,31,24,0.95);
    padding: 30px; border-radius: 12px;
    border: 2px solid var(--pink);
    min-width: 360px;
    box-shadow: 0 0 60px var(--pink-glow);
  }
  #setup h1 {
    color: var(--pink); margin-top: 0; font-size: 26px;
    text-shadow: 0 0 16px var(--pink-glow); text-align: center;
  }
  #setup .tagline { text-align: center; color: var(--ink-dim); font-style: italic; margin-bottom: 20px; }
  .setup-doc-links {
    display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
    margin: -7px auto 18px;
  }
  .setup-doc-links .setup-guide-link { margin: 0; }
  .setup-guide-link {
    display: flex; align-items: center; justify-content: center; gap: 7px;
    width: fit-content; margin: -7px auto 18px; padding: 7px 11px;
    color: var(--gold); background: rgba(15,10,8,0.56);
    border: 1px dashed var(--gold); border-radius: 3px;
    font-size: 10px; font-weight: 800; letter-spacing: 0.65px;
    text-decoration: none; text-transform: uppercase;
    transform: rotate(-0.7deg);
    transition: color 0.16s ease, background 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
  }
  .setup-guide-link:hover {
    color: #2a1f08; background: var(--gold);
    box-shadow: 0 0 18px rgba(242,201,76,0.38);
    transform: rotate(0.5deg) translateY(-1px);
  }
  .setup-guide-link:focus-visible { outline: 2px solid var(--teal); outline-offset: 3px; }
  #setup label { display: block; margin: 10px 0 3px 0; font-size: 10px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 0.5px; }
  #setup input, #setup select {
    width: 100%; padding: 8px; background: var(--panel-2);
    border: 1px solid var(--line); border-radius: 4px; color: var(--ink); font-size: 13px;
  }
  #setup button {
    margin-top: 16px; width: 100%; padding: 10px;
    background: var(--pink); color: white; border: none; border-radius: 4px;
    cursor: pointer; font-weight: 800; font-size: 13px;
    text-transform: uppercase; letter-spacing: 1px;
    box-shadow: 0 0 16px var(--pink-glow);
  }
  #setup button:hover { filter: brightness(1.15); }
  #setup button:disabled { opacity: 0.5; cursor: default; box-shadow: none; filter: none; }
  .setup-err { color: var(--bad); font-size: 12px; margin-top: 10px; min-height: 16px; font-weight: 600; }
  .setup-hint { color: var(--ink-dim); font-size: 11px; margin-top: 12px; line-height: 1.45; }
  .recovery-details { margin-top: 10px; border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; }
  .recovery-details summary { cursor: pointer; color: var(--ink-dim); font-size: 11px; }
  .recovery-details[open] summary { margin-bottom: 7px; }
  .recovery-details .setup-hint { margin-top: 6px; }
  .lobby-head { font-size: 13px; font-weight: 800; color: var(--ink); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 10px; }
  .lobby-count { color: var(--pink); }
  #lobbyList { display: flex; flex-direction: column; gap: 6px; }
  .lobby-row {
    display: flex; align-items: center; gap: 8px;
    background: var(--panel-2); border: 1px solid var(--line);
    border-radius: 6px; padding: 8px 10px; font-size: 13px;
  }
  .lobby-row .seat-no { color: var(--ink-dim); font-size: 11px; width: 18px; }
  .lobby-row .seat-name { font-weight: 700; flex: 1; }
  .lobby-row .seat-tag { font-size: 9px; text-transform: uppercase; letter-spacing: 0.5px; padding: 2px 6px; border-radius: 10px; }
  .lobby-row .seat-tag.host { background: var(--gold); color: #2a1f08; }
  .lobby-row .seat-tag.you { background: var(--teal); color: #06201d; }
  .lobby-row .seat-tag.off { background: #3a2a22; color: var(--ink-dim); }
  .lobby-row .seat-tag.bot { background: var(--teal); color: #06201d; }
  .lobby-row .seat-tag.spec { background: #3a2a22; color: var(--ink); }
  .lobby-row.disconnected { opacity: 0.5; }
  .lobby-row.bot { border-color: var(--teal); }
  .lobby-row.spec { border-style: dashed; opacity: 0.85; }
  #setup button.seat-remove {
    width: 22px; height: 22px; padding: 0; margin: 0; line-height: 1; flex: 0 0 auto;
    border-radius: 50%; border: 1px solid var(--bad); background: transparent;
    color: var(--bad); cursor: pointer; font-size: 12px; font-weight: 700;
    box-shadow: none; letter-spacing: 0; text-transform: none;
  }
  #setup button.seat-remove:hover { background: var(--bad); color: #fff; filter: none; }
  #setup button.secondary-btn {
    margin-top: 10px; background: var(--panel-2); color: var(--teal);
    border: 1px solid var(--teal); box-shadow: none;
  }
  #setup button.secondary-btn:hover { background: var(--teal); color: #06201d; filter: none; }
  #setup button.secondary-btn:disabled { opacity: 0.4; }

  /* ── SPECTATOR MODE ───────────────────────── */
  /* Watch-only clients get the full board view but no hand, no action
     buttons, and no New Game control — everything else stays identical. */
  .spec-badge {
    align-self: center; white-space: nowrap;
    background: var(--teal); color: #06201d;
    font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px;
    padding: 4px 10px; border-radius: 12px;
    box-shadow: 0 0 12px rgba(74, 214, 200, 0.45);
  }
  body.spectator #handPanel { display: none; }
  body.spectator #phasePanel .btn { display: none; }
  body.spectator #newGameBtn { display: none; }

  #setupLoading {
    position: fixed; inset: 0; z-index: 260;
    display: flex; align-items: center; justify-content: center;
    background:
      linear-gradient(180deg, rgba(10,7,5,0.16), rgba(10,7,5,0.74)),
      url('./loading-screens/trailer-park-titans-loading-background.png');
    background-size: cover, cover;
    background-position: center, center;
    opacity: 0; pointer-events: none;
    transition: opacity 0.22s ease;
  }
  #setupLoading.active { opacity: 1; pointer-events: auto; }
  .setup-loading-panel {
    width: min(340px, calc(100vw - 40px));
    padding: 18px 20px;
    border: 1px solid rgba(255,91,138,0.72);
    border-radius: 8px;
    background: rgba(24,16,12,0.9);
    box-shadow: 0 12px 46px rgba(0,0,0,0.72), 0 0 28px rgba(255,91,138,0.24);
  }
  .setup-loading-panel h2 {
    margin: 0 0 14px;
    color: var(--pink);
    font-size: 18px;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 1px;
  }
  .setup-loading-bar {
    height: 7px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(0,0,0,0.42);
    border: 1px solid var(--line);
  }
  .setup-loading-bar span {
    display: block;
    width: 44%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--teal), var(--pink), var(--gold));
    animation: setupLoadSweep 1.05s ease-in-out infinite;
  }
  @keyframes setupLoadSweep {
    0% { transform: translateX(-120%); }
    100% { transform: translateX(260%); }
  }

  /* ── PARK SETUP (build your park) ─────────────────────────── */
  #parkSetup {
    position: fixed; inset: 0; z-index: 150; display: none;
    align-items: stretch; justify-content: stretch; padding: 0;
    background:
      radial-gradient(circle at 50% 20%, rgba(255,91,138,0.12), transparent 55%),
      rgba(10,7,5,0.96);
  }
  #parkSetup.active { display: flex; }
  /* Full-screen setup: header, a two-column body that fills the screen, and a
     footer for Randomize/Ready + player readiness. */
  .ps-box {
    width: 100%; height: 100%;
    background: linear-gradient(180deg, #241a14 0%, #1a1410 100%);
    border: none; border-radius: 0;
    padding: 16px clamp(16px, 3vw, 40px) 14px;
    display: flex; flex-direction: column; gap: 10px; min-height: 0;
  }
  .ps-head { flex: 0 0 auto; }
  .ps-head h2 { margin: 0 0 3px; color: var(--pink); text-shadow: 0 0 14px var(--pink-glow); font-size: clamp(20px, 2.4vw, 30px); }
  .ps-sub { color: var(--ink-dim); font-size: 12px; line-height: 1.5; margin: 0; }
  .ps-section-label {
    font-size: 11px; text-transform: uppercase; letter-spacing: 1px; font-weight: 700;
    color: var(--ink-dim); margin: 0 0 8px;
  }
  /* Two-column stage/picker layout — the park on the left, the design gallery
     on the right. Fills all the vertical space between header and footer. */
  .ps-body {
    flex: 1 1 auto; min-height: 0;
    display: grid; gap: clamp(14px, 2vw, 26px);
    grid-template-columns: minmax(0, 1.35fr) minmax(340px, 0.85fr);
  }
  .ps-stage { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
  .ps-stage .ps-section-label { flex: 0 0 auto; }
  .ps-picker {
    display: flex; flex-direction: column; min-height: 0; min-width: 0;
  }
  .ps-picker > .ps-section-label { flex: 0 0 auto; }
  #psPlayboardPhase { display: flex; flex-direction: column; min-height: 0; }
  .ps-dim { color: var(--teal); font-weight: 600; text-transform: none; letter-spacing: 0; }
  .ps-park {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
    gap: 7px; max-height: 38vh; overflow-y: auto; padding: 4px;
    background: rgba(0,0,0,0.25); border: 1px solid var(--line); border-radius: 8px;
  }
  .ps-slot {
    position: relative; aspect-ratio: 1 / 1; border-radius: 6px;
    background-size: cover; background-position: center; background-color: var(--panel-2);
    border: 2px solid var(--line); cursor: pointer; transition: transform 0.1s, border-color 0.1s;
  }
  .ps-slot:hover { transform: scale(1.06); border-color: var(--teal); z-index: 2; }
  .ps-slot.locked { cursor: default; }
  .ps-slot.locked:hover { transform: none; border-color: var(--line); z-index: auto; }
  .ps-slot .ps-num {
    position: absolute; bottom: 1px; right: 3px; font-size: 9px; font-weight: 700;
    color: #fff; text-shadow: 0 1px 3px #000;
  }
  /* 3D park preview inside the setup overlay (reuses the in-game 3D environment).
     Shown when Three.js is available; otherwise the flat .ps-park grid is used. */
  #ps3d-area {
    position: relative; width: 100%; flex: 1 1 auto; min-height: 240px;
    border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
    background: rgba(0,0,0,0.25);
  }
  #ps3d-container { position: absolute; inset: 0; }
  #ps3d-container canvas { display: block; }
  #ps3d-loading {
    position: absolute; inset: 0; z-index: 3;
    display: none; flex-direction: column; align-items: center; justify-content: center;
    gap: 12px; color: var(--ink-dim); font-size: 12px; letter-spacing: 0.5px;
    background: rgba(15,10,8,0.55); pointer-events: none;
  }
  #ps3d-loading.show { display: flex; }
  #ps3d-hint {
    position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
    z-index: 3; pointer-events: none;
    background: rgba(0,0,0,0.45); color: var(--ink-dim);
    font-size: 10px; padding: 4px 10px; border-radius: 12px;
    border: 1px solid var(--line); white-space: nowrap;
  }
  /* Show the 3D park when active, the flat grid otherwise. */
  #parkSetup.ps-3d .ps-park { display: none; }
  #parkSetup:not(.ps-3d) #ps3d-area { display: none; }
  #parkSetup:not(.ps-choosing-playboard) #psPlayboardPhase { display: none; }
  .ps-playboards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
    flex: 1 1 auto; min-height: 0;
    align-content: start;
    overflow-y: auto;
    padding: 6px;
    background: rgba(0,0,0,0.25);
    border: 1px solid var(--line);
    border-radius: 8px;
  }
  .ps-board-choice {
    position: relative;
    min-height: 104px;
    aspect-ratio: 4 / 3;
    border: 2px solid transparent;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    background-size: cover;
    background-position: center;
    background-color: var(--panel-2);
    padding: 0;
    color: var(--ink);
    font: inherit;
    text-align: left;
    transition: transform 0.1s, border-color 0.1s, box-shadow 0.1s;
  }
  .ps-board-choice:hover { transform: translateY(-2px); border-color: var(--teal); }
  .ps-board-choice.active {
    border-color: var(--pink);
    box-shadow: 0 0 16px var(--pink-glow);
  }
  .ps-board-choice span {
    position: absolute; left: 0; right: 0; bottom: 0;
    padding: 18px 8px 7px;
    background: linear-gradient(180deg, transparent, rgba(0,0,0,0.78));
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    text-shadow: 0 1px 3px #000;
  }
  /* The trailer-design gallery — the star of this screen. Big rotating 3D
     swatches fill the picker column and scroll within it. */
  .ps-palette {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(clamp(110px, 12vw, 160px), 1fr));
    gap: 12px; padding: 10px;
    flex: 1 1 auto; min-height: 0; align-content: start;
    overflow-y: auto;
    background: rgba(0,0,0,0.25); border: 1px solid var(--line); border-radius: 8px;
  }
  .ps-swatch {
    position: relative; overflow: hidden;
    aspect-ratio: 1 / 1; border-radius: 10px; cursor: pointer;
    background-size: cover; background-position: center; background-color: var(--panel-2);
    border: 2px solid var(--line); transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
  }
  .ps-swatch:hover { transform: scale(1.05); border-color: var(--teal); z-index: 2; }
  .ps-swatch.active { border-color: var(--pink); box-shadow: 0 0 18px var(--pink-glow); }
  /* Design number tag so each swatch is identifiable at a glance. */
  .ps-swatch::after {
    content: attr(data-design); position: absolute; bottom: 4px; right: 6px;
    font-size: 10px; font-weight: 800; color: #fff; text-shadow: 0 1px 3px #000;
    pointer-events: none;
  }
  /* Rotating 3D model thumbnail, drawn into a per-swatch canvas (see
     TrailerThumbnails). Sits over the flat-texture fallback background. */
  .ps-swatch-canvas {
    position: absolute; inset: 0; width: 100%; height: 100%;
    display: block; pointer-events: none;
  }
  /* Footer holds the Randomize/Ready actions and everyone's readiness chips. */
  .ps-footer {
    flex: 0 0 auto;
    display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
    padding-top: 10px; border-top: 1px solid var(--line);
  }
  .ps-footer .ps-actions { flex: 0 0 auto; margin-top: 0; min-width: 300px; }
  .ps-footer .ps-players { margin-top: 0; flex: 1 1 auto; justify-content: flex-end; }
  #psPlayboardPhase .ps-actions { margin-top: 12px; }
  .ps-actions { display: flex; gap: 10px; margin-top: 16px; }
  .ps-btn {
    flex: 1; padding: 11px 18px; border: 1px solid var(--line); border-radius: 6px;
    background: var(--panel-2); color: var(--ink); cursor: pointer;
    font-weight: 800; font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px;
  }
  .ps-btn:hover { filter: brightness(1.15); }
  .ps-btn.primary { background: var(--pink); color: #fff; border-color: var(--pink); box-shadow: 0 0 16px var(--pink-glow); }
  .ps-btn.primary.readied { background: var(--good); border-color: var(--good); box-shadow: 0 0 16px rgba(111,207,151,0.5); color: #06210f; }
  .ps-players { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
  .ps-pchip {
    display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700;
    background: var(--panel-2); border: 1px solid var(--line); border-radius: 14px; padding: 5px 12px;
  }
  .ps-pchip.ready { border-color: var(--good); color: var(--good); }
  .ps-pchip .ps-state { font-size: 11px; color: var(--ink-dim); font-weight: 600; }
  .ps-pchip.ready .ps-state { color: var(--good); }

  /* Narrow screens: stack the stage over the picker and let the whole box
     scroll, so the park preview and the design gallery each keep a usable size.
     The body takes natural height (flex: 0 0 auto) so it never compresses its
     content onto the footer. */
  @media (max-width: 900px) {
    .ps-box { overflow-y: auto; }
    .ps-body {
      flex: 0 0 auto; min-height: 0;
      grid-template-columns: 1fr;
      grid-auto-rows: auto;
    }
    .ps-stage { min-height: 0; }
    #ps3d-area { flex: 0 0 auto; height: 44vh; min-height: 240px; }
    .ps-palette, .ps-playboards { flex: 0 0 auto; max-height: 48vh; }
    .ps-footer { flex-direction: column; align-items: stretch; }
    .ps-footer .ps-players { justify-content: flex-start; }
  }

  /* Compact the rack before it can crowd the park stage on short screens. */
  @media (max-height: 820px) {
    :root { --hand-card-width: clamp(142px, 10vw, 176px); }
    header { padding-top: 6px; padding-bottom: 6px; }
    .hand { min-height: clamp(206px, 15vw, 258px); }
    .panel { padding: 8px; }
    .panel h2 { margin-bottom: 6px; }
  }

  /* On narrow desktops — and on any short-and-wide viewport (phones in
     landscape can exceed 900px wide) — the status rail becomes a drawer. */
  @media (max-width: 900px), (orientation: landscape) and (max-height: 520px) {
    main { position: relative; grid-template-columns: minmax(0, 1fr); }
    .rail-toggle { display: inline-block; background: var(--panel-2); color: var(--teal); border: 1px solid var(--teal); box-shadow: none; }
    .right {
      position: absolute; top: 8px; right: 8px; bottom: 8px; z-index: 190;
      width: min(320px, calc(100vw - 16px)); padding: 8px;
      border: 1px solid var(--line); border-radius: 10px;
      background: rgba(15,10,8,0.97); box-shadow: 0 16px 50px rgba(0,0,0,0.84);
      transform: translateX(calc(100% + 18px)); transition: transform 0.22s ease;
    }
    body.rail-open .right { transform: translateX(0); }
    #toast-stack { right: 14px; width: min(430px, calc(100vw - 28px)); }
  }

  @media (max-width: 600px) {
    header { gap: 10px; padding-inline: 10px; }
    header h1 { width: 100%; font-size: 17px; }
    .cr-wrap { grid-template-columns: 132px minmax(0, 1fr); gap: 11px; padding: 10px; }
    .cr-name { font-size: 17px; }
    .cr-act { font-size: 10px; }
    .zoom-header { padding-inline: 104px; }
  }

  @media (hover: none) {
    .hand-show-btn, .hand-flip-btn { opacity: 1; }
  }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; }
    .cr-wrap, #cardReveal.out .cr-wrap, .cr-progress::after { animation: none !important; }
    .right, .hand-card, .mini-park { transition-duration: 0.01ms !important; }
  }

  /* ══ MOBILE — the game plays landscape-only on phones ═══════════════════
     A small touch screen held upright gets a full-screen rotate prompt; the
     rules below it re-fit every screen to a short, wide viewport
     (roughly 640-930 x 320-460). Tablets keep the desktop layout. */
  #rotateOverlay {
    position: fixed; inset: 0; z-index: 300; display: none;
    align-items: center; justify-content: center; text-align: center;
    background:
      radial-gradient(circle at 50% 30%, rgba(255,91,138,0.14), transparent 60%),
      var(--bg);
    padding: 24px;
  }
  .rotate-card { max-width: 300px; }
  .rotate-icon {
    font-size: 56px; display: inline-block;
    transform: rotate(90deg);
    animation: rotatePhone 1.6s ease-in-out infinite alternate;
  }
  @keyframes rotatePhone { from { transform: rotate(0deg); } to { transform: rotate(90deg); } }
  @media (prefers-reduced-motion: reduce) { .rotate-icon { animation: none; } }
  #rotateOverlay h2 { color: var(--pink); text-shadow: 0 0 14px var(--pink-glow); margin: 10px 0 6px; }
  #rotateOverlay p { color: var(--ink-dim); line-height: 1.5; margin: 0; }
  @media (pointer: coarse) and (orientation: portrait) and (max-width: 940px) {
    #rotateOverlay { display: flex; }
  }

  /* Touch screens of any size: hover can't reveal things, so keep inline
     card buttons visible (see hover:none rule above) and stop iOS zooming
     the whole page when a sub-16px input gains focus. */
  @media (pointer: coarse) {
    #setup input, #setup select { font-size: 16px; }
  }

  /* Phone landscape (or any short, wide window): shrink chrome, keep the
     park stage. Not gated on touch so squat desktop windows benefit too. */
  @media (orientation: landscape) and (max-height: 520px) {
    :root {
      --hand-card-width: clamp(80px, 24vh, 112px);
      --zoom-trailer-w: 46px;
      --zoom-trailer-h: 64px;
    }

    /* One row of parks: a short, wide viewport fits 4-6 side by side with a
       far better aspect ratio than the desktop 2-row grids. */
    #overview-area.p4 { grid-template-columns: repeat(4, 1fr); grid-template-rows: 1fr; }
    #overview-area.p5 { grid-template-columns: repeat(5, 1fr); grid-template-rows: 1fr; }
    #overview-area.p5 > .mini-park,
    #overview-area.p5 > .mini-park:nth-child(4),
    #overview-area.p5 > .mini-park:nth-child(5) { grid-column: auto; }
    #overview-area.p6 { grid-template-columns: repeat(6, 1fr); grid-template-rows: 1fr; }

    /* Respect notch / home-indicator safe areas. */
    header {
      padding: 3px max(10px, env(safe-area-inset-right)) 3px max(10px, env(safe-area-inset-left));
      gap: 10px;
    }
    header h1 { font-size: 13px; letter-spacing: 0.5px; }
    .stat .label { font-size: 8px; letter-spacing: 0.6px; }
    .stat .val { font-size: 12px; }
    header button { padding: 5px 9px; font-size: 10px; }
    main {
      gap: 6px;
      padding: 6px max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
    }
    .left { gap: 6px; }
    .panel { padding: 6px; }

    /* Hand: cards sized off viewport height so the parks keep the majority. */
    #handPanel { padding: 3px 8px 5px; }
    #handPanel h2 { margin-bottom: 3px; padding-bottom: 2px; }
    .hand { gap: 7px; padding: 5px 2px; min-height: 0; }
    .hand-card:hover { transform: none; }
    .hand-card.selected { transform: translateY(-2px) scale(1.02); }

    /* Zoomed park chrome. */
    .zoom-header { min-height: 30px; padding: 4px 92px; gap: 8px; }
    .zoom-header .pname { font-size: 14px; }
    #zoom-back, #view-toggle { padding: 7px 10px; }

    /* Right rail drawer (activated by the shared drawer query above). */
    .right {
      top: 6px; bottom: 6px;
      right: max(6px, env(safe-area-inset-right));
      width: min(300px, 62vw);
    }

    /* Join / lobby: allow the box to scroll inside the short viewport. */
    #setup { padding: 10px; }
    #setup .box {
      min-width: min(420px, 100%);
      max-width: min(520px, 100%);
      max-height: 100%;
      overflow-y: auto;
      padding: 14px 22px;
    }
    #setup h1 { font-size: 20px; margin-bottom: 2px; }
    #setup .tagline { margin-bottom: 10px; }
    .setup-doc-links { margin: -2px auto 10px; }
    .setup-doc-links .setup-guide-link { margin: 0; }
    #setup button { margin-top: 10px; padding: 9px; }
    #setup button.secondary-btn { margin-top: 8px; }
    .setup-hint { margin-top: 8px; }

    /* Park setup: side-by-side again (the narrow-screen stacking above is for
       portrait-ish shapes); the picker column scrolls, the 3D stage flexes. */
    .ps-box { overflow: hidden; gap: 6px; padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left)); }
    .ps-head h2 { font-size: 16px; margin: 0; }
    .ps-sub { display: none; }
    .ps-body {
      flex: 1 1 auto; min-height: 0;
      grid-template-columns: minmax(0, 1.2fr) minmax(220px, 0.8fr);
      gap: 8px;
    }
    .ps-stage { min-height: 0; }
    #ps3d-area { flex: 1 1 auto; height: auto; min-height: 0; }
    .ps-picker { min-height: 0; }
    /* Undo the narrow-screen "natural height" mode: in landscape the grids
       must shrink to the picker column and scroll inside it. */
    .ps-palette, .ps-playboards { flex: 1 1 auto; max-height: none; }
    .ps-palette { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; padding: 7px; }
    .ps-playboards { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
    .ps-footer { flex-direction: row; align-items: center; gap: 10px; padding-top: 6px; }
    .ps-footer .ps-players { justify-content: flex-end; }
    .ps-footer .ps-actions { min-width: 240px; }
    .ps-btn { padding: 8px 12px; font-size: 12px; }

    /* Overlays sized to the short viewport. */
    .modal { padding: 12px 14px; min-width: 0; width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 20px); }
    .ci-card { width: min(330px, 60vw, calc((100dvh - 76px) * 5 / 7)); }
    .cr-wrap {
      width: min(470px, calc(100% - 16px));
      grid-template-columns: minmax(92px, 118px) minmax(0, 1fr);
      gap: 10px; padding: 10px;
    }
    .cr-name { font-size: 15px; }
  }
