/* =================================================================
   MIDDEN — stylesheet
   :root holds the neutral MIDDEN palette (used by lobby + as a fallback).
   Each theme provides body.theme-<id> overrides via theme-styles
   (injected by js/theme.js).  The lobby explicitly re-overrides those
   variables back to neutral so it always reads as MIDDEN itself,
   independent of the user's theme selection.
   ================================================================= */

:root {
  /* MIDDEN — the umbrella brand's own visual identity. "Cabinet at Twilight":
     a museum vitrine at dusk. Cool charcoal field, bone-cream specimen
     surfaces, verdigris (patina) accent, earth-tone suits keyed to dig-site
     finds. Distinct from Bureau (warm sepia + rust) and Shiver (deep ocean
     + cyan) — neither palette appears here. */
  --bg-page: #14181c;
  --bg-app:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.012) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, #252a2e 0%, #0e1114 100%);
  --card-bg: #e8e3d5;
  --card-text: #1a1c20;
  --surface-light: #e8e3d5;
  --surface-text: #1a1c20;
  --accent: #5d8e7e;          /* verdigris — patina on buried bronze */
  --accent-text: #0e1114;
  --accent-line: #5d8e7e;
  --top-bar-bg: #0e1114;
  --top-bar-text: #e8e3d5;

  /* Suit accents — earth tones, all distinct from both bundled themes. */
  --suit-DOM: #b35a2c;        /* terracotta — clay shards */
  --suit-MNE: #c4a468;        /* sandy ochre — bone fragments */
  --suit-SEN: #4f5b6b;        /* flint slate — knapped tools */
  --suit-PRO: #6e4a6b;        /* mulberry — pottery glaze */

  /* Generic labels — themes override with their own flavor (CITIZEN INQUIRY,
     HUNGER, etc.). MIDDEN-neutral defaults are descriptive of mechanic. */
  --label-inquiry: 'AIM';
  --label-filed:   'KEPT';
  --label-memo:    'HIDDEN';

  /* MIDDEN typography — Cinzel as a Roman-inscribed wordmark for the brand,
     Inter for clean museum-label UI text, Spectral for scholarly italics.
     Themes override on body.theme-X. */
  --font-display: 'Cinzel', Georgia, serif;
  --font-body:    'Inter', system-ui, sans-serif;
  --font-flavor:  'Spectral', Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-body);
  background: var(--bg-page);
  color: #2b2620;
  overflow: hidden;
}

/* Themed app surface (game screen reads this; lobby paints over it).
   100dvh accounts for mobile browser chrome (iOS Chrome/Safari URL bar);
   100vh is the fallback for browsers that don't support dvh yet. */
#app {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: var(--bg-app);
  overflow: hidden;
}

/* The lobby (title + waiting room + feedback modal) always reads as MIDDEN's
   own identity, regardless of which theme is selected for play. We re-pin
   every palette variable to the MIDDEN values from :root so an active
   body.theme-X can never bleed into the lobby. */
#title-screen,
#waiting-screen,
#feedback-overlay {
  --bg-app:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.012) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, #252a2e 0%, #0e1114 100%);
  --card-bg: #e8e3d5;
  --card-text: #1a1c20;
  --surface-light: #e8e3d5;
  --surface-text: #1a1c20;
  --accent: #5d8e7e;
  --accent-text: #0e1114;
  --accent-line: #5d8e7e;
  --top-bar-bg: #0e1114;
  --top-bar-text: #e8e3d5;
  --font-display: 'Cinzel', Georgia, serif;
  --font-body:    'Inter', system-ui, sans-serif;
  --font-flavor:  'Spectral', Georgia, serif;
  background: var(--bg-app);
  /* Re-resolve font-family inside the lobby scope. Without this, children
     that don't declare their own font-family (.dept-header, .title-foot,
     <input>) inherit the body-level resolved value, which would be the
     active theme's body font (e.g. Bureau's Special Elite typewriter). */
  font-family: var(--font-body);
}

/* Form controls don't inherit font-family by default (UA stylesheets pin
   them to a system sans). Force them to use the lobby's body font so the
   name input + room-code input read in MIDDEN's Inter, not the OS default
   nor the active theme's typewriter. */
#title-screen input,
#title-screen select,
#waiting-screen input,
#waiting-screen select,
#feedback-overlay input,
#feedback-overlay textarea,
#feedback-overlay select {
  font-family: var(--font-body);
}

.hidden { display: none !important; }

.screen {
  width: 100%;
  height: 100%;
}

/* ============= TITLE SCREEN ============= */
#title-screen {
  display: flex;
  align-items: center;
  justify-content: center;
}

.title-card {
  width: 540px;
  background: var(--surface-light);
  color: var(--surface-text);
  border: 2px solid var(--surface-text);
  padding: 36px 44px 28px;
  box-shadow:
    0 0 0 6px var(--surface-light),
    0 0 0 8px var(--surface-text),
    8px 12px 20px rgba(0,0,0,0.6);
  text-align: center;
  position: relative;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(0,0,0,0.04) 0%, transparent 30%),
    radial-gradient(circle at 80% 70%, rgba(0,0,0,0.04) 0%, transparent 30%);
}

