:root {
  color-scheme: light;
  --ink: #1d2128;
  --muted: #5c6570;
  --paper: #e7e2d8;
  --card: #f7f5f0;
  --line: #d5d0c6;
  --accent: #0e6b56;
  --accent-ink: #f4fbf8;
  --danger-bg: #f8e4df;
  --danger-ink: #7d2218;
  --scene: #10141c;
  --selected: #ffb020;
  --route: #3ecf8e;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

body.is-phone .scene-screen { color-scheme: dark; }

button, textarea, select {
  font: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.library {
  max-width: 44rem;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

h1, h2 { font-weight: 650; }

h1 {
  margin: 0 0 8px;
  font-size: 2rem;
}

.lead {
  margin: 0 0 24px;
  color: var(--muted);
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 16px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 1.15rem;
}

.error {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--danger-bg);
  color: var(--danger-ink);
  white-space: pre-line;
}

.status {
  margin: 0;
  color: var(--muted);
}

.topology-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.topology-list button {
  width: 100%;
  text-align: left;
  display: grid;
  gap: 2px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: inherit;
  min-height: 44px;
}

.topology-list button:hover { border-color: var(--accent); }

.entry-warehouse { font-weight: 650; }

.entry-sector { color: var(--muted); }

label { display: block; margin-bottom: 8px; }

textarea {
  width: 100%;
  min-height: 16rem;
  resize: vertical;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: inherit;
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 16px;
  line-height: 1.4;
}

#paste-show,
.settings button,
.scene-bar button {
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  padding: 0 16px;
  background: var(--accent);
  color: var(--accent-ink);
}

#paste-show { margin-top: 12px; }

.scene-screen {
  position: fixed;
  inset: 0;
  background: var(--scene);
  color: #f4f6f8;
  color-scheme: dark;
  touch-action: none;
}

.viewport,
.labels {
  position: absolute;
  inset: 0;
}

.viewport canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

.viewport.is-hover canvas { cursor: pointer; }

.viewport.is-dragging canvas { cursor: grabbing; }

.labels {
  overflow: hidden;
  pointer-events: none;
}

.point-label {
  position: absolute;
  left: 0;
  top: 0;
  color: #f4f6f8;
  font-size: 13px;
  line-height: 1.2;
  white-space: nowrap;
  text-shadow: 0 1px 2px #000, 0 0 4px #000;
}

.point-label.is-selected { color: var(--selected); }

.scene-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: linear-gradient(#10141cf2, #10141c00);
  pointer-events: none;
}

.scene-bar button { pointer-events: auto; }

.scene-bar .icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  flex: 0 0 auto;
}

.icon-button svg {
  width: 22px;
  height: 22px;
  display: block;
}

.scene-bar :focus-visible { outline-color: var(--selected); }

.scene-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 450;
  line-height: 1.35;
}

.warehouse,
.sector {
  overflow-wrap: anywhere;
}

.sector { font-weight: 650; }

.details,
.settings {
  position: absolute;
  z-index: 2;
  width: min(22rem, calc(100% - 24px));
  background: var(--card);
  color: var(--ink);
  color-scheme: light;
  border-radius: 16px;
  box-shadow: 0 10px 30px #00000040;
}

.details {
  top: 72px;
  right: 12px;
  max-height: calc(100% - 96px);
  overflow: auto;
  padding: 0 16px 16px;
  touch-action: pan-y;
}

.details.is-dragging {
  user-select: none;
}

.details-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 -16px 4px;
  padding: 12px 10px 10px 16px;
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.details.is-dragging .details-head,
body.is-details-dragging,
body.is-details-dragging * {
  cursor: grabbing;
}

.details-head h2 {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 1.05rem;
}

.details-close {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.details-close:hover {
  background: var(--line);
  color: var(--ink);
}

.details-extra {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.details-extra h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
}

.details-note {
  margin: 10px 0 0;
  color: var(--muted);
}

.field {
  margin-top: 10px;
  overflow-wrap: anywhere;
}

.field-label { color: var(--muted); }

.route-action {
  position: sticky;
  bottom: 0;
  z-index: 1;
  margin: 14px -16px -16px;
  padding: 12px 16px 16px;
  background: var(--card);
  border-top: 1px solid var(--line);
}

.route-action button {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1rem;
  touch-action: manipulation;
}

.settings {
  top: 64px;
  right: 12px;
  z-index: 3;
  padding: 16px;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  min-height: 44px;
}

.setting {
  display: grid;
  gap: 6px;
  margin: 0 0 12px;
}

.setting select {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: inherit;
  font-size: 16px;
}

.settings button { width: 100%; }

.route-message {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  width: min(36rem, calc(100% - 24px));
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: #2a2116;
  color: #ffd7a1;
  text-align: center;
}

.zoom {
  position: absolute;
  z-index: 2;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.zoom button {
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 14px;
  background: #f4f6f8;
  color: var(--ink);
  font-size: 1.6rem;
  line-height: 1;
}

@media (max-width: 767px) {
  .route-message { bottom: 128px; }

  .details { max-height: calc(100% - 200px); }

  .library { padding-top: 20px; }
}

@media (min-width: 768px) {
  .zoom { display: none !important; }
}
