:root {
  --bg: #12151b;
  --panel: #1b212b;
  --panel-light: #232b37;
  --border: #333d4c;
  --hairline: rgba(255, 255, 255, 0.07);
  --text: #f2efe6;
  --text-dim: #8d97a6;
  --accent: #e0b661;
  --good: #6fbf6a;
  --bad: #dd5b56;
  --resource: #3a5da8;
  --survival: #d4801f;
  --sabotage: #b83535;
  --event: #7d47a8;

  /* ---- typography ------------------------------------------------------
     A type-led interface: one display face for names and numerals, one
     text face for prose, and wide-tracked uppercase micro-labels doing the
     work that boxes and borders used to do. */
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia,
                  "Times New Roman", serif;
  --font-text: "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-num: "SF Mono", "Cascadia Mono", "Segoe UI Mono", "Roboto Mono",
              ui-monospace, monospace;

  --tracking-label: 0.16em;   /* uppercase micro-labels */
  --tracking-title: 0.34em;   /* the masthead */
}

* { box-sizing: border-box; }

/* Layout is sized to avoid ever needing to scroll except the Expedition Log
   -- but if a very long recipe/character list ever does overflow, the
   scrollbar should still read as part of this UI, not a default OS control. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
*::-webkit-scrollbar { width: 7px; height: 7px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
#log-lines { scrollbar-color: var(--accent) transparent; }
#log-lines::-webkit-scrollbar-thumb { background: var(--accent); }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden; /* the game view is sized to fit -- nothing should ever need page scroll */
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-text);
  font-feature-settings: "kern" 1, "liga" 1;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

/* Every label that names a thing rather than saying something. */
.u-label,
#log-label, #char-list-label, #lobby-recipe-label, #lobby-roster-label,
.pile-caption, .stat-bar-label, .char-big-archetype, #hand-label {
  font-family: var(--font-text);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  font-weight: 600;
  font-size: 0.62rem;
  color: var(--text-dim);
}

/* Numerals read as data: monospaced, tabular, never reflowing. */
.u-num, .stat-bar-label .value, .pile-count, .char-row-stat, .recipe-meta {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

#conn-banner {
  margin: 0 16px 8px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  line-height: 1.45;
  flex-shrink: 0;
  text-align: center;
}
#conn-banner.bad { background: rgba(217, 83, 79, 0.15); border: 1px solid var(--bad); color: #f0b3b1; }
#conn-banner.warn { background: rgba(222, 178, 90, 0.15); border: 1px solid var(--accent); color: var(--accent); }
#conn-banner code {
  background: rgba(0,0,0,0.35);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.95em;
}
#conn-banner a { color: inherit; }

#app-title {
  text-align: center;
  font-family: var(--font-display);
  font-size: 1.32rem;
  font-weight: 400;
  letter-spacing: var(--tracking-title);
  text-indent: var(--tracking-title); /* offset trailing letterspace, keeps it optically centred */
  color: var(--accent);
  padding: 9px 0 8px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--hairline);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
}

button {
  background: var(--panel-light);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 8px 14px;
  cursor: pointer;
  font-family: var(--font-text);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: 0.4; cursor: default; }
button.primary { border-color: var(--accent); color: var(--accent); }
button.danger { border-color: var(--bad); color: var(--bad); }
button.danger:hover:not(:disabled) { border-color: var(--bad); color: var(--bad); background: rgba(217, 83, 79, 0.14); }

select, input[type=text] {
  background: var(--panel-light);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
}

/* ---------------------------------------------------------------- lobby */

#lobby-view {
  max-width: 1120px;
  margin: 0 auto;
  padding: 10px 16px 16px;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 14px;
  width: 100%;
  flex: 1;
  min-height: 0;
}

#lobby-status-banner {
  padding: 8px 12px;
  background: var(--panel-light);
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--accent);
  font-size: 0.85rem;
  text-align: center;
}

/* left pane: persistent scrollable character list */
#char-list-pane {
  width: 260px;
  flex-shrink: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#char-list-label {
  color: var(--text-dim);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
  flex-shrink: 0;
  padding: 0 4px;
}
#char-list {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.char-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 11px;
  border-radius: 7px;
  border: 1.5px solid transparent;
  background: var(--panel-light);
  cursor: pointer;
  font-size: 0.85rem;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.char-row:hover { border-color: var(--text-dim); }
.char-row.selected { border-color: var(--accent); background: rgba(222, 178, 90, 0.12); }
.char-row.taken { opacity: 0.4; }
.char-row-left { display: flex; align-items: center; gap: 9px; min-width: 0; }
.char-row-portrait {
  width: 32px;
  height: 44px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: #000;
  flex-shrink: 0;
}
.char-row-name {
  font-family: var(--font-display);
  font-size: 0.98rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.char-row-stat { font-size: 0.7rem; color: var(--text-dim); flex-shrink: 0; margin-left: 8px; }

/* right side: big detail panel + roster/start */
#lobby-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

#char-detail-pane {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 22px;
  flex-shrink: 0;
}