.dept-header {
  font-size: 11px;
  letter-spacing: 2px;
  border-bottom: 1px solid var(--surface-text);
  padding-bottom: 8px;
  margin-bottom: 18px;
}

.title-card h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 48px;
  margin: 0 0 8px;
  letter-spacing: 2px;
  line-height: 1;
}

.title-card .subtitle {
  font-family: var(--font-flavor);
  font-style: italic;
  font-size: 32px;
  font-weight: 500;
  letter-spacing: 0;
}

.title-blurb {
  font-family: var(--font-flavor);
  font-size: 18px;
  margin: 24px 8px;
  line-height: 1.4;
}

.big-btn {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 3px;
  background: var(--accent);
  color: var(--accent-text);
  border: 2px solid var(--surface-text, #2b2620);
  padding: 12px 36px;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--surface-text, #2b2620);
  margin-top: 8px;
  transition: transform 80ms;
}
.big-btn:hover { transform: translate(-1px,-1px); box-shadow: 4px 4px 0 var(--surface-text, #2b2620); }
.big-btn:active { transform: translate(2px,2px); box-shadow: 1px 1px 0 var(--surface-text, #2b2620); }

.small-btn {
  font-family: var(--font-body);
  font-size: 11px;
  letter-spacing: 1px;
  background: color-mix(in srgb, var(--surface-light) 92%, transparent);
  color: var(--surface-text);
  border: 1px solid color-mix(in srgb, var(--surface-text) 35%, transparent);
  border-radius: 3px;
  padding: 4px 12px;
  cursor: pointer;
  margin-left: 4px;
  transition: background 120ms, border-color 120ms, color 120ms;
}
.small-btn:hover {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.title-foot {
  font-size: 10px;
  letter-spacing: 1.5px;
  margin-top: 22px;
  border-top: 1px solid var(--surface-text);
  padding-top: 8px;
  opacity: 0.7;
}
.footer-link {
  color: inherit;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
}
.footer-link:hover { color: var(--accent); }

/* Small "BETA" pill alongside the main wordmark */
.beta-tag {
  display: inline-block;
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  padding: 3px 8px;
  border-radius: 3px;
  background: var(--accent);
  color: var(--accent-text);
  vertical-align: middle;
  /* Float up so the pill sits next to the title's cap height, not its baseline */
  transform: translateY(-12px);
  margin-left: 10px;
}

/* Italic note below the title blurb, points users at the feedback form */
.beta-note {
  font-family: var(--font-flavor);
  font-style: italic;
  font-size: 14px;
  margin: 6px 0 0;
  color: color-mix(in srgb, var(--surface-text) 75%, transparent);
}

/* ============= FEEDBACK FORM =============
   Styled to match the lobby's neutral MIDDEN palette. */
.feedback-card { width: min(520px, 92vw); }
.feedback-card form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.feedback-card .lobby-label {
  text-align: left;
  width: 100%;
  max-width: none;
  margin-top: 6px;
}
.feedback-card input,
.feedback-card textarea {
  width: 100%;
  font-family: var(--font-body);
  font-size: 14px;
  background: color-mix(in srgb, var(--surface-light) 92%, white);
  color: var(--surface-text);
  border: 1px solid var(--surface-text);
  padding: 8px 10px;
  resize: vertical;
}
.feedback-card textarea {
  min-height: 120px;
  line-height: 1.4;
}
.feedback-card .lobby-actions {
  margin-top: 10px;
  flex-direction: row;
  justify-content: center;
}
.feedback-card #feedback-status {
  text-align: center;
  margin: 4px 0 0;
  min-height: 18px;
}
.feedback-card #feedback-status.error { color: #b03828; }
.feedback-card #feedback-status.ok    { color: var(--accent); font-weight: 600; }

/* ============= LANDSCAPE TITLE LAYOUT =============
   Main menu reads horizontally (the game screen is landscape, the entry
   should match). Two-column body: brand on the left (header + monumental
   wordmark + blurb stacked), form on the right (pickers + name + actions),
   a thin vertical divider between them, and a centered footer bar.
   Falls back to the portrait single-column at <760px viewports. */
#title-screen .title-card {
  width: min(880px, 92vw);
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  grid-template-rows: auto auto auto 1fr auto;
  grid-template-areas:
    "header header"
    "title  form"
    "blurb  form"
    "beta   form"
    "foot   foot";
  column-gap: 44px;
  row-gap: 12px;
  padding: 28px 44px 22px;
  text-align: left;
  align-items: start;
}

#title-screen .dept-header { grid-area: header; text-align: center; }

#title-screen .title-card h1 {
  grid-area: title;
  align-self: end;
  font-size: 72px;
  letter-spacing: 6px;
  text-align: left;
  margin: 0;
}

#title-screen .title-blurb {
  grid-area: blurb;
  text-align: left;
  margin: 4px 0 0;
}

#title-screen .beta-note {
  grid-area: beta;
  text-align: left;
  margin: 8px 0 0;
}

#title-screen #lobby-form-wrap {
  grid-area: form;
  align-self: stretch;
  justify-content: center;
  align-items: stretch;
  margin: 0;
  border-left: 1px solid color-mix(in srgb, var(--surface-text) 22%, transparent);
  padding-left: 32px;
}

