:root {
  --bg: #0c0e12;
  --surface: #141820;
  --surface2: #1c2230;
  --border: #2a3344;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --accent: #5b8cff;
  --accent-dim: #3d5fa8;
  --ok: #3ecf8e;
  --warn: #f0b429;
  --danger: #f07178;
  --radius: 12px;
  --sidebar: 240px;
  font-family: "DM Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.loading .splash {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}
.brand span { color: var(--accent); }

.scope-toggle {
  display: flex;
  gap: 0.35rem;
  background: var(--bg);
  padding: 0.25rem;
  border-radius: var(--radius);
}
.scope-toggle button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0.45rem 0.5rem;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: 0.8rem;
}
.scope-toggle button.active {
  background: var(--surface2);
  color: var(--text);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.nav button {
  text-align: left;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}
.nav button.active {
  background: var(--accent-dim);
  color: var(--text);
}

.sidebar-foot {
  margin-top: auto;
  font-size: 0.75rem;
  color: var(--muted);
}
.sidebar-foot button {
  width: 100%;
  margin-top: 0.5rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: 0.5rem;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}

.main {
  padding: 1.5rem 2rem 2rem;
  overflow: auto;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.panel-head h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
}
.stats {
  color: var(--muted);
  font-size: 0.85rem;
}

.grid {
  display: grid;
  gap: 0.75rem;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  cursor: pointer;
  transition: border-color 0.15s;
}
.card:hover { border-color: var(--accent-dim); }
.card h3 {
  margin: 0 0 0.25rem;
  font-size: 0.95rem;
  font-weight: 600;
}
.card p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}
.badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: var(--surface2);
  color: var(--ok);
  margin-left: 0.35rem;
}
.badge.muted { color: var(--muted); }

.editor {
  max-width: 720px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.editor label {
  font-size: 0.8rem;
  color: var(--muted);
}
.editor textarea,
.editor input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.75rem;
  font: inherit;
  font-size: 0.9rem;
}
.editor textarea { min-height: 200px; resize: vertical; font-family: ui-monospace, monospace; font-size: 0.82rem; }

