:root {
  color-scheme: dark;
  --bg: #050b12;
  --surface: #0a1622;
  --surface-2: #0f2030;
  --surface-3: #152c3f;
  --border: rgba(132, 196, 225, 0.2);
  --text: #f4f8fb;
  --muted: #91a8b9;
  --cyan: #20d5e8;
  --cyan-soft: rgba(32, 213, 232, 0.14);
  --gold: #f7c84b;
  --purple: #b783ff;
  --green: #51df91;
  --red: #ff6f79;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.38);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% -20%, rgba(28, 159, 194, 0.22), transparent 42%),
    linear-gradient(145deg, #050b12, #07131f 55%, #090a14);
  color: var(--text);
}

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

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

.topbar {
  min-height: 76px;
  padding: 12px 18px;
  display: grid;
  grid-template-columns: minmax(260px, auto) minmax(220px, 420px) 1fr;
  gap: 18px;
  align-items: center;
  background: rgba(5, 13, 22, 0.94);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(18px);
  position: relative;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand img { filter: drop-shadow(0 0 18px rgba(32, 213, 232, 0.34)); }
.brand h1, .panel h2, .details-panel h2, .dialog-card h2 { margin: 0; }
.brand h1 { font-size: clamp(1.15rem, 2vw, 1.45rem); letter-spacing: 0.02em; }
.eyebrow { margin: 0 0 3px; color: var(--cyan); font-size: 0.68rem; font-weight: 800; letter-spacing: 0.14em; }

.map-picker { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 10px; color: var(--muted); font-size: 0.82rem; }
.map-picker select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 36px 10px 12px;
  background: var(--surface-2);
  color: var(--text);
}

.topbar-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
.status-badge, .ready-pill, .state-pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(81, 223, 145, 0.32);
  border-radius: 999px;
  padding: 6px 9px;
  background: rgba(81, 223, 145, 0.1);
  color: #91f5bd;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.05em;
}

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

.sidebar {
  min-height: 0;
  padding: 14px;
  overflow: auto;
  background: rgba(7, 18, 29, 0.96);
  border-right: 1px solid var(--border);
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
  z-index: 15;
}

.panel {
  margin-bottom: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: linear-gradient(145deg, rgba(15, 32, 48, 0.92), rgba(8, 20, 31, 0.92));
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.14);
}