/* Form-column children fill the column, not the global 320px cap */
#title-screen .lobby-pickers,
#title-screen .lobby-label,
#title-screen #display-name,
#title-screen #room-code-input {
  max-width: none;
  width: 100%;
}

/* Stack action buttons in the right column so each gets its own line */
#title-screen .lobby-actions {
  flex-direction: column;
  align-items: stretch;
  flex-wrap: nowrap;
}
#title-screen .lobby-actions .big-btn {
  width: 100%;
  margin-top: 0;
}

#title-screen .title-foot {
  grid-area: foot;
  text-align: center;
  margin-top: 14px;
}

/* Narrow viewports — collapse back to single-column portrait */
@media (max-width: 760px) {
  #title-screen .title-card {
    width: min(540px, 92vw);
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto auto auto;
    grid-template-areas:
      "header"
      "title"
      "blurb"
      "beta"
      "form"
      "foot";
    text-align: center;
    padding: 28px 32px 20px;
  }
  #title-screen .title-card h1 {
    font-size: 48px;
    letter-spacing: 2px;
    text-align: center;
    align-self: center;
  }
  #title-screen .title-blurb { text-align: center; }
  #title-screen .beta-note { text-align: center; }
  #title-screen #lobby-form-wrap {
    border-left: none;
    padding-left: 0;
    align-items: center;
  }
  #title-screen .lobby-pickers,
  #title-screen .lobby-label,
  #title-screen #display-name,
  #title-screen #room-code-input {
    max-width: 320px;
  }
  #title-screen .lobby-actions {
    flex-direction: row;
    flex-wrap: wrap;
  }
  #title-screen .lobby-actions .big-btn {
    width: auto;
  }
}

/* ============= GAME SCREEN =============
   Tight grid: top bar fixed, opponents single-row, trick takes leftover
   vertical, player area sized to its content (cards + header + optional
   inline pinned panel). All four areas share padding + gap of 4px. */
#game-screen {
  display: grid;
  grid-template-rows: 34px auto 1fr auto;
  height: 100vh;
  height: 100dvh;
  gap: 4px;
  padding: 4px;
}

#top-bar {
  display: flex;
  background: var(--top-bar-bg);
  color: var(--top-bar-text);
  padding: 4px 10px;
  align-items: center;
  font-size: 11px;
  letter-spacing: 1.5px;
  border-bottom: 2px solid var(--accent-line);
  gap: 10px;
}
.top-section { flex: 1; display: flex; gap: 18px; }
.top-section.center { justify-content: center; }
.top-section.right { justify-content: flex-end; }
.round-label, .trick-label { padding: 2px 10px; border: 1px solid var(--top-bar-text); }
#status-msg { font-style: italic; opacity: 0.95; letter-spacing: 1px; }

