:root {
  --bg: #071016;
  --panel: #0d1820;
  --panel-2: #12222c;
  --line: #263b47;
  --text: #eef6f7;
  --muted: #94a8b2;
  --cyan: #42d6c7;
  --blue: #68aef5;
  --amber: #efb95d;
  --red: #f57680;
  --green: #72dca2;
  --shadow: 0 18px 48px rgba(0, 0, 0, .2);
  --radius: 12px;
}

html { scroll-padding-top: 70px; }
body {
  overflow-x: clip;
  background:
    radial-gradient(circle at 16% -16%, rgba(66, 214, 199, .1), transparent 31rem),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 10px;
  z-index: 100;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  font-weight: 850;
  text-decoration: none;
  transform: translateY(-150%);
  transition: transform .16s ease;
}
.skip-link:focus { transform: translateY(0); }

.public-nav {
  position: sticky;
  top: 0;
  z-index: 30;
  width: 100%;
  padding: 0 max(22px, calc((100vw - 1680px) / 2));
  justify-content: flex-start;
  gap: 2px;
  border-bottom: 1px solid rgba(38, 59, 71, .82);
  background: rgba(7, 16, 22, .92);
  backdrop-filter: blur(16px);
}
.public-nav .nav-wordmark {
  margin-right: auto;
  padding-left: 0;
  color: var(--text);
  font-size: .85rem;
  letter-spacing: -.02em;
}
.public-nav .nav-wordmark span { color: var(--cyan); }
.public-nav a {
  min-height: 54px;
  display: inline-flex;
  align-items: center;
  padding: 0 11px;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  font-size: .75rem;
  letter-spacing: .01em;
}
.public-nav a:hover,
.public-nav a:focus-visible { background: transparent; }
.public-nav a[aria-current="page"] { color: var(--text); border-bottom-color: var(--cyan); }

.app-shell { width: min(1680px, 100%); padding: 28px 22px 40px; }
.topbar { margin-bottom: 22px; }
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: rgba(66, 214, 199, .08);
  box-shadow: none;
}
h1 { font-size: clamp(1.3rem, 2.2vw, 1.85rem); }
.subtitle { font-size: .82rem; }
.privacy-badge {
  border-radius: 8px;
  background: rgba(114, 220, 162, .06);
  font-size: .68rem;
  box-shadow: none;
}
.privacy-dot { box-shadow: none; }

/* Keep future ad inventory out of the primary calculation journey. */
.app-shell > .ad-slot:first-of-type { display: none; }
.ad-slot {
  min-height: 64px;
  border-radius: 8px;
  background: rgba(4, 12, 18, .22);
}
.ad-slot[hidden] { display: none !important; }
.ads-enabled .app-shell > .ad-slot:first-of-type { display: grid; }

