:root {
  --bg: #0f172a;
  --panel: #111827;
  --panel-2: #1f2937;
  --panel-3: #334155;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #0ea5e9;
  --danger: #ef4444;
  --success: #22c55e;
  --border: rgba(148, 163, 184, 0.22);
  --shadow: 0 16px 40px rgba(2, 6, 23, 0.28);
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #0b1220, #0f172a 35%);
  color: var(--text);
}
button, input, textarea, select {
  font: inherit;
}
button {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #0b1220;
  color: var(--text);
  padding: 0.7rem 0.95rem;
  cursor: pointer;
}
button:hover { border-color: rgba(56, 189, 248, 0.5); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.primary-btn {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: #082f49;
  border: none;
  font-weight: 700;
}
.danger-btn {
  border-color: rgba(239, 68, 68, 0.45);
  color: #fecaca;
}
.file-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.7rem 0.95rem;
  cursor: pointer;
}

.app-shell {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  /* background: rgba(15, 23, 42, 0.75); */
  background:#030A23;
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 1rem 1.25rem;
}
.brand-block h1 {
  margin: 0;
  font-size: 1.35rem;
}
.brand-block p {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}
.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 320px 320px;
  gap: 1rem;
  min-height: 0;
}

.layout.right-panel-collapsed {
  grid-template-columns: 280px minmax(0, 1fr) 320px;
}

.layout.right-panel-collapsed .right-panel {
  display: none;
}

.sidebar, .canvas-panel {
  min-height: 0;
}
.panel-card, .canvas-panel {
  background: rgba(17, 24, 39, 0.88);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.panel-card {
  padding: 1rem;
  overflow: auto;
}
.panel-card h2 {
  margin: 0 0 0.85rem;
  font-size: 1rem;
}
.panel-header-inline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}
.health-score {
  font-weight: 800;
  color: #7dd3fc;
}
.maps-list, .outline-tree, .issues-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.map-list-item {
  padding: 0.8rem;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.map-list-item.active {
  border-color: rgba(56, 189, 248, 0.55);
  background: rgba(14, 165, 233, 0.15);
}

.map-list-item small {
  color: var(--muted);
  display: block;
  margin-top: 0.25rem;
}

.map-open-btn {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  padding: 0;
}

.map-open-btn:hover {
  border-color: transparent;
}

.map-delete-btn {
  align-self: flex-start;
  padding: 0.45rem 0.7rem;
  font-size: 0.85rem;
}
.outline-item {
  padding: 0.3rem 0.45rem;
  border-radius: 10px;
  cursor: pointer;
}
.outline-item:hover, .outline-item.active {
  background: rgba(56, 189, 248, 0.12);
}
.issue-item {
  color: #cbd5e1;
  border-left: 3px solid rgba(56, 189, 248, 0.45);
  padding-left: 0.7rem;
}
.issue-item strong {
  display: block;
  margin-bottom: 0.2rem;
}

.canvas-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.canvas-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border);
}
.save-status {
  margin-left: 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.canvas-toolbar-actions {
  display: flex;
  gap: 0.6rem;
}
.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 480px;
  overflow: auto;
  background:
    radial-gradient(circle at center, rgba(56, 189, 248, 0.07), transparent 38%),
    linear-gradient(rgba(148, 163, 184, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.05) 1px, transparent 1px);
  background-size: auto, 28px 28px, 28px 28px;
  background-position: center;
}
.links-layer, .nodes-layer {
  position: absolute;
  inset: 0;
  min-width: 1800px;
  min-height: 1200px;
}
.nodes-layer {
  z-index: 2;
}
.links-layer {
  z-index: 1;
  overflow: visible;
}
.map-node {
  position: absolute;
  min-width: 140px;
  max-width: 220px;
  padding: 0.75rem 0.85rem;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.96), rgba(15, 23, 42, 0.96));
  box-shadow: 0 10px 30px rgba(2, 6, 23, 0.22);
  user-select: none;
  cursor: grab;
}
.map-node.selected {
  border-color: rgba(56, 189, 248, 0.7);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.18), 0 10px 30px rgba(2, 6, 23, 0.22);
}
.map-node[data-kind="root"] {
  background: linear-gradient(180deg, rgba(2, 132, 199, 1), rgba(14, 116, 144, 1));
  color: #e0f2fe;
  font-weight: 700;
}
.map-node[data-kind="question"] { border-color: rgba(245, 158, 11, 0.55); }
.map-node[data-kind="example"] { border-color: rgba(34, 197, 94, 0.55); }
.map-node[data-kind="mistake"] { border-color: rgba(239, 68, 68, 0.55); }
.node-kind-badge {
  display: inline-flex;
  margin-top: 0.4rem;
  font-size: 0.73rem;
  color: var(--muted);
}
.map-node.collapsed::after {
  content: "Collapsed";
  display: block;
  margin-top: 0.4rem;
  font-size: 0.72rem;
  color: #7dd3fc;
}
.link-line {
  stroke: rgba(148, 163, 184, 0.55);
  stroke-width: 2;
}
.cross-link-line {
  stroke: rgba(245, 158, 11, 0.75);
  stroke-dasharray: 6 6;
  stroke-width: 2;
}
.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 2rem;
  z-index: 3;
}
.empty-state h2 {
  margin: 0 0 0.5rem;
}
.empty-state p {
  color: var(--muted);
  margin: 0 0 1rem;
}
.hidden { display: none !important; }