/* ===== Opponent areas — each opponent is a single-line strip ===== */
#opponents {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.opponent {
  background: rgba(241,227,196,0.06);
  border: none;
  padding: 4px 8px;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto 1fr;
  gap: 3px 8px;
  min-height: 0;
  min-width: 0;
  align-items: center;
}
.opp-header {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.opp-header > * { white-space: nowrap; }
.opp-hand-row {
  grid-column: 1;
  grid-row: 2;
  align-self: center;
  min-width: 0;
}
.opponent .cabinet-row {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}
.opponent .cabinet-label {
  flex: 0 0 auto;
}
.opponent .cabinet {
  flex: 1;
  min-width: 0;
  min-height: 0;
}

.opp-name {
  font-weight: bold;
  color: var(--top-bar-text);
  font-size: 12px;
  letter-spacing: 1px;
}
.opp-score, .player-score {
  background: transparent;
  color: #ffffff;
  font-size: 9px;
  padding: 1px 5px;
  border: 1px solid #ffffff;
  letter-spacing: 1px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
.score-num {
  font-weight: bold;
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
.opp-stamp-status, .player-stamp-status {
  font-size: 9px;
  padding: 1px 5px;
  border: 1px solid var(--top-bar-text);
  color: var(--top-bar-text);
  letter-spacing: 1px;
}
.opp-stamp-status.spent, .player-stamp-status.spent {
  opacity: 0.4;
  text-decoration: line-through;
}

.opp-hand-row { display: flex; align-items: center; min-height: 0; }
.opp-hand { display: flex; }
.opp-hand .card-back {
  width: 44px;
  height: 62px;
  margin-right: -20px;
  background: #6e2a20;
  border: 1px solid #2b2620;
  border-radius: 3px;
  background-image:
    repeating-linear-gradient(45deg, transparent 0 4px, rgba(0,0,0,0.1) 4px 5px);
  box-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}
.opp-hand .card-back:last-child { margin-right: 0; }

.cabinet-row, .player-cabinet-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 0;
}
.cabinet-label, .hand-label {
  color: var(--top-bar-text);
  font-size: 9px;
  letter-spacing: 1.5px;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  padding: 2px 3px;
  border: 1px solid var(--top-bar-text);
  flex-shrink: 0;
}
.cabinet {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  padding: 4px;
  background: rgba(0,0,0,0.15);
  border: 1px solid rgba(241,227,196,0.2);
  flex: 1;
  min-height: 0;
  align-content: flex-start;
}
.opponent .cabinet { min-height: 64px; }
.player-cabinet-row .cabinet { min-height: 110px; }

/* ===== Trick area ===== */
#trick-area {
  background: rgba(0,0,0,0.25);
  border: 2px solid var(--accent-line);
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  position: relative;
  min-height: 0;
}
.trick-label-big {
  color: var(--top-bar-text);
  font-size: 10px;
  letter-spacing: 2.5px;
}
#led-suit { color: #ffb87c; font-weight: bold; }
.trick-slots {
  display: flex;
  gap: 20px;
  justify-content: center;
  align-items: center;
}
.trick-slot {
  width: 116px;
  height: 168px;
  border: none;
  background: rgba(241,227,196,0.04);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  position: relative;
  padding: 4px;
}
.trick-slot-label {
  position: absolute;
  bottom: -14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  letter-spacing: 0.5px;
  color: var(--top-bar-text);
  white-space: nowrap;
  pointer-events: none;
}
.trick-slot.winning {
  border: 2px solid #ffb87c;
  background: rgba(255, 184, 124, 0.15);
}
.trick-slot.fileable {
  border: 2px solid #5fcc6a;
  background: rgba(95, 204, 106, 0.15);
  cursor: pointer;
}
.trick-slot.fileable:hover {
  background: rgba(95, 204, 106, 0.3);
}
#file-prompt {
  margin-top: 4px;
  padding: 6px 16px;
  font-size: 13px;
  background: #5fcc6a;
  color: #1d1a14;
}

/* ===== Player area ===== */
#player-area {
  background: rgba(241,227,196,0.08);
  border: 1px solid rgba(241,227,196,0.3);
  padding: 6px 10px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 4px;
  min-height: 0;
}
body.in-game.show-pinned-inquiry #player-area {
  grid-template-rows: auto auto 1fr;
}
.player-header {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--top-bar-text);
  font-size: 12px;
  letter-spacing: 1px;
  align-items: center;
}
.player-name { font-weight: bold; }

/* Senses + Territory share one row, side-by-side */
.player-play-row {
  display: flex;
  gap: 12px;
  min-height: 0;
  align-items: stretch;
}
.player-cabinet-row {
  flex: 0 1 auto;
  display: flex;
  align-items: stretch;
  gap: 8px;
  min-width: 0;
  max-width: 50%;
}
.player-hand-row {
  flex: 1 1 auto;
  display: flex;
  align-items: stretch;
  gap: 8px;
  min-width: 0;
}
.player-cabinet-row .cabinet {
  flex: 1;
  min-width: 0;
}
.hand {
  display: flex;
  gap: 6px;
  flex: 1;
  flex-wrap: wrap;
  padding: 4px;
  min-width: 0;
  align-content: flex-start;
}

/* =================================================================
   THE CARD ITSELF
   ================================================================= */
.card {
  width: 116px;
  height: 168px;
  background: var(--card-bg);
  border: 1px solid var(--card-text);
  border-radius: 3px;
  position: relative;
  display: flex;
  flex-direction: column;
  cursor: default;
  font-family: var(--font-body);
  color: var(--card-text);
  box-shadow: 1px 1px 3px rgba(0,0,0,0.5);
  user-select: none;
  /* Clip rotated/positioned children (stamp tilt, FILED/MEMO overlays)
     to the card boundary so they don't bleed into the gap between cards. */
  overflow: hidden;
  background-image:
    radial-gradient(circle at 30% 20%, rgba(0,0,0,0.06) 0%, transparent 35%),
    radial-gradient(circle at 70% 80%, rgba(0,0,0,0.06) 0%, transparent 35%);
}

.card.small {
  width: 94px;
  height: 134px;
}

.card.playable {
  cursor: pointer;
}
.card.playable:hover {
  transform: translateY(-8px);
  box-shadow: 2px 6px 8px rgba(0,0,0,0.5);
  z-index: 10;
}

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

.card.selected {
  transform: translateY(-12px);
  box-shadow: 0 0 0 2px var(--accent), 2px 6px 8px rgba(0,0,0,0.5);
}

