@font-face {
  font-family: 'MonoLisa';
  src: url('/fonts/MonoLisa-Light.woff2') format('woff2');
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'MonoLisa';
  src: url('/fonts/MonoLisa-LightItalic.woff2') format('woff2');
  font-weight: 300;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'MonoLisa';
  src: url('/fonts/MonoLisa-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'MonoLisa';
  src: url('/fonts/MonoLisa-RegularItalic.woff2') format('woff2');
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'MonoLisa';
  src: url('/fonts/MonoLisa-Medium.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'MonoLisa';
  src: url('/fonts/MonoLisa-MediumItalic.woff2') format('woff2');
  font-weight: 500;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'MonoLisa';
  src: url('/fonts/MonoLisa-SemiBold.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'MonoLisa';
  src: url('/fonts/MonoLisa-SemiBoldItalic.woff2') format('woff2');
  font-weight: 600;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'MonoLisa';
  src: url('/fonts/MonoLisa-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'MonoLisa';
  src: url('/fonts/MonoLisa-BoldItalic.woff2') format('woff2');
  font-weight: 700;
  font-style: italic;
  font-display: swap;
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ═══════════════════════════════════════════════════════
   MONOKAI LIGHT — all colours in OKLCH
   Source palette: Monokai Pro (light)
   bg #fafaf8 · fg #403e41 · pink #ff6188 · orange #fc9867
   yellow #ffd866 · green #a9dc76 · cyan #78dce8 · purple #ab9df2
   ═══════════════════════════════════════════════════════ */
:root {
  /* Surfaces */
  --bg:       oklch(98%  0.005 88);   /* #fafaf8 */
  --surface:  oklch(100% 0.002 88);   /* #ffffff-ish */
  --surface2: oklch(93%  0.010 85);   /* #ebe8de selection highlight */
  --overlay:  oklch(90%  0.010 85);

  /* Text */
  --text:       oklch(30%  0.008 302); /* #403e41 */
  --text-muted: oklch(52%  0.005 300); /* mid-tone */
  --text-dim:   oklch(70%  0.004 300); /* #c2beb5 comment-ish */

  /* Monokai accent colours — adjusted for legibility on light */
  --pink:       oklch(58%  0.22  5);   /* #ff6188 → slightly darkened */
  --orange:     oklch(68%  0.16  47);  /* #fc9867 */
  --yellow-bg:  oklch(93%  0.12  88);  /* yellow as bg tint only */
  --green:      oklch(56%  0.16  133); /* #a9dc76 → darkened */
  --cyan:       oklch(62%  0.12  195); /* #78dce8 → darkened */
  --purple:     oklch(57%  0.18  298); /* #ab9df2 → darkened */

  /* Semantic mappings */
  --accent:       var(--pink);    /* buttons, keywords */
  --name-color:   var(--orange);  /* monster name */
  --stat-color:   var(--purple);  /* stat values, numbers */
  --label-color:  var(--cyan);    /* stat labels, keys */
  --section-color: var(--pink);   /* section headers */
  --detail-color: var(--green);   /* detail labels */

  /* Borders */
  --border:     oklch(87%  0.006 88);
  --border-dim: oklch(92%  0.004 88);

  /* Spacing (4pt scale) */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px; --sp-8: 64px;

  /* MonoLisa with calibrated fallback stack */
  --font: 'MonoLisa', 'MonoLisa Variable', 'Cascadia Code', 'Fira Code',
          'JetBrains Mono', 'Source Code Pro', ui-monospace, monospace;
  --font-display: 'Vollkorn', 'Georgia', 'Times New Roman', serif;

  --radius:    6px;
  --radius-sm: 3px;

  /* Gold tints for session codes and "your card" accents */
  --gold:     oklch(72% 0.14 68);
  --gold-dim: oklch(65% 0.12 68);

  /* Derived surface tints (extracted from inline values) */
  --chip-selected-bg:   oklch(97% 0.010 195);
  --card-stripe:        oklch(89% 0.008 85);
  --card-stripe-me:     oklch(92% 0.015 68);
  --card-border-me:     oklch(80% 0.08 68);
  --overlay-bg:         oklch(5% 0.005 42 / 0.92);
  --text-on-accent:     oklch(99% 0.002 5);
  --tldr-bg:            oklch(97% 0.010 195 / 0.5);

  /* Card game layout */
  --header-h: 44px;
  --hand-h:   360px;
}

html, body { height: 100%; }

body {
  background:  var(--bg);
  color:       var(--text);
  font-family: var(--font);
  font-size:   13.5px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Pages ── */
.page        { display: none; }
.page.active { display: block; }

/* ── Landing ── */
.landing-container {
  max-width: 500px;
  margin: 0 auto;
  padding: var(--sp-7) var(--sp-4) var(--sp-8);
}

.logo {
  font-family: var(--font-display);
  font-size: 2.2rem;
  font-weight: 900;
  text-align: center;
  color: var(--orange);
  letter-spacing: -0.02em;
  margin-bottom: var(--sp-2);
}

.tagline {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.82rem;
  margin-bottom: var(--sp-7);
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-5);
  margin-bottom: var(--sp-3);
}

/* Landing cards: make all buttons full-width for visual balance */
.landing-container .card .btn-secondary,
.landing-container .card .btn-file { width: 100%; }

.card h2 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: var(--sp-4);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.card h3 {
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--text-muted);
  margin: var(--sp-4) 0 var(--sp-3);
  letter-spacing: 0.03em;
}

.code-badge {
  color: var(--orange);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.divider {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.75rem;
  margin: var(--sp-2) 0;
}
.divider::before, .divider::after {
  content: '';
  display: inline-block;
  width: 28%;
  height: 1px;
  background: var(--border);
  vertical-align: middle;
  margin: 0 var(--sp-3);
}

/* ── Inputs ── */
input[type="text"], select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--sp-2) var(--sp-3);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.875rem;
  margin-bottom: var(--sp-3);
  outline: none;
  transition: border-color 0.12s;
}
input[type="text"]:focus, select:focus { border-color: var(--cyan); }
select { width: auto; margin-bottom: 0; }

/* ── Buttons ── */
.btn-primary, .btn-secondary, .btn-file {
  display: inline-block;
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: opacity 0.12s;
  text-align: center;
  letter-spacing: 0.01em;
}
.btn-primary:hover:not(:disabled),
.btn-secondary:hover:not(:disabled),
.btn-file:hover { opacity: 0.7; }
.btn-primary:disabled, .btn-secondary:disabled { opacity: 0.35; cursor: not-allowed; }

/* Focus indicators — visible for keyboard users, hidden for mouse */
:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}
.btn-primary:focus-visible { outline-color: var(--orange); }

.btn-primary  { background: var(--pink); color: var(--text-on-accent); width: 100%; }
.btn-secondary { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-file      { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }

.btn-icon {
  background: none; border: none;
  color: var(--text-dim); cursor: pointer;
  font-family: var(--font); font-size: 0.85rem;
  padding: 0 var(--sp-1); transition: color 0.12s;
}
.btn-icon:hover { color: var(--text-muted); }

/* ── Filters ── */
.filters-section { margin-top: var(--sp-2); }
.filter-row { margin-bottom: var(--sp-3); }
.filter-row > label { display: block; font-size: 0.75rem; color: var(--text-muted); margin-bottom: var(--sp-2); }

/* label row: filter name on left, "Unique" checkbox on right */
.filter-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-2);
}
.filter-label-row > label:first-child {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0;
}
.unique-label {
  font-size: 0.72rem !important;
  color: var(--text-dim) !important;
  gap: var(--sp-1) !important;
}

.cr-range { display: flex; align-items: center; gap: var(--sp-2); }
.cr-range span { color: var(--text-dim); font-size: 0.78rem; }

.type-grid { display: flex; flex-wrap: wrap; gap: var(--sp-1); }
.type-chip {
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 0.75rem;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.1s, color 0.1s, background-color 0.1s;
}
.type-chip.selected {
  border-color: var(--cyan);
  color: var(--cyan);
  background: var(--chip-selected-bg);
}
.type-chip.chip-disabled {
  opacity: 0.28;
  pointer-events: none;
  cursor: default;
}

/* ── Error / hint ── */
.error-msg { color: var(--pink); font-size: 0.78rem; min-height: 1.2em; margin-top: var(--sp-2); }
.hint      { color: var(--text-dim); font-size: 0.75rem; }
code { font-family: var(--font); background: var(--surface2); padding: 1px var(--sp-1); border-radius: var(--radius-sm); font-size: 0.85em; }

/* ── Session header ── */
.session-header {
  height: var(--header-h);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 var(--sp-5);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.logo-small {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--orange);
  font-size: 1rem;
  letter-spacing: -0.01em;
}

.session-header-right {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.session-code-display { color: var(--text-dim); font-size: 0.78rem; }
.session-code-display strong {
  color: var(--orange);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.btn-header {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 500;
  padding: var(--sp-1) var(--sp-3);
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.12s;
}
.btn-header:hover { opacity: 0.7; }

/* ── Session views ── */
.session-view        { display: none; }
.session-view.active { display: block; }

/* ── Lobby — flex column: filters scroll, button pinned at bottom ── */
#view-lobby {
  display: none;
  flex-direction: column;
  height: calc(100vh - var(--header-h));
  height: calc(100dvh - var(--header-h));
  overflow: hidden;
}
#view-lobby.active { display: flex; }

.lobby-container {
  max-width: 500px;
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-4);
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  width: 100%;
}
.lobby-container h2 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: var(--sp-2);
}