.char-big-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: -18px -22px 12px;
  padding: 16px 22px;
  border-radius: 10px 10px 0 0;
  border-bottom: 2px solid var(--border);
  background: linear-gradient(135deg, var(--panel-light), var(--panel));
}
.char-big-header.arch-tank { border-bottom-color: var(--resource); }
.char-big-header.arch-damage { border-bottom-color: var(--bad); }
.char-big-header.arch-balanced { border-bottom-color: var(--accent); }
.char-big-portrait {
  width: 92px;
  height: 127px;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: #000;
  flex-shrink: 0;
}
.char-big-header-text { min-width: 0; }
.char-big-name {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.01em;
  color: var(--accent);
}
.char-big-stats {
  display: flex;
  gap: 18px;
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: 0.88rem;
  margin-top: 7px;
  font-weight: 600;
}
.char-big-archetype { margin-top: 6px; }

.kit-block {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 13px;
  padding-bottom: 13px;
  border-bottom: 1px solid var(--hairline);
  line-height: 1.55;
}
.kit-block:last-child { border-bottom: none; padding-bottom: 0; }
.kit-block b {
  color: var(--text);
  font-family: var(--font-text);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  font-size: 0.63rem;
}
.kit-inline-icon {
  width: 26px;
  height: 26px;
  object-fit: cover;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: #000;
  vertical-align: middle;
  margin-right: 6px;
  float: left;
}
.kit-tag {
  font-size: 0.66rem;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 5px;
  text-transform: uppercase;
}
.kit-charge { color: var(--text-dim); font-size: 0.78rem; }
.gear-line { margin-bottom: 0; clear: both; }

.char-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.char-actions input { flex: 1; min-width: 130px; }

#lobby-recipe-pane { flex-shrink: 0; }
#lobby-recipe-label { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 8px; }
#recipe-list { display: flex; flex-direction: column; gap: 6px; }
.recipe-row {
  padding: 7px 10px;
  background: var(--panel-light);
  border: 1.5px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.recipe-row:hover { border-color: var(--text-dim); }
.recipe-row.selected { border-color: var(--accent); background: rgba(222, 178, 90, 0.12); }
.recipe-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.recipe-name { font-weight: 600; font-size: 0.86rem; }
.recipe-meta { font-size: 0.68rem; color: var(--text-dim); white-space: nowrap; }
.recipe-desc { font-size: 0.74rem; color: var(--text-dim); margin-top: 2px; line-height: 1.35; }

#lobby-roster-pane { flex-shrink: 0; }
#lobby-roster-label { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 8px; }
#roster-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }

.roster-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: var(--panel-light);
  border-radius: 7px;
  border: 1px solid var(--border);
  font-size: 0.82rem;
}
.roster-row.human { border-color: var(--good); }
.roster-row.mine { box-shadow: 0 0 0 1.5px var(--accent) inset; }
.roster-name { font-weight: 600; }
.roster-char { color: var(--text-dim); flex: 1; }
.roster-tag { color: var(--text-dim); font-size: 0.72rem; text-transform: uppercase; }
.roster-empty { color: var(--text-dim); font-size: 0.82rem; font-style: italic; padding: 4px; }

#lobby-roster-pane #start-btn { width: 100%; padding: 10px; font-size: 0.95rem; }

/* ----------------------------------------------------------------- game */

#game-view {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 12px;
  padding: 4px 12px 8px;
  max-width: 1700px;
  margin: 0 auto;
  width: 100%;
  flex: 1;
  min-height: 0;
}

#game-main {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  min-height: 0;
}

#top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 2px 12px;
  color: var(--text-dim);
  font-size: 0.8rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}
#top-bar-info { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
#exit-game-btn { padding: 3px 10px; font-size: 0.7rem; flex-shrink: 0; }
#turn-info {
  padding: 1px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
#turn-info.my-turn {
  color: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
}
#duel-info {
  color: var(--event);
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
/* A declared-but-not-yet-live duel: present, but visibly not the thing
   happening right now. */
#duel-info.pending {
  opacity: 0.75;
  font-weight: 600;
  border-bottom: 1px dashed currentColor;
}

/* --------------------------------------------------------------- piles */

#piles-row {
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-shrink: 0;
}

