:root {
  color-scheme: dark;

  --bg: #0d1117;
  --bg-soft: #111827;
  --panel: #161b22;
  --panel-2: #1f2937;
  --border: rgba(255, 255, 255, 0.11);
  --border-strong: rgba(255, 255, 255, 0.2);
  --text: #f3f4f6;
  --muted: #9ca3af;
  --muted-2: #6b7280;
  --accent: #22c55e;
  --accent-2: #16a34a;
  --danger: #ef4444;
  --danger-2: #dc2626;
  --warning: #f59e0b;
  --shadow: 0 12px 38px rgba(0, 0, 0, 0.34);

  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at top left, rgba(34, 197, 94, 0.12), transparent 32rem),
    radial-gradient(circle at top right, rgba(59, 130, 246, 0.1), transparent 30rem),
    var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: rgba(13, 17, 23, 0.82);
  backdrop-filter: blur(18px);
  z-index: 4;
}

.topbar h1 {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.2;
  letter-spacing: -0.03em;
}

.topbar p {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.main-layout {
  display: grid;
  grid-template-columns: 390px 1fr;
  min-height: 0;
  flex: 1;
}

.sidebar {
  min-height: 0;
  overflow: auto;
  padding: 1rem;
  border-right: 1px solid var(--border);
  background: rgba(13, 17, 23, 0.72);
}

.panel {
  padding: 1rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(22, 27, 34, 0.98), rgba(17, 24, 39, 0.96));
  box-shadow: var(--shadow);
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.9rem;
}

.panel h2 {
  margin: 0;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}

label {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}

input,
select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.6rem 0.7rem;
  background: rgba(255, 255, 255, 0.055);
  color: var(--text);
  outline: none;
}

input[type="file"] {
  padding: 0.45rem;
}

input[type="checkbox"] {
  width: auto;
}

input:focus,
select:focus {
  border-color: rgba(34, 197, 94, 0.76);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.13);
}

select option {
  background: #111827;
  color: var(--text);
}

.form-grid {
  display: grid;
  gap: 0.7rem;
}

.form-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.checks {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.35rem;
  margin: 0.25rem 0 0.85rem;
}

.checks label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0;
  color: var(--text);
  font-weight: 520;
}

.btn {
  appearance: none;
  border: 1px solid rgba(34, 197, 94, 0.5);
  border-radius: 12px;
  padding: 0.62rem 0.8rem;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: #04110a;
  font-weight: 800;
  box-shadow: 0 8px 22px rgba(34, 197, 94, 0.13);
}

.btn:hover {
  filter: brightness(1.06);
}

.btn:active {
  transform: translateY(1px);
}

.btn.secondary {
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  box-shadow: none;
}

.btn.danger {
  border-color: rgba(239, 68, 68, 0.5);
  background: linear-gradient(180deg, var(--danger), var(--danger-2));
  color: #fff;
}

.btn.full {
  width: 100%;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}

.file-label {
  display: inline-flex;
  align-items: center;
  margin: 0;
}

.canvas-area {
  position: relative;
  min-width: 0;
  min-height: 0;
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    #090d12;
  background-size: 32px 32px;
}

#plannerCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

#plannerCanvas.dragging {
  cursor: grabbing;
}

.hud {
  position: absolute;
  left: 1rem;
  bottom: 1rem;
  display: grid;
  gap: 0.3rem;
  max-width: min(720px, calc(100% - 2rem));
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(13, 17, 23, 0.78);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
  pointer-events: none;
}

#hudCoords {
  font-weight: 850;
  font-size: 0.86rem;
}

.hud-help {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.35;
}

.status {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  max-width: min(420px, calc(100% - 2rem));
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(13, 17, 23, 0.8);
  backdrop-filter: blur(16px);
  color: var(--muted);
  font-size: 0.8rem;
  pointer-events: none;
}

.status.ok {
  color: #86efac;
}

.status.warn {
  color: #fbbf24;
}

.status.error {
  color: #fca5a5;
}

.item-list {
  display: grid;
  gap: 0.6rem;
  margin-top: 0.85rem;
}

.item-list.empty {
  color: var(--muted-2);
  font-size: 0.82rem;
}

.item-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.72rem;
  background: rgba(255, 255, 255, 0.045);
}

.item-card.selected {
  border-color: rgba(34, 197, 94, 0.75);
  background: rgba(34, 197, 94, 0.1);
}

.item-card.locked {
  opacity: 0.72;
}

.item-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.item-title {
  font-weight: 850;
  font-size: 0.86rem;
  line-height: 1.25;
}

.item-meta {
  color: var(--muted);
  font-size: 0.72rem;
  margin-top: 0.18rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 0.18rem 0.45rem;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  white-space: nowrap;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.55rem;
}

.small-btn {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.42rem 0.52rem;
  background: rgba(255, 255, 255, 0.065);
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 750;
}

.small-btn:hover {
  border-color: var(--border-strong);
}

.small-btn.danger {
  border-color: rgba(239, 68, 68, 0.4);
  color: #fecaca;
}

.mini-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  margin-top: 0.45rem;
}

.mini-grid label {
  margin: 0;
  font-size: 0.68rem;
}

.mini-grid input {
  border-radius: 10px;
  padding: 0.42rem 0.5rem;
}

.switch-row {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 0.55rem;
}

.switch-row label {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  color: var(--text);
  font-weight: 600;
}

::-webkit-scrollbar {
  width: 12px;
}

::-webkit-scrollbar-thumb {
  border: 3px solid rgba(13, 17, 23, 0.95);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}

::-webkit-scrollbar-track {
  background: rgba(13, 17, 23, 0.95);
}

@media (max-width: 980px) {
  html,
  body {
    overflow: auto;
  }

  .app-shell {
    min-height: 100vh;
    height: auto;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .main-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .canvas-area {
    height: 68vh;
    min-height: 520px;
  }
}

@media (max-width: 560px) {
  .form-grid.two,
  .button-row,
  .mini-grid {
    grid-template-columns: 1fr;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions .btn,
  .topbar-actions .file-label {
    flex: 1;
    justify-content: center;
  }
}