.player-list { margin: var(--sp-5) 0; display: flex; flex-direction: column; gap: var(--sp-2); }
.player-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  color: var(--text);
}

.badge {
  font-size: 0.68rem;
  background: var(--chip-selected-bg);
  color: var(--cyan);
  border: 1px solid var(--cyan);
  padding: 1px var(--sp-2);
  border-radius: var(--radius-sm);
  font-weight: 500;
  letter-spacing: 0.05em;
}

.host-filters {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-4);
  margin: var(--sp-4) 0;
}
.host-filters h3 {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: var(--sp-4);
}

.hidden { display: none !important; }

.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  flex-shrink: 0;
  max-width: 500px;
  margin: 0 auto;
  padding: 0 var(--sp-4) var(--sp-4);
}
.lobby-actions .btn-primary  { flex: 1; width: auto; }
.lobby-actions .btn-secondary { white-space: nowrap; }

/* ═══════════════════════════════════════════════════
   ACTIVE VIEW — card game layout
   ═══════════════════════════════════════════════════ */
#view-active {
  display: none;
  flex-direction: column;
  height: calc(100vh - var(--header-h));
  height: calc(100dvh - var(--header-h));
  overflow: hidden;
}
#view-active.active { display: flex; }

/* TABLE — top, scrollable */
.table-area {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--sp-4) var(--sp-5);
  background: var(--surface2);
}

