:root {
  --blue: #0026E6;
  --blue-soft: #EBF0FF;
  --blue-mid: #8093F2;
  --black: #08090C;
  --white: #FFFFFF;
  --muted: #687082;

  /* Darkblue Header Widget sizing */
  --dbw-size: 48px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}

body, html {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--white);
  color: var(--black);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

#field {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100%;
  height: 100dvh;
  z-index: 1;
  display: block;
}

.interface {
  position: relative;
  z-index: 2;
  width: 100vw;
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(20px, 3.2vw, 44px) clamp(24px, 4vw, 56px);
  pointer-events: none;
  box-sizing: border-box;
}

/* Элементы, управляемые мобильным представлением */
.mobile-stage-bar {
  display: none;
}

.desc-mobile {
  display: none;
}

.desc-desktop {
  display: inline;
}

.hint-meta-mobile {
  display: none;
}

/* Шапка */
.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  width: 100%;
  gap: 32px;
  pointer-events: auto;
}

.header-actions {
  display: flex;
  align-items: flex-start;
  flex-shrink: 0;
  position: relative;
  z-index: 1050;
  pointer-events: auto;
}

.brand-cluster {
  display: flex;
  align-items: center;
  gap: 18px;
}

.logo {
  width: 48px;
  height: 48px;
  background-color: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.3s ease;
  cursor: pointer;
}

.logo:hover {
  transform: scale(1.06);
  background-color: var(--black);
}

.logo svg {
  width: 32px;
  height: 32px;
}

.context {
  max-width: 540px;
}

.context-title {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.02em;
  color: var(--black);
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 3px;
}

.context-title span.dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  background-color: var(--blue);
}

.context-desc {
  font-size: 13.5px;
  line-height: 1.4;
  color: var(--muted);
}

/* Центральный стек из 8 доменов */
.main-stage {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.subdomain-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  pointer-events: auto;
  gap: 2px;
}

.node-link {
  position: relative;
  display: inline-flex;
  align-items: baseline;
  text-decoration: none;
  padding: 4px 20px 4px 18px;
  margin-left: -18px;
  transition:
    background-color 0.32s cubic-bezier(0.16, 1, 0.3, 1),
    color 0.32s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.38s cubic-bezier(0.16, 1, 0.3, 1);
  cursor: pointer;
}

.node-index {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  color: var(--blue);
  margin-right: 16px;
  width: 20px;
  transition: color 0.3s ease, opacity 0.3s ease;
}

.node-name {
  font-size: clamp(26px, 3.65vh, 48px);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1.05;
  color: var(--black);
  transition: color 0.3s ease;
}

.node-dot {
  color: var(--blue);
  font-size: clamp(26px, 3.65vh, 48px);
  font-weight: 800;
  transition: color 0.3s ease;
}

.node-domain-tail {
  font-family: 'JetBrains Mono', monospace;
  font-size: clamp(12px, 1.2vw, 17px);
  font-weight: 600;
  color: var(--blue);
  opacity: 0;
  transform: translateX(-12px);
  transition: opacity 0.32s cubic-bezier(0.16, 1, 0.3, 1), transform 0.32s cubic-bezier(0.16, 1, 0.3, 1), color 0.3s ease;
  margin-left: 2px;
}

.node-role-pill {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-left: 16px;
  padding: 4px 8px;
  background: var(--black);
  color: var(--white);
  opacity: 0;
  transform: translateY(-3px);
  transition: opacity 0.32s ease, transform 0.32s ease;
  align-self: center;
}

.node-link.active,
.node-link:hover {
  background-color: var(--blue);
  transform: translateX(14px);
}

.node-link.active .node-index,
.node-link:hover .node-index {
  color: var(--white);
  opacity: 0.75;
}

.node-link.active .node-name,
.node-link:hover .node-name,
.node-link.active .node-dot,
.node-link:hover .node-dot {
  color: var(--white);
}

.node-link.active .node-domain-tail,
.node-link:hover .node-domain-tail {
  opacity: 1;
  transform: translateX(0);
  color: var(--white);
}

.node-link.active .node-role-pill,
.node-link:hover .node-role-pill {
  opacity: 1;
  transform: translateY(0);
}

/* Нижний инспектор */
.footer {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  pointer-events: auto;
}

.inspector-bar {
  display: flex;
  align-items: stretch;
  background-color: var(--black);
  color: var(--white);
  max-width: 760px;
  width: 100%;
}

.inspector-accent {
  width: 10px;
  background-color: var(--blue);
  flex-shrink: 0;
}

.inspector-body {
  padding: 16px 22px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
  transition: opacity 0.22s ease;
}