.card-form-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 2px;
  padding: 4px 4px;
  border-bottom: 1px solid var(--card-text);
  font-size: 11px;
  letter-spacing: 0.5px;
}
.card-suit {
  font-family: var(--font-display);
  font-weight: 700;
  /* Smaller than the rank — suits read as a tag, ranks read as the
     number. Sized so "SENTIMENTAL" (11 chars, longest bundled name)
     fits within a 116px card alongside a 2-digit rank. */
  font-size: 9px;
  letter-spacing: 0.3px;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: clip;
}
.card-rank {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.5px; /* tighten "10" so it doesn't push the suit off */
  flex: 0 0 auto; /* never shrink — suit clips first */
}

.card-flavor {
  flex: 1;
  font-family: var(--font-flavor);
  font-style: italic;
  font-size: 13px;
  line-height: 1.2;
  padding: 7px 8px;
  display: flex;
  align-items: center;
  text-align: center;
  overflow: hidden;
}

.card.small .card-form-header { font-size: 10px; padding: 4px 6px; }
.card.small .card-suit { font-size: 7px; }
.card.small .card-rank { font-size: 13px; }
.card.small .card-flavor { font-size: 11px; padding: 5px 6px; line-height: 1.15; }
.card.small .card-stamp { font-size: 9px; padding: 4px 3px; }

.card-stamp {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.4px;
  text-align: center;
  padding: 4px 3px;
  border-top: 1px dashed var(--card-text);
  color: var(--accent);
  background: rgba(0,0,0,0.04);
  position: relative;
  text-transform: uppercase;
  transform: rotate(-1.5deg);
  line-height: 1.1;
  white-space: normal;
  overflow: hidden;
  word-break: break-word;
  hyphens: auto;
}

/* Suit accents — colors come from active theme (or :root for MIDDEN neutral). */
.card[data-suit="DOM"] { box-shadow: inset 4px 0 0 var(--suit-DOM), 1px 1px 3px rgba(0,0,0,0.5); }
.card[data-suit="MNE"] { box-shadow: inset 4px 0 0 var(--suit-MNE), 1px 1px 3px rgba(0,0,0,0.5); }
.card[data-suit="SEN"] { box-shadow: inset 4px 0 0 var(--suit-SEN), 1px 1px 3px rgba(0,0,0,0.5); }
.card[data-suit="PRO"] { box-shadow: inset 4px 0 0 var(--suit-PRO), 1px 1px 3px rgba(0,0,0,0.5); }

.card[data-suit="DOM"] .card-suit { color: var(--suit-DOM); }
.card[data-suit="MNE"] .card-suit { color: var(--suit-MNE); }
.card[data-suit="SEN"] .card-suit { color: var(--suit-SEN); }
.card[data-suit="PRO"] .card-suit { color: var(--suit-PRO); }

/* Card on the table during a trick */
.trick-slot .card {
  margin-bottom: 6px;
  pointer-events: none;
}

/* =================================================================
   OVERLAYS
   ================================================================= */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.rules-card {
  background: var(--surface-light);
  color: var(--surface-text);
  border: 2px solid var(--surface-text);
  padding: 28px 36px;
  max-width: 540px;
  box-shadow:
    0 0 0 6px var(--surface-light),
    0 0 0 8px var(--surface-text),
    8px 12px 20px rgba(0,0,0,0.6);
}

.big-card { max-width: 720px; min-width: 540px; }

.rules-card h2 {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 3px;
  text-align: center;
  margin-top: 0;
  border-bottom: 2px solid var(--surface-text);
  padding-bottom: 8px;
}

.rules-card ol, .rules-card ul {
  font-family: var(--font-flavor);
  font-size: 17px;
  line-height: 1.5;
}

.close-overlay {
  display: block;
  margin: 18px auto 0;
  font-family: var(--font-display);
  background: var(--surface-text);
  color: var(--surface-light);
  border: none;
  padding: 8px 24px;
  letter-spacing: 2px;
  cursor: pointer;
}
.close-overlay:hover { background: var(--accent); color: var(--accent-text); }

.stamp-target-card { min-width: 480px; }
#stamp-overlay-body {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  padding: 14px 0;
}
.stamp-target-option {
  background: var(--surface-light);
  color: var(--surface-text);
  border: 2px solid var(--surface-text);
  padding: 10px 16px;
  cursor: pointer;
  font-family: var(--font-body);
  letter-spacing: 1px;
}
.stamp-target-option:hover { background: var(--accent); color: var(--accent-text); }

#round-end-body, #game-end-body {
  font-family: var(--font-flavor);
  font-size: 16px;
}
.round-result-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 8px;
  border-bottom: 1px dashed var(--surface-text);
}
.round-result-row:last-child { border-bottom: none; }
.round-result-row .player-name-cell {
  font-family: var(--font-display);
  letter-spacing: 1.5px;
}
.round-result-row .score-cell {
  font-family: var(--font-display);
  font-weight: bold;
  font-size: 18px;
}

