:root {
  --bg: #ecebe4;
  --paper: #f8f7f0;
  --ink: #141414;
  --panel: #1d1f22;
  --panel-2: #2b2e33;
  --panel-3: #363a40;
  --text: #f4f4f4;
  --muted: #aeb4bd;
  --line: #111111;
  --guide: #4f6f92;
  --accent: #e5bd45;
  --accent-2: #56a3a6;
  --danger: #d85b61;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  color: var(--ink);
  background: var(--bg);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: 100dvw;
  height: 100dvh;
  min-height: 100vh;
}

.topbar,
.statusbar,
.left-rail,
.side-panel {
  background: var(--panel);
  color: var(--text);
  user-select: none;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: calc(6px + var(--safe-top)) 8px 6px;
  border-bottom: 1px solid #050505;
  overflow-x: auto;
  scrollbar-width: none;
}

.topbar::-webkit-scrollbar {
  display: none;
}

.brand {
  flex: 0 0 auto;
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 0;
  padding: 0 6px;
}

.tool-group,
.button-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.topbar-fill {
  flex: 1 1 auto;
}

.tool-button,
.icon-button,
.file-button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  min-width: 38px;
  padding: 6px 10px;
  border: 1px solid #484d55;
  border-radius: 0;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  line-height: 1;
  white-space: nowrap;
}

.tool-button:hover,
.icon-button:hover,
.file-button:hover {
  border-color: var(--accent);
}

.tool-button.active,
.icon-button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #111;
  font-weight: 750;
}

.tool-button.danger:hover {
  border-color: var(--danger);
  color: #ffd6d8;
}

.file-button {
  font-size: 13px;
}

input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.workspace {
  display: grid;
  grid-template-columns: 48px 1fr 236px;
  min-height: 0;
}

.left-rail {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 5px;
  padding: 6px;
  border-right: 1px solid #050505;
}

.icon-button {
  width: 36px;
  height: 36px;
  padding: 0;
}

.canvas-stage {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(rgba(20,20,20,.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(20,20,20,.05) 1px, transparent 1px),
    var(--bg);
  background-size: 32px 32px;
}

svg {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.side-panel {
  min-width: 0;
  border-left: 1px solid #050505;
  overflow-y: auto;
}

.panel-section {
  padding: 10px;
  border-bottom: 1px solid #343941;
}

.panel-section h2 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.field-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.text-input {
  width: 100%;
  min-height: 32px;
  border: 1px solid #555b64;
  border-radius: 0;
  padding: 5px 7px;
  background: #111316;
  color: var(--text);
}

.status-grid {
  display: grid;
  grid-template-columns: 78px 1fr;
  gap: 5px 8px;
  margin: 0;
  font-size: 12px;
}

.status-grid dt {
  color: var(--muted);
}

.status-grid dd {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.statusbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 10px calc(6px + var(--safe-bottom));
  border-top: 1px solid #050505;
  color: var(--muted);
  font-size: 12px;
}

.artboard {
  fill: var(--paper);
  stroke: rgba(20, 20, 20, .24);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.grid-line {
  stroke: rgba(20, 20, 20, .08);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.horizon {
  stroke: var(--guide);
  stroke-width: 1.5;
  stroke-dasharray: 9 7;
  vector-effect: non-scaling-stroke;
}

.fan-ray,
.hint-ray {
  stroke: var(--guide);
  stroke-width: 1;
  stroke-dasharray: 5 7;
  opacity: .55;
  pointer-events: none;
  vector-effect: non-scaling-stroke;
}

.hint-ray.active {
  stroke: var(--accent-2);
  opacity: .9;
}

.drawn-line,
.preview-line {
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.preview-line {
  stroke: #111;
  stroke-width: 2;
  opacity: .55;
  pointer-events: none;
}

.vp-handle {
  fill: var(--accent);
  stroke: #111;
  stroke-width: 2;
  cursor: grab;
  vector-effect: non-scaling-stroke;
}

.vp-left {
  fill: var(--accent-2);
}

.vp-hit {
  fill: transparent;
  cursor: grab;
  pointer-events: all;
}

.vp-label {
  fill: #111;
  stroke: var(--paper);
  stroke-width: 4px;
  paint-order: stroke;
  font-size: 12px;
  font-weight: 800;
  pointer-events: none;
  vector-effect: non-scaling-stroke;
}

.start-dot {
  fill: #111;
  opacity: .78;
  pointer-events: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 44px 16px;
  background: rgba(0, 0, 0, .42);
  z-index: 50;
}

.modal {
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: min(520px, 100%);
  max-height: 100%;
  background: #f7f7f3;
  color: #141414;
  border: 1px solid #1d1d1d;
  box-shadow: 0 16px 42px rgba(0, 0, 0, .32);
}

.modal-header,
.modal-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  background: #202328;
  color: var(--text);
}

.modal-header {
  justify-content: space-between;
}

.modal-header h2 {
  margin: 0;
  font-size: 15px;
}

.modal-close {
  width: 34px;
  height: 34px;
  min-width: 34px;
  padding: 0;
  font-size: 22px;
}

.modal-body {
  overflow-y: auto;
  padding: 14px;
  line-height: 1.45;
}

.modal-footer {
  justify-content: flex-end;
}

.toast-root {
  position: fixed;
  right: 12px;
  bottom: 32px;
  display: grid;
  gap: 8px;
  z-index: 70;
  pointer-events: none;
}

.toast {
  max-width: 320px;
  padding: 9px 11px;
  border: 1px solid #111;
  background: #202328;
  color: var(--text);
  box-shadow: 0 8px 22px rgba(0, 0, 0, .22);
  font-size: 13px;
}

@media (max-width: 860px) {
  .workspace {
    grid-template-columns: 44px 1fr;
  }

  .side-panel {
    display: none;
  }

  .tool-button,
  .file-button {
    min-height: 34px;
    padding-inline: 8px;
    font-size: 13px;
  }

  .statusbar {
    font-size: 11px;
  }
}