.inspector-url {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  color: var(--blue-mid);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.inspector-text {
  font-size: 14px;
  font-weight: 400;
  line-height: 1.4;
  color: var(--white);
}

.inspector-action {
  background-color: var(--blue);
  color: var(--white);
  text-decoration: none;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 700;
  padding: 0 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background-color 0.25s ease, color 0.25s ease;
  white-space: nowrap;
}

.inspector-action:hover {
  background-color: var(--blue-soft);
  color: var(--blue);
}

.hint-meta {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  text-align: right;
  line-height: 1.6;
}

.hint-meta strong {
  color: var(--black);
  font-weight: 700;
}

@media (max-width: 860px) {
  :root {
    --dbw-size: 38px;
  }

  .interface {
    padding: max(12px, env(safe-area-inset-top, 12px)) max(14px, env(safe-area-inset-right, 14px)) max(10px, env(safe-area-inset-bottom, 10px)) max(14px, env(safe-area-inset-left, 14px));
    gap: 6px;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }

  .desc-desktop {
    display: none;
  }

  .desc-mobile {
    display: inline;
  }

  /* Шапка на мобильных */
  .header {
    gap: 10px;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
  }

  .brand-cluster {
    gap: 10px;
    align-items: center;
    min-width: 0;
    flex: 1;
  }

  .logo {
    width: 38px;
    height: 38px;
  }

  .logo svg {
    width: 24px;
    height: 24px;
  }

  .context {
    min-width: 0;
    flex: 1;
  }

  .context-title {
    font-size: 12.5px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .context-desc {
    font-size: 11px;
    line-height: 1.25;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .header-actions {
    flex-shrink: 0;
  }

  /* Мобильная статусная плашка над холстом */
  .mobile-stage-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 5px 10px;
    background: rgba(8, 9, 12, 0.05);
    border-left: 3px solid var(--blue);
    font-family: 'JetBrains Mono', monospace;
    pointer-events: auto;
    flex-shrink: 0;
    box-sizing: border-box;
  }

  .stage-tag {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    font-weight: 700;
    color: var(--black);
    letter-spacing: 0.02em;
    min-width: 0;
  }

  .live-dot {
    width: 6px;
    height: 6px;
    background-color: var(--blue);
    display: inline-block;
    flex-shrink: 0;
  }

  #stageModeName {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .stage-nav-arrows {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
  }

  .stage-nav-btn {
    background: var(--black);
    color: var(--white);
    border: none;
    width: 28px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s;
  }

  .stage-nav-btn:active {
    background: var(--blue);
  }

  /* Центральная часть и список поддоменов */
  .main-stage {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    width: 100%;
  }

  .subdomain-stack {
    width: 100%;
    gap: 2px;
    max-height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin-left: 0;
    padding-bottom: 2px;
  }

  .subdomain-stack::-webkit-scrollbar {
    display: none;
  }

  .node-link {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 10px 5px 8px;
    margin-left: 0;
    transform: none;
    background: transparent;
    border-left: 2px solid transparent;
    -webkit-tap-highlight-color: transparent;
    text-decoration: none;
    cursor: pointer;
    box-sizing: border-box;
  }

  .node-index {
    font-size: 11px;
    width: 20px;
    margin-right: 6px;
    flex-shrink: 0;
  }

  .node-name {
    font-size: clamp(17px, 4.4vw, 21px);
    font-weight: 800;
    line-height: 1.1;
  }

  .node-dot {
    font-size: clamp(17px, 4.4vw, 21px);
  }

  .node-domain-tail {
    display: none;
  }

  .node-role-pill {
    display: inline-block;
    opacity: 0.7;
    transform: none;
    font-size: 9px;
    padding: 3px 6px;
    margin-left: auto;
    align-self: center;
    flex-shrink: 0;
    background: rgba(8, 9, 12, 0.08);
    color: var(--black);
    transition: background 0.25s, color 0.25s, opacity 0.25s;
  }

  .node-link.active {
    background-color: var(--blue);
    border-left: 2px solid var(--black);
    transform: translateX(3px);
  }

  .node-link.active .node-index {
    color: var(--white);
    opacity: 0.8;
  }

  .node-link.active .node-name,
  .node-link.active .node-dot {
    color: var(--white);
  }

  .node-link.active .node-role-pill {
    opacity: 1;
    background: var(--black);
    color: var(--white);
  }

  /* Инспектор и футер */
  .footer {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    flex-shrink: 0;
  }

  .inspector-bar {
    max-width: 100%;
    width: 100%;
  }

  .inspector-accent {
    width: 6px;
  }

  .inspector-body {
    padding: 8px 12px;
    gap: 3px;
    min-width: 0;
  }

  .inspector-url {
    font-size: 10px;
  }

  .inspector-text {
    font-size: 11.5px;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .inspector-action {
    padding: 0 16px;
    font-size: 11px;
    min-height: 44px;
    flex-shrink: 0;
  }

  .hint-meta {
    display: none;
  }

  .hint-meta-mobile {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 9px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding-top: 2px;
  }

  .hint-meta-mobile span.sep {
    color: var(--blue-mid);
  }
}

@media (max-height: 640px) and (max-width: 860px) {
  .interface {
    padding: 6px 10px;
    gap: 4px;
  }
  .mobile-stage-bar {
    padding: 3px 8px;
  }
  .node-name, .node-dot {
    font-size: 15px;
  }
  .node-link {
    padding: 3px 8px;
  }
  .inspector-body {
    padding: 6px 10px;
  }
  .inspector-text {
    -webkit-line-clamp: 1;
    line-clamp: 1;
  }
}