/* RESIZE HANDLE — sits between table and hand, drag up/down to resize */
.hand-resize-handle {
  height: var(--sp-3);
  flex-shrink: 0;
  cursor: ns-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  transition: border-color 0.12s;
}
.hand-resize-handle::after {
  content: '';
  width: 32px;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  transition: background 0.12s;
}
.hand-resize-handle:hover,
.hand-resize-handle.dragging { border-color: var(--cyan); }
.hand-resize-handle:hover::after,
.hand-resize-handle.dragging::after { background: var(--cyan); }

.table-label {
  font-size: 0.68rem;
  color: var(--text-dim);
  letter-spacing: 0.08em;
  margin-bottom: var(--sp-4);
}

.revealed-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--sp-4);
}

.table-empty {
  color: var(--text-dim);
  font-size: 0.8rem;
  font-style: italic;
  padding: var(--sp-5) 0;
}

/* HAND — bottom strip */
.hand-area {
  height: var(--hand-h);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: var(--sp-3) var(--sp-5);
  gap: var(--sp-2);
  background: var(--surface);
  overflow: hidden;
}

.hand-label {
  font-size: 0.68rem;
  color: var(--text-dim);
  letter-spacing: 0.08em;
  flex-shrink: 0;
}

/* Card + actions share a row so the card doesn't stretch full-width */
.hand-body {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-4);
  flex: 1;
  min-height: 0;
}

#hand-card {
  width: min(960px, calc(100vw - 200px));
  flex-shrink: 0;
  overflow-y: auto;
  height: 100%;
}

/* Hand card: three-column layout — [stats|image] statblock + separate info box */
#hand-card .monster-card {
  display: grid;
  grid-template-columns: 1fr 260px;
  grid-template-rows: auto 1fr;
  gap: 0 var(--sp-4);
  background: none;
  border: none;
  border-radius: 0;
  overflow: visible;
}
#hand-card .monster-card.your-card { border: none; }

