/* Layout: a drafting table. The level fills the window; the toolbox sits on the left, a status line underneath. */
:root {
  --bg: #f3f4f6; --surface: #ffffff; --fg: #1d2330; --muted: #5b6474; --line: #d5d9e0;
  --accent: #1f6fd6; --accent-fg: #ffffff; --hover: #e9ecf1; --danger: #c2332b;
  --solid: #8b93a1; --hazard: #d9423a; --moving: #4f8fb3; --lore: #f2b705; --enemy: #9a4fd1; --pickup: #e8590c; --grapple: #0d8f7a;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --shadow: 0 6px 24px rgba(15, 20, 30, 0.18);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171d; --surface: #1c2028; --fg: #e7eaf0; --muted: #9aa3b2; --line: #2f3541;
    --accent: #6aa9ff; --accent-fg: #0d1522; --hover: #272c37; --danger: #f0625a;
    --solid: #6d7584; --hazard: #f0625a; --moving: #3f7da1; --lore: #f5c211; --enemy: #c084f5; --pickup: #ff8a4c; --grapple: #3fd0b6;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { display: flex; flex-direction: column; background: var(--bg); color: var(--fg); font: 13px/1.4 var(--font); overflow: hidden; -webkit-user-select: none; user-select: none; }
[hidden] { display: none !important; }

button, select, input { font: inherit; color: inherit; }
button, select, input[type="text"], input[type="number"] {
  background: var(--surface); border: 1px solid var(--line); border-radius: 5px; padding: 5px 9px; min-height: 28px;
}
input[type="text"], input[type="number"] { -webkit-user-select: text; user-select: text; }
button { cursor: pointer; }
button:hover:not(:disabled) { background: var(--hover); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
button.danger { color: var(--danger); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Top bar (browser only) */
.bar { display: flex; align-items: center; gap: 12px; padding: 4px 10px; background: var(--surface); border-bottom: 1px solid var(--line); }
body.app .bar { display: none; }
.brand { font-size: 13px; letter-spacing: 0.02em; }
.menubar { display: flex; gap: 2px; }
.menubar button { border-color: transparent; background: none; padding: 3px 9px; min-height: 26px; }
.menubar button[aria-expanded="true"] { background: var(--hover); }
.levelname { color: var(--muted); font-size: 12px; }
.spacer { flex: 1; }

/* Menus: the browser's menu bar dropdowns and its right-click menu */
.menu { position: fixed; z-index: 50; min-width: 190px; padding: 5px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.menu .mi { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: none; text-align: left; padding: 4px 8px; min-height: 26px; border-radius: 5px; }
.menu .mi:hover:not(:disabled), .menu .mi.open { background: var(--accent); color: var(--accent-fg); }
.menu .mi .tick { width: 12px; flex: none; }
.menu .mi .title { flex: 1; white-space: nowrap; }
.menu .mi .key { color: var(--muted); font-size: 12px; margin-left: 18px; }
.menu .mi:hover:not(:disabled) .key, .menu .mi.open .key { color: inherit; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 4px; }

/* Toolbox */
.work { flex: 1; display: flex; min-height: 0; }
.toolbox { width: 172px; flex: none; overflow-y: auto; padding: 8px; background: var(--surface); border-right: 1px solid var(--line); }
.toolbox[hidden] + .stage { border-left: 0; }
.toolrow { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-bottom: 4px; }
.toolrow button { padding: 4px 6px; }
.toolrow button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
.toolbox h2 { margin: 12px 2px 5px; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.tile { display: flex; align-items: center; gap: 8px; width: 100%; padding: 4px 6px; margin-bottom: 3px; text-align: left; cursor: grab; touch-action: none; }
.tile:active { cursor: grabbing; }
.swatch { width: 22px; height: 16px; flex: none; display: grid; place-items: center; }
.swatch i { display: block; }
.sw-box i { width: 20px; height: 8px; background: var(--solid); }
.sw-moving i { width: 20px; height: 8px; background: var(--moving); }
.sw-hazard i { width: 20px; height: 5px; background: var(--hazard); }
.sw-art i { width: 20px; height: 11px; border: 1.5px dashed var(--muted); }
.sw-start i { width: 6px; height: 15px; background: var(--fg); }
.sw-lore_pickup i { width: 10px; height: 13px; background: var(--lore); border-radius: 2px; }
.sw-pickup i { width: 10px; height: 10px; background: var(--pickup); transform: rotate(45deg); }
.sw-structure i { width: 16px; height: 13px; border: 1.5px dashed var(--fg); }
.sw-grapple i { width: 12px; height: 12px; border: 2px dashed var(--grapple); border-radius: 50%; }
.sw-generic i { width: 9px; height: 9px; background: var(--accent); border-radius: 50%; }
.sw-note i::before { content: "Aa"; font-size: 11px; color: var(--muted); }
.sw-enemy i { width: 15px; height: 12px; background: var(--enemy); border-radius: 3px; }
.sw-enemy.flyer i { clip-path: polygon(0 0, 35% 35%, 50% 0, 65% 35%, 100% 0, 72% 100%, 28% 100%); border-radius: 0; width: 20px; }
.sw-enemy.stationary i { clip-path: polygon(0 100%, 22% 0, 78% 0, 100% 100%); border-radius: 0; width: 18px; }
.sw-enemy.other i { border-radius: 6px; }
.chip { position: fixed; z-index: 60; pointer-events: none; padding: 3px 8px; border-radius: 5px; background: var(--fg); color: var(--bg); font-size: 12px; transform: translate(12px, 12px); }

.stage { flex: 1; min-width: 0; position: relative; overflow: hidden; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; touch-action: none; }

/* Inspector: the selected item's fields, floating next to it */
.inspector { position: absolute; z-index: 20; width: 236px; padding: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.inspector header { display: flex; align-items: center; margin-bottom: 8px; }
.inspector header strong { flex: 1; }
.inspector header button { border: 0; background: none; min-height: 0; padding: 0 4px; font-size: 16px; line-height: 1; color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; margin: 6px 2px; }
.fields { display: grid; grid-template-columns: 1fr 86px; gap: 6px 8px; align-items: center; }
.fields.wide { grid-template-columns: 62px 1fr; }
.fields input, .fields select { width: 100%; min-width: 0; }
.fields input[type="number"] { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 10px; }
.checks label, fieldset > label, .row label { display: flex; align-items: center; gap: 6px; }

.status { display: flex; gap: 18px; padding: 5px 10px; background: var(--surface); border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
#statusPos { font-family: var(--mono); min-width: 120px; }

dialog { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--fg); padding: 18px; width: min(430px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10, 14, 20, 0.45); }
dialog h2 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
fieldset { border: 0; padding: 0; margin: 0 0 14px; display: flex; flex-direction: column; gap: 6px; }
legend { padding: 0; margin-bottom: 6px; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.size { font-family: var(--mono); font-size: 12px; margin: 0 0 14px; min-height: 2.8em; }
.size.bad { color: var(--danger); }
.actions { display: flex; justify-content: flex-end; gap: 8px; }

.toast { position: fixed; z-index: 70; left: 50%; bottom: 44px; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 8px 14px; border-radius: 6px; max-width: min(520px, calc(100vw - 32px)); }

@media (max-width: 620px) {
  .toolbox { width: 132px; }
  .levelname { display: none; }
}
