:root {
  --bg:       #0a0a0a;
  --bg-2:     #121110;
  --fg:       #f5f1ea;
  --muted:    #8a857e;
  --muted-2:  #5a5651;
  --line:     #1f1d1b;
  --line-2:   #2a2724;
  --accent:   #c8a97e;
  --danger:   #d07070;

  --serif: 'Fraunces', Georgia, serif;
  --mono:  'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;

  --rail-w: 84px;
  --header-h: 48px;
  --footer-h: 28px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

body {
  display: grid;
  grid-template-rows: var(--header-h) 1fr var(--footer-h);
  grid-template-columns: var(--rail-w) 1fr;
  grid-template-areas:
    "header header"
    "rail   canvas"
    "footer footer";
  height: 100vh;
}

/* ---------- header ---------- */
header {
  grid-area: header;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  z-index: 2;
}

.brand {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 400;
  letter-spacing: -0.01em;
  font-variation-settings: "opsz" 144;
}
.brand em { font-style: italic; color: var(--accent); font-weight: 300; }

.doc-name {
  font-family: var(--serif);
  font-style: italic;
  color: var(--muted);
  font-size: 14px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-group {
  gap: 4px;
  color: var(--muted);
}

.chip {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line-2);
  padding: 5px 10px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 3px;
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}
.chip:hover { color: var(--fg); border-color: var(--muted); background: var(--bg-2); }
.chip-sep { width: 1px; height: 18px; background: var(--line-2); margin: 0 4px; }

.header-spacer { flex: 1; }

.header-group {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-transform: uppercase;
}

.header-group label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.header-group select {
  background: var(--bg-2);
  color: var(--fg);
  border: 1px solid var(--line-2);
  padding: 5px 8px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  outline: none;
}
.header-group select:focus { border-color: var(--accent); }

.toggle {
  appearance: none;
  width: 28px;
  height: 16px;
  background: var(--line-2);
  border-radius: 9999px;
  position: relative;
  cursor: pointer;
  transition: background 150ms ease;
}
.toggle::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 12px; height: 12px;
  background: var(--muted);
  border-radius: 50%;
  transition: transform 150ms ease, background 150ms ease;
}
.toggle:checked { background: rgba(200, 169, 126, 0.35); }
.toggle:checked::after { transform: translateX(12px); background: var(--accent); }

/* ---------- tool rail ---------- */
#tool-rail {
  grid-area: rail;
  border-right: 1px solid var(--line);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 10px 8px;
  gap: 2px;
  z-index: 2;
  overflow-y: auto;
}

#tool-rail button {
  position: relative;
  width: 100%;
  padding: 8px 6px 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--muted);
  font-family: var(--mono);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: color 120ms ease, border-color 120ms ease, background 120ms ease;
}

#tool-rail svg {
  width: 22px;
  height: 22px;
  color: inherit;
}

#tool-rail .label {
  font-size: 10px;
  letter-spacing: 0.06em;
}

#tool-rail .kbd {
  font-size: 9px;
  padding: 0 4px;
  border: 1px solid var(--line-2);
  border-radius: 2px;
  color: var(--muted-2);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
#tool-rail .kbd.soon {
  border-color: transparent;
  color: var(--muted-2);
  font-style: italic;
  text-transform: lowercase;
}

#tool-rail button:hover:not(:disabled) {
  color: var(--fg);
  border-color: var(--line-2);
  background: var(--bg-2);
}
#tool-rail button:hover:not(:disabled) .kbd {
  color: var(--muted);
  border-color: var(--muted-2);
}
#tool-rail button.is-active {
  color: var(--accent);
  border-color: rgba(200, 169, 126, 0.4);
  background: rgba(200, 169, 126, 0.08);
}
#tool-rail button.is-active .kbd {
  color: var(--accent);
  border-color: rgba(200, 169, 126, 0.4);
}
#tool-rail button:disabled {
  color: var(--muted-2);
  cursor: not-allowed;
  opacity: 0.7;
}
#tool-rail .sep {
  height: 1px;
  background: var(--line);
  margin: 6px 10px;
}

/* ---------- canvas ---------- */
#canvas-host {
  grid-area: canvas;
  position: relative;
  background: var(--bg);
  overflow: hidden;
  cursor: default;
}

/* ---------- footer / status ---------- */
footer {
  grid-area: footer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-top: 1px solid var(--line);
  background: var(--bg);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--muted);
  z-index: 2;
}

footer .readout { color: var(--fg); }
footer .dim { color: var(--muted-2); }

/* ---------- util ---------- */
.kbd {
  font-family: var(--mono);
  font-size: 10px;
  padding: 1px 5px;
  border: 1px solid var(--line-2);
  border-radius: 3px;
  color: var(--muted);
}

/* ---------- toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 48px;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  padding: 8px 16px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg);
  border-radius: 3px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 20;
}
#toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
