:root {
  --sandstone: #e3cfa1;
  --sandstone-dark: #c9b27c;
  --sandstone-deep: #b9a36e;
  --ochre: #b5651d;
  --lapis: #26407a;
  --ink: #2b2118;
  --paper: #f3ead6;
  --topbar-h: 42px;
  --panel-h: 156px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--sandstone);
  color: var(--ink);
  user-select: none;
}

body {
  display: flex;
  flex-direction: column;
  font-family: "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
}

/* The canvas is taken out of flow so its bitmap size cannot stop the playfield from shrinking. */
#playfield {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #1a140e;
}

#game {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#topbar, #bottompanel {
  background: linear-gradient(180deg, #f6edd4 0%, var(--sandstone) 55%, var(--sandstone-deep) 100%);
  color: var(--ink);
}

#topbar {
  flex: 0 0 var(--topbar-h);
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 14px;
  border-bottom: 3px solid var(--ochre);
  box-shadow: inset 0 -1px 0 var(--paper);
  font-size: 16px;
  font-weight: 700;
}

.res {
  display: flex;
  align-items: center;
  gap: 6px;
}

.res svg { display: block; flex: 0 0 auto; }

.res-val {
  color: var(--lapis);
  font-variant-numeric: tabular-nums;
  min-width: 1.4em;
}

.res-label {
  font-size: 13px;
  font-weight: 600;
}

#clock {
  margin-left: auto;
  color: var(--lapis);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  letter-spacing: 0.06em;
  min-width: 4.6em;
  text-align: right;
}

#bottompanel {
  flex: 0 0 var(--panel-h);
  height: var(--panel-h);
  display: flex;
  align-items: stretch;
  gap: 12px;
  padding: 8px 12px;
  border-top: 3px solid var(--ochre);
  box-shadow: inset 0 1px 0 var(--paper);
}

#bottompanel [hidden] { display: none !important; }

#sel {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

#hint {
  color: var(--lapis);
  font-size: 15px;
  padding: 0 8px;
}

#single {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 100%;
  min-width: 0;
}

#portrait {
  width: 96px;
  height: 112px;
  background: var(--sandstone-dark);
  border: 2px solid var(--ochre);
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px var(--paper);
  flex: 0 0 auto;
}

#meta {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  min-width: 176px;
}

#sel-name {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.1;
}

.stat {
  display: flex;
  align-items: center;
  gap: 6px;
}

.track {
  flex: 1 1 auto;
  height: 10px;
  min-width: 72px;
  background: var(--ink);
  border: 1px solid var(--lapis);
  border-radius: 2px;
  overflow: hidden;
}

.fill { height: 100%; width: 0; background: #3f7d4a; }

#xp-fill { background: var(--lapis); }

#hp-text, #xp-text {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  min-width: 4.2em;
  color: var(--ink);
}

#mil {
  display: flex;
  align-items: center;
  gap: 6px;
}

#lv {
  color: var(--lapis);
  font-weight: 700;
  font-size: 13px;
  min-width: 2.6em;
}

#badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 14px;
}

.pip {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c9a227;
  box-shadow: inset 0 -1px 0 #8a6a12;
}

.laurel { display: block; line-height: 0; }

#task {
  font-size: 13px;
  color: var(--ink);
}

#icons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-content: center;
  max-width: 280px;
}

.icon {
  position: relative;
  width: 52px;
  text-align: center;
}

.mini {
  width: 40px;
  height: 40px;
  background: var(--sandstone-dark);
  border: 1px solid var(--ochre);
  border-radius: 3px;
}

.icon .count {
  position: absolute;
  top: 26px;
  right: 2px;
  min-width: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--lapis);
  color: var(--paper);
  font-size: 11px;
  font-weight: 700;
  line-height: 14px;
}

.icon-name {
  display: block;
  font-size: 10px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#queue {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 168px;
  justify-content: center;
}

.q-head {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--lapis);
  font-weight: 700;
}

#queue-empty {
  font-size: 13px;
  color: #6a5436;
}

.queue-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.q-name {
  flex: 0 0 68px;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.q-track {
  flex: 1 1 auto;
  height: 8px;
  background: var(--ink);
  border: 1px solid var(--ochre);
  border-radius: 2px;
  overflow: hidden;
  min-width: 36px;
}

.q-fill { height: 100%; width: 0; background: var(--ochre); }

.q-cancel {
  width: 18px;
  height: 18px;
  padding: 0;
  border: 1px solid var(--ochre);
  border-radius: 3px;
  background: var(--sandstone);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}

.q-cancel:hover { border-color: var(--lapis); color: var(--lapis); }

#commands {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-content: center;
  gap: 6px;
  min-width: 0;
  overflow: auto;
}