/* Inquiry card display */
.inquiry-card-display {
  background: color-mix(in srgb, var(--surface-light) 92%, white);
  color: var(--surface-text);
  border: 1px solid color-mix(in srgb, var(--surface-text) 35%, transparent);
  border-radius: 3px;
  padding: 16px 20px;
  margin: 14px auto;
  max-width: 360px;
  font-family: var(--font-flavor);
  position: relative;
  box-shadow: 0 1px 3px rgba(0,0,0,0.18);
}
.inquiry-card-display::before {
  content: var(--label-inquiry, 'INQUIRY');
  position: absolute;
  top: -9px;
  left: 16px;
  background: var(--accent);
  color: var(--accent-text);
  font-family: var(--font-display);
  font-size: 9px;
  letter-spacing: 2px;
  padding: 2px 10px;
  border-radius: 3px;
}
.inquiry-card-display .inq-title {
  font-family: var(--font-display);
  letter-spacing: 1.5px;
  font-size: 14px;
  margin-bottom: 6px;
}
.inquiry-card-display .inq-desc {
  font-style: italic;
  font-size: 14px;
}
.inquiry-card-display .inq-score {
  margin-top: 6px;
  font-family: var(--font-flavor);
  font-size: 12px;
  color: var(--accent);
}

/* Card-action popup (anchored, no longer used as fixed) */
#card-action-popup {
  position: fixed;
  background: var(--surface-light);
  color: var(--surface-text);
  border: 2px solid var(--surface-text);
  padding: 8px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: 4px 4px 8px rgba(0,0,0,0.5);
}
#card-action-popup button {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 1.5px;
  padding: 6px 12px;
  background: var(--surface-text);
  color: var(--surface-light);
  border: none;
  cursor: pointer;
}
#card-action-popup button:hover { background: var(--accent); color: var(--accent-text); }
#cancel-action-btn { background: #777 !important; }

/* Subtle stamp-impression overlay on used cabinet cards */
.card.stamped::after {
  content: var(--label-filed, 'FILED');
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-12deg);
  font-family: var(--font-display);
  color: color-mix(in srgb, var(--accent) 65%, transparent);
  font-size: 18px;
  letter-spacing: 3px;
  border: 2px solid color-mix(in srgb, var(--accent) 65%, transparent);
  padding: 2px 8px;
  pointer-events: none;
}

.card.memo {
  background:
    repeating-linear-gradient(45deg, var(--card-bg) 0 6px, color-mix(in srgb, var(--card-bg) 88%, black) 6px 7px);
}
.card.memo .card-flavor { opacity: 0.5; }
.card.memo::after {
  content: var(--label-memo, 'MEMO');
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%) rotate(-8deg);
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--accent);
  font-size: 16px;
  letter-spacing: 2px;
  border: 2px double var(--accent);
  padding: 3px 7px;
  pointer-events: none;
  white-space: nowrap;
  max-width: 90%;
}
/* Smaller MEMO overlay on small (cabinet) cards so it fits inside the card */
.card.small.memo::after {
  font-size: 11px;
  letter-spacing: 1px;
  border-width: 1px;
  padding: 2px 5px;
}

/* Animation for cards entering trick */
@keyframes plopdown {
  0%   { transform: translateY(-30px) rotate(-8deg); opacity: 0; }
  100% { transform: translateY(0) rotate(0deg); opacity: 1; }
}
.trick-slot .card { animation: plopdown 0.25s ease-out; }

/* =================================================================
   COMPACT (iPad-friendly) — viewports under ~1100w or 850h
   Cards shrink so 7 in the hand fit alongside the cabinet.
   ================================================================= */
@media (max-width: 1100px), (max-height: 850px) {
  .card { width: 88px; height: 128px; }
  .card.small { width: 72px; height: 104px; }
  .trick-slot { width: 92px; height: 132px; }
  .opp-hand .card-back { width: 36px; height: 50px; margin-right: -16px; }
  .opp-hand .card-back:last-child { margin-right: 0; }
  .opp-hand-row { min-height: 52px; }
  .cabinet { min-height: 80px; }

  .card-form-header { padding: 3px 4px; font-size: 10px; gap: 2px; }
  .card-rank { font-size: 14px; }
  .card-suit { font-size: 8px; letter-spacing: 0.1px; }
  .card-flavor { font-size: 11px; padding: 5px 6px; line-height: 1.15; }
  .card-stamp { font-size: 9px; padding: 3px 3px; letter-spacing: 0.2px; line-height: 1.05; }

  .card.small .card-form-header { font-size: 9px; padding: 3px 5px; }
  .card.small .card-rank { font-size: 11px; }
  .card.small .card-suit { font-size: 6px; letter-spacing: 0; }
  .card.small .card-flavor { font-size: 9px; padding: 4px 4px; }
  .card.small .card-stamp { font-size: 8px; padding: 2px 2px; letter-spacing: 0; line-height: 1.0; }
  .card.memo::after { font-size: 13px; letter-spacing: 1px; padding: 2px 6px; }
  .card.small.memo::after { font-size: 9px; letter-spacing: 0.5px; padding: 1px 4px; border-width: 1px; }

  #game-screen {
    grid-template-rows: 36px minmax(124px, auto) 1fr minmax(160px, auto);
  }
}