.node-editor {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.node-editor label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  color: #cbd5e1;
}
.node-editor input,
.node-editor textarea,
.node-editor select,
.app-dialog input,
.app-dialog select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #0b1220;
  color: var(--text);
  padding: 0.75rem 0.85rem;.layout.right-panel-collapsed {
  grid-template-columns: 280px minmax(0, 1fr) 320px;
}

.layout.right-panel-collapsed .right-panel {
  display: none;
}
}
.node-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}
.tips-list {
  margin: 0;
  padding-left: 1.2rem;
  color: #cbd5e1;
}
.tips-list li + li { margin-top: 0.45rem; }

.app-dialog {
  border: 1px solid var(--border);
  border-radius: 22px;
  background: #111827;
  color: var(--text);
  width: min(92vw, 460px);
  padding: 0;
}
.app-dialog::backdrop {
  background: rgba(2, 6, 23, 0.65);
}
.app-dialog form,
.app-dialog > div {
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.dialog-tip {
  color: var(--muted);
  margin: 0;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}

.review-panel {
  position: fixed;
  right: 340px;
  bottom: 28px;
  z-index: 20;
  pointer-events: none;
}

.review-panel-card {
  width: min(360px, calc(100vw - 420px));
  background: rgba(17, 24, 39, 0.96);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 1rem;
  pointer-events: auto;
}

.review-panel-card h2 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
}

.review-panel-card p {
  margin: 0;
  color: #cbd5e1;
}

.review-panel-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.9rem;
}

.ad-rail {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 0;
}

.ad-card {
  background: rgba(17, 24, 39, 0.88);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 0.85rem;
}

.ad-card-tall {
  position: sticky;
  top: 1rem;
}

.ad-label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.ad-placeholder {
  display: grid;
  place-items: center;
  text-align: center;
  border: 1px dashed rgba(148, 163, 184, 0.38);
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.75);
  color: var(--muted);
  line-height: 1.4;
}

.ad-placeholder-rect {
  min-height: 250px;
}

.ad-placeholder-tall {
  min-height: 600px;
}

.mobile-ad-section {
  display: none;
}

.ad-placeholder-responsive {
  min-height: 90px;
}

.sponsor-card {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  color: var(--text);
  text-decoration: none;
}

.sponsor-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.sponsor-cta {
  display: inline-flex;
  align-self: flex-start;
  border: 1px solid rgba(56, 189, 248, 0.45);
  border-radius: 999px;
  padding: 0.45rem 0.7rem;
  color: #7dd3fc;
  font-weight: 700;
  font-size: 0.85rem;
}

