:root {
  color-scheme: dark;
  --bg: #12141a;
  --panel: #1c2028;
  --fg: #e8eaed;
  --muted: #8b919c;
  --err: #e07070;
  --accent: #6aa84f;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.4 system-ui, Segoe UI, sans-serif;
}
#login {
  max-width: 320px;
  margin: 12vh auto;
  padding: 24px;
  background: var(--panel);
  border-radius: 8px;
}
#login h1 { margin: 0 0 8px; font-size: 20px; }
.hint, #status { color: var(--muted); }
label { display: block; margin: 10px 0; }
input {
  width: 100%;
  margin-top: 4px;
  padding: 8px;
  background: #0e1014;
  color: var(--fg);
  border: 1px solid #333;
}
button {
  margin-top: 8px;
  padding: 8px 14px;
  background: var(--accent);
  color: #111;
  border: 0;
  cursor: pointer;
  font-weight: 600;
}
header button { margin-left: 8px; }
.err { color: var(--err); min-height: 1.2em; }
#app {
  position: relative;
  display: grid;
  grid-template-columns: 260px 1fr;
  grid-template-rows: auto auto auto 1fr auto;
  height: 100%;
}
header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 10px 12px;
  padding: 6px 12px;
  background: var(--panel);
  min-height: 40px;
}
#who, #rev, #kit { color: var(--muted); font-size: 12px; }
#rev { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 280px; }
.map-pick {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}
.map-pick select, #gotoForm input, #townSelect, #houseSelect, #npcSelect, #monsterSelect, #regKit {
  width: auto;
  margin: 0;
  padding: 4px 8px;
  background: #0e1014;
  color: var(--fg);
  border: 1px solid #333;
}
#gotoForm {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0;
}
#gotoForm input { width: 56px; }
#lookPop {
  position: absolute;
  z-index: 4;
  min-width: 260px;
  max-width: 380px;
  padding: 8px;
  background: #16181ee6;
  border: 1px solid #3a404c;
  box-shadow: 0 8px 24px #0008;
  pointer-events: auto;
}
#lookPop[hidden] { display: none; }
.look-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.layer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0;
}
.layer-row input { width: auto; margin: 0; }
.monster-search {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}
.monster-search input { width: 120px; margin: 0; }
#moveHouseBtn {
  width: 100%;
  margin-top: 6px;
  background: #2a2f38;
  color: var(--fg);
  font-weight: 500;
}
#moveHouseBtn[hidden] { display: none; }
#lookCoord { margin: 0; color: var(--muted); }
#lookBody {
  margin: 6px 0 0;
  padding: 6px;
  background: #0e1014;
  font: 11px/1.35 ui-monospace, Consolas, monospace;
  max-height: 32vh;
  overflow: auto;
}
.look-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 22px;
}
.look-row + .look-row { margin-top: 2px; }
.look-row-text {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}
.look-row-acts {
  display: flex;
  flex-shrink: 0;
  gap: 2px;
}
.look-act {
  margin: 0;
  padding: 0;
  width: 20px;
  height: 20px;
  background: #2a2f38;
  color: var(--fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.look-act svg {
  width: 12px;
  height: 12px;
  display: block;
}
.look-act:hover { background: #3a404c; }
#registerBox {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
#registerBox input, #registerBox select {
  width: auto;
  margin: 0;
  padding: 4px 8px;
}
#palettePane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #16181e;
}
#paletteSearch {
  width: calc(100% - 16px);
  margin: 10px 8px 4px;
}
.palette-mode {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 8px;
}
.palette-mode[hidden] { display: none; }
.palette-mode button {
  flex: 1 1 40%;
  margin: 0;
  background: #2a2f38;
  color: var(--fg);
  font-weight: 500;
}
#placeHint {
  margin: 4px 8px 0;
  min-height: 1.2em;
}
.palette-mode button.on { outline: 2px solid var(--accent); }
.brush-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
}
.brush-row button {
  margin: 0;
  padding: 4px 10px;
  background: #2a2f38;
  color: var(--fg);
}
#brushSizeLabel {
  min-width: 1.5em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
#folderBar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 0;
}
#folderBar[hidden] { display: none; }
#folderBack {
  margin: 0;
  padding: 4px 8px;
  background: #2a2f38;
  color: var(--fg);
  font-weight: 500;
}
#folderTitle { color: var(--muted); font-size: 12px; }
#folders {
  padding: 8px;
  overflow-y: auto;
  flex: 1;
}
.folder-btn {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  margin: 0 0 2px;
  padding: 6px 8px;
  background: transparent;
  color: var(--fg);
  text-align: left;
  font-weight: 400;
}
.folder-btn:hover { background: #22262e; }
.folder-count { color: var(--muted); }
#palette {
  padding: 8px;
  overflow-y: auto;
  flex: 1;
  display: none;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 4px;
  align-content: start;
}
#palette.show { display: grid; }
#folders.hidden, #palettePane .hidden { display: none; }
#moreBtn {
  margin: 0 8px 10px;
  background: #2a2f38;
  color: var(--fg);
  font-weight: 500;
}
#eraseBtn {
  margin: 8px;
  width: calc(100% - 16px);
}
.swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  margin: 0;
  padding: 4px;
  background: transparent;
  color: var(--fg);
  text-align: center;
  font-weight: 400;
}
#eraseBtn.swatch { flex-direction: row; justify-content: flex-start; }
.swatch.on { outline: 2px solid var(--accent); }
.chip {
  width: 32px;
  height: 32px;
  border: 1px solid #444;
  image-rendering: pixelated;
  object-fit: contain;
  flex: 0 0 32px;
  background: #2a3230;
}
.chip-void {
  background: #1a1d23;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
}
.swatch-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  font-size: 10px;
  font-weight: 400;
}
#map {
  display: block;
  width: 100%;
  height: 100%;
  background: #0b0c0f;
  cursor: crosshair;
}
#mapWrap {
  position: relative;
  min-width: 0;
  min-height: 0;
}
#palettePane[hidden] { display: none; }
#palettePane[hidden] + #mapWrap { grid-column: 1 / -1; }
#miniWrap {
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 3;
  border: 1px solid #3a404c;
  background: #0b0c0f;
  display: flex;
  flex-direction: column;
}
#miniWrap[hidden] { display: none; }
#mini {
  display: block;
  width: 192px;
  height: 192px;
  image-rendering: pixelated;
  cursor: pointer;
}
#status { grid-column: 1 / -1; margin: 0; padding: 6px 12px; }