/* Tighter still — 7 cards * 88px ≈ 616 + cabinet ≈ 250 fits 1024 with room */
@media (max-width: 900px) {
  .card { width: 78px; height: 114px; }
  .card.small { width: 64px; height: 92px; }
  .trick-slot { width: 82px; height: 118px; }
}

/* =================================================================
   LOBBY / WAITING ROOM
   ================================================================= */
#lobby-form-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin: 18px 0 8px;
}
.lobby-pickers {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 320px;
}
.lobby-pickers .picker {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
/* Static GAME card — there's only one game (MIDDEN), so the picker is
   shown as a non-interactive label that visually parallels the THEME
   <select> below it. Restore a real <select> here when more games ship. */
.lobby-pickers .game-display {
  width: 100%;
  font-family: var(--font-display);
  font-size: 14px;
  letter-spacing: 3px;
  background: color-mix(in srgb, var(--surface-light) 92%, white);
  color: var(--surface-text);
  border: 1px solid color-mix(in srgb, var(--surface-text) 35%, transparent);
  border-radius: 3px;
  padding: 6px 10px;
  text-align: center;
  user-select: none;
}

.lobby-pickers select {
  width: 100%;
  font-family: var(--font-body);
  font-size: 14px;
  background: color-mix(in srgb, var(--surface-light) 92%, white);
  color: var(--surface-text);
  border: 1px solid var(--surface-text);
  padding: 6px 8px;
  cursor: pointer;
}
.lobby-label {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--surface-text);
  text-align: left;
  width: 100%;
  max-width: 320px;
  margin-bottom: -4px;
}
#display-name, #room-code-input {
  width: 100%;
  max-width: 320px;
  font-family: var(--font-body);
  font-size: 16px;
  background: color-mix(in srgb, var(--surface-light) 92%, white);
  color: var(--surface-text);
  border: 1px solid var(--surface-text);
  padding: 8px 12px;
  letter-spacing: 1px;
}
#room-code-input { text-transform: uppercase; letter-spacing: 6px; text-align: center; font-size: 22px; }

.lobby-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
}
.big-btn.alt {
  background: var(--surface-light);
  color: var(--surface-text);
  border: 2px solid var(--surface-text);
  box-shadow: 3px 3px 0 var(--surface-text);
}
.big-btn.alt:hover { background: color-mix(in srgb, var(--surface-light) 80%, black); }

#join-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin-top: 6px;
}
.lobby-error {
  color: var(--accent);
  min-height: 18px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: bold;
}
.lobby-hint {
  font-family: var(--font-flavor);
  font-style: italic;
  text-align: center;
  font-size: 14px;
  margin: 6px 0 4px;
}
#waiting-screen { display: flex; align-items: center; justify-content: center; }
.waiting-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 48px;
  letter-spacing: 4px;
  text-align: left;
  margin: 0;
  line-height: 1;
}
.room-code-display {
  font-family: var(--font-display);
  color: var(--surface-text);
}
/* Small "ROOM CODE" label on its own line */
.room-code-display > span:first-child {
  display: block;
  font-size: 11px;
  letter-spacing: 2px;
  margin-bottom: 4px;
}
/* The actual 4-letter code is the headline */
#room-code-value {
  display: block;
  font-size: 56px;
  font-weight: 700;
  letter-spacing: 12px;
  color: var(--accent);
  line-height: 1;
}

/* ============= LANDSCAPE WAITING-ROOM LAYOUT =============
   Mirrors the title screen: two columns with a thin vertical divider.
   Left column  = brand identity (header + title + room-code headline + hint).
   Right column = seat list.
   Bottom       = actions + status.
   Falls back to single-column at <760px. */
#waiting-screen .title-card {
  width: min(880px, 92vw);
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  grid-template-areas:
    "header  header"
    "title   seats"
    "code    seats"
    "hint    seats"
    "actions actions"
    "status  status";
  grid-template-rows: auto auto auto 1fr auto auto;
  column-gap: 44px;
  row-gap: 10px;
  padding: 28px 44px 22px;
  text-align: left;
  align-items: start;
}
#waiting-screen .dept-header { grid-area: header; text-align: center; }
#waiting-screen .waiting-title { grid-area: title; }
#waiting-screen .room-code-display { grid-area: code; text-align: left; }
#waiting-screen .title-card > .lobby-hint {
  grid-area: hint;
  text-align: left;
  margin: 0;
  font-size: 13px;
}
#waiting-screen .seat-list {
  grid-area: seats;
  margin: 0;
  max-width: none;
  align-self: stretch;
  border-left: 1px solid color-mix(in srgb, var(--surface-text) 22%, transparent);
  padding-left: 28px;
}
#waiting-screen .lobby-actions {
  grid-area: actions;
  flex-direction: row;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 6px;
}
#waiting-screen #waiting-status {
  grid-area: status;
  text-align: center;
  margin: 0;
}

