@font-face {
  font-family: "Plex Mono";
  src: url("fonts/IBMPlexMono-Regular.ttf") format("truetype");
  font-weight: 400;
}
@font-face {
  font-family: "Plex Mono";
  src: url("fonts/IBMPlexMono-Bold.ttf") format("truetype");
  font-weight: 700;
}

:root {
  --bg: #0b0b0e;
  --panel: #131218;
  --panel-2: #1a1920;
  --line: #2a2831;
  --text: #dedad3;
  --muted: #8f8b96;
  --gold: #d4ad3a;
  --hp: #4fbf6a;
  --sp: #5b8fe0;
  --danger: #e0573f;
  --mono: "Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 var(--sans);
}

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

#top {
  height: 40px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
#brand {
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--gold);
  flex: none;
}
#tiles-pick {
  margin-left: auto;
  flex: none;
  color: var(--muted);
  font-size: 13px;
}
#tiles {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 6px;
  margin-left: 6px;
}
#prompt {
  font-family: var(--mono);
  font-size: 15px;
  white-space: pre;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

#game {
  height: calc(100% - 40px);
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 320px;
  gap: 10px;
  padding: 10px 16px 12px;
}

.pane {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

#left, #right {
  overflow-y: auto;
  padding: 12px 14px;
}

#centre {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto 150px;
  gap: 8px;
  min-width: 0;
  min-height: 0;
}

#mapwrap {
  position: relative;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
#map {
  display: block;
  image-rendering: pixelated;
  cursor: crosshair;
}
#classic {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}
#classic-canvas { display: block; }

#statusline {
  font-family: var(--mono);
  font-size: 14px;
  white-space: pre;
  overflow: hidden;
  min-height: 20px;
  padding: 0 4px;
}

#log {
  overflow-y: auto;
  padding: 8px 12px;
  font-size: 14px;
}
#log .m { padding: 1px 0; }
#log .m.old { opacity: 0.55; }

/* --------------------------------------------------------------- character */

#char .name {
  font-size: 19px;
  font-weight: 700;
  line-height: 1.2;
}
#char .who { color: var(--muted); margin: 2px 0 12px; }
.bar {
  margin: 6px 0 10px;
}
.bar .label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.bar .label b { color: var(--text); font-weight: 600; }
.bar .track {
  height: 8px;
  border-radius: 4px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  overflow: hidden;
}
.bar .fill { height: 100%; border-radius: 3px; transition: width 0.2s; }

.stats {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  margin: 12px 0;
  font-family: var(--mono);
  font-size: 13.5px;
}
.stats .k { color: var(--muted); }
.stats .v { text-align: right; color: #7fd88e; }
.stats .v.reduced { color: #e6c84c; }

.facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  font-variant-numeric: tabular-nums;
}
.facts .k { color: var(--muted); }
.facts .v { text-align: right; }

/* ------------------------------------------------------------------- items */

#right h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 4px 0 6px;
  display: flex;
  justify-content: space-between;
}
#right h2 + .items { margin-bottom: 14px; }
#burden { text-transform: none; letter-spacing: 0; }

.items {
  list-style: none;
  margin: 0;
  padding: 0;
}
.items li {
  display: grid;
  grid-template-columns: 26px 18px minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  padding: 2px 4px;
  border-radius: 4px;
  min-height: 28px;
}
.items li .lbl { color: var(--muted); font-family: var(--mono); }
.items li .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.items li .wt { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.items li.empty .nm { color: #4c4955; }
.items li .slot { color: var(--muted); font-size: 12px; }

.tile {
  width: 24px;
  height: 24px;
  background-repeat: no-repeat;
  image-rendering: pixelated;
  flex: none;
}
.tile.big { width: 32px; height: 32px; }
.glyph {
  width: 24px;
  text-align: center;
  font-family: var(--mono);
  font-weight: 700;
}

/* ------------------------------------------------------------------ dialog */

#scrim {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 5, 8, 0.55);
}
#dialog {
  min-width: 340px;
  max-width: min(620px, calc(100vw - 32px));
  max-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid #3a3742;
  border-radius: 10px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.6);
}
#dialog .q {
  padding: 16px 18px 10px;
  font-size: 16px;
  font-weight: 600;
}
#dialog .tabs {
  display: flex;
  gap: 4px;
  padding: 0 14px 8px;
  border-bottom: 1px solid var(--line);
}
#dialog .tabs button {
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  padding: 3px 10px;
  cursor: pointer;
}
#dialog .tabs button.on { color: var(--text); border-color: var(--gold); }
#dialog .tabs kbd { font-family: var(--mono); color: var(--gold); margin-left: 4px; }
#dialog .list {
  overflow-y: auto;
  padding: 6px 8px;
}
#dialog .row {
  display: grid;
  grid-template-columns: 34px 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}
#dialog .row.text { grid-template-columns: 22px minmax(0, 1fr); }
#dialog .row:hover, #dialog .row.sel { background: var(--panel-2); }
#dialog .row.sel { outline: 1px solid #4b4654; }
#dialog .row.off { opacity: 0.4; cursor: default; }
#dialog .row .lbl { font-family: var(--mono); color: var(--gold); }
#dialog .row .wt { color: var(--muted); font-size: 12px; }
#dialog .foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 14px 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}
#dialog .buttons { display: flex; gap: 8px; margin-left: auto; }
#dialog button.act {
  font: inherit;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: 6px;
  border: 1px solid #3a3742;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}
#dialog button.act.primary { background: var(--gold); color: #1a1508; border-color: var(--gold); }
#dialog input {
  font: 16px var(--mono);
  margin: 4px 18px 6px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #3a3742;
  background: #0d0c11;
  color: var(--text);
}
#dialog kbd {
  font-family: var(--mono);
  color: var(--gold);
}

