*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green: #33ff33;
  --green-dim: #1f9e1f;
  --amber: #ffb000;
  --red: #ff4444;
  --blue: #66aaff;
  --dim: #aaaaaa;
  --muted: #666666;
  --border: #333333;
  --border-bright: #555555;
  --bg: #0d0d0d;
  --bg-raise: #141414;
  --font-mono: 'Courier New', Courier, monospace;
}

html, body { min-height: 100vh; }
body {
  font-family: var(--font-mono);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px;
  background: #c8c8c8;
  color: var(--dim);
}
@media (prefers-color-scheme: dark) {
  body { background: #1a1a1a; }
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ── terminal window ─────────────────────────────────────────────────────── */
.terminal {
  width: min(96vw, 1200px);
  min-height: min(90vh, 820px);
  display: flex;
  flex-direction: column;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}

.terminal-titlebar {
  background: #2d2d2d;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  user-select: none;
  position: relative;
}
.terminal-dots { display: flex; gap: 7px; position: relative; z-index: 1; }
.dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  transition: filter 0.15s;
}
.dot-red    { background: #ff5f57; }
.dot-yellow { background: #febc2e; }
.dot-green  { background: #28c840; }
.terminal-title {
  position: absolute; left: 0; right: 0;
  text-align: center;
  font-size: 12px;
  color: #888;
  pointer-events: none;
  font-family: var(--font-mono);
}

.terminal-body {
  background: var(--bg);
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* scanline overlay */
.terminal-body::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 3px,
    rgba(0,0,0,0.10) 3px,
    rgba(0,0,0,0.10) 4px
  );
  pointer-events: none;
  z-index: 9999;
}

/* ── app layout ──────────────────────────────────────────────────────────── */
#app {
  padding: 20px 24px;
  width: 100%;
  overflow: auto;
  color: var(--dim);
  font-size: 13px;
  position: relative;
  z-index: 1;
}

/* ── top bar ─────────────────────────────────────────────────────────────── */
.top-bar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--border);
}

.mode-tog, .unit-tog, .io-ctrl, .zoom-ctrl {
  display: flex; align-items: center;
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
  background: var(--bg);
}

.mode-tog button, .unit-tog button, .ztog {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 5px 12px;
  border: none;
  background: transparent;
  color: var(--dim);
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.2;
  transition: background 0.12s, color 0.12s;
}
.mode-tog button:hover, .unit-tog button:hover, .ztog:hover {
  background: #1a1a1a;
  color: var(--green);
}
.mode-tog button.active, .unit-tog button.active {
  background: var(--green);
  color: #000;
  font-weight: bold;
}

.sep {
  width: 1px; height: 20px;
  background: var(--border);
  flex-shrink: 0;
}

.rdims {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--amber);
}

#zoom-pct {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--dim);
  min-width: 42px;
  text-align: center;
  user-select: none;
}

/* ── canvas ──────────────────────────────────────────────────────────────── */
.canvas-wrap {
  border: 1px solid var(--border);
  background: var(--bg);
  overflow: auto;
  max-height: calc(100vh - 320px);
  position: relative;
}
#canvas { display: block; max-width: 100%; cursor: default; }

/* ── info bar ────────────────────────────────────────────────────────────── */
.info-bar {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--dim);
  margin-top: 8px;
  min-height: 22px;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.info-bar input[type="number"] {
  font-family: var(--font-mono);
  background: var(--bg);
  color: var(--green);
  border: 1px solid var(--border-bright);
  padding: 3px 6px;
  border-radius: 2px;
  outline: none;
}
.info-bar input[type="number"]:focus { border-color: var(--green); }
.info-bar .lbl { color: var(--green); font-weight: bold; }
.info-bar .dim { color: var(--dim); }
.info-bar .muted { color: var(--muted); }

.hint {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  min-height: 16px;
}

.warn { color: var(--red); }

/* ── furniture panel ─────────────────────────────────────────────────────── */
.fur-panel { margin-top: 14px; }

.custom-form {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: #0a0a0a;
  border: 1px solid var(--border);
  border-radius: 3px;
}
.custom-form .prompt {
  font-family: var(--font-mono);
  color: var(--green);
  font-size: 12px;
}
.custom-form .mul {
  font-family: var(--font-mono);
  color: var(--muted);
  font-size: 12px;
}
.custom-form input[type=text],
.custom-form input[type=number] {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 4px 8px;
  background: var(--bg);
  border: 1px solid var(--border-bright);
  border-radius: 2px;
  color: var(--green);
  outline: none;
}
.custom-form input[type=text]:focus,
.custom-form input[type=number]:focus { border-color: var(--green); }
.custom-form input[type=text] { width: 110px; }
.custom-form input[type=number] { width: 62px; }

.plab {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

.add-panel { display: flex; flex-direction: column; gap: 0; }

.fur-group-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--amber);
  text-transform: lowercase;
  margin-top: 12px;
  margin-bottom: 6px;
}
.fur-group-label::before { content: '>> '; color: var(--muted); }

.fur-group-items { display: flex; flex-wrap: wrap; gap: 6px; }

/* ── buttons (bracketed TUI style) ───────────────────────────────────────── */
.abtn {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 4px 10px;
  border: 1px solid var(--border-bright);
  border-radius: 2px;
  background: var(--bg);
  color: var(--dim);
  cursor: pointer;
  line-height: 1.2;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.abtn:hover {
  border-color: var(--green);
  color: var(--green);
  background: #0a0a0a;
}
.abtn:not(select)::before { content: '[ '; color: var(--muted); }
.abtn:not(select)::after { content: ' ]'; color: var(--muted); }
.abtn:not(select):hover::before,
.abtn:not(select):hover::after { color: var(--green); }

select.abtn {
  appearance: auto;
  background-color: var(--bg);
  color: var(--green);
}
select.abtn option { background: var(--bg); color: var(--green); }

.abtn.cust {
  border-color: var(--amber);
  color: var(--amber);
}
.abtn.cust:hover { background: rgba(255,176,0,0.1); border-color: var(--amber); color: var(--amber); }
.abtn.cust::before, .abtn.cust::after { color: var(--amber); }

.act-btn {
  font-family: var(--font-mono);
  font-size: 12px; padding: 3px 8px;
  border: 1px solid var(--border-bright);
  border-radius: 2px;
  color: var(--dim);
  background: transparent;
  cursor: pointer;
}
.act-btn::before { content: '[ '; color: var(--muted); }
.act-btn::after { content: ' ]'; color: var(--muted); }
.act-btn:hover { border-color: var(--green); color: var(--green); }

.del-btn {
  font-family: var(--font-mono);
  font-size: 12px; padding: 3px 8px;
  border: 1px solid var(--border-bright);
  border-radius: 2px;
  color: var(--red);
  background: transparent;
  cursor: pointer;
}
.del-btn::before { content: '[ '; color: var(--muted); }
.del-btn::after { content: ' ]'; color: var(--muted); }
.del-btn:hover { border-color: var(--red); background: rgba(255,68,68,0.08); }

/* ── walls tip ───────────────────────────────────────────────────────────── */
.walls-tip {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--dim);
  padding: 10px 14px;
  background: #0a0a0a;
  border: 1px solid var(--amber);
  border-radius: 3px;
  margin-top: 10px;
  line-height: 1.7;
}
.walls-tip strong { color: var(--green); font-weight: normal; }
.walls-tip em { color: var(--amber); font-style: normal; }
.tip-tag { color: var(--amber); margin-right: 6px; }

/* reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
