:root {
  --ink: #100e0d;
  --ash: #1c1a18;
  --slab: #262320;
  --edge: #3a3530;
  --paper: #ded5c6;
  --muted: #9a9086;
  --ember: #d9782f;
  --gold: #e6c07a;
  --hollow: #7d68b0;
  --void: #2c2a3d;
  --good: #86b06a;
  --bad: #c05a4a;
  --face: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --grot: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--face);
  overflow: hidden;
}

button {
  font-family: var(--grot);
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--paper);
  background: var(--slab);
  border: 1px solid var(--edge);
  border-radius: 2px;
  padding: 7px 12px;
  cursor: pointer;
}

button:hover:not(:disabled) { border-color: var(--gold); color: var(--gold); }
button:disabled { opacity: 0.36; cursor: default; }
button.primary { background: #3a2415; border-color: var(--ember); color: var(--gold); }

[hidden] { display: none !important; }

#shell {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100%;
}

header#bar {
  display: flex;
  align-items: baseline;
  gap: 18px;
  padding: 8px 14px;
  background: linear-gradient(180deg, #1e1b19, #141211);
  border-bottom: 1px solid var(--edge);
}

header#bar h1 {
  margin: 0;
  font-size: 19px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
}

header#bar .sub { font-size: 12px; color: var(--muted); letter-spacing: 0.1em; }
header#bar .spacer { flex: 1; }

.readout {
  font-family: var(--grot);
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.readout b { color: var(--paper); font-weight: 600; }
.readout .kindled { color: var(--gold); }
.readout .hollow { color: var(--hollow); }

main#table {
  display: grid;
  grid-template-columns: 1fr 288px;
  min-height: 0;
}

#fieldwrap { position: relative; min-width: 0; min-height: 0; background: #0c0b0a; }
#field { display: block; width: 100%; height: 100%; touch-action: none; }

#tidebar {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  gap: 3px;
  align-items: center;
  padding: 6px 8px;
  background: rgba(12, 11, 10, 0.82);
  border: 1px solid var(--edge);
  border-radius: 2px;
}

#tidebar span.pip { width: 13px; height: 13px; border: 1px solid #000; display: block; }
#tidebar span.pip.now { outline: 1px solid var(--paper); outline-offset: 1px; }
#tidebar .label { font-family: var(--grot); font-size: 11px; color: var(--muted); margin-right: 6px; }

aside#panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--ash);
  border-left: 1px solid var(--edge);
}

.pane { padding: 9px 11px; border-bottom: 1px solid var(--edge); }
.pane h2 {
  margin: 0 0 7px 0;
  font-family: var(--grot);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

#roster { overflow-y: auto; flex: 1; min-height: 60px; }

.piece {
  display: grid;
  grid-template-columns: 16px 1fr auto;
  gap: 7px;
  align-items: center;
  padding: 3px 4px;
  border-radius: 2px;
  cursor: pointer;
  font-size: 13px;
}

.piece:hover { background: #2b2724; }
.piece.picked { background: #3a2b18; }
.piece.spent { opacity: 0.45; }
.piece .glyph { text-align: center; font-size: 13px; }
.piece .bar { height: 3px; background: #000; margin-top: 2px; }
.piece .bar i { display: block; height: 3px; background: var(--good); }
.piece .bar i.low { background: var(--bad); }
.piece .name { font-size: 12px; }
.piece .num { font-family: var(--grot); font-size: 11px; color: var(--muted); }

#workings { display: flex; flex-wrap: wrap; gap: 4px; }
#workings button { padding: 4px 7px; font-size: 11px; }

#log {
  height: 132px;
  overflow-y: auto;
  font-family: var(--grot);
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--muted);
}

#log p { margin: 0 0 3px 0; }
#log p b { color: var(--paper); font-weight: 600; }

#hint {
  min-height: 34px;
  font-size: 13px;
  color: var(--gold);
  padding: 7px 11px;
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 7, 7, 0.9);
  z-index: 40;
}

.sheet {
  width: min(760px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--slab);
  border: 1px solid var(--edge);
  border-top: 3px solid var(--ember);
  padding: 22px 26px;
}

.sheet h2 {
  margin: 0 0 4px 0;
  font-size: 24px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
}

.sheet h3 {
  font-family: var(--grot);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 16px 0 6px 0;
}

.sheet p { line-height: 1.55; font-size: 14px; }
.sheet ul { line-height: 1.55; font-size: 14px; padding-left: 20px; }
.sheet .row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.sheet .actions { display: flex; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.choice.on { border-color: var(--gold); color: var(--gold); background: #33261a; }

#duel {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #080707;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

#duelhead {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 14px;
  align-items: center;
  padding: 9px 16px;
  border-bottom: 1px solid var(--edge);
}

.combatant { min-width: 0; }
.combatant .who { font-size: 14px; letter-spacing: 0.06em; }
.combatant .lot { font-family: var(--grot); font-size: 11px; color: var(--muted); }
.combatant .gauge { height: 8px; background: #000; border: 1px solid var(--edge); margin-top: 4px; }
.combatant .gauge i { display: block; height: 6px; }
.combatant.right { text-align: right; }
.combatant.left .gauge i { background: var(--gold); }
.combatant.right .gauge i { background: var(--hollow); }

#duelclock { font-family: var(--grot); font-size: 22px; color: var(--paper); }
#duelground { font-family: var(--grot); font-size: 11px; color: var(--muted); text-align: center; }

#arenawrap { position: relative; min-height: 0; }
#arena { display: block; width: 100%; height: 100%; touch-action: none; }

#duelfoot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-top: 1px solid var(--edge);
  font-family: var(--grot);
  font-size: 12px;
  color: var(--muted);
}

#pad {
  position: absolute;
  left: 14px;
  bottom: 14px;
  display: none;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(3, 46px);
  gap: 4px;
  opacity: 0.8;
}

#pad button { font-size: 15px; padding: 0; }
#strike {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: none;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  font-size: 13px;
  opacity: 0.85;
}

body.touch #pad { display: grid; }
body.touch #strike { display: block; }

@media (max-width: 860px) {
  main#table { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  aside#panel { border-left: none; border-top: 1px solid var(--edge); max-height: 44vh; }
  #roster { max-height: 26vh; }
  #log { height: 84px; }
  header#bar { flex-wrap: wrap; gap: 10px; }
  header#bar h1 { font-size: 16px; }
}