.panel h2 { font-size: 0.95rem; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.panel-heading.compact { align-items: center; }
.muted, .hint { color: var(--muted); }
.muted { margin: 9px 0 0; line-height: 1.45; }
.hint { margin: 10px 0 0; font-size: 0.76rem; line-height: 1.4; }
.ready-pill { color: var(--cyan); border-color: rgba(32, 213, 232, 0.3); background: var(--cyan-soft); }

.progress-track { height: 7px; margin: 12px 0; overflow: hidden; border-radius: 999px; background: #06101a; }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--cyan), var(--green)); transition: width 180ms ease; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat-grid div { padding: 9px; border-radius: 10px; background: rgba(3, 11, 18, 0.5); }
.stat-grid span { display: block; color: var(--muted); font-size: 0.7rem; }
.stat-grid strong { display: block; margin-top: 3px; font-size: 1rem; }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-top: 11px; padding: 4px; border-radius: 11px; background: #06101a; }
.segmented button, .filter-list button {
  border: 0;
  border-radius: 8px;
  padding: 8px 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.segmented button.active { background: var(--cyan-soft); color: var(--cyan); }
.filter-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
.filter-list button { text-align: left; border: 1px solid transparent; background: rgba(2, 10, 17, 0.45); }
.filter-list button.active { color: var(--text); border-color: rgba(32, 213, 232, 0.45); background: var(--cyan-soft); }

.button {
  min-height: 38px;
  border: 1px solid rgba(32, 213, 232, 0.38);
  border-radius: 9px;
  padding: 8px 12px;
  background: linear-gradient(145deg, #157f98, #0b6077);
  color: white;
  font-weight: 750;
  cursor: pointer;
}
.button:hover { filter: brightness(1.12); }
.button:focus-visible, .segmented button:focus-visible, .filter-list button:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.button.secondary, .button.ghost { background: rgba(18, 42, 59, 0.85); border-color: var(--border); }
.button.danger-ghost { background: transparent; border-color: rgba(255, 111, 121, 0.4); color: #ff9ca4; }
.button.icon-button { width: 40px; padding: 6px; font-size: 1.2rem; }
.button-stack { display: grid; gap: 7px; margin-top: 10px; }

.map-catalog { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 7px; }
.map-catalog li { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 9px 10px; border-radius: 9px; background: rgba(3, 11, 18, 0.48); }
.map-catalog strong { font-size: 0.78rem; }
.map-catalog span { color: var(--muted); font-size: 0.66rem; }
.map-catalog .catalog-ready { color: var(--green); }

.map-stage { min-width: 0; min-height: 0; position: relative; background: #040a11; }
.canvas-wrap { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
#maze-canvas { display: block; width: 100%; height: 100%; cursor: grab; }
#maze-canvas.dragging { cursor: grabbing; }

.map-toolbar { position: absolute; z-index: 9; top: 14px; left: 14px; display: flex; gap: 6px; }
.toolbar-label { min-height: 40px; background: rgba(8, 24, 36, 0.9); border-color: var(--border); backdrop-filter: blur(12px); }

.details-panel {
  position: absolute;
  z-index: 8;
  top: 14px;
  right: 14px;
  width: min(330px, calc(100% - 28px));
  max-height: calc(100% - 190px);
  overflow: auto;
  padding: 15px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(7, 20, 31, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  transition: transform 160ms ease, opacity 160ms ease;
}
.details-panel.hidden { transform: translateX(calc(100% + 30px)); opacity: 0; pointer-events: none; }
.details-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.details-heading h2 { font-size: 1.05rem; }
.state-pill { color: var(--muted); border-color: var(--border); background: rgba(145, 168, 185, 0.08); }
.state-pill.planned { color: var(--gold); border-color: rgba(247, 200, 75, 0.38); background: rgba(247, 200, 75, 0.1); }
.state-pill.completed { color: var(--green); border-color: rgba(81, 223, 145, 0.38); background: rgba(81, 223, 145, 0.1); }
.details-list { display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; margin: 14px 0; font-size: 0.79rem; }
.details-list dt { color: var(--muted); }
.details-list dd { margin: 0; text-align: right; }
.object-list { display: grid; gap: 6px; }
.object-chip { display: flex; justify-content: space-between; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 9px; background: rgba(15, 40, 56, 0.62); font-size: 0.78rem; }
.object-chip span:last-child { color: var(--cyan); }

.minimap-card { position: absolute; z-index: 7; right: 14px; bottom: 34px; width: 230px; padding: 8px; border: 1px solid var(--border); border-radius: 12px; background: rgba(7, 20, 31, 0.91); box-shadow: var(--shadow); }
.minimap-card > span { display: block; margin: 0 0 5px 4px; color: var(--muted); font-size: 0.63rem; font-weight: 800; letter-spacing: 0.11em; }
#minimap { display: block; width: 100%; height: 150px; border-radius: 7px; background: #03090f; cursor: crosshair; }
.legend { position: absolute; z-index: 7; left: 14px; bottom: 14px; display: flex; gap: 12px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 9px; background: rgba(7, 20, 31, 0.85); color: var(--muted); font-size: 0.72rem; }
.dot { display: inline-block; width: 9px; height: 9px; margin-right: 4px; border-radius: 50%; }
.dot.planned { background: var(--gold); }
.dot.completed { background: var(--green); }

.empty-state { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; padding: 30px; background: radial-gradient(circle, rgba(32, 213, 232, 0.08), transparent 50%); }
.empty-state[hidden] { display: none; }
.empty-state span { font-size: 3rem; }
.empty-state h2 { margin: 12px 0 4px; }
.empty-state p { color: var(--muted); }

.footer { min-height: 28px; padding: 6px 14px; display: flex; justify-content: space-between; gap: 20px; border-top: 1px solid var(--border); background: #050d16; color: var(--muted); font-size: 0.7rem; }

.editor-dialog { width: min(760px, calc(100% - 28px)); max-height: calc(100% - 28px); padding: 0; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.editor-dialog::backdrop { background: rgba(0, 5, 10, 0.78); backdrop-filter: blur(4px); }
.dialog-card { padding: 18px; }
.dialog-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; }
.editor-field { display: grid; gap: 7px; margin-top: 16px; color: var(--muted); font-size: 0.8rem; }
.editor-field textarea { width: 100%; resize: vertical; border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: #030a11; color: #bfefff; font-family: "Cascadia Code", Consolas, monospace; font-size: 0.78rem; line-height: 1.5; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.editor-message { min-height: 1.2em; margin: 8px 0 0; color: var(--gold); font-size: 0.78rem; }

#sidebar-toggle { display: none; }

@media (max-width: 900px) {
  .topbar { grid-template-columns: 1fr auto; min-height: 68px; }
  .map-picker { grid-column: 1 / -1; grid-row: 2; }
  .status-badge { display: none; }
  #sidebar-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .workspace { grid-template-columns: 1fr; }
  .sidebar { position: absolute; top: 0; bottom: 0; left: 0; width: min(340px, 88vw); transform: translateX(-105%); transition: transform 180ms ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .details-panel { top: auto; right: 10px; bottom: 10px; width: calc(100% - 20px); max-height: 42%; }
  .details-panel.hidden { transform: translateY(calc(100% + 20px)); }
  .minimap-card { top: 10px; right: 10px; bottom: auto; width: 150px; }
  #minimap { height: 95px; }
  .map-toolbar { top: 10px; left: 10px; }
  .map-toolbar #close-details { display: none; }
  .legend { display: none; }
  .footer span:last-child { display: none; }
}

@media (max-width: 520px) {
  .topbar { padding: 10px; gap: 10px; }
  .brand img { width: 36px; height: 36px; }
  .brand .eyebrow { display: none; }
  .brand h1 { font-size: 1rem; }
  .topbar-actions .ghost { display: none; }
  .map-picker { gap: 7px; }
  .map-picker span { display: none; }
  .footer { padding-inline: 10px; }
  .minimap-card { width: 125px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