@media (max-width: 760px) {
  #waiting-screen .title-card {
    width: min(540px, 92vw);
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "title"
      "code"
      "hint"
      "seats"
      "actions"
      "status";
    grid-template-rows: auto auto auto auto auto auto auto;
    text-align: center;
    padding: 28px 32px 20px;
  }
  #waiting-screen .waiting-title { text-align: center; font-size: 32px; }
  #waiting-screen .room-code-display { text-align: center; }
  #waiting-screen #room-code-value { letter-spacing: 8px; font-size: 44px; }
  #waiting-screen .title-card > .lobby-hint { text-align: center; }
  #waiting-screen .seat-list { border-left: 0; padding-left: 0; }
}
.seat-list { list-style: none; padding: 0; margin: 14px auto; max-width: 360px; }
.seat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin-bottom: 6px;
  background: color-mix(in srgb, var(--surface-light) 92%, white);
  color: var(--surface-text);
  border: 1px solid var(--surface-text);
  font-family: var(--font-body);
  font-size: 13px;
}
.seat.empty { opacity: 0.55; font-style: italic; }
.seat.me { box-shadow: inset 4px 0 0 var(--accent); }
.seat.disconnected { background: color-mix(in srgb, var(--surface-light) 80%, black); }
.seat-num { font-family: var(--font-display); font-size: 10px; letter-spacing: 2px; }
.seat-tag { font-size: 10px; letter-spacing: 2px; opacity: 0.7; }

/* Game log toast (multiplayer) */
#game-log-toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: color-mix(in srgb, var(--surface-light) 95%, transparent);
  border: 1px solid var(--surface-text);
  color: var(--surface-text);
  font-family: var(--font-body);
  font-size: 13px;
  padding: 8px 14px;
  z-index: 600;
  box-shadow: 2px 2px 6px rgba(0,0,0,0.4);
  pointer-events: none;
}

/* Opponent disconnect tag */
.opp-conn-status {
  font-size: 10px;
  padding: 2px 6px;
  border: 1px solid var(--accent);
  color: var(--accent);
  letter-spacing: 1.5px;
}

/* =================================================================
   PINNED PANELS — show inquiry above territory + marks reference
   ================================================================= */
.topbar-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  letter-spacing: 1px;
  cursor: pointer;
  margin-left: 8px;
  user-select: none;
  color: var(--top-bar-text);
}
.topbar-toggle input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}

/* Hunger / inquiry panel — single-line strip above player cabinet.
   Hugs its content rather than stretching across the player-area grid
   cell. justify-self anchors it to the left edge of the row. */
.pinned-inquiry {
  display: none;
  width: fit-content;
  max-width: 100%;
  justify-self: start;
  background: color-mix(in srgb, var(--card-bg) 92%, white);
  color: var(--card-text);
  border: 1px solid color-mix(in srgb, var(--card-text) 30%, transparent);
  border-radius: 3px;
  padding: 4px 14px;
  font-family: var(--font-flavor);
  font-size: 12px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.pinned-inquiry .pinned-inquiry-label {
  display: inline-block;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 9px;
  letter-spacing: 1.5px;
  color: var(--accent);
  margin-right: 6px;
}
.pinned-inquiry .pinned-inquiry-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 1px;
  margin-right: 6px;
}
.pinned-inquiry .pinned-inquiry-bonus {
  display: inline;
  font-style: italic;
  font-size: 10px;
  color: var(--accent);
  margin-left: 8px;
}
body.in-game.show-pinned-inquiry .pinned-inquiry { display: block; }

/* Marks reference panel — fixed top-right, auto-height */
.pinned-marks {
  display: none;
  position: fixed;
  right: 8px;
  top: 44px;
  width: 168px;
  background: color-mix(in srgb, var(--card-bg) 95%, white);
  color: var(--card-text);
  border: 1px solid color-mix(in srgb, var(--card-text) 30%, transparent);
  border-radius: 3px;
  padding: 8px 12px;
  z-index: 400;
  box-shadow: 0 4px 12px rgba(0,0,0,0.35), 0 1px 2px rgba(0,0,0,0.25);
  font-family: var(--font-body);
  font-size: 10px;
}
.pinned-marks h3 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 1.5px;
  text-align: center;
  border-bottom: 1px solid var(--card-text);
  padding-bottom: 3px;
}
.pinned-marks .mark-row {
  margin-bottom: 4px;
}
.pinned-marks .mark-row:last-child { margin-bottom: 0; }
.pinned-marks .mark-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--accent);
}
.pinned-marks .mark-desc {
  font-size: 10px;
  line-height: 1.2;
  font-family: var(--font-flavor);
  font-style: italic;
}
body.in-game.show-pinned-marks .pinned-marks { display: block; }