.cmd {
  appearance: none;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "kind hotkey"
    "label label"
    "cost cost"
    "miss miss";
  align-items: center;
  flex: 0 0 auto;
  min-width: 104px;
  padding: 4px 6px 5px;
  background: linear-gradient(#f7edd6, var(--sandstone));
  border: 2px solid var(--ochre);
  border-radius: 4px;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.cmd:hover { border-color: var(--lapis); }

.cmd.is-active {
  border-color: var(--lapis);
  box-shadow: inset 0 0 0 1px var(--lapis);
  background: var(--paper);
}

.cmd.is-disabled {
  opacity: 0.5;
  filter: grayscale(0.55);
}

.cmd-kind {
  grid-area: kind;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ochre);
  font-weight: 700;
}

.cmd-hotkey {
  grid-area: hotkey;
  justify-self: end;
  color: var(--paper);
  background: var(--lapis);
  border-radius: 3px;
  font-size: 12px;
  font-weight: 700;
  padding: 0 4px;
  line-height: 16px;
}

.cmd-label {
  grid-area: label;
  font-weight: 700;
  font-size: 14px;
  line-height: 1.15;
}

.cmd-cost {
  grid-area: cost;
  font-size: 12px;
  color: var(--lapis);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.cmd-missing {
  grid-area: miss;
  font-size: 11px;
  color: #8e2f2f;
  min-height: 1em;
  white-space: nowrap;
}

#settings-btn {
  appearance: none;
  width: 28px;
  height: 28px;
  margin-left: 10px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--ochre);
  border-radius: 4px;
  background: var(--sandstone);
  color: var(--ink);
  cursor: pointer;
}

#settings-btn:hover { border-color: var(--lapis); color: var(--lapis); }

#minimap-wrap {
  flex: 0 0 auto;
  align-self: center;
  width: 132px;
  height: 132px;
  border: 2px solid var(--ochre);
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px var(--paper);
  background: #000;
}

#minimap {
  display: block;
  width: 128px;
  height: 128px;
  cursor: pointer;
  background: #000;
  touch-action: none;
}

#alerts {
  position: fixed;
  top: 50px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 28;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

.alert {
  appearance: none;
  pointer-events: auto;
  min-width: 220px;
  padding: 6px 12px;
  background: var(--paper);
  border: 2px solid var(--ochre);
  border-radius: 4px;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
}

.alert.is-attack { border-color: #8e2f2f; color: #8e2f2f; background: #f8e4d8; }
.alert.is-veteran {
  border-color: #8a6a12;
  background: #e6b325;
  color: #2b2118;
}
.alert.is-level { border-color: var(--lapis); color: var(--lapis); }
.alert.is-jump { cursor: pointer; }

#pause-overlay,
#help-overlay,
#gameover {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#pause-overlay {
  z-index: 20;
  background: rgba(26, 20, 14, 0.35);
  pointer-events: none;
}

#pause-overlay strong {
  font-size: 42px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--paper);
  text-shadow: 0 2px 0 #2b2118;
}

#help-overlay {
  z-index: 30;
  padding: 16px;
  background: rgba(26, 20, 14, 0.45);
}

#settings {
  position: fixed;
  z-index: 36;
  width: 260px;
  padding: 12px 14px 14px;
  background: linear-gradient(180deg, #f6edd4, var(--sandstone-deep));
  border: 2px solid var(--ochre);
  border-radius: 6px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}

.settings-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--lapis);
}

.art-line {
  margin: 8px 0;
  font-size: 14px;
}

.art-toggle { display: flex; gap: 6px; }

.art-toggle button,
.gameover-card button {
  appearance: none;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  background: var(--paper);
  border: 2px solid var(--ochre);
  border-radius: 4px;
  color: var(--ink);
}

.art-toggle button {
  flex: 1 1 auto;
  padding: 6px 8px;
}

.art-toggle button.is-active {
  border-color: var(--lapis);
  color: var(--lapis);
  box-shadow: inset 0 0 0 1px var(--lapis);
}

#gameover {
  z-index: 40;
  background: rgba(26, 20, 14, 0.62);
}

.overlay-card,
.gameover-card {
  width: min(460px, 92vw);
  max-height: 100%;
  min-height: 0;
  overflow: auto;
  padding: 12px 16px 14px;
  background: linear-gradient(180deg, #f6edd4, var(--sandstone-deep));
  border: 3px solid var(--ochre);
  border-radius: 6px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  color: var(--ink);
}

.gameover-card {
  width: min(360px, 92vw);
  text-align: center;
}

.overlay-card h2,
.gameover-card h2 {
  margin: 0 0 4px;
  font-size: 24px;
  line-height: 1.1;
}

#victory h2 { color: #6a5410; }
#defeat h2 { color: #8e2f2f; }

.gameover-card p,
.overlay-card p { margin: 0; }

.gameover-card button {
  margin-top: 14px;
  padding: 8px 14px;
  border-color: var(--lapis);
  color: var(--lapis);
}

#help-overlay dl { margin: 2px 0 0; }
#help-overlay dt {
  margin-top: 4px;
  color: var(--lapis);
  font-weight: 700;
  font-size: 14px;
}
#help-overlay dd { margin: 0; font-size: 13px; line-height: 1.25; }

#pause-overlay[hidden],
#help-overlay[hidden],
#settings[hidden],
#gameover[hidden],
#victory[hidden],
#defeat[hidden] {
  display: none !important;
}
