:root {
  --table: #1d3a2a;
  --table-deeper: #142a1f;
  --felt-edge: #0a1a12;
  --panel: #2a2018;
  --panel-light: #3a2c20;
  --ink: #f3eadb;
  --ink-dim: #b9ad96;
  --gold: #d4a544;
  --gold-bright: #f0c267;
  --crimson: #8a2a2a;
  --slot-empty: rgba(255, 255, 255, 0.04);
  --slot-empty-border: rgba(255, 255, 255, 0.12);
  --drop-hover: rgba(212, 165, 68, 0.4);
  --card-w: 110px;
  --card-h: 185px;
  --hand-card-w: 95px;
  --hand-card-h: 160px;
  --pile-w: 100px;
  --pile-h: 165px;
  --slot-w: 95px;
  --slot-h: 160px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: 'Cormorant Garamond', 'Hoefler Text', Georgia, serif;
  background: var(--table);
  color: var(--ink);
  overflow: hidden;
}

button {
  font: inherit;
  background: var(--panel-light);
  color: var(--ink);
  border: 1px solid var(--gold);
  border-radius: 3px;
  padding: 6px 14px;
  cursor: pointer;
  letter-spacing: 0.5px;
}
button:hover { background: var(--gold); color: #1a1208; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

input[type=text], input[type=number] {
  font: inherit;
  background: rgba(0, 0, 0, 0.3);
  color: var(--ink);
  border: 1px solid var(--gold);
  border-radius: 3px;
  padding: 5px 10px;
}

h1, h2, h3 { font-weight: 600; letter-spacing: 0.5px; margin: 0; }

/* ---------- Join overlay ---------- */

.overlay {
  position: fixed; inset: 0;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0.7), rgba(0,0,0,0.95));
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.join-card {
  background: var(--panel);
  border: 2px solid var(--gold);
  border-radius: 8px;
  padding: 32px 48px;
  text-align: center;
  min-width: 360px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.6);
}
.join-card h1 { font-size: 28px; color: var(--gold-bright); }
.join-card .subtitle { color: var(--ink-dim); font-style: italic; margin: 4px 0 24px; }
.join-row { display: flex; gap: 8px; margin-bottom: 16px; }
.join-row input { flex: 1; }
.divider { color: var(--ink-dim); margin: 16px 0; font-style: italic; }
.error { color: #e88; min-height: 1.2em; margin: 12px 0 0; font-size: 14px; }

/* ---------- App layout ---------- */

#app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
}

#topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 8px 16px;
  background: linear-gradient(to bottom, #251c14, #1a140e);
  border-bottom: 2px solid var(--gold);
}
#phase-display {
  display: flex; align-items: baseline; gap: 8px;
}
#phase-display .label { font-size: 12px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 1px; }
#phase-name { font-size: 22px; color: var(--gold-bright); font-weight: 600; text-transform: capitalize; }

#initiative-tracker {
  display: flex; align-items: center; gap: 8px;
  flex: 1; justify-content: center;
}
#count-cells { display: flex; gap: 2px; }
.count-cell {
  min-width: 28px; padding: 4px 6px;
  text-align: center;
  background: var(--panel-light);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  font-size: 13px;
  color: var(--ink-dim);
}
.count-cell.current {
  background: var(--gold);
  color: #1a1208;
  font-weight: 700;
  border-color: var(--gold-bright);
  box-shadow: 0 0 8px var(--gold);
}
.count-btn { padding: 2px 10px; font-size: 18px; line-height: 1; }
#who-am-i { font-size: 13px; color: var(--ink-dim); }

/* ---------- Main layout (non-challenge: 3-col grid; challenge: flex column) ---------- */

#table {
  display: grid;
  grid-template-columns: 220px 1fr 220px;
  overflow: hidden;
}

/* Challenge layout: two-child flex row */
#table.challenge-layout {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Left column: actors-col takes 2/3 */
#actors-col {
  flex: 2;
  display: flex;
  flex-direction: column;
}

/* Actor panels */
#table.challenge-layout .side-panel {
  background: var(--table-deeper);
  border: none;
  border-bottom: 1px solid var(--felt-edge);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: visible;
}
#table.challenge-layout .side-panel h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--ink-dim);
  margin: 0;
}
#table.challenge-layout .actor-list {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 10px;
}
#table.challenge-layout .actor-card { min-width: 260px; }

/* Right column: center takes 1/3 */
#table.challenge-layout #center {
  flex: 0 0 auto;
  width: calc(var(--hand-card-w) * 2 + 12px + 40px);
  overflow-y: visible;
  align-items: center;
  border-left: 1px solid var(--felt-edge);
}