/* ------------------------------------------------------- making a character */

#birth {
  position: fixed;
  top: 40px;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  padding: 16px;
  background: var(--bg);
}
#birth.waiting { cursor: progress; }
body.birthing #prompt, body.birthing #tiles-pick { visibility: hidden; }

.bcard {
  width: min(1120px, 100%);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.steps {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  list-style: none;
  margin: 0;
  padding: 14px 20px 0;
  font-size: 13px;
  color: #5d5966;
}
.steps li + li::before { content: "›"; margin-right: 6px; color: #3d3a45; }
.steps li.done { color: var(--muted); }
.steps li.now { color: var(--gold); font-weight: 700; }
.bq {
  padding: 6px 20px 14px;
  font-size: 16px;
  font-weight: 600;
  border-bottom: 1px solid var(--line);
}
.bcard.compact { align-self: flex-start; max-height: 100%; }
.bbody { flex: 1; min-height: 0; display: flex; }

.bmenu {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
}
.blist {
  overflow-y: auto;
  padding: 8px;
  border-right: 1px solid var(--line);
}
.brow {
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
}
.brow:hover { background: var(--panel-2); }
.brow.sel { background: var(--panel-2); outline: 1px solid #4b4654; color: var(--gold); }
.bdetail { overflow-y: auto; padding: 18px 22px; }
.bhead { display: flex; align-items: center; gap: 18px; margin-bottom: 14px; }
.bhead h3, .bsum h3 { margin: 0; font-size: 22px; }
.sub { color: var(--muted); }
.prose p { margin: 0 0 10px; max-width: 72ch; line-height: 1.55; }
pre.bdesc {
  margin: 14px 0 0;
  padding: 10px 14px;
  font: 13px/1.45 var(--mono);
  color: #c8c3bb;
  white-space: pre-wrap;
  background: #0d0c11;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.portrait {
  flex: none;
  background-image: url("portraits/portraits.png"), url("portraits/portraits.png");
  background-repeat: no-repeat;
  image-rendering: pixelated;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.portrait.none { background: var(--panel-2); }

.bpair {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px;
  align-content: start;
  gap: 28px;
  padding: 20px 22px;
}
.bpair.one { grid-template-columns: minmax(0, 1fr); }
.bwho { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; }
.bwho .portrait { margin-bottom: 8px; }
.bwho .nm { font-size: 17px; font-weight: 700; }
.note { color: var(--muted); }
.note b { color: var(--text); }

table.bstats { border-collapse: collapse; font-family: var(--mono); font-size: 14.5px; }
table.bstats th {
  padding: 0 12px 6px;
  font: 600 12px var(--sans);
  color: var(--muted);
  text-align: right;
}
table.bstats td { padding: 3px 12px; text-align: right; font-variant-numeric: tabular-nums; }
table.bstats .k { text-align: left; color: var(--muted); }
table.bstats td.best { color: #7fd88e; font-weight: 700; }
table.bstats tr.sel td { background: var(--panel-2); }
table.bstats tr.sel td:first-child { border-radius: 6px 0 0 6px; }
table.bstats tr.sel td:last-child { border-radius: 0 6px 6px 0; }
table.bstats td.pm { white-space: nowrap; }
.pmb {
  width: 28px;
  height: 26px;
  margin-left: 4px;
  font: 600 15px var(--sans);
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid #3a3742;
  border-radius: 6px;
  cursor: pointer;
}
.pmb:disabled { opacity: 0.3; cursor: default; }

#b-name, #b-hist {
  color: var(--text);
  background: #0d0c11;
  border: 1px solid #3a3742;
  border-radius: 8px;
}
#b-name { width: min(380px, 100%); padding: 10px 12px; font: 20px var(--mono); }
#b-hist { width: 100%; min-height: 150px; padding: 10px 12px; font: 15px/1.55 var(--sans); resize: vertical; }
#b-name.bad { border-color: var(--danger); animation: shake 0.3s; }
@keyframes shake {
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.bsum { display: flex; gap: 28px; align-items: flex-start; }
.bsum .main { min-width: 0; max-width: 72ch; }
.bsum .facts { margin-top: 14px; max-width: 260px; }
.bsum .stats { max-width: 260px; grid-template-columns: auto auto; justify-content: space-between; }
.bsum p { line-height: 1.55; margin: 12px 0 0; }
.bsum .patron b { color: var(--gold); }

.bfoot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}
.bfoot .gap { flex: 1; }
.bb {
  font: inherit;
  font-weight: 600;
  padding: 6px 14px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid #3a3742;
  border-radius: 6px;
  cursor: pointer;
}
.bb.primary { color: #1a1508; background: var(--gold); border-color: var(--gold); }
.bb:disabled { opacity: 0.4; cursor: default; }
.bb kbd { margin-left: 7px; font: 12px var(--mono); color: var(--gold); }
.bb.primary kbd { color: #5a4612; }

@media (max-width: 760px) {
  .bmenu { grid-template-columns: minmax(0, 1fr); grid-template-rows: 30% minmax(0, 1fr); }
  .blist { border-right: 0; border-bottom: 1px solid var(--line); }
  .bpair { grid-template-columns: minmax(0, 1fr); }
  .bsum { flex-direction: column; }
}

/* ---------------------------------------------------------------- loading */

#loading {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--bg);
}
#loading .title { color: var(--gold); font-size: 20px; font-weight: 700; }
#loading-text { color: var(--muted); }
#loading button {
  font: inherit;
  font-weight: 600;
  margin-top: 12px;
  padding: 8px 20px;
  border: 0;
  border-radius: 6px;
  background: var(--gold);
  color: #1a1508;
  cursor: pointer;
}
