:root {
  --slate:     #26302B;
  --slate-2:   #323E38;
  --chalk:     #F2F4EF;
  --manila:    #E3D9BE;
  --manila-2:  #D6C9A6;
  --ink:       #1B211E;
  --rule:      #9DA69F;

  --goblin: #4F7A3C;
  --slime:  #2F6690;
  --vermin: #7D5BA6;
  --spirit: #C9992E;
  --rare:   #B23A2E;

  --round: 3px;
  --display: "Baloo 2", "Trebuchet MS", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--slate);
  color: var(--chalk);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.55;
}

button, input, select, textarea { font: inherit; }
:focus-visible { outline: 2px solid var(--spirit); outline-offset: 2px; }

/* ---------- shell ---------- */

header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 18px;
  padding: 14px 20px 0;
  border-bottom: 1px solid var(--slate-2);
}
header h1 {
  font-family: var(--display);
  font-weight: 800;
  font-size: 21px;
  letter-spacing: -0.01em;
  margin: 0;
}
header p { margin: 0; color: var(--rule); font-size: 13px; flex: 1 1 200px; }
header .abstract {
  flex: 1 1 100%; width: 100%; max-width: 68ch;
  margin: 6px 0 2px; color: var(--chalk); font-size: 15px; line-height: 1.5;
}
header .warn { flex: 1 1 100%; width: 100%; margin: 0 0 4px; color: var(--spirit); font-size: 12px; }

nav { display: flex; gap: 2px; margin: 10px -20px -1px; padding: 0 20px; width: 100%; }
nav button {
  background: none;
  border: 1px solid transparent;
  border-bottom: none;
  color: var(--rule);
  padding: 7px 15px 8px;
  border-radius: var(--round) var(--round) 0 0;
  cursor: pointer;
  font-family: var(--display);
  font-weight: 600;
}
nav button:hover { color: var(--chalk); }
nav button[aria-selected="true"] {
  background: var(--slate-2);
  border-color: var(--slate-2);
  color: var(--chalk);
}

main { padding: 20px; max-width: 1180px; }
.panel[hidden] { display: none; }

/* ---------- shared bits ---------- */

.col-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 8px; gap: 10px;
}
.col-head h2 { font-family: var(--display); font-size: 15px; margin: 0; font-weight: 700; }
.col-head span { color: var(--rule); font-size: 12px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--rule); margin-bottom: 3px; }
.field input[type=text], .field select, .field textarea, .field input[type=number] {
  width: 100%; background: var(--slate); color: var(--chalk);
  border: 1px solid var(--rule); border-radius: var(--round); padding: 7px 9px;
}
.field textarea { resize: vertical; min-height: 86px; line-height: 1.45; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.row.wrap { flex-wrap: wrap; }
.row.wrap > .field { flex: 0 1 160px; min-width: 130px; }

.flags { display: flex; flex-wrap: wrap; gap: 6px; }
.flags label {
  display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--chalk);
  background: var(--slate); border: 1px solid var(--rule); border-radius: var(--round);
  padding: 5px 9px; cursor: pointer; margin: 0;
}
.flags input { accent-color: var(--spirit); margin: 0; }
.chk { display: flex; align-items: center; gap: 6px; color: var(--rule); font-size: 13px; }
.chk input { accent-color: var(--spirit); }