.hub-editor { max-width: 880px; display: flex; flex-direction: column; gap: 1.25rem; }
.hub-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.hub-section h2 { margin: 0 0 0.85rem; font-size: 1rem; }
.hub-banner-wrap { margin-bottom: 0.75rem; }
.hub-banner-img {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--bg);
}
.hub-banner-empty {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  background: var(--bg);
  border-radius: 8px;
  font-size: 0.85rem;
}
.hub-block {
  border-top: 1px solid var(--border);
  padding-top: 0.85rem;
  margin-top: 0.85rem;
}
.hub-block:first-of-type { border-top: none; padding-top: 0; margin-top: 0; }
.hub-textarea {
  width: 100%;
  min-height: 120px;
  margin: 0.5rem 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.65rem;
  font: inherit;
  font-size: 0.82rem;
  font-family: ui-monospace, monospace;
}
.hub-btn-row {
  display: grid;
  grid-template-columns: 1fr 1.2fr 9.5rem auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.5rem 0;
  border-top: 1px solid var(--border);
}
.hub-btn-row:first-of-type { border-top: none; }
.hub-btn-meta code { display: block; font-size: 0.72rem; color: var(--muted); }
.hub-btn-input {
  width: 100%;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.hub-btn-style {
  width: 100%;
  padding: 0.45rem 0.4rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.78rem;
}
.hub-meta { font-size: 0.78rem; color: var(--muted); margin: 0.35rem 0 0; }
.hub-card { cursor: pointer; }
.search-input {
  width: min(100%, 320px);
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.login-simple h1 .accent { color: var(--accent); }
.login-simple .pin-form input { width: 100%; margin-bottom: 0; }
.login-simple .btn-primary { width: 100%; margin-top: 0.75rem; }

@media (max-width: 720px) {
  .hub-btn-row { grid-template-columns: 1fr; }
}
.preview-box {
  background: var(--surface2);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 0.85rem;
  font-size: 0.88rem;
  line-height: 1.45;
}
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.actions button {
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font: inherit;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }

.login-wrap {
  max-width: 420px;
  margin: 4rem auto;
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
}
.login-wrap h1 { margin: 0 0 0.5rem; font-size: 1.25rem; }
.login-wrap p { color: var(--muted); font-size: 0.9rem; }
.login-hint {
  font-size: 0.82rem !important;
  line-height: 1.45;
  margin-top: 0.75rem;
}
.login-hint code {
  background: var(--bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}
.domain-steps {
  text-align: left;
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 1rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.domain-steps ol {
  margin: 0.5rem 0 0;
  padding-left: 1.2rem;
}
.manual-login {
  margin-top: 1rem;
  text-align: left;
  font-size: 0.85rem;
  color: var(--muted);
}
.manual-login summary {
  cursor: pointer;
  color: var(--accent);
}
.pin-form { margin-top: 1.25rem; text-align: left; }
.pin-form input {
  width: 100%;
  padding: 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  letter-spacing: 0.2em;
}
.msg {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--danger);
}
.toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 0.65rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.toast.show { opacity: 1; }

.banner-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}
.banner-card img {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  border-radius: 8px;
  background: var(--bg);
}
.banner-card .placeholder {
  aspect-ratio: 16/9;
  background: var(--bg);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.8rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.filter-tabs {
  display: flex;
  gap: 0.35rem;
  background: var(--surface);
  padding: 0.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.filter-tabs button {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0.4rem 0.65rem;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: 0.8rem;
}

.filter-tabs button.active {
  background: var(--surface2);
  color: var(--text);
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.65rem;
}

.btn-sm {
  padding: 0.35rem 0.65rem !important;
  font-size: 0.78rem !important;
}

.upload-label {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}

.card .card-actions button,
.card .card-actions label {
  position: relative;
  z-index: 2;
}

.layout-constructor .main {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.constructor-page {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 0px);
  min-height: 480px;
}

.constructor-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.constructor-toolbar h1 {
  margin: 0;
  font-size: 1.1rem;
}

.constructor-toolbar .muted {
  margin: 0;
  font-size: 0.78rem;
  flex: 1;
  min-width: 180px;
}

.constructor-zoom {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.constructor-stage-wrap {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

.constructor-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  background:
    radial-gradient(circle at 1px 1px, #2a3344 1px, transparent 0) 0 0 / 24px 24px,
    #0a0c10;
}

.constructor-viewport.is-panning {
  cursor: grabbing;
}

.constructor-world {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  min-width: 1400px;
  min-height: 900px;
}

.constructor-edges {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.cedge {
  fill: none;
  stroke: #5b8cff88;
  stroke-width: 2;
}

.constructor-nodes {
  position: relative;
  z-index: 1;
}

.cnode {
  position: absolute;
  width: 300px;
  cursor: default;
}

.cnode.selected .cnode-drag {
  box-shadow: 0 0 0 2px var(--accent);
}

.cnode-drag {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
}

.cnode-head {
  background: linear-gradient(135deg, #3d5fa8, #5b8cff);
  color: #fff;
  font-weight: 600;
  font-size: 0.82rem;
  padding: 0.45rem 0.65rem;
  cursor: pointer;
  flex-shrink: 0;
}

.cnode-message {
  background: #1a1d24;
  flex: 0 1 auto;
}

.cnode-banner {
  height: 72px;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
}

.cnode-banner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cnode-no-img {
  font-size: 1.5rem;
  opacity: 0.5;
}

.cnode-caption {
  margin: 0;
  padding: 0.5rem 0.65rem 0.6rem;
  font-size: 0.72rem;
  color: #e8ecf4;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 7.5em;
  overflow: hidden;
}

.cnode-keyboard {
  flex-shrink: 0;
  padding: 0.35rem 0.45rem 0.5rem;
  background: var(--surface2);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
}

.cnode-btn {
  font-size: 0.68rem;
  padding: 0.38rem 0.5rem;
  border-radius: 8px;
  border: 1px solid #3a4458;
  background: rgba(255, 255, 255, 0.04);
  color: #dce3f0;
  text-align: center;
  white-space: normal;
  word-break: break-word;
  line-height: 1.25;
}

.cnode-btn-muted {
  color: var(--muted);
  font-style: italic;
}

.cnode-btn.cbtn-primary {
  border-color: #5b8cff;
  color: #9ec0ff;
}

.cnode-btn.cbtn-success {
  border-color: #3ecf8e;
  color: #8ee8b8;
}

.cnode-btn.cbtn-danger {
  border-color: #f07178;
  color: #ffb0b5;
}

.constructor-drawer {
  width: 0;
  overflow: hidden;
  border-left: 1px solid var(--border);
  background: var(--surface);
  transition: width 0.2s ease;
  flex-shrink: 0;
}

.constructor-drawer.open {
  width: min(420px, 92vw);
  overflow-y: auto;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
}

.drawer-head h2 {
  margin: 0;
  font-size: 0.95rem;
}

.drawer-body {
  padding: 0.75rem 0.85rem 1.5rem;
}

.drawer-body section {
  margin-bottom: 1.1rem;
}

.drawer-body h3 {
  margin: 0 0 0.45rem;
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.drawer-hint {
  font-size: 0.72rem;
  color: var(--muted);
  margin: 0.25rem 0 0.5rem;
}

.drawer-hint code {
  font-size: 0.68rem;
}

.drawer-text {
  min-height: 72px;
  margin-bottom: 0.35rem;
}

.drawer-btn-row {
  display: grid;
  grid-template-columns: 1fr 7rem auto;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}

.drawer-loading {
  padding: 2rem;
  color: var(--muted);
}

.layout-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.5rem;
  align-items: start;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
}
.layout-row.dragging { opacity: 0.55; }
.layout-drag {
  cursor: grab;
  color: var(--muted);
  padding: 0.35rem 0.25rem;
  user-select: none;
}
.layout-cells {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.layout-cell {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  padding: 0.35rem 0.5rem;
  background: var(--surface2);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.layout-cell-title { font-size: 0.82rem; font-weight: 600; }
.layout-cell code { font-size: 0.68rem; color: var(--muted); }
.layout-row-actions { display: flex; flex-direction: column; gap: 0.2rem; }
.layout-add-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
  align-items: center;
}

@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
}