.layout { grid-template-columns: minmax(330px, 368px) minmax(0, 1fr); gap: 14px; }
.layout,
.layout > *,
.workspace,
.result-grid,
.result-grid > *,
.panel,
.controls { min-width: 0; }
.panel { background: var(--panel); box-shadow: none; }
.controls {
  top: 70px;
  max-height: calc(100vh - 86px);
  overflow: auto;
  scrollbar-color: #38515e transparent;
  scrollbar-width: thin;
}
.panel-head { padding: 14px 16px; }
.panel-head h2,
.panel-head h3 { font-size: .76rem; letter-spacing: .1em; }
.controls > .panel-head:first-child {
  position: sticky;
  top: 0;
  z-index: 4;
  background: rgba(13, 24, 32, .98);
}
.topology-grid { gap: 6px; padding: 12px; }
.topology-card {
  min-height: 60px;
  padding: 9px 10px;
  border-radius: 8px;
  transition: border-color .14s ease, background-color .14s ease, transform .14s ease;
}
.topology-card:hover { transform: translateY(-1px); }
.topology-card.active { box-shadow: inset 3px 0 var(--cyan); }
.topology-name { font-size: .77rem; line-height: 1.25; }
.preset-box { margin: 0 12px 10px; border-radius: 8px; }
.preset-row button,
select,
input,
.input-tab { border-radius: 7px; }
select,
input { min-height: 42px; }
.mode-row { padding: 0 12px 12px; }
.input-tabs { padding: 0 12px 9px; }
.input-tab { min-height: 38px; }
.fields { gap: 9px; max-height: none; padding: 2px 12px 13px; overflow: visible; }
.actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  padding: 12px;
  background: rgba(13, 24, 32, .97);
  box-shadow: 0 -12px 24px rgba(7, 16, 22, .88);
}
.primary,
.secondary,
.ghost { min-height: 44px; border-radius: 8px; }
.primary {
  background: var(--cyan);
  box-shadow: 0 7px 20px rgba(66, 214, 199, .13);
  transition: background-color .14s ease, transform .14s ease;
}
.primary:hover { background: #67e3d7; transform: translateY(-1px); }
.primary:active { transform: translateY(0); }
.secondary:hover { background: rgba(66, 214, 199, .12); }
.ghost:hover { border-color: #466371; color: var(--text); }

.workspace { gap: 14px; }
.hero {
  position: relative;
  padding: 22px;
  border-left: 3px solid var(--cyan);
}
.hero h2 { max-width: 18ch; font-size: clamp(1.55rem, 3vw, 2.35rem); line-height: 1.04; }
.hero p { font-size: .84rem; }
.hero-state { gap: 0; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.state-tile {
  min-width: 0;
  padding: 12px;
  border: 0;
  border-radius: 0;
  background: #0a141b;
}
.state-tile:nth-child(odd) { border-right: 1px solid var(--line); }
.state-tile:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
.state-tile strong { overflow-wrap: anywhere; }

.schematic-canvas-wrap { border-radius: 8px; }
#schematicCanvas { height: 310px; }
.schematic-key { border-radius: 8px; }
.device-ref { border-radius: 6px; }
.metrics { gap: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.metric {
  padding: 16px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}
.metric:last-child { border-right: 0; }
.metric-value { margin-top: 6px; }
.metric-note { line-height: 1.35; }
.result-grid { gap: 14px; }
.table-wrap { scrollbar-color: #38515e transparent; }
.table-wrap { width: 100%; max-width: 100%; }
.scope-wrap { background: #050b10; }
.scope-tab { min-height: 36px; }
.content-panel { background: transparent; box-shadow: none; }
.content-grid,
.topology-directory,
.reference-grid { gap: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.content-card,
.topology-summary,
.reference-card {
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: rgba(13, 24, 32, .62);
}
.public-footer { padding-top: 28px; }

dialog { border-radius: 12px; }
.close-button { min-width: 44px; min-height: 44px; }
.toast { border-radius: 8px; }

@media (max-width: 1050px) {
  .layout { grid-template-columns: 1fr; }
  .controls { position: static; max-height: none; overflow: visible; }
  .actions { position: static; box-shadow: none; }
  .topology-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .topology-card { min-height: 64px; }
}

@media (max-width: 760px) {
  .public-nav {
    overflow-x: auto;
    padding: 0 12px;
    gap: 0;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
  }
  .public-nav::-webkit-scrollbar { display: none; }
  .public-nav .nav-wordmark { display: none; }
  .public-nav a { flex: 0 0 auto; min-height: 48px; padding: 0 12px; }
  .app-shell { padding: 18px 12px 30px; }
  .layout { width: 100%; }
  .topbar { align-items: flex-start; gap: 12px; }
  .brand { align-items: flex-start; }
  .brand-mark { width: 40px; height: 40px; flex: 0 0 auto; }
  .privacy-badge { margin-top: 2px; white-space: normal; text-align: right; line-height: 1.25; }
  .topology-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero { padding: 18px; }
  .hero h2 { max-width: none; }
  .schematic-body { padding: 10px; }
  #schematicCanvas { height: 280px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric { border-bottom: 1px solid var(--line); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(n+3) { border-bottom: 0; }
  .scope-panel .panel-head { align-items: flex-start; flex-direction: column; }
  .scope-toolbar { width: 100%; }
  .scope-tab { flex: 1; }
  .content-panel { padding: 24px 4px; border-width: 1px 0 0; border-radius: 0; }
  .content-grid,
  .topology-directory,
  .reference-grid { grid-template-columns: 1fr; }
  .content-card,
  .topology-summary,
  .reference-card { border-right: 0; }
}

@media (max-width: 430px) {
  .topbar { display: block; }
  .privacy-badge { width: fit-content; margin: 12px 0 0 54px; text-align: left; }
  .mode-row { grid-template-columns: 1fr; }
  .fields { grid-template-columns: 1fr; }
  .actions { grid-template-columns: 1fr 1fr; }
  .wide-action { grid-column: 1 / -1; }
  .primary,
  .secondary { grid-column: 1 / -1; }
  .hero-state { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric { padding: 13px 11px; }
  .metric-note { display: none; }
  .schematic-legend { grid-template-columns: 1fr; }
  .system-details { grid-template-columns: 1fr; }
  .tank-checks { grid-template-columns: 1fr; }
  .public-footer nav { gap: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

@media print {
  .skip-link { display: none !important; }
  .metrics { border-color: #bbb; }
}