/* Piles hand-card sized in the right column */
#table.challenge-layout #decks-row .pile {
  width: var(--hand-card-w);
  height: var(--hand-card-h);
}
#table.challenge-layout #decks-row { flex-direction: column; gap: 12px; align-items: center; }
#table.challenge-layout #action-log { height: 200px; }
.side-panel {
  background: var(--table-deeper);
  border-right: 1px solid var(--felt-edge);
  padding: 12px 8px;
  overflow-y: auto;
}
#right-panel { border-right: none; border-left: 1px solid var(--felt-edge); }
.side-panel h2 {
  font-size: 14px; text-transform: uppercase; letter-spacing: 1.5px;
  color: var(--ink-dim); margin-bottom: 12px;
}
.actor-list { display: flex; flex-direction: column; gap: 12px; }

.actor-card {
  background: var(--panel);
  border: 1px solid var(--felt-edge);
  border-radius: 4px;
  padding: 8px;
}
.actor-name {
  font-weight: 600;
  color: var(--gold-bright);
  font-size: 14px;
  margin-bottom: 6px;
  display: flex; justify-content: space-between;
}
.actor-hand-count { color: var(--ink-dim); font-size: 12px; font-weight: normal; }
.actor-slots-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  justify-content: space-between;
}
.actor-slot-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: 1;
}
.actor-slot {
  width: var(--hand-card-w); height: var(--hand-card-h);
  background: var(--slot-empty);
  border: 1px dashed var(--slot-empty-border);
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  font-size: 10px;
  color: var(--ink-dim);
  text-align: center;
}
.actor-slot[data-drop-active="true"] {
  border-color: var(--gold);
  background: var(--drop-hover);
}

.fd-type-label {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  text-align: center;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--gold-bright);
  background: rgba(0, 0, 0, 0.65);
  padding: 2px 0;
  pointer-events: none;
}

.actor-pills-row {
  display: flex;
  gap: 5px;
  margin-top: 4px;
  flex-wrap: wrap;
}
.actor-pill {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 10px;
  border: 1px solid var(--slot-empty-border);
  background: var(--slot-empty);
  color: var(--ink-dim);
  white-space: nowrap;
}
.actor-pill[data-drop-active="true"] {
  border-color: var(--gold);
  background: var(--drop-hover);
}
.pill-insp-active {
  color: var(--ink);
  border-color: rgba(255,255,255,0.25);
}
.pill-minor-active {
  color: #1a2e10;
  background: #5a9e3a;
  border-color: #7ac050;
  font-weight: 700;
}

#center {
  display: flex; flex-direction: column;
  background: radial-gradient(ellipse at center top, var(--table) 30%, var(--table-deeper) 100%);
  padding: 12px;
  overflow-y: auto;
  align-items: center;
  gap: 12px;
}

#decks-row {
  display: flex;
  gap: 28px;
  justify-content: center;
}
.deck-block {
  display: flex; flex-direction: column;
  align-items: center; gap: 6px;
}
.deck-label {
  font-size: 13px; text-transform: uppercase; letter-spacing: 2px;
  color: var(--gold);
}
.deck-block > .pile + .pile { margin-top: 8px; }
.deck-block { display: grid; grid-template-columns: auto auto; grid-template-rows: auto 1fr; column-gap: 12px; row-gap: 6px; align-items: center; }
.deck-block .deck-label { grid-column: 1 / -1; text-align: center; }

.pile {
  width: var(--pile-w); height: var(--pile-h);
  position: relative;
  background: var(--table-deeper);
  border: 1px dashed var(--slot-empty-border);
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-dim);
}
.pile.has-cards {
  border-style: solid; border-color: rgba(255,255,255,0.2);
  background-size: cover; background-position: center;
}
.pile.draw-pile.has-cards { background-image: url('/cards/back.jpg'); }

/* ---------- Cards ---------- */

.card {
  background: var(--ink);
  border-radius: 5px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  cursor: grab;
  user-select: none;
  position: relative;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
}
.card.dragging { opacity: 0.4; }
.card.facedown { background-image: url('/cards/back.jpg'); }
.card[data-faceup="true"] { background-color: var(--ink); }
.card.size-slot { width: var(--slot-w); height: var(--slot-h); }
.card.size-pile { width: var(--pile-w); height: var(--pile-h); }
.card.size-hand { width: var(--hand-card-w); height: var(--hand-card-h); }
.card.size-mini { width: 60px; height: 95px; }

.card-badge {
  position: absolute;
  top: 3px; left: 4px;
  background: rgba(0, 0, 0, 0.72);
  border-radius: 3px;
  padding: 1px 4px;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.4;
  font-variant-numeric: lining-nums;
  pointer-events: none;
  color: var(--ink);
  display: flex;
  gap: 2px;
  align-items: baseline;
  white-space: nowrap;
}
.card-badge-suit { font-size: 12px; }