.pile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.pile-stack {
  width: 104px;
  height: 142px;
  border-radius: 9px;
  background: linear-gradient(135deg, #2c3648, #1a212c);
  border: 2px solid var(--border);
  box-shadow: 3px 3px 0 -1px var(--bg), 3px 3px 0 1px var(--border),
              6px 6px 0 -1px var(--bg), 6px 6px 0 1px var(--border);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: box-shadow 0.3s ease;
}
.pile-stack::after {
  content: "";
  width: 38px;
  height: 38px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  opacity: 0.45;
}
.pile-stack.face-up {
  background: var(--panel-light);
  align-items: flex-start;
  justify-content: flex-start;
  padding: 6px;
  text-align: left;
}
.pile-stack.face-up::after { content: none; }
.pile-stack.face-up .pile-card-name {
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.2;
}
.pile-stack.face-up.monster {
  border-color: var(--bad);
  padding: 0;
  overflow: hidden;
  flex-direction: column;
  align-items: stretch;
}
.pile-monster-img { width: 100%; flex: 1; min-height: 0; object-fit: cover; display: block; }
.pile-stack.monster .pile-card-name {
  color: #f0a0a0;
  background: rgba(0, 0, 0, 0.55);
  padding: 2px 4px;
  text-align: center;
}
.pile-stack.type-Resource { border-left: 4px solid var(--resource); }
.pile-stack.type-Survival { border-left: 4px solid var(--survival); }
.pile-stack.type-Sabotage { border-left: 4px solid var(--sabotage); }
.pile-stack.type-Event { border-left: 4px solid var(--event); }
.pile-stack.empty { box-shadow: none; opacity: 0.35; }

.pile-count {
  position: absolute;
  bottom: -8px;
  right: -8px;
  background: var(--accent);
  color: #14181f;
  font-weight: bold;
  font-size: 0.72rem;
  border-radius: 50%;
  width: 23px;
  height: 23px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg);
}

.pile-caption { font-size: 0.6rem; }

.pile-stack.pulse { animation: pile-pulse 0.5s ease; }
@keyframes pile-pulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* ----------------------------------------------------------------- log */

#log-sidebar {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
#log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 6px;
  flex-shrink: 0;
}
#log-label {
  color: var(--text-dim);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
#log-toggle {
  padding: 2px 8px;
  font-size: 0.8rem;
  line-height: 1.2;
  flex-shrink: 0;
}
#log-lines {
  font-size: 0.8rem;
  line-height: 1.6;
  color: var(--text-dim);
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
#log-lines div {
  padding: 5px 2px;
  border-bottom: 1px solid var(--hairline);
  text-wrap: pretty;
}
#log-lines div:last-child { color: var(--text); font-weight: 500; }

/* Round/turn header: a visible break between one player's turn and the next. */
#log-lines div.log-turn {
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
}
#log-lines div.log-turn:first-child { margin-top: 0; }
#log-lines div.log-dmg { color: var(--bad); }
#log-lines div.log-heal { color: var(--good); }
#log-lines div.log-death { color: var(--bad); font-weight: 700; }
#log-lines div.log-event { color: #b9a6f0; font-weight: 600; }
#log-lines div.log-victory { color: var(--accent); font-weight: 600; }
#log-lines div.log-block { color: #8fd0ff; }

/* collapsed state: sidebar shrinks to a thin strip, only the toggle remains */
#game-view.log-collapsed { grid-template-columns: 1fr 34px; }
#game-view.log-collapsed #log-sidebar { padding: 10px 4px; }
#game-view.log-collapsed #log-header { flex-direction: column; gap: 8px; }
#game-view.log-collapsed #log-label,
#game-view.log-collapsed #log-lines { display: none; }

/* --------------------------------------------------------------- table */

#table {
  /* Hug the seats rather than absorbing every spare pixel -- the slack goes
     to the hand panel below instead, so your cards sit close to the board.

     min-height is min-content, NOT 0. With `min-height: 0` this flex item was
     allowed to shrink past its own seat cards, and the hand panel below (which
     is flex: 1 1 auto) would happily take that space -- so on a short window
     the bottom of every character card got cut off and you had to scroll
     inside #table to read your own stats. Refusing to shrink below the seats
     is what makes "never scroll to see your character card" true; the hand
     panel yields instead, and the tiers further down shrink the seat's own
     furniture so both still fit. */
  flex: 0 1 auto;
  min-height: min-content;
  overflow-y: auto; /* last-resort valve; the height tiers below should keep it unused */
  scroll-behavior: smooth;
}

#seats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
  justify-content: center;
  gap: 6px;
}

.seat-card {
  background: var(--panel);
  border: 1.5px solid var(--border);
  border-radius: 7px;
  padding: 7px 9px;
  transition: border-color 0.3s ease;
  position: relative;
  font-size: 0.82rem;
}
.seat-card.active-turn {
  border-color: var(--accent);
  animation: seat-glow 1.8s ease-in-out infinite;
}
@keyframes seat-glow {
  0%, 100% { box-shadow: 0 0 8px rgba(222, 178, 90, 0.3); }
  50% { box-shadow: 0 0 16px rgba(222, 178, 90, 0.55); }
}
.seat-card.dead { opacity: 0.45; }