/* Top section: stats left (50%), image right (50%) — 3 explicit rows */
#hand-card .mc-top {
  grid-column: 1;
  grid-row: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  overflow: hidden;
}
#hand-card .monster-card.your-card .mc-top { border-color: var(--orange); }
#hand-card .mc-top .mc-header     { grid-column: 1; grid-row: 1; }
#hand-card .mc-top .mc-core-stats { grid-column: 1; grid-row: 2; }
#hand-card .mc-top .mc-abilities  { grid-column: 1; grid-row: 3; }

/* Image: spans all 3 rows, centered and zoomed to fill */
#hand-card .mc-top .mc-image {
  grid-column: 2;
  grid-row: 1 / 4;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  object-fit: cover;
  object-position: center center;
  border-bottom: none;
  border-left: 1px solid var(--border);
}

/* Body: continues the card below mc-top */
#hand-card .mc-body {
  grid-column: 1;
  grid-row: 2;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
}
#hand-card .monster-card.your-card .mc-body { border-color: var(--orange); }

/* Info: separate box to the right (column always reserved even without lore) */
#hand-card .mc-lore {
  grid-column: 2;
  grid-row: 1 / -1;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.hand-actions {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  justify-content: flex-end;
  padding-bottom: var(--sp-1);
}
.hand-actions .btn-primary,
.hand-actions .btn-secondary { width: auto; white-space: nowrap; }

/* ── Monster card ── */
.monster-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-family: var(--font);
}

.monster-card.your-card { border-color: var(--orange); border-width: 1px; }

/* Image */
.mc-image {
  width: 100%;
  max-height: 260px;
  object-fit: cover;
  object-position: top center;
  display: block;
  border-bottom: 1px solid var(--border);
}

/* Header */
.mc-header {
  padding: var(--sp-3) var(--sp-4) var(--sp-2);
  border-bottom: 1px solid var(--border);
}
.mc-name {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--orange);
  letter-spacing: -0.01em;
  margin-bottom: 2px;
}
.mc-subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Core stats row */
.mc-core-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--border);
}
.mc-stat {
  padding: var(--sp-2) var(--sp-3);
  text-align: center;
  border-right: 1px solid var(--border);
}
.mc-stat:last-child { border-right: none; }
.mc-stat-label { font-size: 0.58rem; color: var(--label-color); letter-spacing: 0.08em; text-transform: uppercase; }
.mc-stat-value { font-size: 0.88rem; font-weight: 700; color: var(--stat-color); margin-top: 1px; }
.mc-stat-sub   { font-size: 0.62rem; color: var(--text-muted); font-weight: 400; }
.mc-stat--speed { text-align: left; }
.mc-stat--speed .mc-stat-value { font-size: 0.78rem; line-height: 1.4; }

/* Ability scores — 2024 stat block: 3 rows × 8 columns */
.mc-abilities {
  display: grid;
  grid-template-columns: auto repeat(3, 1fr) auto repeat(3, 1fr);
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
  padding: var(--sp-2) var(--sp-3);
  gap: 1px var(--sp-2);
  align-items: center;
}
.ab-head {
  font-size: 0.5rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: center;
}
.ab-name {
  font-size: 0.58rem;
  font-weight: 700;
  color: var(--label-color);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.ab-score {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  text-align: center;
}
.ab-mod {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--stat-color);
  text-align: center;
}
.ab-save {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
}
.ab-save--prof {
  font-weight: 700;
  color: var(--stat-color);
}