.btn {
  background: var(--manila); color: var(--ink); border: none;
  border-radius: var(--round); padding: 8px 14px; cursor: pointer;
  font-family: var(--display); font-weight: 700;
}
.btn:hover { background: var(--chalk); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.ghost { background: none; color: var(--rule); border: 1px solid var(--rule); }
.btn.ghost:hover { background: var(--slate-2); color: var(--chalk); }
.btn.danger { background: none; color: var(--rare); border: 1px solid var(--rare); }
.btn.danger:hover { background: var(--rare); color: var(--chalk); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; align-items: center; }

.hint { color: var(--rule); font-size: 12px; margin: 10px 0 0; }

/* ---------- card workbench ---------- */

.bench { display: grid; grid-template-columns: 250px 1fr 280px; gap: 20px; align-items: start; }
@media (max-width: 900px) { .bench { grid-template-columns: 1fr; } }

.roster { display: flex; flex-direction: column; gap: 3px; max-height: 62vh; overflow-y: auto; padding-right: 4px; }
.roster li { list-style: none; }
.roster ul { margin: 0; padding: 0; }
.rosterItem {
  display: flex; align-items: center; gap: 9px; width: 100%;
  background: var(--slate-2); border: 1px solid transparent; color: var(--chalk);
  padding: 7px 9px; border-radius: var(--round); cursor: pointer; text-align: left;
}
.rosterItem:hover { border-color: var(--rule); }
.rosterItem[aria-current="true"] { border-color: var(--spirit); }
.swatch { width: 5px; align-self: stretch; border-radius: 2px; flex: none; }
.rosterItem b { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rosterItem em { font-style: normal; color: var(--rule); font-size: 12px; flex: none; }
.rosterItem .glyph { font-size: 11px; color: var(--rule); flex: none; }
.rosterItem .glyph.manual { color: var(--rare); }

.fxRow { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; font-size: 13px; }
.fxRow select, .fxRow input {
  background: var(--slate); color: var(--chalk); border: 1px solid var(--rule);
  border-radius: var(--round); padding: 4px 6px; font-size: 13px;
}
.fxRow input[type=number] { width: 58px; }
.fxRow .lbl { color: var(--rule); font-size: 12px; }
.fxRow .x { background: none; border: none; color: var(--rule); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 4px; }
.fxRow .x:hover { color: var(--rare); }
.fxSay { color: var(--rule); font-size: 12px; margin: 0 0 8px; }
.fxSay.manual { color: var(--spirit); }

/* ---------- the card itself (shared by preview + print) ---------- */

.card {
  width: 2.5in; height: 3.5in;
  background: #FBFAF6; color: var(--ink);
  border-radius: 9px;
  padding: 0.17in 0.19in 0.15in;
  display: flex; flex-direction: column;
  font-family: var(--body);
  overflow: hidden;
  border: 1px solid #C9C4B4;
}
.card .band {
  height: 0.19in; margin: -0.17in -0.19in 0.13in; border-radius: 8px 8px 0 0;
  background: var(--goblin);
  display: flex; align-items: center; justify-content: flex-end;
  padding-right: 0.12in;
}
.card .band span { color: #fff; font-size: 7.5pt; font-weight: 700; letter-spacing: .02em; }
.card h3 {
  font-family: var(--display); font-weight: 800; font-size: 15pt; line-height: 1.05;
  margin: 0 0 2px;
}
.card .kind { font-size: 8pt; color: #6B675C; margin-bottom: 0.11in; }
.card .rule { border: none; border-top: 1px solid #DDD8C8; margin: 0 0 0.11in; }
.card .text { font-size: 9.2pt; line-height: 1.38; flex: 1; white-space: pre-wrap; }
.card .foot {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 6px;
  font-size: 7.5pt; color: #6B675C; margin-top: 0.08in;
}
.card .flees { display: flex; align-items: center; gap: 4px; }
.card .arrow { font-size: 12pt; line-height: 1; color: var(--ink); }
.card .tagline { font-style: italic; text-align: right; }
.card.rare { border-color: var(--rare); box-shadow: inset 0 0 0 2px #F0DBD8; }

.previewWrap { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.previewWrap .note { color: var(--rule); font-size: 12px; text-align: center; }

/* ---------- print sheet ---------- */

.sheet {
  display: grid; grid-template-columns: repeat(3, 2.5in); gap: 0;
  background: #fff; padding: 0.25in; width: max-content; border-radius: var(--round);
}
.sheet .card { border-radius: 0; border: 1px dashed #B9B4A4; }
.sheet.noguides .card { border-color: transparent; }
.sheetScroll { overflow-x: auto; padding-bottom: 8px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar label { display: flex; align-items: center; gap: 6px; color: var(--rule); font-size: 13px; }
.toolbar input { accent-color: var(--spirit); }

/* ---------- the table ---------- */

.tableGrid { display: grid; grid-template-columns: minmax(340px, 1fr) 340px; gap: 20px; align-items: start; }
@media (max-width: 900px) { .tableGrid { grid-template-columns: 1fr; } }

.banner {
  display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap;
  font-family: var(--display); font-weight: 700; font-size: 17px; margin-bottom: 8px;
}
.banner .phase { color: var(--rule); font-weight: 500; font-size: 13px; font-family: var(--body); }

.decision {
  background: var(--slate-2); border-left: 3px solid var(--spirit);
  padding: 10px 12px; border-radius: 0 var(--round) var(--round) 0; margin-bottom: 10px;
}
.decision[hidden] { display: none; }
.decision p { margin: 0; }
.decision .actions { margin-top: 8px; }

.board { display: grid; gap: 6px; margin-bottom: 10px; }
.sq {
  background: var(--slate-2); border: 1px solid transparent; border-radius: var(--round);
  min-height: 122px; padding: 6px 7px; cursor: pointer; display: flex; flex-direction: column;
}
.sq:hover { border-color: var(--rule); }
.sq.target:hover { border-color: var(--spirit); }
.sq.locked { border-style: dashed; border-color: var(--rare); }
.sqHead { display: flex; justify-content: space-between; font-size: 11px; color: var(--rule); margin-bottom: 4px; }
.sqHead .locks { color: var(--rare); }
.stack { display: flex; flex-direction: column-reverse; gap: 2px; }
.chip {
  font-size: 12px; background: var(--slate); border-left: 4px solid var(--rule);
  padding: 2px 6px; border-radius: 2px; opacity: .5;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip.top { opacity: 1; font-weight: 600; }
.chip.picked { outline: 2px solid var(--spirit); }
.chip .arrow { color: var(--rule); margin-left: 4px; }

.hand { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; min-height: 40px; }
.mini {
  width: 152px; background: #FBFAF6; color: var(--ink); border-radius: 6px;
  padding: 6px 8px 7px; border: 1px solid #C9C4B4; border-top: 6px solid var(--goblin);
  cursor: pointer; font-size: 12px; line-height: 1.35; text-align: left;
}
.mini:hover { border-color: var(--spirit); }
.mini.sel { outline: 3px solid var(--spirit); }
.mini b { display: block; font-family: var(--display); font-size: 13px; }
.mini .arrow { float: right; font-size: 14px; }
.mini .fx { color: #6B675C; font-size: 11px; margin-top: 3px; }
.mini .fx.manual { color: var(--rare); }

.players { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.pl { background: var(--slate-2); border-left: 4px solid; padding: 6px 10px; border-radius: var(--round); font-size: 13px; }
.pl.cur { outline: 1px solid var(--chalk); }
.pl .score { font-family: var(--display); font-weight: 800; font-size: 18px; float: right; }
.pl .nums { color: var(--rule); font-size: 12px; }
.pl .names { color: var(--rule); font-size: 12px; }

.log {
  list-style: none; margin: 0; padding: 8px 10px; max-height: 52vh; overflow-y: auto;
  font-size: 12.5px; background: var(--slate-2); border-radius: var(--round);
}
.log li { padding: 2px 0; border-bottom: 1px solid var(--slate); color: #D8DED9; }
.log li.head { color: var(--spirit); font-weight: 700; }
.log li.hand { color: var(--rule); font-style: italic; }

.handTools { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; font-size: 13px; color: var(--rule); }
.handTools select { background: var(--slate); color: var(--chalk); border: 1px solid var(--rule); border-radius: var(--round); padding: 4px 6px; }

.enrol { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }

.result { background: var(--slate-2); padding: 10px 12px; border-radius: var(--round); margin-top: 14px; font-size: 14px; }

/* ---------- rules ---------- */

.rules { max-width: 68ch; }
.rules h2 { font-family: var(--display); font-size: 19px; margin: 26px 0 6px; font-weight: 700; }
.rules h3 { font-family: var(--display); font-size: 15px; margin: 18px 0 4px; font-weight: 700; color: var(--manila); }
.rules p, .rules li { color: #D8DED9; }
.rules ul { padding-left: 20px; }
.rules li { margin-bottom: 5px; }
.rules .dial { color: var(--spirit); }
.rules blockquote {
  margin: 14px 0; padding: 10px 14px; border-left: 3px solid var(--spirit);
  background: var(--slate-2); color: var(--chalk); border-radius: 0 var(--round) var(--round) 0;
}

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--manila); color: var(--ink); padding: 9px 16px;
  border-radius: var(--round); font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.35);
  max-width: 90vw;
}
.toast[hidden] { display: none; }

@media print {
  @page { size: letter portrait; margin: 0.25in; }
  body { background: #fff; }
  header, nav, .toolbar, .panel:not(#panel-print), .toast, .hint { display: none !important; }
  main { padding: 0; max-width: none; }
  .sheetScroll { overflow: visible; }
  .sheet { padding: 0; gap: 0; width: auto; border-radius: 0; }
  .sheet .card { break-inside: avoid; page-break-inside: avoid; box-shadow: none; }
}