/* Seat card acting as a click target for a "choose a player" prompt. */
.seat-card.targetable {
  cursor: pointer;
  border-color: var(--bad);
  animation: target-pulse 1.2s ease-in-out infinite;
}
.seat-card.targetable:hover {
  border-color: #ff8a85;
  transform: translateY(-3px);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.5);
}
.seat-card.targetable::after {
  content: "◎ CLICK TO TARGET";
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 0.56rem;
  letter-spacing: 0.08em;
  color: var(--bad);
  font-weight: 700;
  pointer-events: none;
}
@keyframes target-pulse {
  0%, 100% { box-shadow: 0 0 6px rgba(217, 83, 79, 0.45); }
  50% { box-shadow: 0 0 16px rgba(217, 83, 79, 0.85); }
}

.seat-card.hit-flash { animation: hit-flash 0.4s ease; }

/* Drag-a-card-onto-this-seat drop affordance. */
.seat-card.card-drop-hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(224, 182, 97, 0.35);
  transform: translateY(-3px);
}
.seat-card.heal-flash { animation: heal-flash 0.4s ease; }
@keyframes hit-flash { 0% { box-shadow: inset 0 0 0 999px rgba(217, 83, 79, 0.35); } 100% { box-shadow: inset 0 0 0 999px rgba(217, 83, 79, 0); } }
@keyframes heal-flash { 0% { box-shadow: inset 0 0 0 999px rgba(92, 184, 92, 0.35); } 100% { box-shadow: inset 0 0 0 999px rgba(92, 184, 92, 0); } }

.seat-name {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  font-family: var(--font-display);
  font-size: 0.98rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0.01em;
  padding-bottom: 3px;
  border-bottom: 1px solid var(--hairline);
}
.seat-name .ai-tag {
  font-family: var(--font-text);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.56rem;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}
.seat-name-left { display: flex; align-items: baseline; gap: 5px; min-width: 0; overflow: hidden; }
.seat-name-left > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.class-tag {
  flex-shrink: 0;
  font-family: var(--font-text);
  font-weight: 700;
  font-size: 0.5rem;
  letter-spacing: 0.06em;
  padding: 1px 5px;
  border-radius: 999px;
  border: 1px solid currentColor;
}
.class-tag.arch-tank { color: var(--resource); }
.class-tag.arch-damage { color: var(--bad); }
.class-tag.arch-balanced { color: var(--accent); }

.badge-row { display: flex; flex-wrap: wrap; gap: 4px; margin: 3px 0; }
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  cursor: default;
  opacity: 0.9;
}
.badge.minion { opacity: 1; }
.badge.marks { filter: drop-shadow(0 0 2px var(--accent)); }
/* The curse is a standing -2 HP a round, so it should read as an active
   affliction rather than a static icon sitting in the badge row. */
.badge.cursed {
  opacity: 1;
  filter: drop-shadow(0 0 3px var(--event));
  animation: curse-pulse 2.2s ease-in-out infinite;
}
@keyframes curse-pulse {
  0%, 100% { transform: translateY(0); opacity: 0.85; }
  50%      { transform: translateY(-1.5px); opacity: 1; }
}

.stat-bar { margin-top: 4px; position: relative; }
.stat-bar-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 2px;
  line-height: 1.25;
}
.stat-bar-label > span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stat-bar-label .value {
  color: var(--text);
  font-weight: 600;
  font-size: 0.72rem;
  letter-spacing: 0;
  text-transform: none;
  flex-shrink: 0;
}