#ribbon {
  grid-column: 1 / -1;
  display: flex;
  gap: 2px;
  padding: 0 8px;
  background: #16181e;
  border-bottom: 1px solid #2a2f38;
}
#ribbonStrip {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  padding: 4px 10px;
  background: #16181e;
  border-bottom: 1px solid #2a2f38;
  min-height: 32px;
}
.strip-cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}
.strip-cluster[hidden] { display: none; }
.icon-btn {
  margin: 0;
  padding: 4px;
  width: 28px;
  height: 28px;
  background: #2a2f38;
  color: var(--fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn svg {
  width: 16px;
  height: 16px;
  display: block;
}
.icon-btn.on, .icon-btn[aria-pressed="true"] {
  outline: 2px solid var(--accent);
}
.icon-btn[hidden] { display: none; }
.strip-cluster button:not(.icon-btn) {
  margin: 0;
  padding: 4px 10px;
  background: #2a2f38;
  color: var(--fg);
}
#ribbonStrip #gotoForm button {
  background: var(--accent);
  color: #111;
}
#ribbon button {
  margin: 0;
  padding: 8px 16px;
  background: transparent;
  color: var(--fg);
  font-weight: 600;
  border-bottom: 2px solid transparent;
}
#ribbon button.on {
  border-bottom-color: var(--accent);
  outline: none;
}
.overlay-table {
  width: auto;
  border-collapse: collapse;
  font-size: 12px;
}
.overlay-table th, .overlay-table td {
  padding: 4px 6px;
  text-align: left;
  font-weight: 500;
}
.overlay-table th { color: var(--muted); font-weight: 500; }
.overlay-table input { width: auto; margin: 0; }
.overlay-also {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.overlay-light {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin: 0;
}
#fileMenuWrap {
  margin-left: auto;
  position: relative;
}
#fileMenuBtn { margin: 0; }
#fileMenu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 8;
  min-width: 140px;
  background: #16181e;
  border: 1px solid #3a404c;
  padding: 4px;
}
#fileMenu[hidden] { display: none; }
#fileMenu button {
  display: block;
  width: 100%;
  margin: 0;
  padding: 8px 12px;
  background: transparent;
  color: var(--fg);
  text-align: left;
  font-weight: 500;
}
#fileMenu button:hover { background: #2a2f38; }
#fileMenu button[hidden] { display: none; }
#fileMenu #mapStats {
  margin: 8px 8px 4px;
  max-width: 220px;
  white-space: normal;
  font-size: 10px;
  line-height: 1.3;
}
.tool-pop {
  position: fixed;
  z-index: 7;
  min-width: 220px;
  max-width: 420px;
  background: #16181ee6;
  border: 1px solid #3a404c;
  box-shadow: 0 8px 24px #0008;
}
.tool-pop[hidden] { display: none; }
.tool-pop-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: #1c2028;
  cursor: grab;
  user-select: none;
}
.tool-pop-head span { flex: 1; font-weight: 600; font-size: 12px; }
.tool-pop-head .layer-row { margin: 0; }
.pop-close {
  margin: 0;
  padding: 2px 8px;
  background: #2a2f38;
  color: var(--fg);
}
.tool-pop-body {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px;
}
.tool-pop-body button {
  margin: 0;
  padding: 4px 10px;
  background: #2a2f38;
  color: var(--fg);
}
.tool-pop-body select, .monster-search input, .monster-search select {
  width: 100%;
  min-width: 200px;
}
#gotoForm button {
  background: var(--accent);
  color: #111;
}
#mapHud {
  position: absolute;
  left: 8px;
  top: 8px;
  z-index: 4;
}
.hud-pad {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  background: #16181ee6;
  border: 1px solid #3a404c;
}
.mini-hud {
  border: 0;
  border-bottom: 1px solid #3a404c;
  padding: 4px;
}
.compass {
  display: grid;
  grid-template-columns: 22px 22px 22px;
  grid-template-rows: 22px 22px 22px;
  gap: 1px;
}
.compass button {
  margin: 0;
  padding: 0;
  width: 22px;
  height: 22px;
  font-size: 10px;
  background: #2a2f38;
  color: var(--fg);
}
.comp-n { grid-column: 2; grid-row: 1; }
.comp-w { grid-column: 1; grid-row: 2; }
.comp-c {
  grid-column: 2;
  grid-row: 2;
  font-size: 9px;
  font-weight: 700;
}
.comp-e { grid-column: 3; grid-row: 2; }
.comp-s { grid-column: 2; grid-row: 3; }
.hud-stack { display: flex; flex-direction: column; gap: 4px; }
.hud-row {
  display: flex;
  align-items: center;
  gap: 4px;
}
.hud-row button {
  margin: 0;
  padding: 0;
  width: 22px;
  height: 22px;
  background: #2a2f38;
  color: var(--fg);
  font-size: 11px;
}
.hud-floor, .hud-zoom-label, .mini-floor, .mini-zoom-label {
  min-width: 2.4em;
  text-align: center;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
#mapStats { font-size: 11px; }
