* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

:root {
  --bg: #0d1117;
  --bg-soft: #111827;
  --surface: #171f2b;
  --surface-strong: #1f2a3a;
  --accent: #f4b63f;
  --accent-2: #2fc7b2;
  --text: #f8fafc;
  --muted: #94a3b8;
  --danger: #fb7185;
  --radius: 16px;
  --ring: 0 0 0 3px rgba(47, 199, 178, 0.25);
}

body {
  margin: 0;
  font-family: "Manrope", sans-serif;
  background: radial-gradient(circle at 20% 20%, rgba(47, 199, 178, 0.15), transparent 55%),
    radial-gradient(circle at 80% 10%, rgba(244, 182, 63, 0.15), transparent 50%),
    linear-gradient(130deg, #0b0f16 0%, #0f172a 50%, #0b0f16 100%);
  color: var(--text);
  min-height: 100vh;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 120px 120px;
  opacity: 0.35;
}

.app {
  max-width: 100%;
  margin: 0 auto;
  padding: 24px 24px 36px;
  position: relative;
  z-index: 1;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 22px;
  border-radius: var(--radius);
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(148, 163, 184, 0.2);
  margin-bottom: 16px;
}

.title {
  font-family: "Rubik Mono One", sans-serif;
  font-size: 26px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.subtitle {
  font-size: 14px;
  color: var(--muted);
}

.status {
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 12px;
}

.ws-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(15, 23, 42, 0.6);
}

.ws-toggle input {
  display: none;
}

.ws-slider {
  width: 34px;
  height: 18px;
  border-radius: 999px;
  position: relative;
  background: rgba(148, 163, 184, 0.3);
  transition: background 0.2s ease;
}

.ws-slider::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #0f172a;
  transition: transform 0.2s ease;
}

.ws-toggle input:checked + .ws-slider {
  background: linear-gradient(120deg, var(--accent-2), var(--accent));
}

.ws-toggle input:checked + .ws-slider::after {
  transform: translateX(16px);
}

.ws-label {
  font-weight: 600;
}

.message {
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(47, 199, 178, 0.12);
  border: 1px solid rgba(47, 199, 178, 0.4);
  margin-bottom: 14px;
}

.message.error {
  background: rgba(251, 113, 133, 0.15);
  border-color: rgba(251, 113, 133, 0.5);
}

.tabs {
  display: flex;
  gap: 10px;
  padding: 8px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.2);
  margin-bottom: 16px;
}

.tab {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s ease;
}

.tab.active {
  background: linear-gradient(120deg, rgba(47, 199, 178, 0.9), rgba(244, 182, 63, 0.9));
  color: #111827;
}

.view {
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border-radius: var(--radius);
  background: rgba(17, 24, 39, 0.8);
  border: 1px solid rgba(148, 163, 184, 0.18);
  margin-bottom: 14px;
}

.toolbar.bottom {
  margin-top: 16px;
}

.control {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.overlay-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.overlay-switch {
  background: rgba(148, 163, 184, 0.12);
  color: var(--text);
  border: 1px solid rgba(148, 163, 184, 0.2);
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 600;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.overlay-switch.active {
  background: linear-gradient(120deg, rgba(47, 199, 178, 0.9), rgba(244, 182, 63, 0.9));
  color: #111827;
  box-shadow: 0 8px 18px rgba(47, 199, 178, 0.18);
}

.overlay-switch:hover {
  transform: translateY(-1px);
}

input,
select,
button {
  font-family: inherit;
}

input,
select {
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(15, 23, 42, 0.7);
  color: var(--text);
  padding: 8px 10px;
  min-width: 180px;
}

input:focus,
select:focus,
button:focus {
  outline: none;
  box-shadow: var(--ring);
}

.file-input {
  min-width: 220px;
}

button {
  border-radius: 12px;
  border: none;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

button.primary {
  background: linear-gradient(120deg, var(--accent-2), var(--accent));
  color: #111827;
}

button.ghost {
  background: rgba(148, 163, 184, 0.12);
  color: var(--text);
  border: 1px solid rgba(148, 163, 184, 0.2);
}

button:hover {
  transform: translateY(-1px);
}

.hint {
  font-size: 13px;
  color: var(--muted);
}

.canvas-shell {
  border-radius: var(--radius);
  padding: 16px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.2);
  overflow: hidden;
  height: clamp(420px, 70vh, 900px);
}

.canvas-stage {
  position: relative;
  background: rgba(15, 23, 42, 0.6);
  border: 1px dashed rgba(148, 163, 184, 0.2);
  min-height: 420px;
  background-size: 100% 100%;
  background-repeat: no-repeat;
}

.field {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 4px 8px;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid rgba(47, 199, 178, 0.4);
  border-radius: 8px;
  color: #f8fafc;
  font-size: 20px;
  cursor: move;
  user-select: none;
}

.field.active {
  box-shadow: 0 0 0 2px rgba(244, 182, 63, 0.6);
}

.resize-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  right: -6px;
  bottom: -6px;
  border-radius: 4px;
  background: var(--accent-2);
  border: 2px solid #0f172a;
  cursor: se-resize;
}

.manage-grid {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 16px;
}

.driver-panel,
.overlay-panel {
  border-radius: var(--radius);
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.2);
  padding: 14px;
  min-width: 0;
}

.driver-panel {
  width: 240px;
}

.panel-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 10px;
}

.driver-form {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.driver-form input {
  flex: 1;
  min-width: 0;
}

.driver-list {
  display: grid;
  gap: 8px;
}

.driver-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid rgba(148, 163, 184, 0.2);
  cursor: grab;
}

.driver-item button {
  padding: 4px 8px;
  font-size: 12px;
  background: rgba(251, 113, 133, 0.2);
  color: #fca5a5;
}

.overlay-stage {
  position: relative;
  min-height: 420px;
  border-radius: 12px;
  overflow: hidden;
  background: rgba(15, 23, 42, 0.5);
  border: 1px dashed rgba(148, 163, 184, 0.25);
  transform-origin: top left;
}

.overlay-field {
  position: absolute;
  display: flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(12, 16, 22, 0.65);
  border: 1px dashed rgba(244, 182, 63, 0.6);
  color: #f8fafc;
  font-size: 20px;
  min-height: 24px;
}

.overlay-field.drop-target {
  box-shadow: 0 0 0 2px rgba(47, 199, 178, 0.6);
}

.overlay-meta {
  font-size: 13px;
  color: var(--muted);
}

.overlay-shell {
  position: relative;
  width: 100%;
  height: clamp(520px, 72vh, 980px);
  border-radius: 12px;
  overflow: hidden;
  background: rgba(15, 23, 42, 0.5);
  border: 1px dashed rgba(148, 163, 184, 0.25);
  padding: 0;
  min-width: 0;
}

.overlay-stage {
  position: relative;
  transform-origin: top left;
}

.context-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: fixed;
  z-index: 999;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.25);
}

.context-menu button {
  width: 100%;
  background: rgba(251, 113, 133, 0.18);
  color: #fecaca;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid rgba(251, 113, 133, 0.35);
  font-size: 13px;
  cursor: pointer;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(8, 11, 18, 0.65);
  display: grid;
  place-items: center;
  z-index: 1000;
}

.modal-card {
  background: rgba(15, 23, 42, 0.95);
  border-radius: 16px;
  padding: 20px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  width: min(420px, 90vw);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
}

.modal-card h3 {
  margin: 0 0 8px;
  font-size: 18px;
}

.modal-card p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 14px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.grow {
  flex: 1;
}

@media (max-width: 980px) {
  .manage-grid {
    grid-template-columns: 1fr;
  }
}