/* Detail rows */
.mc-details {
  padding: var(--sp-2) var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.mc-detail-row {
  display: flex;
  gap: var(--sp-2);
  font-size: 0.73rem;
  line-height: 1.5;
  flex-wrap: wrap;
}
.mc-detail-row + .mc-detail-row { margin-top: 2px; }
.mc-detail-label { color: var(--detail-color); font-weight: 500; min-width: 120px; flex-shrink: 0; }
.mc-detail-value { color: var(--text); flex: 1; }

/* Stat blocks */
.mc-section {
  padding: var(--sp-2) var(--sp-4);
  border-bottom: 1px solid var(--border-dim);
}
.mc-section:last-child { border-bottom: none; }
.mc-section-title {
  font-size: 0.58rem;
  font-weight: 700;
  color: var(--section-color);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: var(--sp-2);
  padding-top: var(--sp-1);
}

.mc-block { margin-bottom: var(--sp-2); font-size: 0.77rem; line-height: 1.5; }
.mc-block:last-child { margin-bottom: 0; }
.mc-block-name { font-weight: 700; color: var(--orange); display: inline; }
.mc-block-name::after { content: '.'; margin-right: 0.3em; color: var(--text-muted); }
.mc-block-text { color: var(--text-muted); display: inline; }
.mc-block-continuation {
  color: var(--text-muted);
  font-size: 0.77rem;
  line-height: 1.5;
  margin-top: var(--sp-1);
  padding-left: 1em;   /* indent matches printed stat block convention */
}

/* Lore / Info section — open by default */
.mc-lore {
  padding: var(--sp-2) var(--sp-4) var(--sp-3);
  border-top: 1px solid var(--border-dim);
  background: var(--surface2);
}
.mc-lore-toggle {
  background: none; border: none;
  color: var(--section-color);
  font-family: var(--font);
  font-size: 0.58rem;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  display: flex; align-items: center; gap: var(--sp-2);
  letter-spacing: 0.1em;
  width: 100%;
  padding: var(--sp-1) 0;
}
.mc-lore-toggle:hover { color: var(--cyan); }
.mc-lore-toggle .toggle-arrow { font-size: 0.5rem; transition: transform 0.12s; display: inline-block; transform: rotate(90deg); }
.mc-lore-toggle.closed .toggle-arrow { transform: rotate(0deg); }

.mc-lore-content {
  display: block;   /* open by default */
  margin-top: var(--sp-2);
  font-size: 0.77rem;
  line-height: 1.65;
  color: var(--text-muted);
}
.mc-lore-content.closed { display: none; }
.mc-lore-content p  { margin-bottom: var(--sp-2); }
.mc-lore-content h4 {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text);
  margin: var(--sp-3) 0 var(--sp-1);
}
.mc-lore-content blockquote {
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-style: italic;
  margin: var(--sp-2) 0;
}

/* Roll tables in lore sections */
.mc-lore-table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--sp-3) 0;
  font-size: 0.75rem;
  line-height: 1.5;
}
.mc-lore-table caption {
  text-align: left;
  font-weight: 700;
  font-size: 0.72rem;
  color: var(--text);
  padding-bottom: var(--sp-2);
  letter-spacing: 0.02em;
}
.mc-lore-table th {
  text-align: left;
  font-weight: 600;
  font-size: 0.68rem;
  color: var(--label-color);
  letter-spacing: 0.04em;
  padding: var(--sp-1) var(--sp-2);
  border-bottom: 1px solid var(--border);
}
.mc-lore-table th:first-child { width: 2.5em; text-align: center; }
.mc-lore-table td {
  padding: var(--sp-1) var(--sp-2);
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-dim);
  vertical-align: top;
}
.mc-lore-table td:first-child { text-align: center; color: var(--stat-color); font-weight: 600; }
.mc-lore-table tbody tr:last-child td { border-bottom: none; }

/* Rolled row highlight */
.mc-lore-table tbody tr.rolled td {
  background: var(--yellow-bg);
  color: var(--text);
  transition: background 0.2s;
}
.mc-lore-table tbody tr.rolled td:first-child { color: var(--orange); }

/* Roll button for lore tables */
.mc-lore-table-wrap { margin: var(--sp-3) 0; }
.btn-roll-table {
  display: inline-block;
  margin-top: var(--sp-2);
  padding: var(--sp-1) var(--sp-3);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s;
}
.btn-roll-table:hover { border-color: var(--orange); color: var(--orange); }

/* ── Card slots & backs ── */
.card-slot {
  /* Starts as a card-back, grows to fit the monster card once flipped */
  transform-origin: center;
}

/* Card back — fixed-size face-down placeholder */
.card-back {
  background-color: var(--surface2);
  background-image: repeating-linear-gradient(
    -45deg,
    transparent 0px,
    transparent 5px,
    var(--card-stripe) 5px,
    var(--card-stripe) 6px
  );
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  height: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  user-select: none;
}

.card-slot--me .card-back {
  border-color: var(--orange);
  background-image: repeating-linear-gradient(
    -45deg,
    transparent 0px,
    transparent 5px,
    var(--card-stripe-me) 5px,
    var(--card-stripe-me) 6px
  );
}