/* ---------- Slots ---------- */

.slot {
  width: var(--slot-w); height: var(--slot-h);
  background: var(--slot-empty);
  border: 1px dashed var(--slot-empty-border);
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  position: relative;
  font-size: 10px;
  color: var(--ink-dim);
  text-align: center;
}
.slot[data-drop-active="true"] {
  border-color: var(--gold);
  background: var(--drop-hover);
}
.slot[data-cross-space="true"] {
  border-color: var(--crimson);
  background: rgba(138, 42, 42, 0.3);
}
.slot-tag {
  font-size: 9px; text-transform: uppercase;
  letter-spacing: 1px; color: var(--ink-dim);
  pointer-events: none;
}

#your-slots {
  display: flex; gap: 8px; align-items: center;
}

.staging-pair {
  display: flex; flex-direction: column;
  gap: 4px;
}
.staging-sub {
  width: var(--slot-w);
  height: calc(var(--slot-h) / 2 - 2px);
  background: var(--slot-empty);
  border: 1px dashed var(--slot-empty-border);
  border-radius: 3px;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px;
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  position: relative;
}
.staging-sub[data-drop-active="true"] {
  border-color: var(--gold);
  background: var(--drop-hover);
}

/* ---------- Action log ---------- */

#action-log-wrap {
  width: 100%;
  max-width: 600px;
}
#action-log-wrap h3 {
  font-size: 12px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 1.5px;
  margin-bottom: 4px;
}
#action-log {
  height: 110px;
  overflow-y: auto;
  background: var(--table-deeper);
  border: 1px solid var(--felt-edge);
  border-radius: 3px;
  padding: 6px 8px;
  font-size: 13px;
  font-family: 'Iowan Old Style', Georgia, serif;
}
.log-entry { padding: 1px 0; line-height: 1.35; }
.log-actor { color: var(--gold-bright); margin-right: 6px; }
.log-system { color: var(--ink-dim); font-style: italic; }

/* ---------- GM controls ---------- */

#gm-controls {
  flex-shrink: 0;
  border-left: 1px solid var(--felt-edge);
  padding-left: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.gm-row {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.gm-row span { font-size: 13px; color: var(--ink-dim); }

#undo-row { width: 100%; max-width: 700px; display: flex; justify-content: flex-end; }

/* ---------- Quick reference ---------- */

#quick-ref {
  width: 100%; max-width: 700px;
  font-size: 13px;
  color: var(--ink-dim);
  font-style: italic;
  text-align: center;
  padding: 6px;
}

/* ---------- Bottom panel ---------- */

#bottom-panel {
  background: linear-gradient(to top, #1a140e, #251c14);
  border-top: 2px solid var(--gold);
  padding: 10px 16px;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 16px;
  min-height: calc(var(--hand-card-h) + 50px);
}
#your-slots-wrap, #your-hand-wrap {
  display: flex; flex-direction: column; gap: 6px;
}
#your-hand-wrap { flex: 1; }
.slot-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px;
  color: var(--ink-dim);
}
.hand-count { color: var(--gold); font-weight: 600; }
#your-hand {
  display: flex; gap: 6px;
  min-height: var(--hand-card-h);
  padding: 4px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
  overflow-x: auto;
}

/* ---------- Discard browser ---------- */

#discard-browser .browser-card {
  background: var(--panel);
  border: 2px solid var(--gold);
  border-radius: 6px;
  width: min(90vw, 1100px);
  max-height: 80vh;
  display: flex; flex-direction: column;
}
.browser-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--felt-edge);
}
#browser-close {
  background: transparent; border: none; color: var(--ink); font-size: 24px;
  padding: 0 8px;
}
#browser-close:hover { color: var(--gold-bright); background: transparent; }
.browser-cards {
  display: flex; flex-wrap: wrap;
  padding: 16px; gap: 10px;
  overflow-y: auto;
}

/* ---------- Phase confirm modal ---------- */

.confirm-card {
  background: var(--panel);
  border: 2px solid var(--gold);
  border-radius: 6px;
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: center;
  max-width: 360px;
  text-align: center;
}
.confirm-card p {
  font-size: 17px;
  color: var(--ink);
  margin: 0;
}
.confirm-btns {
  display: flex;
  gap: 12px;
}
.confirm-btns button { min-width: 100px; }
#phase-confirm-no {
  background: transparent;
  border-color: var(--felt-edge);
  color: var(--ink-dim);
}
#phase-confirm-no:hover { border-color: var(--gold); color: var(--ink); }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--crimson);
  color: var(--ink);
  padding: 10px 18px;
  border-radius: 4px;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}
