/* Mistfall — map editor. The skin is the design system of the game (docs/design-system/MISTFALL_UI.md): the
   frames of the HUD kit (assets/hud/a0744), the tokens of Mistfall UI (A0761), the type stack of the game.
   Dark panels, aged bronze, a discreet gold, blue only where it speaks of the server. No text under 11 px. */
:root {
  color-scheme: dark;
  --ms-ink: #10140f; --ms-ink-deep: #0a0d0a; --ms-bronze: #8a5a24; --ms-bronze-dark: #6b4a1e; --ms-gold: #d9ad63; --ms-gold-bright: #f1c56d;
  --ms-blue: #2f6fd3; --ms-blue-light: #5b9cf0; --ms-blue-ink: #0c1830; --ms-blue-text: #dbe6fb;
  --ms-text: #f1eadb; --ms-muted: #a8b2aa; --ms-faint: #8d968e;
  --ms-text-min: 11px; --ms-text-body: 12px; --ms-text-strong: 13px; --ms-text-title: 16px;
  --hud-panel: url("../../assets/hud/a0744/panel.png");
  --hud-button: url("../../assets/hud/a0744/button.png");
  --hud-slot: url("../../assets/hud/a0744/slot.png");
  --ms-icons: url("../../assets/ui/a0761/ui-icons.png");
  --line: rgba(225, 197, 139, .16);
  --danger: #e86052;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--ms-ink-deep); color: var(--ms-text); font: 400 var(--ms-text-body)/1.35 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden; -webkit-font-smoothing: antialiased; user-select: none; -webkit-user-select: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
[hidden] { display: none !important; }
.bi { width: 16px; height: 16px; flex: none; display: block; }

/* ── Frame ─────────────────────────────────────────────────────────────────────────────────────────────── */
.app { height: 100dvh; display: grid; grid-template-columns: 52px 296px minmax(0, 1fr) 300px; grid-template-rows: 54px minmax(0, 1fr) 30px;
  grid-template-areas: "top top top top" "tools palette stage side" "status status status status";
  background: radial-gradient(120% 90% at 50% 0%, #161b15 0%, var(--ms-ink-deep) 62%); }
.topbar { grid-area: top; display: flex; align-items: center; gap: 14px; padding: 0 14px 0 10px; min-width: 0;
  background: linear-gradient(to bottom, #1b2019, #11150f); border-bottom: 1px solid var(--ms-bronze-dark); box-shadow: 0 1px 0 #000, inset 0 -1px 0 rgba(241, 197, 109, .12); z-index: 3; }
.toolbar { grid-area: tools; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 0; background: #0d110c; border-right: 1px solid var(--line); overflow-y: auto; scrollbar-width: none; }
.palette { grid-area: palette; }
.stage { grid-area: stage; position: relative; min-width: 0; min-height: 0; background: var(--ms-ink-deep); overflow: hidden; }
.side { grid-area: side; display: flex; flex-direction: column; gap: 6px; padding: 6px 6px 6px 0; min-height: 0; overflow: hidden; scrollbar-width: thin; scrollbar-color: var(--ms-bronze-dark) transparent; }
.statusbar { grid-area: status; display: flex; align-items: center; gap: 0; padding: 0 10px; min-width: 0; background: #0d110c; border-top: 1px solid var(--ms-bronze-dark);
  font-size: var(--ms-text-body); color: var(--ms-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ── Pieces of the kit ─────────────────────────────────────────────────────────────────────────────────── */
.panel, .card { border: 1px solid transparent; border-image: var(--hud-panel) 48 fill / 20px; padding: 12px 13px 13px; min-width: 0; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 0 1px 8px; }
.panel-head b { color: var(--ms-gold); font-size: 14px; font-weight: 700; letter-spacing: .02em; }
.panel-head span { color: var(--ms-faint); font-size: var(--ms-text-min); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plate { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 32px; padding: 0 12px; border: 1px solid transparent;
  border-image: var(--hud-button) 30 fill / 10px; background: none; color: var(--ms-text); font-size: var(--ms-text-strong); font-weight: 600; white-space: nowrap; }
.plate:hover:not(:disabled) { filter: brightness(1.18); color: #fff; }
.plate:active:not(:disabled) { filter: brightness(.92); transform: translateY(1px); }
.plate:disabled { color: var(--ms-faint); filter: saturate(.55) brightness(.82); }
.plate.icon-only { width: 34px; min-width: 34px; padding: 0; }
.plate[aria-pressed="true"], .plate.on { color: var(--ms-gold-bright); filter: brightness(1.22); }
:focus-visible { outline: 2px solid var(--ms-gold-bright); outline-offset: 1px; }

/* ── Top bar ───────────────────────────────────────────────────────────────────────────────────────────── */
.brand { display: flex; align-items: center; gap: 4px; flex: none; }
.brand-mark { width: 40px; height: 40px; flex: none; background: var(--ms-icons) calc(200% / 3) 50% / 400% 300% no-repeat; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text b { color: var(--ms-gold); font-size: 17px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.brand-text span { color: var(--ms-muted); font-size: var(--ms-text-min); letter-spacing: .08em; text-transform: uppercase; }
.world-name { display: flex; flex-direction: column; min-width: 0; padding-left: 14px; border-left: 1px solid var(--line); line-height: 1.2; }
.world-name b { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.world-name span { color: var(--ms-faint); font-size: var(--ms-text-min); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.env-badge { flex: none; padding: 3px 10px; border: 1px solid var(--ms-blue); border-radius: 3px; background: linear-gradient(to bottom, #10203f, var(--ms-blue-ink));
  color: var(--ms-blue-text); font-size: var(--ms-text-min); font-weight: 700; letter-spacing: .1em; box-shadow: inset 0 0 0 1px #5b9cf02e; }
.top-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; flex: none; }
.top-drawers { display: none; gap: 6px; flex: none; }

/* ── Tool bar ──────────────────────────────────────────────────────────────────────────────────────────── */
.tool { position: relative; width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid transparent; border-image: var(--hud-slot) 20 fill / 9px; background: none; color: var(--ms-text); }
.tool .bi { width: 17px; height: 17px; }
.tool:hover:not(:disabled) { filter: brightness(1.25); }
.tool[aria-pressed="true"] { color: var(--ms-gold-bright); filter: brightness(1.3); box-shadow: inset 0 0 0 1px rgba(241, 197, 109, .7); }
.tool:disabled { color: #6f786f; filter: saturate(.4) brightness(.78); }
.tool-sep { width: 26px; height: 1px; margin: 4px 0; background: var(--line); flex: none; }
.tool[data-tip]:hover::after, .tool[data-tip]:focus-visible::after { content: attr(data-tip); position: fixed; left: 58px; margin-top: 0; padding: 5px 9px; border: 1px solid var(--ms-bronze-dark);
  background: #141912; color: var(--ms-text); font-size: var(--ms-text-body); font-weight: 400; white-space: nowrap; z-index: 20; pointer-events: none; box-shadow: 0 4px 14px #000a; }

/* ── Palette ───────────────────────────────────────────────────────────────────────────────────────────── */
.palette { display: flex; flex-direction: column; margin: 6px 6px 6px 6px; min-height: 0; }
.palette-tabs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; margin-bottom: 8px; }
.palette-tab { display: grid; grid-template-columns: 14px minmax(0, 1fr) auto; align-items: center; gap: 6px; min-height: 30px; padding: 0 9px; text-align: left; border: 1px solid transparent; border-image: var(--hud-button) 30 fill / 9px;
  background: none; color: var(--ms-muted); font-size: var(--ms-text-body); font-weight: 600; min-width: 0; }
.palette-tab .bi { width: 14px; height: 14px; opacity: .8; }
.palette-tab span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-tab small { color: var(--ms-faint); font-size: 10.5px; font-weight: 400; font-variant-numeric: tabular-nums; }
.palette-tab:hover { color: var(--ms-text); filter: brightness(1.15); }
.palette-tab[aria-selected="true"] { color: var(--ms-gold-bright); filter: brightness(1.25); }
.palette-tab[aria-selected="true"] small { color: var(--ms-gold); }
.search { display: flex; align-items: center; gap: 7px; height: 32px; padding: 0 9px; margin-bottom: 8px; border: 1px solid var(--ms-bronze-dark); background: var(--ms-ink-deep); color: var(--ms-faint); }
.search:focus-within { border-color: var(--ms-gold); color: var(--ms-gold); }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: none; color: var(--ms-text); font-size: var(--ms-text-strong); user-select: text; -webkit-user-select: text; }
.search input::placeholder { color: var(--ms-faint); }
.palette-grid { flex: 1; min-height: 0; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); grid-auto-rows: min-content; gap: 4px; align-content: start;
  padding: 2px 4px 2px 2px; scrollbar-width: thin; scrollbar-color: var(--ms-bronze-dark) transparent; }
.palette-group { grid-column: 1 / -1; margin: 6px 0 1px; padding-bottom: 3px; border-bottom: 1px solid var(--line); color: var(--ms-gold); font-size: var(--ms-text-min); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; display: flex; justify-content: space-between; }
.palette-group:first-child { margin-top: 0; }
.palette-group small { color: var(--ms-faint); font-weight: 400; letter-spacing: 0; }
.swatch { position: relative; aspect-ratio: 1; padding: 0; border: 1px solid transparent; border-image: var(--hud-slot) 20 fill / 9px; background: none; display: grid; place-items: center; overflow: hidden; }
.swatch canvas { width: calc(100% - 10px); height: calc(100% - 10px); image-rendering: pixelated; display: block; }
.swatch:hover { filter: brightness(1.2); }
.swatch[aria-selected="true"] { box-shadow: inset 0 0 0 2px var(--ms-gold-bright); filter: brightness(1.15); }
.swatch.wide { grid-column: span 2; aspect-ratio: 2.06; }
.swatch.named { aspect-ratio: auto; grid-column: 1 / -1; display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 8px; align-items: center; justify-items: start; padding: 4px 8px 4px 4px; text-align: left; }
.swatch.named canvas { width: 48px; height: 48px; }
.swatch.named b { display: block; font-size: var(--ms-text-strong); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.swatch.named small { display: block; color: var(--ms-faint); font-size: var(--ms-text-min); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.swatch.named > div { min-width: 0; width: 100%; }
.palette-empty { grid-column: 1 / -1; padding: 22px 8px; color: var(--ms-faint); text-align: center; }
.palette-foot { margin: 8px 1px 0; min-height: 30px; color: var(--ms-muted); font-size: var(--ms-text-min); line-height: 1.35; }
.palette-foot b { color: var(--ms-text); font-weight: 600; }

/* ── Stage ─────────────────────────────────────────────────────────────────────────────────────────────── */
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: 0; cursor: crosshair; touch-action: none; }
#map.panning { cursor: grabbing; }
#map.can-pan { cursor: grab; }
.stage::after { content: ""; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .7), inset 0 0 38px rgba(0, 0, 0, .45); }
.stage-controls { position: absolute; left: 12px; bottom: 12px; display: flex; align-items: center; gap: 4px; padding: 5px; border: 1px solid transparent; border-image: var(--hud-panel) 48 fill / 16px; z-index: 2; }
.stage-controls .gap { width: 8px; }
.zoom-read { min-width: 48px; text-align: center; color: var(--ms-gold); font-size: var(--ms-text-strong); font-weight: 700; font-variant-numeric: tabular-nums; }
.stage-note { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); max-width: min(520px, 80%); padding: 6px 14px; border: 1px solid transparent; border-image: var(--hud-button) 30 fill / 10px;
  color: var(--ms-text); font-size: var(--ms-text-strong); text-align: center; z-index: 2; pointer-events: none; }
.stage-note:empty { display: none; }
.stage-note.error { color: #ffc9c1; }
.stage-corner { position: absolute; top: 12px; right: 12px; z-index: 2; display: flex; gap: 8px; }
.layers-button[aria-expanded="true"] { color: var(--ms-gold-bright); filter: brightness(1.22); }
.roofs-button[aria-pressed="true"] { color: var(--ms-gold-bright); filter: brightness(1.22); }
.layers-card { position: absolute; top: 52px; right: 12px; width: 232px; z-index: 3; box-shadow: 0 10px 30px #000a; max-height: calc(100% - 64px); overflow-y: auto; scrollbar-width: thin; }
.goto { position: absolute; left: 12px; bottom: 64px; width: 250px; display: grid; gap: 6px; z-index: 3; box-shadow: 0 10px 30px #000a; }
.goto label { color: var(--ms-gold); font-size: 14px; font-weight: 700; }
.goto-row { display: flex; gap: 6px; }
.goto input { flex: 1; min-width: 0; height: 32px; padding: 0 9px; border: 1px solid var(--ms-bronze-dark); background: var(--ms-ink-deep); outline: 0; font-size: var(--ms-text-strong); font-variant-numeric: tabular-nums; user-select: text; -webkit-user-select: text; }
.goto input:focus { border-color: var(--ms-gold); }
.goto small { color: var(--ms-faint); font-size: var(--ms-text-min); }
.goto small.error { color: #ffb4a8; }

/* ── Side: minimap, floors, layers, properties ─────────────────────────────────────────────────────────── */
.minimap-box { position: relative; aspect-ratio: 1; background: #060907; border: 1px solid var(--ms-bronze-dark); box-shadow: inset 0 0 0 1px #000, inset 0 0 18px #000c; }
#minimap { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; cursor: pointer; touch-action: none; }
.floors { display: grid; gap: 3px; }
.floor { display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; align-items: center; gap: 8px; min-height: 28px; padding: 0 9px 0 4px; border: 1px solid transparent; border-image: var(--hud-button) 30 fill / 8px;
  background: none; color: var(--ms-muted); font-size: var(--ms-text-body); text-align: left; }
.floor i { display: grid; place-items: center; height: 18px; border: 1px solid var(--ms-bronze-dark); background: var(--ms-ink-deep); color: var(--ms-text); font-style: normal; font-weight: 700; font-size: var(--ms-text-min); font-variant-numeric: tabular-nums; }
.floor b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.floor small { color: var(--ms-faint); font-size: var(--ms-text-min); font-variant-numeric: tabular-nums; }
.floor:hover { color: var(--ms-text); filter: brightness(1.15); }
.floor[aria-current="true"] { color: var(--ms-gold-bright); filter: brightness(1.25); }
.floor[aria-current="true"] i { border-color: var(--ms-gold); color: var(--ms-gold-bright); }
.layers { display: grid; gap: 1px; }
.layer-group { margin: 7px 1px 2px; color: var(--ms-faint); font-size: var(--ms-text-min); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.layer-group:first-child { margin-top: 0; }
.layer { display: grid; grid-template-columns: 18px minmax(0, 1fr); align-items: center; gap: 8px; min-height: 25px; padding: 0 4px; border: 0; background: none; color: var(--ms-muted); text-align: left; font-size: var(--ms-text-body); }
.layer .bi { width: 15px; height: 15px; color: #6f786f; }
.layer:hover { background: rgba(225, 197, 139, .07); color: var(--ms-text); }
.layer[aria-pressed="true"] { color: var(--ms-text); }
.layer[aria-pressed="true"] .bi { color: var(--ms-gold); }
.properties-panel { flex: 1 1 0; min-height: 120px; display: flex; flex-direction: column; }
.properties { display: grid; gap: 8px; align-content: start; min-height: 0; flex: 1; overflow-y: auto; padding: 0 4px 4px 0; scrollbar-width: thin; scrollbar-color: var(--ms-bronze-dark) transparent; user-select: text; -webkit-user-select: text; }
.properties .empty { color: var(--ms-faint); line-height: 1.45; }
.prop-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.prop-title b { font-size: 15px; font-weight: 700; color: var(--ms-text); font-variant-numeric: tabular-nums; }
.prop-title span { color: var(--ms-faint); font-size: var(--ms-text-min); }
.facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 3px 10px; margin: 0; }
.facts dt { color: var(--ms-faint); font-size: var(--ms-text-min); padding-top: 1px; }
.facts dd { margin: 0; color: var(--ms-text); font-size: var(--ms-text-body); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.facts dd small { display: block; color: var(--ms-faint); font-size: var(--ms-text-min); }
.tag { display: inline-block; padding: 0 6px; border: 1px solid var(--ms-bronze-dark); color: var(--ms-gold); font-size: var(--ms-text-min); font-weight: 600; line-height: 16px; }
.tag.no { border-color: #7a3a33; color: #ffb4a8; }
.tag.yes { border-color: #3d6b45; color: #a8e0b0; }
.items { display: grid; gap: 4px; }
.item { padding: 6px 8px; border: 1px solid var(--line); background: rgba(10, 13, 10, .55); }
.item b { display: block; font-size: var(--ms-text-body); font-weight: 600; }
.item b em { color: var(--ms-gold); font-style: normal; font-weight: 700; font-size: var(--ms-text-min); letter-spacing: .06em; text-transform: uppercase; margin-right: 6px; }
.item small { display: block; color: var(--ms-faint); font-size: var(--ms-text-min); overflow-wrap: anywhere; }
.item p { margin: 4px 0 0; color: var(--ms-muted); font-size: var(--ms-text-body); line-height: 1.4; }
.item .plate { margin-top: 5px; min-height: 26px; font-size: var(--ms-text-body); }
.prop-sub { margin: 2px 0 -2px; color: var(--ms-gold); font-size: var(--ms-text-min); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.prop-art { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 10px; align-items: center; }
.prop-art canvas { width: 72px; height: 72px; border: 1px solid transparent; border-image: var(--hud-slot) 20 fill / 9px; image-rendering: pixelated; }

/* ── Status bar ────────────────────────────────────────────────────────────────────────────────────────── */
.stat { display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; height: 100%; border-right: 1px solid var(--line); min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.stat:first-child { padding-left: 2px; }
.stat:empty { display: none; }
.stat b { color: var(--ms-gold); font-weight: 700; min-width: 108px; }
.stat .bi { width: 13px; height: 13px; color: var(--ms-gold); }
.stat.wide { flex: 1; color: var(--ms-text); display: block; line-height: 29px; }
.stat:last-child { border-right: 0; }

/* ── Help and boot ─────────────────────────────────────────────────────────────────────────────────────── */
dialog.card { color: var(--ms-text); background: none; max-width: min(460px, calc(100vw - 24px)); padding: 16px 18px 18px; }
dialog.card::backdrop { background: rgba(4, 6, 4, .72); }
.help .panel-head { align-items: center; }
.help dl { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 14px; margin: 0; }
.help dt { justify-self: start; padding: 1px 7px; border: 1px solid var(--ms-bronze-dark); background: var(--ms-ink-deep); color: var(--ms-gold); font-size: var(--ms-text-body); font-weight: 600; white-space: nowrap; }
.help dd { margin: 0; align-self: center; font-size: var(--ms-text-strong); }
.help-note { margin: 14px 0 0; padding-top: 10px; border-top: 1px solid var(--line); color: var(--ms-muted); line-height: 1.45; }
.boot { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 8px; background: radial-gradient(90% 70% at 50% 40%, #171c15, var(--ms-ink-deep)); z-index: 30; text-align: center; padding: 20px; }
.boot .brand-mark { width: 72px; height: 72px; }
.boot b { color: var(--ms-gold); font-size: 18px; letter-spacing: .06em; }
.boot span { color: var(--ms-muted); font-size: var(--ms-text-strong); max-width: 420px; }
.app[data-state="ready"] .boot { display: none; }

/* ── Narrow screens: the map takes the screen; palette and side panels slide over it ───────────────────── */
@media (max-width: 1180px) {
  .app { grid-template-columns: 52px 248px minmax(0, 1fr) 268px; }
  .top-actions .plate:not(.icon-only) span:last-child { display: none; }
  .top-actions .plate:not(.icon-only) { width: 34px; padding: 0; }
}
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: 48px minmax(0, 1fr) 28px; grid-template-areas: "top" "stage" "status"; }
  .topbar { gap: 8px; padding: 0 8px 0 6px; }
  .env-badge { padding: 3px 7px; letter-spacing: .06em; }
  .toolbar { display: none; }
  .top-actions { display: none; }
  .top-drawers { display: flex; margin-left: auto; }
  .world-name { display: none; }
  .brand-text span { display: none; }
  .palette, .side { position: fixed; top: 48px; bottom: 28px; width: min(320px, 88vw); z-index: 10; margin: 0; background: #0d110cf2; transition: transform .16s ease; box-shadow: 0 0 40px #000c; }
  .palette { left: 0; transform: translateX(-104%); padding: 12px; }
  .side { right: 0; transform: translateX(104%); padding: 6px 8px 6px 6px; }
  .app[data-drawer="palette"] .palette, .app[data-drawer="side"] .side { transform: none; }
  .plate.icon-only { width: 40px; min-width: 40px; min-height: 40px; }
  .stage-controls { left: 8px; bottom: 8px; }
  .stage-controls #actualButton, .stage-controls #homeButton { display: none; }
  .stat b { min-width: 0; }
  #statChunk, #statFrame, #statRegion { display: none; }
  .goto { left: 8px; bottom: 66px; }
  .stage-corner { top: 8px; right: 8px; }
  .layers-button span:last-child { display: none; }
  .layers-button { width: 40px; min-width: 40px; min-height: 40px; padding: 0; }
  .roofs-button { min-height: 40px; }
  .layers-card { top: 54px; right: 8px; }
  .side { overflow-y: auto; }
  .properties-panel { flex: none; }
}
@media (max-width: 390px) {
  .topbar { gap: 6px; }
  .brand-mark { width: 32px; height: 32px; }
  .brand-text b { font-size: 14px; }
  .topbar .env-badge { flex: 0 1 auto; min-width: 0; padding: 3px 5px; font-size: 10px; line-height: 1.15; letter-spacing: normal; text-align: center; }
  .top-drawers .plate.icon-only { width: 44px; min-width: 44px; min-height: 44px; }
}

/* ── Stage E2 (A0776): ground tools, history, session and draft ─────────────────────────────────────────── */
/* The bar leaves the corner of the stage to the Telhados and Camadas buttons (A0796, A0797): what does not fit wraps below. */
.edit-bar { position: absolute; top: 12px; left: 12px; display: flex; align-items: center; gap: 14px; padding: 7px 14px 7px 8px; z-index: 2; max-width: calc(100% - 262px); box-shadow: 0 8px 24px #0009; }
.edit-swatch { width: 46px; height: 46px; flex: none; display: grid; place-items: center; border: 1px solid transparent; border-image: var(--hud-slot) 20 fill / 9px; }
.edit-swatch canvas { width: 36px; height: 36px; display: block; image-rendering: pixelated; }
.edit-what { display: flex; flex-direction: column; min-width: 118px; max-width: 190px; line-height: 1.25; }
.edit-what b { color: var(--ms-gold); font-size: 14px; font-weight: 700; letter-spacing: .02em; }
.edit-what span { color: var(--ms-text); font-size: var(--ms-text-body); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.edit-bar.needs-ground .edit-what span { color: #ffb4a8; }
.edit-group { display: flex; flex-direction: column; gap: 3px; flex: none; }
.edit-group small { color: var(--ms-faint); font-size: var(--ms-text-min); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.stepper { display: flex; align-items: center; gap: 3px; }
.stepper .plate.icon-only, .history-buttons .plate.icon-only { width: 28px; min-width: 28px; min-height: 28px; }
.stepper .bi, .history-buttons .bi { width: 14px; height: 14px; }
.stepper-read { min-width: 22px; text-align: center; color: var(--ms-gold-bright); font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.edit-hint { color: var(--ms-muted); font-size: var(--ms-text-min); line-height: 1.35; max-width: 212px; padding-left: 14px; border-left: 1px solid var(--line); }
.edit-toast { position: absolute; left: 50%; bottom: 64px; transform: translateX(-50%); display: flex; align-items: center; gap: 9px; width: max-content; max-width: min(560px, calc(100% - 32px)); padding: 8px 16px;
  border: 1px solid transparent; border-image: var(--hud-button) 30 fill / 10px; color: var(--ms-text); font-size: var(--ms-text-strong); line-height: 1.35; z-index: 5; box-shadow: 0 8px 26px #000b; pointer-events: none; }
.edit-toast .bi { color: var(--ms-blue-light); }
.edit-toast.ok .bi { color: #a8e0b0; }
.edit-toast.error { color: #ffd6cf; }
.edit-toast.error .bi { color: var(--danger); }

.save-state { display: flex; flex-direction: column; min-width: 0; margin-left: auto; padding: 0 12px 0 14px; border-left: 1px solid var(--line); line-height: 1.2; text-align: right; }
.save-state b { color: var(--ms-muted); font-size: var(--ms-text-strong); font-weight: 600; white-space: nowrap; }
.save-state span { color: var(--ms-faint); font-size: var(--ms-text-min); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.save-state.unsaved b { color: var(--ms-gold-bright); }
.save-state.unsaved b::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: var(--ms-gold-bright); box-shadow: 0 0 0 3px rgba(241, 197, 109, .18); vertical-align: 1px; }
.save-state.saved b { color: #a8e0b0; }
.save-state + .top-actions { margin-left: 0; }
#sessionButton span { max-width: 96px; overflow: hidden; text-overflow: ellipsis; }

.history-panel { flex: none; padding-bottom: 11px; }
.history-head { align-items: center; margin-bottom: 6px; }
.history-head > span { flex: 1; }
.history-buttons { display: flex; gap: 3px; flex: none; }
.history-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; max-height: 28px; overflow: hidden; }
.history-panel.open .history-list { max-height: 150px; overflow-y: auto; padding-right: 3px; scrollbar-width: thin; scrollbar-color: var(--ms-bronze-dark) transparent; }
.history-list li { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; min-height: 26px; padding: 4px 8px; border: 1px solid var(--line); background: rgba(10, 13, 10, .55); }
.history-list li b { font-size: var(--ms-text-body); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-list li small { flex: none; color: var(--ms-faint); font-size: var(--ms-text-min); font-variant-numeric: tabular-nums; }
.history-list li.undone { opacity: .55; }
.history-list li.undone b { text-decoration: line-through; }
.history-list li.empty { color: var(--ms-faint); font-size: var(--ms-text-min); border-style: dashed; }
.history-panel:not(.open) .history-list li.empty { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; line-height: 17px; }

dialog.edit-dialog { width: min(470px, calc(100vw - 24px)); }
.edit-dialog p { margin: 0 0 12px; line-height: 1.5; font-size: var(--ms-text-strong); color: var(--ms-text); }
.edit-dialog .field { display: grid; gap: 5px; margin-bottom: 10px; }
.edit-dialog .field span { color: var(--ms-gold); font-size: var(--ms-text-min); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.edit-dialog input { height: 36px; padding: 0 10px; border: 1px solid var(--ms-bronze-dark); background: var(--ms-ink-deep); outline: 0; font-size: var(--ms-text-strong); user-select: text; -webkit-user-select: text; }
.edit-dialog input:focus { border-color: var(--ms-gold); }
.dialog-note { color: var(--ms-muted) !important; font-size: var(--ms-text-body) !important; }
.dialog-note code { padding: 1px 5px; border: 1px solid var(--ms-bronze-dark); background: var(--ms-ink-deep); color: var(--ms-gold); font: 600 11.5px/1.6 ui-monospace, "Cascadia Mono", Consolas, monospace; user-select: all; -webkit-user-select: all; white-space: nowrap; }
.dialog-error { color: #ffb4a8 !important; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.edit-dialog .facts { margin-bottom: 14px; gap: 6px 12px; }
.edit-dialog .facts dd { font-size: var(--ms-text-strong); }

.recover { position: absolute; top: 70px; left: 50%; transform: translateX(-50%); width: min(380px, calc(100% - 24px)); z-index: 4; box-shadow: 0 12px 34px #000c; }
.recover p { margin: 0 0 12px; line-height: 1.45; font-size: var(--ms-text-strong); }
.validation { position: absolute; right: 12px; top: 134px; width: min(360px, calc(100% - 24px)); max-height: min(62%, 440px); overflow-y: auto; z-index: 3; box-shadow: 0 12px 34px #000c; scrollbar-width: thin; scrollbar-color: var(--ms-bronze-dark) transparent; }
.validation .panel-head { align-items: center; }
.validation.valid .panel-head b { color: #a8e0b0; }
.validation.invalid .panel-head b { color: #ffb4a8; }
.validation p { display: flex; gap: 9px; margin: 0; line-height: 1.45; font-size: var(--ms-text-strong); }
.validation p .bi { margin-top: 2px; color: #a8e0b0; }
.issues { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.issues li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px; border: 1px solid var(--line); background: rgba(10, 13, 10, .55); }
.issues li b { display: block; font-size: var(--ms-text-body); font-weight: 600; line-height: 1.35; }
.issues li small { display: block; color: var(--ms-faint); font-size: var(--ms-text-min); overflow-wrap: anywhere; }
.issues .plate { min-height: 26px; padding: 0 9px; font-size: var(--ms-text-body); flex: none; }

@media (max-width: 1320px) { .edit-hint { display: none; } }
@media (max-width: 1180px) { .save-state span { display: none; } #sessionButton { width: auto !important; padding: 0 10px !important; } #sessionButton span:last-child { display: inline !important; } }
@media (max-width: 900px) { .edit-bar, .history-panel, .save-state { display: none; } }

/* ── Stages E3 and E4 (A0779): selection, objects, walls and passage ────────────────────────────────────── */
.content-bar { gap: 14px; }
.content-bar .edit-swatch[hidden] { display: none; }
.content-groups { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 6px 14px; flex: 0 1 auto; min-width: 0; }
.content-groups:empty { display: none; }
.content-bar .stepper .plate:not(.icon-only) { min-height: 28px; padding: 0 9px; font-size: var(--ms-text-body); white-space: nowrap; }
.content-bar .stepper .plate[aria-pressed="true"] { box-shadow: inset 0 0 0 1px rgba(241, 197, 109, .7); }
.content-bar .stepper-read { min-width: 34px; }
.content-bar .edit-what { min-width: 128px; }
.plate.mini { min-height: 22px; padding: 0 8px; font-size: var(--ms-text-min); }
.passage-line { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.item.with-art { display: grid; grid-template-columns: 44px minmax(0, 1fr); column-gap: 9px; align-items: start; }
.item.with-art > * { grid-column: 2; min-width: 0; }
.item.with-art > .item-art { grid-column: 1; grid-row: 1 / span 4; width: 44px; height: 44px; image-rendering: pixelated; border: 1px solid transparent; border-image: var(--hud-slot) 20 fill / 9px; padding: 3px; }
.item.with-art > .plate { justify-self: start; }
.issues li.place { margin-left: 14px; border-style: dashed; }
#map.painting-tool { cursor: crosshair; }
@media (max-width: 1500px) { .content-bar .edit-hint { display: none; } }
@media (max-width: 900px) { .content-bar { display: none; } }

/* ── Stage E7 (A0784): publish on the test server, version history, work from another version ───────────── */
dialog.publish-dialog, dialog.versions-dialog { width: min(560px, calc(100vw - 24px)); max-width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--ms-bronze-dark) transparent; }
dialog.versions-dialog { width: min(640px, calc(100vw - 24px)); max-width: min(640px, calc(100vw - 24px)); }
dialog.carry-dialog { width: min(500px, calc(100vw - 24px)); max-width: min(500px, calc(100vw - 24px)); }
dialog.busy { cursor: progress; }
.publish-body { display: grid; gap: 0; }
.publish-steps { list-style: none; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; margin: 0 0 14px; padding: 0; counter-reset: step; }
.publish-steps li { display: flex; align-items: center; gap: 6px; min-width: 0; padding: 6px 7px; border: 1px solid var(--line); background: rgba(10, 13, 10, .55);
  color: var(--ms-faint); font-size: var(--ms-text-min); font-weight: 600; line-height: 1.2; }
.publish-steps li span { overflow: hidden; text-overflow: ellipsis; }
.publish-steps li .bi { width: 14px; height: 14px; }
.publish-steps li[data-state="running"] { color: var(--ms-text); border-color: var(--ms-bronze); }
.publish-steps li[data-state="running"] .bi, .publish-working .bi { color: var(--ms-gold-bright); animation: publish-spin 1s linear infinite; }
.publish-steps li[data-state="done"] { color: var(--ms-text); }
.publish-steps li[data-state="done"] .bi { color: #a8e0b0; }
.publish-steps li[data-state="failed"] { color: #ffd6cf; border-color: #7a3a33; }
.publish-steps li[data-state="failed"] .bi { color: var(--danger); }
@keyframes publish-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .publish-steps li[data-state="running"] .bi, .publish-working .bi { animation: none; } }
.publish-working { display: flex; align-items: center; gap: 10px; color: var(--ms-muted) !important; }
.publish-verdict { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 14px !important; }
.publish-verdict .bi { width: 18px; height: 18px; color: var(--ms-gold); }
.publish-verdict.good .bi { color: #a8e0b0; }
.publish-verdict.bad { color: #ffd6cf !important; }
.publish-verdict.bad .bi { color: var(--danger); }
.publish-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin: 0 0 12px; }
.publish-fact { display: grid; grid-template-columns: 34px minmax(0, 1fr); align-items: center; gap: 9px; padding: 8px 10px; border: 1px solid transparent; border-image: var(--hud-slot) 20 fill / 9px; }
.publish-fact > .bi { width: 20px; height: 20px; justify-self: center; color: var(--ms-gold); }
.publish-fact b { display: block; color: var(--ms-gold-bright); font-size: 15px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.publish-fact small { display: block; color: var(--ms-muted); font-size: var(--ms-text-min); line-height: 1.3; }
.publish-packs { list-style: none; margin: -4px 0 12px; padding: 0; display: grid; gap: 3px; }
.publish-packs li { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 4px 8px; border: 1px solid var(--line); background: rgba(10, 13, 10, .55); }
.publish-packs b { font-size: var(--ms-text-body); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.publish-packs small { flex: none; color: var(--ms-faint); font-size: var(--ms-text-min); }
.publish-alert, .publish-warn { display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: 10px; margin: 0 0 12px; padding: 10px 12px; border: 1px solid var(--ms-blue);
  background: linear-gradient(to bottom, #10203f, var(--ms-blue-ink)); color: var(--ms-blue-text); box-shadow: inset 0 0 0 1px #5b9cf02e; }
.publish-alert .bi { color: var(--ms-blue-light); margin-top: 2px; }
.publish-alert b, .publish-warn b { display: block; font-size: var(--ms-text-strong); font-weight: 700; margin-bottom: 3px; }
.edit-dialog .publish-alert p, .edit-dialog .publish-warn p { margin: 0; color: inherit; font-size: var(--ms-text-body); line-height: 1.45; }
.publish-warn { border-color: #8a6a24; background: rgba(58, 40, 10, .55); color: #f6e2b8; box-shadow: none; }
.publish-warn .bi { color: var(--ms-gold-bright); margin-top: 2px; }
.publish-warn ul { margin: 6px 0 0; padding-left: 16px; font-size: var(--ms-text-body); line-height: 1.4; }
.publish-warn .plate { margin-top: 8px; justify-self: start; min-height: 28px; font-size: var(--ms-text-body); }
.publish-dialog .issues { max-height: 300px; overflow-y: auto; margin-bottom: 12px; padding-right: 3px; scrollbar-width: thin; scrollbar-color: var(--ms-bronze-dark) transparent; }
.publish-dialog .field input { width: 100%; }
.publish-dialog code, .versions-dialog code { color: var(--ms-gold); font: 600 12px/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace; overflow-wrap: anywhere; user-select: all; -webkit-user-select: all; }
.versions { list-style: none; margin: 0 0 12px; padding: 0 3px 0 0; display: grid; gap: 4px; max-height: min(52vh, 430px); overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--ms-bronze-dark) transparent; }
.version { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 9px; border: 1px solid var(--line); background: rgba(10, 13, 10, .55); }
.version.live { border-color: var(--ms-bronze); background: rgba(58, 40, 10, .35); }
.version-main { min-width: 0; display: grid; gap: 2px; }
.version-line { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.version-line b { font-size: var(--ms-text-strong); font-weight: 700; font-variant-numeric: tabular-nums; }
.edit-dialog .version p { margin: 0; font-size: var(--ms-text-body); color: var(--ms-text); line-height: 1.35; overflow-wrap: anywhere; }
.version small { color: var(--ms-faint); font-size: var(--ms-text-min); overflow-wrap: anywhere; }
.version .plate { flex: none; min-height: 28px; padding: 0 10px; font-size: var(--ms-text-body); }
.origin { padding: 0 6px; border: 1px solid var(--line); color: var(--ms-muted); font-size: var(--ms-text-min); font-weight: 600; line-height: 16px; }
.origin.editor { border-color: var(--ms-bronze); color: var(--ms-gold); }
.origin.generator { border-color: #34508a; color: var(--ms-blue-text); }
.tag.live { border-color: #3d6b45; color: #a8e0b0; text-transform: uppercase; letter-spacing: .06em; }
.carry-dialog .dialog-actions .plate:first-child { margin-right: auto; }
@media (max-width: 640px) { .publish-steps, .publish-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); } .version { flex-direction: column; align-items: stretch; } }

/* ── Stage E5 (A0785): spawns, NPCs, passages and signs ─────────────────────────────────────────────────────── */
.things-bar { flex-wrap: wrap; row-gap: 8px; }
.things-bar .content-groups { flex-wrap: wrap; row-gap: 6px; }
.things-bar .edit-what { max-width: 230px; }
.thing-chip { display: inline-flex; align-items: center; gap: 4px; min-height: 28px; padding: 0 3px 0 9px; border: 1px solid var(--ms-bronze-dark); background: var(--ms-ink-deep); color: var(--ms-text);
  font-size: var(--ms-text-body); font-weight: 600; white-space: nowrap; }
.thing-chip:only-child, .thing-chip:has(+ .plate) { padding-right: 9px; }
.thing-chip button { display: grid; place-items: center; width: 22px; height: 22px; padding: 0; border: 0; background: none; color: var(--ms-faint); }
.thing-chip button:hover { color: #ffb4a8; }
.thing-chip .bi { width: 11px; height: 11px; }
.sign-dialog textarea { display: block; width: 100%; min-height: 96px; resize: vertical; padding: 8px 10px; border: 1px solid var(--ms-bronze-dark); background: var(--ms-ink-deep); color: var(--ms-text);
  font: inherit; font-size: var(--ms-text-strong); line-height: 1.45; outline: 0; user-select: text; -webkit-user-select: text; }
.sign-dialog textarea:focus { border-color: var(--ms-gold); }
.sign-count { display: block; margin: -4px 1px 10px; color: var(--ms-faint); font-size: var(--ms-text-min); text-align: right; font-variant-numeric: tabular-nums; }
.sign-count.over { color: #ffb4a8; }
.item.thing-item.selected { border-color: rgba(241, 197, 109, .55); box-shadow: inset 0 0 0 1px rgba(241, 197, 109, .2); }
.spawn-schedule-dialog input { width: 100%; min-width: 0; }
.spawn-schedule-dialog input[aria-invalid="true"] { border-color: var(--danger); }
@media (max-width: 900px) {
  .spawn-schedule-dialog .plate, .item .spawn-schedule-button { min-height: 44px; }
  .spawn-schedule-dialog input { height: 44px; font-size: 16px; }
}
.item small.warn { color: #ffb4a8; }
.thing-lines { list-style: none; margin: 4px 0 2px; padding: 0; display: grid; gap: 3px; }
.thing-lines li { color: var(--ms-muted); font-size: var(--ms-text-body); line-height: 1.4; }

/* ── A0819: Gestão de contas (accounts/accounts-ui.js) ──────────────────────────────────────────────────────────── */
/* Its own screen over the editor, laid out like the importer and the weapon bench: the player accounts on the left and, on
   the right, the owner's model (modelo-do-dono/4-gestao-de-contas.png): the account, "Tipo de conta", "Salvar alteração". */
.acc { position: fixed; inset: 0; z-index: 31; display: grid; grid-template-columns: minmax(300px, 400px) minmax(0, 1fr); grid-template-rows: 54px minmax(0, 1fr) 46px;
  grid-template-areas: "head head" "list main" "foot foot"; background: radial-gradient(120% 90% at 50% 0%, #161b15 0%, var(--ms-ink-deep) 62%); color: var(--ms-text); }
.acc-head { grid-area: head; display: flex; align-items: center; justify-content: space-between; gap: 14px; min-width: 0; padding: 0 14px 0 12px;
  background: linear-gradient(to bottom, #1b2019, #11150f); border-bottom: 1px solid var(--ms-bronze-dark); box-shadow: 0 1px 0 #000, inset 0 -1px 0 rgba(241, 197, 109, .12); }
.acc-title { display: flex; align-items: center; gap: 11px; min-width: 0; }
.acc-title > .bi { width: 22px; height: 22px; color: var(--ms-gold); }
.acc-title div { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.acc-title b { color: var(--ms-gold); font-size: 16px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
.acc-title span { color: var(--ms-muted); font-size: var(--ms-text-min); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc-head-actions { display: flex; gap: 8px; flex: none; }
.acc-primary { color: var(--ms-gold-bright); filter: brightness(1.2); }
.acc .tag.quiet { border-color: var(--line); color: var(--ms-muted); }

/* The list */
.acc-side { grid-area: list; display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 6px 0 6px 6px; }
.acc-list-panel { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.acc-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 5px; padding: 1px 4px 2px 1px;
  scrollbar-width: thin; scrollbar-color: var(--ms-bronze-dark) transparent; }
.acc-row { display: grid; grid-template-columns: 40px minmax(0, 1fr); align-items: center; gap: 10px; width: 100%; flex: none; padding: 6px 8px 6px 6px; border: 1px solid var(--line);
  border-radius: 5px; background: rgba(255, 255, 255, .02); color: var(--ms-text); text-align: left; }
.acc-row:hover { border-color: rgba(225, 197, 139, .34); }
.acc-row[aria-selected="true"] { border-color: var(--ms-gold); background: rgba(241, 197, 109, .08); }
.acc-row-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; line-height: 1.3; }
.acc-row-text b { font-size: var(--ms-text-strong); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-row-text small { color: var(--ms-faint); font-size: var(--ms-text-min); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.acc-row-text .acc-row-chars { color: var(--ms-muted); }
.acc-row-line { display: flex; align-items: center; gap: 7px; min-width: 0; }
.acc-row-line .tag { flex: none; }
.acc-avatar { display: grid; place-items: center; width: 40px; height: 40px; flex: none; border: 1px solid transparent; border-image: var(--hud-slot) 20 fill / 9px;
  color: var(--ms-gold-bright); font-size: 17px; font-weight: 700; line-height: 1; text-shadow: 0 1px 0 #000; }
.acc-list-note { margin: 8px 1px 0; color: var(--ms-faint); font-size: var(--ms-text-min); line-height: 1.45; }
.acc-list-note:empty { display: none; }
.acc-message { display: flex; gap: 8px; align-items: flex-start; margin: 0 0 2px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 5px; background: rgba(10, 13, 10, .55);
  color: var(--ms-text); font-size: var(--ms-text-body); line-height: 1.45; }
.acc-message .bi { width: 14px; height: 14px; margin-top: 2px; color: var(--ms-blue-light); }
.acc-message div { display: flex; flex-direction: column; align-items: flex-start; gap: 7px; min-width: 0; }
.acc-message.error { border-color: #7a3a33; background: rgba(232, 96, 82, .08); color: #ffd6cf; }
.acc-message.error .bi { color: var(--danger); }
.acc-message .plate { min-height: 28px; padding: 0 10px; font-size: var(--ms-text-body); }

/* The owner's model */
.acc-main { grid-area: main; min-width: 0; min-height: 0; overflow-y: auto; display: flex; justify-content: center; align-items: flex-start; padding: 12px 14px 16px;
  scrollbar-width: thin; scrollbar-color: var(--ms-bronze-dark) transparent; }
.acc-card { width: min(430px, 100%); padding: 16px 18px 18px; }
.acc-card-title { margin: 2px 0 0; color: var(--ms-gold); font-size: 24px; font-weight: 700; letter-spacing: .02em; line-height: 1.2; text-align: center; text-shadow: 0 1px 0 #000; }
.acc-rule { position: relative; height: 1px; margin: 11px 8px; background: linear-gradient(to right, transparent, var(--ms-bronze) 18%, var(--ms-bronze) 82%, transparent); }
.acc-rule::after { content: ""; position: absolute; left: 50%; top: 50%; width: 7px; height: 7px; border: 1px solid var(--ms-gold); background: var(--ms-ink-deep); transform: translate(-50%, -50%) rotate(45deg); }
.acc-who { display: grid; grid-template-columns: 72px minmax(0, 1fr); align-items: center; gap: 14px; }
.acc-avatar.big { width: 72px; height: 72px; font-size: 32px; border-image: var(--hud-slot) 20 fill / 12px; }
.acc-who div { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.acc-who b { font-size: 21px; font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; }
.acc-who span { color: var(--ms-text); font-size: var(--ms-text-strong); overflow-wrap: anywhere; user-select: text; -webkit-user-select: text; }
.acc-who small { color: var(--ms-faint); font-size: var(--ms-text-min); line-height: 1.4; font-variant-numeric: tabular-nums; }
.acc-types { display: grid; gap: 5px; min-width: 0; margin: 0; padding: 0; border: 0; }
.acc-types legend { margin: 0 0 6px; padding: 0; color: var(--ms-text); font-size: 15px; font-weight: 600; }
.acc-type { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; align-items: center; gap: 12px; min-height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 6px;
  background: rgba(10, 13, 10, .55); font-size: 14px; font-weight: 600; cursor: pointer; }
.acc-type:hover { border-color: rgba(225, 197, 139, .34); }
.acc-type:has(input:checked) { border-color: var(--ms-gold); background: rgba(241, 197, 109, .08); color: var(--ms-gold-bright); }
.acc-type:has(input:focus-visible) { outline: 2px solid var(--ms-gold-bright); outline-offset: 1px; }
.acc-type:has(input:disabled) { cursor: progress; opacity: .72; }
.acc-type input { width: 16px; height: 16px; margin: 0; accent-color: var(--ms-gold); cursor: inherit; }
.acc-type input:focus-visible { outline: none; }
.acc-type small { color: var(--ms-faint); font-size: var(--ms-text-min); font-weight: 400; }
.acc-hint { margin: 10px 1px 0; color: var(--ms-faint); font-size: var(--ms-text-min); line-height: 1.45; }
.acc-save { width: 100%; min-height: 44px; margin-top: 14px; font-size: 15px; }
.acc-save:not(:disabled) { color: var(--ms-gold-bright); filter: brightness(1.2); }
.acc-note { margin: 10px 1px 0; color: var(--ms-muted); font-size: var(--ms-text-body); line-height: 1.45; text-align: center; }
.acc-note:empty { display: none; }
.acc-note.ok { color: #a8e0b0; }
.acc-note.error { color: #ffb4a8; }
.acc-empty { margin: 0; color: var(--ms-faint); font-size: var(--ms-text-strong); line-height: 1.5; text-align: center; }
.acc-back { display: none; margin-bottom: 8px; }

/* The foot and the way in */
.acc-foot { grid-area: foot; display: flex; align-items: center; gap: 12px; min-width: 0; padding: 0 14px; border-top: 1px solid var(--ms-bronze-dark); background: #0d110c; }
.acc-foot-text { flex: 1; min-width: 0; color: var(--ms-muted); font-size: var(--ms-text-body); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-foot-text.ok { color: #a8e0b0; }
.acc-gate { position: absolute; inset: 54px 0 46px; z-index: 4; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 24px; text-align: center;
  background: rgba(10, 13, 10, .92); }
.acc-gate > .bi { width: 40px; height: 40px; color: var(--ms-bronze); }
.acc-gate b { color: var(--ms-gold); font-size: 19px; }
.acc-gate p { max-width: 460px; margin: 0; color: var(--ms-muted); font-size: var(--ms-text-strong); line-height: 1.5; }

/* A ficha usa os mesmos controles do editor e preserva a arte de paleta. */
.palette-foot .edit-species-button { display: flex; margin-top: 6px; }
.species-new { width: 100%; min-height: 38px; margin-bottom: 7px; color: var(--ms-gold); }
dialog.species-dialog {
  box-sizing: border-box; width: min(640px, calc(100vw - 24px)); max-width: none;
  max-height: calc(100dvh - max(12px, env(safe-area-inset-top)) - max(12px, env(safe-area-inset-bottom)));
  padding: 0; overflow: hidden; border: 1px solid var(--ms-bronze); border-radius: 9px; background: var(--ms-ink-deep); border-image: none;
}
.species-dialog[open] { display: flex; flex-direction: column; }
.spellcraft-dialog .species-head { justify-content: space-between; }
.spellcraft-dialog .species-field[hidden] { display: none; }
.spellcraft-pick { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 8px; }
.spellcraft-pick .plate { min-height: 36px; }
.spellcraft-name { grid-column: span 2; }
.spellcraft-save-draft { display: none; }
@media (max-width: 900px) { .spellcraft-save-draft { display: inline-flex; } }
@media (max-width: 370px) { .topbar .env-badge { display: none; } }
.spellcraft-visual { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.spellcraft-tiles { display: grid; gap: 2px; }
.spellcraft-tiles i { width: 12px; height: 12px; border: 1px solid var(--ms-bronze-dark); background: #6e4c24; }
.spellcraft-tiles .origin { background: var(--ms-ink); border-color: var(--ms-gold-bright); }
.spellcraft-tiles .target { background: var(--ms-gold); }
.spellcraft-hash { font-size: 12px; }
.spellcraft-hash summary { cursor: pointer; color: var(--ms-gold); }
.spellcraft-fingerprint { overflow-wrap: anywhere; }
.spellcraft-preview { display: block; padding: 8px; color: var(--ms-gold); border: 1px solid var(--ms-bronze-dark); border-radius: 5px; font-size: 12px; }
@media (max-width: 540px) {
  .spellcraft-dialog .species-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .spellcraft-dialog .species-field :is(input, select) { min-height: 42px; font-size: 16px; }
  .spellcraft-pick .plate { min-height: 42px; }
}
.species-head { display: flex; align-items: center; gap: 10px; flex: none; padding: 9px 14px; border-bottom: 1px solid var(--ms-bronze-dark); }
.species-head h2 { margin: 0; color: var(--ms-gold); font-family: Georgia, serif; font-size: 20px; }
.species-art { width: 52px; height: 52px; flex: none; image-rendering: pixelated; }
.species-art-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
.species-art-choices > div { display: grid; min-width: 0; gap: .5rem; }
.species-art-preview { width: 76px; height: 76px; justify-self: center; image-rendering: pixelated;
  border: 1px solid var(--ms-bronze-dark); border-radius: 5px; background: #0d1713; }
.species-identity { margin: 4px 0 0; color: var(--ms-muted); font-size: 11px; overflow-wrap: anywhere; }
.species-form { display: flex; flex-direction: column; min-height: 0; }
.species-sections { display: grid; flex: none; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; padding: 8px 14px 0; }
.species-sections .plate { min-width: 0; min-height: 38px; font-size: 12px; }
.species-sections .plate[aria-pressed="true"] { color: var(--ms-gold); background: #342918; }
.species-profile, .species-profile-inputs, .species-effect-fields { display: grid; gap: 9px; align-content: start; min-width: 0; }
.species-profile-inputs, .species-inline-fields { min-width: 0; margin: 0; padding: 0; border: 0; }
.species-inline-fields { display: grid; gap: 5px; }
.species-effects { display: grid; gap: 5px; }
.species-effects:empty { display: none; }
.species-effect { min-width: 0; padding: 0 .48rem .4rem; border: 1px solid var(--ms-bronze-dark); border-radius: 6px; }
.species-effect > summary { min-height: 40px; align-content: center; cursor: pointer; color: var(--ms-gold); font-size: .84rem; }
.species-effect[open] > summary { margin-bottom: 6px; border-bottom: 1px solid var(--line); }
.species-effect:not([open]) { padding-bottom: 0; }
.species-effect-remove { margin-top: 8px; }
.species-effect-add, .species-load { justify-self: start; }
.species-check { display: inline-flex; gap: 6px; align-items: center; min-height: 34px; width: fit-content; font-size: 12px; }
.species-check input { accent-color: var(--ms-gold); }
.species-profile input:disabled, .species-profile select:disabled { color: var(--ms-muted); opacity: 1; }

.species-fields { display: grid; gap: 10px; min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 10px 14px 14px; }
.species-section { display: grid; gap: 8px; min-width: 0; margin: 0; padding: 8px; border: 1px solid var(--line); border-radius: 6px; }
.species-section legend { padding: 0 5px; color: var(--ms-gold); font-size: 13px; font-weight: 700; }
.species-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.species-field { display: grid; gap: 3px; min-width: 0; font-size: 12px; }
.species-field input, .species-field select { width: 100%; min-width: 0; min-height: 36px; padding: 4px 7px; color: var(--ms-text); background: var(--ms-ink); border: 1px solid var(--ms-bronze-dark); border-radius: 4px; font: inherit; }
.species-field :is(input, select):focus-visible, .species-biomes input:focus-visible { outline: 2px solid var(--ms-gold-bright); outline-offset: 1px; }
.species-biomes { display: flex; gap: 6px 13px; flex-wrap: wrap; }
.species-biomes label { display: inline-flex; align-items: center; gap: 4px; min-height: 30px; font-size: 12px; }
.species-biomes input { accent-color: var(--ms-gold); }
.species-section p, .species-footer p, .species-error { margin: 0; }
.species-error { color: #ffb4a8; }
.species-footer { display: flex; flex: none; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 7px; padding: 9px 14px; border-top: 1px solid var(--ms-bronze-dark); }
.species-footer p { margin-right: auto; }
.species-footer .species-error { flex-basis: 100%; }
.species-footer .plate { min-height: 40px; }
.species-loot-groups, .species-loot-rows, .species-loot-row { display: grid; min-width: 0; gap: 8px; }
.species-loot-row { padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--ms-ink); }
.species-loot-group > :is(.species-grid, .species-loot-rows, .species-loot-picker) { margin-bottom: 8px; }
.species-loot-odds { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.species-loot .species-loot-quantity { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.species-loot-actions { display: flex; flex-wrap: wrap; gap: 5px; }
.species-loot-actions .plate { padding-inline: 8px; }
.species-loot-list { display: grid; gap: 4px; min-width: 0; list-style: none; margin: 0; padding: 0; }
.species-loot-preview, .species-loot-choice { display: flex; gap: 8px; align-items: center; min-width: 0; }
.species-loot-choice { width: 100%; padding: 2px 8px; justify-content: flex-start; text-align: left; white-space: normal; }
.species-loot-item-name { min-width: 0; overflow-wrap: anywhere; }
.species-loot-item-name b, .species-loot-item-name small { display: block; }
.species-loot-item-name b { font-size: 12px; }
.species-loot-item-name small { color: var(--ms-muted); font-size: 11px; }
.species-loot-icon { --size: 32px; display: grid; place-items: center; flex: none; width: var(--size); height: var(--size); color: var(--ms-faint); }
.species-loot-icon.has-sprite { background: var(--species-item-sheet) calc(var(--size) * var(--ix) * -1) calc(var(--size) * var(--iy) * -1) /
  calc(var(--size) * var(--species-item-columns)) calc(var(--size) * var(--species-item-rows)) no-repeat; image-rendering: pixelated; }
@media (max-width: 480px) {
  .species-new { min-height: 44px; }
  .species-sections { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .species-sections .plate { padding-inline: 4px; }
  .species-sections .plate, .species-effect > summary, .species-check, .species-profile .plate { min-height: 44px; }
  .species-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .species-field input, .species-field select { min-height: 44px; font-size: 16px; }
  .species-footer .plate { min-height: 44px; }
}

/* Narrow screens: the list, and the model in its place once an account is picked */
@media (max-width: 900px) {
  .acc { grid-template-columns: minmax(0, 1fr); grid-template-areas: "head" "list" "foot"; }
  .acc-head { gap: 8px; padding: 0 8px 0 10px; }
  .acc-head-actions .plate { width: 40px; min-width: 40px; min-height: 40px; padding: 0; }
  .acc-head-actions .plate span { display: none; }
  .acc-side { padding: 6px; }
  .acc-main { grid-area: list; padding: 6px 6px 16px; }
  .acc:not(.acc-picked) .acc-main { display: none; }
  .acc.acc-picked .acc-side { display: none; }
  .acc-back { display: inline-flex; }
  .acc-card { padding: 14px 14px 16px; }
  .acc-foot { padding: 0 10px; }
}