.card-back-pattern {
  width: 80px;
  height: 100px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-slot--me .card-back-pattern {
  border-color: var(--card-border-me);
}

.card-back-ornament {
  font-size: 2rem;
  color: var(--text-dim);
  line-height: 1;
}

.card-slot--me .card-back-ornament {
  color: var(--gold-dim, var(--orange));
}

.card-back-name {
  font-size: 0.72rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.card-back-you {
  color: var(--text-dim);
  font-size: 0.68rem;
}

/* Card front — revealed monster */
.table-card-player {
  font-size: 0.68rem;
  color: var(--text-dim);
  letter-spacing: 0.06em;
  margin-bottom: var(--sp-2);
}

.card-front { }

/* ── Lightbox ── */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--overlay-bg);
  cursor: zoom-out;
  align-items: center;
  justify-content: center;
}
.lightbox.open {
  display: flex;
}
#lightbox-img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius);
  box-shadow: 0 8px 40px var(--overlay-bg);
  animation: lightbox-in 0.18s ease-out;
}
@keyframes lightbox-in {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

/* ── Flip animation (scaleX: card narrows to edge, swaps, widens back) ── */
@keyframes card-shrink {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}
@keyframes card-grow {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

.card-slot.is-shrinking { animation: card-shrink 0.18s ease-in forwards; }
.card-slot.is-growing   { animation: card-grow   0.18s ease-out; }

/* ── Source tags ── */
.source-tag {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 1px var(--sp-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--cyan);
  color: var(--cyan);
  background: var(--chip-selected-bg);
  cursor: default;
  user-select: none;
}
.source-tag--more {
  border-color: var(--border);
  color: var(--text-dim);
  background: transparent;
  cursor: help;
}

/* ── Checkbox label (inline checkbox + text) ── */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.checkbox-label input[type="checkbox"] {
  width: auto;
  margin: 0;
  cursor: pointer;
}

/* ── TL;DR / How it works card ── */
.tldr-card {
  background: var(--tldr-bg);
  border-color: var(--cyan);
}
.tldr-card h2 {
  color: var(--cyan);
}
.tldr-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.tldr-list li {
  padding-left: var(--sp-4);
  position: relative;
  font-size: 0.82rem;
  color: var(--text);
  line-height: 1.55;
}
.tldr-list li::before {
  content: '▸';
  position: absolute;
  left: 0;
  color: var(--cyan);
  font-size: 0.7rem;
  top: 0.15em;
}

/* ═══════════════════════════════════════════════════════
   MOBILE — vertical / touch screens
   ═══════════════════════════════════════════════════════ */
@media (max-width: 600px) {

  /* ── Global touch sizing ── */
  body { font-size: 14.5px; }

  input[type="text"], select {
    font-size: 1rem;
    padding: var(--sp-3) var(--sp-3);
    min-height: 44px;
  }

  .btn-primary, .btn-secondary, .btn-file {
    font-size: 0.88rem;
    padding: var(--sp-3) var(--sp-4);
    min-height: 44px;
    white-space: normal;
    line-height: 1.3;
  }

  /* ── Landing ── */
  .landing-container {
    padding: var(--sp-5) var(--sp-3) var(--sp-7);
  }

  .logo { font-size: 1.8rem; }
  .tagline { font-size: 0.78rem; margin-bottom: var(--sp-5); }

  .card { padding: var(--sp-4); }

  /* ── Session header ── */
  .session-header {
    padding: 0 var(--sp-3);
    gap: var(--sp-2);
  }

  .logo-small { font-size: 0.78rem; }

  .session-header-right { gap: var(--sp-2); }

  .btn-header {
    font-size: 0.68rem;
    padding: var(--sp-1) var(--sp-2);
    min-height: 40px;
    white-space: normal;
    text-align: center;
    line-height: 1.3;
  }

  .session-code-display { font-size: 0.68rem; }
  .session-code-display strong { font-size: 0.82rem; }

  /* Wrap header when buttons + code overflow (host sees 3 items) */
  .session-header { flex-wrap: wrap; height: auto; min-height: var(--header-h); padding: var(--sp-1) var(--sp-3); }

  /* ── Lobby mobile overrides ── */
  .lobby-container {
    padding: var(--sp-4) var(--sp-3);
    -webkit-overflow-scrolling: touch;
  }

  .lobby-actions {
    max-width: none;
    padding: var(--sp-3);
    padding-bottom: calc(var(--sp-3) + env(safe-area-inset-bottom, 0px));
  }

  /* Bigger chip tap targets */
  .type-chip {
    padding: var(--sp-2) var(--sp-3);
    font-size: 0.78rem;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .type-grid { gap: var(--sp-2); }

  .checkbox-label { font-size: 0.82rem; min-height: 44px; }

  .filter-label-row { flex-wrap: wrap; gap: var(--sp-2); }

  .cr-range select {
    min-width: 60px;
    min-height: 40px;
    font-size: 0.88rem;
  }

  /* ── Active view ── */
  :root { --hand-h: 50vh; }

  .table-area { padding: var(--sp-3); }
  .table-label { margin-bottom: var(--sp-3); }

  .revealed-cards {
    grid-template-columns: 1fr;
    gap: var(--sp-3);
  }

  /* Stack hand vertically: card on top, actions below */
  .hand-area {
    padding: var(--sp-3);
    padding-bottom: calc(var(--sp-3) + env(safe-area-inset-bottom, 0px));
  }

  .hand-body {
    flex-direction: column;
    gap: var(--sp-3);
  }

  #hand-card {
    width: 100%;
    flex-shrink: 1;
    overflow-y: auto;
  }

  #hand-card .monster-card {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
  }
  #hand-card .monster-card.your-card { border-color: var(--orange); }

  #hand-card .mc-top {
    display: block;
    background: none;
    border: none;
    border-radius: 0;
  }
  #hand-card .mc-body {
    background: none;
    border: none;
    border-radius: 0;
  }
  #hand-card .mc-lore {
    min-width: 0;
    max-width: none;
    border: none;
    border-radius: 0;
    border-top: 1px solid var(--border-dim);
  }

  #hand-card .mc-image {
    max-width: 100%;
    max-height: 200px;
    border-left: none;
    border-bottom: 1px solid var(--border);
  }

  .hand-actions {
    flex-direction: row;
    flex-wrap: wrap;
    gap: var(--sp-2);
  }

  .hand-actions .btn-primary,
  .hand-actions .btn-secondary {
    flex: 1;
    min-width: 0;
    white-space: normal;
    text-align: center;
    line-height: 1.3;
  }

  /* ── Monster cards ── */
  .mc-image { max-height: 200px; }

  .mc-header { padding: var(--sp-3); }
  .mc-name { font-size: 1rem; }
  .mc-subtitle { font-size: 0.72rem; }

  /* Ability grid: tighter on mobile */
  .mc-abilities {
    padding: var(--sp-2);
    gap: 1px var(--sp-1);
    font-size: 0.72rem;
  }
  .ab-name  { font-size: 0.52rem; }
  .ab-score, .ab-mod, .ab-save { font-size: 0.72rem; }

  /* Detail rows: stack label above value */
  .mc-detail-row { flex-direction: column; gap: 0; }
  .mc-detail-label { min-width: 0; }

  .mc-details { padding: var(--sp-2) var(--sp-3); }
  .mc-section { padding: var(--sp-2) var(--sp-3); }
  .mc-lore    { padding: var(--sp-2) var(--sp-3); }

  /* Resize handle — larger touch target */
  .hand-resize-handle { height: 20px; }

  /* Card backs — shorter on mobile */
  .card-back { height: 140px; }
  .card-back-pattern { width: 60px; height: 75px; }
  .card-back-ornament { font-size: 1.5rem; }

  /* Lightbox — safe areas */
  #lightbox-img {
    max-width: 95vw;
    max-height: 85vh;
  }

  /* Source tags — bigger tap target */
  .source-tag {
    font-size: 0.68rem;
    padding: var(--sp-1) var(--sp-2);
  }
}

/* ── Small phones (≤375px, e.g. iPhone SE) ── */
@media (max-width: 375px) {
  body { font-size: 14px; }

  .logo { font-size: 1.4rem; }

  .session-header { --header-h: 40px; }
  .logo-small { font-size: 0.72rem; }

  /* Hide invite button text, keep it functional */
  .btn-header { font-size: 0.65rem; padding: var(--sp-1) var(--sp-2); }

  .mc-stat { padding: var(--sp-1) var(--sp-2); }
  .mc-stat-label { font-size: 0.52rem; }
  .mc-stat-value { font-size: 0.8rem; }

  .ab-name { font-size: 0.48rem; }
  .ab-score, .ab-mod, .ab-save { font-size: 0.68rem; }
}