.sponsor-image {
  width: 100%;
  border-radius: 14px;
  object-fit: cover;
  max-height: 140px;
}

.sponsor-card-tall {
  min-height: 560px;
}

.internal-sponsor-card {
  width: 100%;
  background: transparent;
  border: none;
  text-align: left;
  padding: 0;
  cursor: pointer;
}

.internal-sponsor-card:hover .sponsor-cta {
  border-color: rgba(56, 189, 248, 0.8);
}


.brand-block {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-logo {
  width: 80px;
  height: auto;
}

.brand-text {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.brand-name {
  height: 35px;
  width: auto;
}

.brand-tagline {
  height: 19px;
  width: auto;
  opacity: 0.85;
}

.sponsor-dialog {
  width: min(92vw, 760px);
}

.sponsor-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.2rem;
}

.sponsor-info-grid h3 {
  margin: 0 0 0.5rem;
}

.sponsor-info-grid ul {
  margin: 0;
  padding-left: 1.2rem;
  color: #cbd5e1;
}

.sponsor-info-grid li + li {
  margin-top: 0.4rem;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  padding: 0.7rem 0.95rem;
  text-decoration: none;
}

.app-dialog a {
  color: #7dd3fc;
}

@media (max-width: 720px) {
  .sponsor-info-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1180px) {
  .review-panel {
    right: 20px;
    left: 20px;
    bottom: 20px;
  }

  .review-panel-card {
    width: 100%;
  }
}

@media (max-width: 1180px) {

  .topbar{
    flex-direction: column;
  }

  .topbar-actions{
    justify-content: center;
  }

   #toggleRightPanelBtn {
    display: none;
  }

  .layout.right-panel-collapsed {
    grid-template-columns: 1fr;
  }

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

  .sidebar {
    max-height: none;
  }

  .canvas-panel {
    order: 1;
    min-height: 68vh;
  }

  .mobile-ad-section {
    order: 2;
    display: block;
    background: rgba(17, 24, 39, 0.88);
    border: 1px solid var(--border);
    border-radius: 22px;
    box-shadow: var(--shadow);
    padding: 0.85rem;
  }

  .left-panel {
    order: 3;
  }

  .right-panel {
    order: 4;
  }

  .ad-rail {
    display: none;
  }
}

@media print {
  body.printing-canvas {
    background: #ffffff !important;
    color: #000000 !important;
  }

  body.printing-canvas .topbar,
  body.printing-canvas .left-panel,
  body.printing-canvas .right-panel,
  body.printing-canvas .ad-rail,
  body.printing-canvas .mobile-ad-section,
  body.printing-canvas .canvas-toolbar,
  body.printing-canvas .review-panel {
    display: none !important;
  }

  body.printing-canvas .app-shell,
  body.printing-canvas .layout,
  body.printing-canvas .canvas-panel,
  body.printing-canvas .canvas-wrap {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    min-height: auto !important;
    overflow: visible !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    box-shadow: none !important;
    background: #ffffff !important;
  }

  body.printing-canvas .links-layer,
  body.printing-canvas .nodes-layer {
    position: absolute !important;
    inset: 0 !important;
    min-width: 1800px !important;
    min-height: 1200px !important;
  }

  body.printing-canvas .canvas-wrap {
    position: relative !important;
    width: 1800px !important;
    height: 1200px !important;
  }

  body.printing-canvas .map-node {
    color: #000000 !important;
    background: #ffffff !important;
    border: 1px solid #444 !important;
    box-shadow: none !important;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  body.printing-canvas .map-node[data-kind="root"] {
    color: #000000 !important;
    background: #dbeafe !important;
  }

  body.printing-canvas .link-line {
    stroke: #555555 !important;
  }

  body.printing-canvas .cross-link-line {
    stroke: #92400e !important;
  }
}