:root {
  --bg: #111318;
  --panel: #1b1f27;
  --panel-2: #242a35;
  --line: #363f4f;
  --line-strong: #4a5568;
  --text: #f1f3f7;
  --muted: #9aa4b2;
  --accent: #66d9ef;
  --accent-2: #3bb8d2;
  --walkable: rgba(82, 196, 126, 0.28);
  --walkable-line: #52c47e;
  --selected: #f4d35e;
  --transition: #f59e0b;
  --danger: #ff5d73;
  --shadow: rgba(0, 0, 0, 0.35);
  --radius: 8px;
  --topbar-height: 54px;
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea { font: inherit; }

button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }

.app-shell {
  display: grid;
  grid-template-rows: var(--topbar-height) minmax(0, 1fr);
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #1c222c 0%, #171b22 100%);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.brand-mark {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid var(--accent);
  border-radius: 7px;
  color: var(--accent);
  background: rgba(102, 217, 239, 0.08);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.button,
.tool-button {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--text);
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

.button:hover,
.tool-button:hover:not(:disabled) {
  border-color: var(--accent);
  background: #2a3240;
}

.button:active,
.tool-button:active:not(:disabled) { transform: translateY(1px); }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  text-decoration: none;
}

.button-primary {
  border-color: #2e9db4;
  background: #157f98;
}

.button-primary:hover { background: #1993af; }

.workbench {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) 310px;
  min-height: 0;
}

.tool-rail {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.tool-button {
  display: grid;
  gap: 4px;
  justify-items: center;
  min-height: 62px;
  padding: 8px 6px;
  color: var(--muted);
  font-size: 12px;
}

.tool-button.active {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(102, 217, 239, 0.12);
}

.tool-button.danger:hover:not(:disabled) { border-color: var(--danger); }

.tool-icon {
  color: var(--text);
  font-size: 20px;
  line-height: 1;
}

.tool-divider {
  height: 1px;
  margin: 4px 0;
  background: var(--line);
}

.canvas-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.025) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.025) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.025) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.025) 75%),
    #0b0d11;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

#mapCanvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

.canvas-status {
  position: absolute;
  left: 14px;
  bottom: 14px;
  max-width: min(520px, calc(100% - 28px));
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(17, 19, 24, 0.86);
  color: var(--muted);
  pointer-events: none;
  box-shadow: 0 12px 30px var(--shadow);
}

.inspector {
  min-width: 0;
  overflow: auto;
  border-left: 1px solid var(--line);
  background: var(--panel);
}

.panel-section {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-section h2 {
  margin: 0 0 14px;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.field-label {
  display: block;
  margin: 12px 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.text-input,
.text-area {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #111720;
  color: var(--text);
  outline: none;
}

.text-input { height: 36px; padding: 0 10px; }
.text-area { min-height: 84px; padding: 9px 10px; resize: vertical; }

.text-input:focus,
.text-area:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(102, 217, 239, 0.12);
}

.field-help,
.empty-state p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.meta-list {
  display: grid;
  gap: 10px;
  margin: 14px 0 0;
}

.meta-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.meta-list dt {
  color: var(--muted);
  font-size: 12px;
}

.meta-list dd {
  margin: 0;
  max-width: 180px;
  overflow: hidden;
  color: var(--text);
  font-size: 12px;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meta-list.compact { margin-top: 16px; }

.toast-root {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 20;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  background: rgba(27, 31, 39, 0.96);
  box-shadow: 0 14px 35px var(--shadow);
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
}

.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--walkable-line); }
.toast.warning { border-left-color: var(--transition); }

.modal-root:not(:empty) {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(4, 6, 10, 0.68);
}

.modal-card {
  width: min(460px, 100%);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
}

.modal-header,
.modal-body,
.modal-actions { padding: 16px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.modal-title {
  margin: 0;
  font-size: 16px;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
}

.modal-close:hover {
  border-color: var(--line-strong);
  color: var(--text);
}

.modal-body {
  color: var(--muted);
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--line);
}

.button-danger {
  border-color: #b9394d;
  background: #8e2938;
}

.button-danger:hover { background: #a93142; }

@media (max-width: 920px) {
  .workbench { grid-template-columns: 80px minmax(0, 1fr) 260px; }
  .tool-button { min-height: 58px; font-size: 11px; }
}