.bar-track {
  height: 7px;
  background: #0b0e13;
  border-radius: 4px;
  overflow: hidden;
}
.bar-fill { height: 100%; border-radius: 4px; transition: width 0.4s ease, background 0.4s ease; }
.bar-fill.hp { background: linear-gradient(90deg, #7fbf5f, #4f9b3f); }
.bar-fill.hp.low { background: linear-gradient(90deg, #d9534f, #a83a37); }
.bar-fill.dmg { background: linear-gradient(90deg, #e08a5f, #c25f36); }
.bar-fill.dmg.top { background: linear-gradient(90deg, #ff9d6b, #e0562a); }
.bar-fill.ability { background: linear-gradient(90deg, #6faee0, #3a7fc0); }
.bar-fill.perk { background: linear-gradient(90deg, #d0a44c, #b0842f); }

.stat-bar.ready .bar-track { box-shadow: 0 0 6px rgba(222, 178, 90, 0.65); }
.stat-bar.ready .stat-bar-label .value { color: var(--accent); }

.stat-line {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  color: var(--text-dim);
  margin-top: 4px;
}

/* kit row: 4 mini "cards" -- character / minion / armor / weapon */
.kit-row { display: flex; gap: 3px; margin-top: 4px; height: 32px; }
.kit-card {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px 1px;
  gap: 1px;
  cursor: default;
}
.kit-card-icon { font-size: 0.82rem; line-height: 1; }
.kit-card-val {
  font-size: 0.54rem;
  color: var(--text-dim);
  font-weight: 600;
  line-height: 1;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kit-card.locked { opacity: 0.5; }
.kit-card.char-avatar { background: var(--panel-light); border-color: var(--accent); }
.kit-card.char-avatar .kit-card-icon { color: var(--accent); font-weight: bold; font-size: 0.92rem; }

.kit-card.img-tile { padding: 0; overflow: hidden; }
.kit-card-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.kit-card.locked .kit-card-img { filter: grayscale(1) brightness(0.55); }

.monster-chip {
  position: relative;
  margin-top: 4px;
  padding: 2px 5px;
  background: var(--panel-light);
  border-radius: 5px;
  font-size: 0.73rem;
  display: flex;
  align-items: center;
  gap: 5px;
}
/* The risen beast reads as the owner's own unit, not another encounter. */
.beast-chip {
  border: 1px solid var(--good);
  background: color-mix(in srgb, var(--good) 12%, var(--panel-light));
}
.monster-chip-img {
  width: 19px;
  height: 26px;
  object-fit: cover;
  border-radius: 3px;
  background: #000;
  flex-shrink: 0;
}

/* ----------------------------------------------------------------- hand */

#hand-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  /* Takes the leftover height so there's no dead gap above the hand. */
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  transition: border-color 0.3s ease;
}
/* The panel you're actually looking at most of the time -- same glow
   language as a seat card's active-turn highlight, just bigger and closer. */
#hand-panel.your-turn {
  border-color: var(--accent);
  animation: seat-glow 1.8s ease-in-out infinite;
}

#hand-label { color: var(--text-dim); margin-bottom: 6px; font-size: 0.8rem; flex-shrink: 0; }

#hand-cards {
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 14px 2px 6px; /* top room so the hover-lift isn't clipped by overflow-y */
}
#hand-cards { flex: 1 1 auto; min-height: 0; }

.card {
  width: 148px;
  height: 194px;
  border-radius: 11px;
  border: 2px solid var(--border);
  background: var(--panel-light);
  padding: 10px;
  display: flex;
  flex-direction: column;
  cursor: default;
  opacity: 0.55;
  transition: transform 0.15s ease, opacity 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.card.playable { opacity: 1; cursor: pointer; border-color: var(--accent); }
.card.playable:hover { transform: translateY(-10px); box-shadow: 0 10px 20px rgba(0,0,0,0.45); }
.card.playable:active { transform: translateY(-4px) scale(0.97); }
.card-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.15;
  letter-spacing: 0.005em;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--hairline);
}
.card-text {
  font-size: 0.74rem;
  color: var(--text-dim);
  margin-top: 7px;
  flex: 1;
  overflow: hidden;
  line-height: 1.42;
  hyphens: auto;
}
.card.type-Resource { border-left: 6px solid var(--resource); }
.card.type-Survival { border-left: 6px solid var(--survival); }
.card.type-Sabotage { border-left: 6px solid var(--sabotage); }
.card.type-Event { border-left: 6px solid var(--event); }

.card.playing {
  animation: card-play-out 0.4s ease forwards;
  pointer-events: none;
}
@keyframes card-play-out {
  0% { transform: translateY(-8px) scale(1); opacity: 1; }
  100% { transform: translateY(-60px) scale(0.6); opacity: 0; }
}

/* face-down Loot picker: card backs, click to flip-and-reveal */
.card.facedown {
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #2c3648, #1a212c);
  border-color: var(--accent);
  opacity: 1;
  cursor: pointer;
}
.facedown-mark { font-size: 2rem; color: var(--accent); opacity: 0.6; }
.card.facedown.flipping { animation: card-flip 0.26s ease forwards; }
@keyframes card-flip {
  0% { transform: rotateY(0deg) scale(1); }
  100% { transform: rotateY(90deg) scale(0.9); opacity: 0.4; }
}

/* Must never be compressed or pushed out of reach -- the page itself cannot
   scroll (html,body are overflow:hidden), so if this row is clipped the
   player is left unable to answer the prompt at all. */
#action-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 8px;
  flex-shrink: 0;
  max-height: 96px;
  overflow-y: auto;
}
#action-buttons button { padding: 8px 14px; font-size: 0.85rem; }

#prompt-banner {
  min-height: 1.3em;
  text-align: center;
  color: var(--accent);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.02rem;
  letter-spacing: 0.02em;
  padding: 3px 0;
  flex-shrink: 0;
  transition: color 0.3s ease;
}
/* Between your turns: quieter and not accent-colored, so it reads as
   "the game is still moving" rather than a call to action aimed at you. */
#prompt-banner.waiting {
  color: var(--text-dim);
  font-weight: 500;
  font-style: italic;
  animation: waiting-pulse 1.6s ease-in-out infinite;
}
@keyframes waiting-pulse {
  0%, 100% { opacity: 0.65; }
  50% { opacity: 1; }
}

/* ---------------------------------------------------- short-screen mode
   Laptops at 720-800px tall can't afford the full-size piles and card
   chrome. Everything below scales the furniture down while leaving the
   type hierarchy (and therefore readability) intact. */
@media (max-height: 820px) {
  #app-title { font-size: 1.12rem; padding: 5px 0 4px; }
  .pile-stack { width: 78px; height: 106px; }
  .pile-stack::after { width: 28px; height: 28px; }
  .pile-stack.face-up .pile-card-name { font-size: 0.68rem; }
  .pile-count { width: 19px; height: 19px; font-size: 0.6rem; }
  #piles-row { gap: 12px; }
  .kit-row { height: 26px; }
  .bar-track { height: 6px; }
  .stat-bar { margin-top: 3px; }
  .card { width: 124px; height: 168px; }
  .card-name { font-size: 0.88rem; padding-bottom: 4px; }
  .card-text { font-size: 0.67rem; margin-top: 5px; line-height: 1.34; }
  #prompt-banner { font-size: 0.9rem; }
  .seat-card { padding: 6px 7px; }
  .monster-chip { margin-top: 3px; }
}

@media (max-height: 730px) {
  .pile-stack { width: 66px; height: 90px; }
  .card { width: 112px; height: 150px; }
  .kit-row { height: 22px; }
  .badge-row { display: none; } /* detail still available via the kit row */
}

/* Short windows (a browser that isn't maximized, a small laptop panel):
   shrink everything further so the table and hand both keep fitting without
   #table's scroll safety-valve or hand cards clipping against #hand-cards'
   hidden vertical overflow. */
@media (max-height: 640px) {
  #game-main { gap: 3px; }
  #piles-row { gap: 8px; }
  .pile-stack { width: 52px; height: 70px; }
  .pile-stack::after { width: 20px; height: 20px; }
  .pile-count { width: 16px; height: 16px; font-size: 0.55rem; }
  .seat-card { padding: 4px 6px; font-size: 0.72rem; }
  .kit-row { height: 18px; }
  .stat-bar { margin-top: 2px; }
  .bar-track { height: 4px; }
  #hand-panel { padding: 4px 10px; }
  #hand-label { margin-bottom: 2px; }
  #hand-cards { padding: 8px 2px 4px; }
  .card { width: 92px; height: 122px; padding: 6px; }
  .card-name { font-size: 0.76rem; padding-bottom: 3px; }
  .card-art { font-size: 1.2rem; margin: 3px 0 1px; }
  .card-text { font-size: 0.6rem; margin-top: 3px; line-height: 1.25; }
  .card.playable:hover { transform: translateY(-6px); }
  #prompt-banner { font-size: 0.8rem; min-height: 1em; }
}

/* -------------------------------------------------------------- overlay */

#game-over-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
#game-over-modal .panel { text-align: center; min-width: 320px; }

/* -------------------------------------------------------------- effects */

@keyframes float-up {
  from { transform: translateY(0); opacity: 1; }
  to { transform: translateY(-40px); opacity: 0; }
}
.floater {
  position: absolute;
  font-weight: bold;
  font-size: 1rem;
  pointer-events: none;
  animation: float-up 1s ease-out forwards;
}
.floater.dmg { color: var(--bad); }
.floater.heal { color: var(--good); }

/* Small badge flashed on a seat when its perk/card blocks, dodges, or
   redirects an attack -- otherwise that only ever showed up as a log line. */
.block-flash {
  position: absolute;
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 12, 16, 0.82);
  color: var(--accent);
  font-weight: 800;
  font-size: 0.58rem;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  pointer-events: none;
  z-index: 5;
  animation: block-flash-pop 1.1s ease forwards;
}
@keyframes block-flash-pop {
  0% { opacity: 0; transform: translateX(-50%) translateY(-6px); }
  15% { opacity: 1; transform: translateX(-50%) translateY(0); }
  78% { opacity: 1; }
  100% { opacity: 0; }
}

.fly-card {
  position: fixed;
  width: 64px;
  height: 60px;
  margin-left: -32px;
  margin-top: -30px;
  border-radius: 6px;
  background: linear-gradient(135deg, #2c3648, #1a212c);
  border: 2px solid var(--accent);
  box-shadow: 0 6px 18px rgba(0,0,0,0.5);
  z-index: 999;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2px 4px;
  font-size: 0.58rem;
  font-weight: 700;
  line-height: 1.15;
  color: var(--text);
  overflow: hidden;
  transform: translate(0, 0) scale(1) rotate(0deg);
  opacity: 1;
  transition: transform 0.5s cubic-bezier(0.22, 0.7, 0.32, 1), opacity 0.5s ease 0.15s;
}
.fly-card.discard { border-color: var(--text-dim); }
.fly-card.type-Resource { border-left: 5px solid var(--resource); }
.fly-card.type-Survival { border-left: 5px solid var(--survival); }
.fly-card.type-Sabotage { border-left: 5px solid var(--sabotage); }
.fly-card.type-Event { border-left: 5px solid var(--event); }


/* ------------------------------------------------- the minion, in play
   It has a rule, a name and a state, so it gets a strip of its own under
   the gear row instead of hiding as a fourth 32px icon. */

.minion-strip {
  display: flex;
  align-items: center;
  cursor: help;   /* the passive's rules text is in the tooltip -- advertise it */
  gap: 7px;
  margin-top: 5px;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: linear-gradient(100deg, rgba(111, 191, 106, 0.10), rgba(0,0,0,0));
  cursor: default;
}
.minion-strip.asleep {
  background: none;
  border-style: dashed;
  opacity: 0.72;
}
.minion-art {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  object-fit: cover;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: #000;
}
.minion-strip.asleep .minion-art { filter: grayscale(1) brightness(0.6); }
.minion-strip.awake .minion-art { border-color: var(--good); }
.minion-text { min-width: 0; flex: 1; }
.minion-name {
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.1;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.minion-line {
  font-size: 0.62rem;
  line-height: 1.25;
  color: var(--text-dim);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.minion-strip.awake .minion-line { color: #b8e8b4; }
.minion-state {
  flex-shrink: 0;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--text-dim);
  font-family: var(--font-num);
}
.minion-strip.awake .minion-state { color: var(--good); font-size: 0.85rem; }

@media (max-height: 820px) {
  .minion-strip { padding: 3px 5px; gap: 6px; }
  .minion-art { width: 24px; height: 24px; }
  .minion-name { font-size: 0.72rem; }
  .minion-line { -webkit-line-clamp: 1; font-size: 0.58rem; }
}

/* ==========================================================================
   FIT-WITHOUT-SCROLLING + MOTION
   --------------------------------------------------------------------------
   Goal: in a live game nobody should ever have to scroll to read their own
   character card. #table now refuses to shrink below its seats (see its rule
   above), so the remaining job is to make a seat cost less vertical space as
   the window gets shorter -- shrinking the FURNITURE (bar tracks, minion
   strip, chip padding) rather than the numbers you actually read.

   The tiers below are additive on top of the existing 820 / 730 / 640 tiers.
   ========================================================================== */

/* The hand must never be crushed to the point that cards clip against
   #hand-cards' hidden vertical overflow. This floor is card height + the
   label + padding; the table takes what it needs first, and this guarantees
   the remainder is still enough to show a whole card. */
#hand-panel { min-height: 172px; }
@media (max-height: 730px) { #hand-panel { min-height: 156px; } }
@media (max-height: 640px) { #hand-panel { min-height: 138px; } }
@media (max-height: 580px) { #hand-panel { min-height: 122px; } }

/* Seats sit tight to the top so a short window loses slack, not content. */
#seats-grid { align-content: start; }

@media (max-height: 700px) {
  .stat-bar { margin-top: 2px; }
  .stat-bar-label { margin-bottom: 1px; }
  .minion-strip { margin-top: 3px; }
  .monster-chip { margin-top: 3px; padding: 1px 5px; }
  .monster-chip-img { width: 16px; height: 22px; }
}

@media (max-height: 660px) {
  .bar-track { height: 5px; }
  .minion-art { width: 20px; height: 20px; }
  .minion-strip { padding: 2px 5px; gap: 5px; }
}

/* Below this an ASLEEP minion is just noise taking a whole line: its name and
   its wake level are the only parts that matter until it unlocks, and both
   survive. An awake minion keeps its text -- that one is live information. */
@media (max-height: 620px) {
  .minion-strip.asleep .minion-line { display: none; }
  .minion-strip.asleep { padding: 1px 5px; }
  .seat-card { padding: 3px 6px; }
  .kit-row { height: 16px; margin-top: 3px; }
  .monster-chip-img { width: 14px; height: 19px; }
}

@media (max-height: 560px) {
  .stat-bar-label { font-size: 0.66rem; }
  .bar-track { height: 4px; }
  .minion-art { width: 16px; height: 16px; }
  .minion-name { font-size: 0.66rem; }
  .kit-row { height: 14px; }
  #piles-row { gap: 6px; }
  .pile-stack { width: 44px; height: 60px; }
  .pile-caption { font-size: 0.55rem; }
  /* The hand shrinks in step with the panel floor above it. Without this the
     card keeps its 92px height inside a 122px panel and clips against
     #hand-cards' hidden vertical overflow -- the same class of bug as the
     seat cards, one row down. */
  .card { width: 80px; height: 96px; padding: 5px; }
  .card-name { font-size: 0.68rem; padding-bottom: 2px; }
  .card-art { font-size: 1rem; margin: 2px 0 0; }
  .card-text { font-size: 0.55rem; margin-top: 2px; line-height: 1.2; }
  #hand-label { margin-bottom: 1px; }
  #hand-cards { padding: 6px 2px 3px; }
}

@media (max-height: 480px) {
  .card { width: 68px; height: 82px; }
  .card-text { display: none; }   /* the name and art still identify it */
  .pile-stack { width: 36px; height: 48px; }
  .minion-strip.asleep { display: none; }
}

/* -------------------------------------------------------------- motion --
   One shared easing and duration so panels, seats and cards all move with
   the same hand. Layout-affecting properties are transitioned deliberately
   and nothing else, so a resize settles instead of snapping. */
:root {
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --dur: 0.22s;
}

#table,
#hand-panel,
#piles-row,
#seats-grid { transition: height var(--dur) var(--ease), padding var(--dur) var(--ease); }

.seat-card {
  transition: border-color 0.3s ease,
              padding var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease),
              transform var(--dur) var(--ease);
}

.minion-strip,
.monster-chip,
.kit-row,
.bar-track,
.pile-stack { transition: all var(--dur) var(--ease); }

.card { transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease); }

/* Any surface that can still scroll does it smoothly rather than jumping. */
#hand-cards,
#log-lines,
#table { scroll-behavior: smooth; }

/* Motion is decoration here -- never let it fight an accessibility setting. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ===================================================== account bar
   Sign-in and the profile chip. A seat now belongs to an account, so this is
   the first thing a new player has to get past -- it sits in the app bar
   rather than behind a tab for that reason. */

#account-bar { margin-left: auto; display: flex; align-items: center; gap: 8px; }

#account-bar button {
  font: inherit;
  font-size: 0.78rem;
  padding: 5px 11px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
#account-bar button:hover { border-color: var(--accent); }

#guest-signin { display: flex; gap: 6px; align-items: center; }
#guest-name {
  font: inherit;
  font-size: 0.78rem;
  padding: 5px 9px;
  width: 128px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
#guest-name:focus { outline: none; border-color: var(--accent); }

#account-chip { display: flex; align-items: center; gap: 7px; padding: 4px 10px 4px 4px; }
#account-avatar {
  width: 24px; height: 24px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--bg);
}
#account-level {
  font-size: 0.68rem;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--bg);
  font-weight: 700;
}

#account-panel {
  position: absolute;
  top: 46px; right: 10px;
  z-index: 60;
  width: min(420px, calc(100vw - 20px));
  max-height: 70vh;
  overflow-y: auto;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
}
#account-panel h3 { margin: 0 0 2px; font-family: var(--font-display); font-size: 1rem; }
#account-panel .ap-sub { font-size: 0.72rem; color: var(--text-dim); margin-bottom: 12px; }
#account-panel .ap-section { font-size: 0.68rem; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-dim); margin: 14px 0 7px; }

.ap-xp-track { height: 7px; border-radius: 999px; background: var(--bg);
  overflow: hidden; border: 1px solid var(--border); }
.ap-xp-fill { height: 100%; background: var(--accent); }
.ap-xp-label { display: flex; justify-content: space-between;
  font-size: 0.7rem; color: var(--text-dim); margin-top: 4px; }

.ap-avatars { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 6px; }
.ap-avatar { width: 100%; aspect-ratio: 1; border-radius: 8px; cursor: pointer;
  object-fit: cover; border: 2px solid transparent; background: var(--bg); }
.ap-avatar:hover { border-color: var(--border); }
.ap-avatar.chosen { border-color: var(--accent); }

.ap-mastery-row { display: flex; align-items: center; gap: 8px; padding: 5px 0;
  border-bottom: 1px solid var(--border); }
.ap-mastery-row:last-child { border-bottom: none; }
.ap-mastery-row img { width: 26px; height: 26px; border-radius: 6px; object-fit: cover; }
.ap-mastery-name { flex: 1; min-width: 0; font-size: 0.78rem; }
.ap-mastery-name small { display: block; color: var(--text-dim); font-size: 0.66rem; }
.ap-mastery-lvl { font-size: 0.7rem; font-weight: 700; color: var(--accent); }
