/* Modern CSS Architecture (@layer + CSS Nesting + ZX Spectrum 128K Tactical HUD) */
@layer base, layout, components, utilities;

@layer base {
  :root {
    --bg-space: #010515;
    --bg-panel: rgba(5, 14, 38, 0.84);
    --bg-panel-solid: #050f29;
    --grid-line: rgba(24, 72, 140, 0.24);
    --border-hud: rgba(40, 140, 255, 0.38);
    --border-bright: #28ffff;

    /* Палитра ZXColors.cs */
    --zx-cyan: #28ffff;
    --zx-blue: #0064ff;
    --zx-yellow: #ffff28;
    --zx-green: #28ff28;
    --zx-red: #ff2828;
    --zx-magenta: #ff3cff;
    --zx-white: #eef4ff;
    --zx-muted: #8ea7cc;

    --font-mono: ui-monospace, "Cascadia Mono", "JetBrains Mono", "Consolas", monospace;
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Inter", sans-serif;
    --radius: 4px;
    --max-w: 1240px;
  }

  *, *::before, *::after {
    box-sizing: border-box;
  }

  html {
    scroll-behavior: smooth;
    background-color: var(--bg-space);
    color: var(--zx-white);
    font-family: var(--font-sans);
    line-height: 1.55;
  }

  body {
    margin: 0;
    min-height: 100vh;
    background-color: var(--bg-space);
    background-image:
      linear-gradient(var(--grid-line) 1px, transparent 1px),
      linear-gradient(90deg, var(--grid-line) 1px, transparent 1px),
      radial-gradient(circle at 75% 15%, rgba(0, 100, 255, 0.14), transparent 55%);
    background-size: 48px 48px, 48px 48px, 100% 100%;
    overflow-x: hidden;
  }

  img {
    display: block;
    max-width: 100%;
    height: auto;
  }

  a {
    color: var(--zx-cyan);
    text-decoration: none;
  }

  button {
    font: inherit;
    cursor: pointer;
    color: inherit;
  }
}

@layer layout {
  .container {
    width: min(100% - 2rem, var(--max-w));
    margin-inline: auto;
  }

  .section {
    padding-block: clamp(3.2rem, 6vw, 5.2rem);
    position: relative;
  }

  .section-head {
    margin-bottom: 2rem;

    & .section-tag {
      font-family: var(--font-mono);
      font-size: 0.82rem;
      letter-spacing: 0.14em;
      color: var(--zx-yellow);
      margin-bottom: 0.45rem;
    }

    & h2 {
      margin: 0 0 0.65rem;
      font-family: var(--font-mono);
      font-size: clamp(1.55rem, 3vw, 2.3rem);
      letter-spacing: 0.04em;
      color: var(--zx-cyan);
      text-transform: uppercase;
    }

    & p {
      margin: 0;
      max-width: 74ch;
      color: var(--zx-muted);
    }
  }
}

@layer components {
  /* Верхний HUD-бар в стиле игровой панели */
  .hud-header {
    position: sticky;
    top: 0;
    z-index: 40;
    background: rgba(1, 5, 21, 0.9);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-hud);
  }

  .hud-header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding-block: 0.72rem;
    flex-wrap: wrap;
  }

  .brand {
    display: inline-flex;
    align-items: center;
    gap: 0.7rem;
    font-family: var(--font-mono);
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--zx-yellow);
    font-size: 0.95rem;
  }

  .hud-nav {
    display: flex;
    align-items: center;
    gap: 1.15rem;
    flex-wrap: wrap;

    & a {
      font-family: var(--font-mono);
      font-size: 0.82rem;
      text-transform: uppercase;
      letter-spacing: 0.06em;
      color: var(--zx-muted);
      transition: color 0.16s ease;

      &:hover, &:focus-visible {
        color: var(--zx-cyan);
      }
    }
  }

  .hud-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
  }

  .hud-chip {
    background: rgba(0, 40, 110, 0.35);
    border: 1px solid var(--border-hud);
    border-radius: var(--radius);
    padding: 0.36rem 0.68rem;
    font-family: var(--font-mono);
    font-size: 0.76rem;
    letter-spacing: 0.05em;
    color: var(--zx-cyan);
    transition: border-color 0.15s, background-color 0.15s, color 0.15s, box-shadow 0.15s;

    &:hover {
      border-color: var(--zx-cyan);
      background: rgba(40, 255, 255, 0.12);
    }

    &.is-wireframe, &.is-active {
      border-color: var(--zx-yellow);
      color: var(--zx-yellow);
      background: rgba(255, 255, 40, 0.12);
      box-shadow: 0 0 12px rgba(255, 255, 40, 0.16);
    }
  }

  .lang-switch {
    display: inline-flex;
    border: 1px solid var(--border-hud);
    border-radius: var(--radius);
    overflow: hidden;

    & button {
      background: transparent;
      border: 0;
      padding: 0.34rem 0.56rem;
      font-family: var(--font-mono);
      font-size: 0.76rem;
      color: var(--zx-muted);

      &.is-active {
        background: var(--zx-blue);
        color: #fff;
      }
    }
  }

  /* Видоискательная HUD-рамка с угловыми скобками как в Blueprint Archive */
  .hud-box {
    position: relative;
    background: var(--bg-panel);
    border: 1px solid var(--border-hud);
    border-radius: var(--radius);

    &::before, &::after {
      content: "";
      position: absolute;
      width: 12px;
      height: 12px;
      pointer-events: none;
    }

    &::before {
      top: -1px;
      left: -1px;
      border-top: 2px solid var(--zx-cyan);
      border-left: 2px solid var(--zx-cyan);
    }

    &::after {
      bottom: -1px;
      right: -1px;
      border-bottom: 2px solid var(--zx-cyan);
      border-right: 2px solid var(--zx-cyan);
    }
  }

  .bg-3d-canvas {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 0;
  }

  .bg-telemetry-tag {
    position: fixed;
    bottom: 0.9rem;
    left: 1rem;
    z-index: 15;
    padding: 0.28rem 0.6rem;
    background: rgba(1, 5, 21, 0.72);
    border: 1px solid rgba(40, 140, 255, 0.28);
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    color: var(--zx-muted);
    pointer-events: none;
  }

  main, .site-footer {
    position: relative;
    z-index: 2;
  }

  /* Hero секция поверх глобального живого 3D-фона */
  .hero {
    position: relative;
    min-height: clamp(560px, 84vh, 800px);
    display: grid;
    align-items: center;
    border-bottom: 1px solid var(--border-hud);
    overflow: hidden;
  }

  .hero-scrim {
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, rgba(1, 5, 21, 0.78) 0%, rgba(1, 5, 21, 0.5) 55%, rgba(1, 5, 21, 0.12) 100%);
    pointer-events: none;
    z-index: 1;
  }

  .hero-grid {
    position: relative;
    z-index: 2;
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.85fr);
    gap: 2.2rem;
    align-items: center;
    padding-block: 3.5rem;
  }

  .hero-badge {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    letter-spacing: 0.14em;
    color: var(--zx-yellow);
    background: rgba(255, 255, 40, 0.08);
    border: 1px solid rgba(255, 255, 40, 0.35);
    padding: 0.32rem 0.72rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
  }

  .hero-title {
    margin: 0 0 1rem;
    font-family: var(--font-mono);
    font-size: clamp(2.15rem, 5vw, 3.85rem);
    line-height: 1.04;
    letter-spacing: 0.05em;
    color: var(--zx-cyan);
    text-shadow: 0 0 28px rgba(40, 255, 255, 0.25), 3px 3px 0 #072864;
  }

  .hero-subtitle {
    margin: 0 0 1.6rem;
    max-width: 58ch;
    font-size: clamp(1rem, 1.4vw, 1.14rem);
    color: #cddcf5;
  }

  .hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.85rem;
    margin-bottom: 1.8rem;
  }

  .btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.82rem 1.35rem;
    background: linear-gradient(135deg, #0058e6, #0098ff);
    border: 1px solid var(--zx-cyan);
    border-radius: var(--radius);
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.9rem;
    letter-spacing: 0.04em;
    color: #fff;
    box-shadow: 0 0 22px rgba(0, 140, 255, 0.32);
    transition: transform 0.15s ease, box-shadow 0.15s ease;

    &:hover {
      transform: translateY(-1px);
      box-shadow: 0 0 30px rgba(40, 255, 255, 0.45);
    }
  }

  .btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.82rem 1.25rem;
    background: rgba(5, 18, 46, 0.85);
    border: 1px solid var(--zx-green);
    border-radius: var(--radius);
    font-family: var(--font-mono);
    font-size: 0.88rem;
    color: var(--zx-green);
    transition: background-color 0.15s ease;

    &:hover {
      background: rgba(40, 255, 40, 0.14);
    }
  }

  .hero-specs {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;
  }

  .hero-spec-item {
    background: rgba(6, 18, 48, 0.78);
    border: 1px solid var(--border-hud);
    border-radius: var(--radius);
    padding: 0.6rem 0.75rem;

    & span {
      display: block;
      font-family: var(--font-mono);
      font-size: 0.7rem;
      color: var(--zx-muted);
      text-transform: uppercase;
    }

    & strong {
      font-family: var(--font-mono);
      font-size: 0.92rem;
      color: var(--zx-white);
    }
  }

  /* Виджет радара справа в Hero */
  .radar-card {
    padding: 1.15rem;
    display: grid;
    gap: 0.9rem;
  }

  .radar-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--zx-green);
    border-bottom: 1px solid var(--border-hud);
    padding-bottom: 0.5rem;
  }

  .radar-canvas {
    width: 100%;
    height: auto;
    background: rgba(0, 10, 26, 0.85);
    border: 1px solid rgba(0, 216, 0, 0.35);
    border-radius: var(--radius);
  }

  .hud-bars {
    display: grid;
    gap: 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.74rem;
  }

  .hud-bar-row {
    display: grid;
    gap: 0.2rem;

    & .hud-bar-label {
      display: flex;
      justify-content: space-between;
      color: var(--zx-muted);
    }

    & .hud-bar-track {
      height: 7px;
      background: rgba(255, 255, 255, 0.08);
      border: 1px solid rgba(255, 255, 255, 0.18);
      overflow: hidden;

      & span {
        display: block;
        height: 100%;
      }
    }
  }

  .server-pill {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    background: rgba(0, 24, 62, 0.7);
    border: 1px solid var(--border-hud);
    border-radius: var(--radius);
    padding: 0.6rem 0.75rem;
    font-family: var(--font-mono);

    & small {
      display: block;
      font-size: 0.68rem;
      color: var(--zx-muted);
    }

    & code {
      font-size: 0.92rem;
      color: var(--zx-yellow);
      font-weight: 700;
    }
  }

  /* Интерактивный Ангар 3D */
  .hangar-layout {
    display: grid;
    grid-template-columns: 260px minmax(0, 1.3fr) 310px;
    gap: 1.15rem;
    align-items: stretch;
  }

  .ship-list {
    display: grid;
    gap: 0.45rem;
    align-content: start;
  }

  .ship-tab {
    text-align: left;
    background: rgba(5, 14, 38, 0.85);
    border: 1px solid var(--border-hud);
    border-radius: var(--radius);
    padding: 0.65rem 0.82rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: var(--font-mono);
    transition: border-color 0.15s, background-color 0.15s, transform 0.15s;

    &:hover {
      border-color: var(--zx-cyan);
      transform: translateX(3px);
    }

    &.is-active {
      border-color: var(--zx-cyan);
      background: rgba(0, 96, 200, 0.28);
      box-shadow: inset 3px 0 0 var(--zx-yellow);

      & .ship-tab-name {
        color: var(--zx-yellow);
      }
    }

    & .ship-tab-name {
      font-size: 0.84rem;
      font-weight: 700;
      color: var(--zx-white);
    }

    & .ship-tab-meta {
      font-size: 0.7rem;
      color: var(--zx-muted);
    }
  }

  .hangar-stage {
    padding: 0.9rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 410px;
  }

  .hangar-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.5rem;
  }

  .btn-group {
    display: inline-flex;
    gap: 0.35rem;
    flex-wrap: wrap;
  }

  .hangar-canvas-wrap {
    position: relative;
    flex: 1;
    min-height: 310px;
    cursor: grab;

    &:active {
      cursor: grabbing;
    }

    & canvas {
      width: 100%;
      height: 100%;
      display: block;
    }
  }

  .drag-hint {
    text-align: center;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    letter-spacing: 0.1em;
    color: var(--zx-muted);
    margin-top: 0.35rem;
  }

  .hangar-dossier {
    padding: 1.15rem;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;

    & h3 {
      margin: 0;
      font-family: var(--font-mono);
      font-size: 1.3rem;
      color: var(--zx-cyan);
    }

    & .dossier-role {
      font-family: var(--font-mono);
      font-size: 0.8rem;
      color: var(--zx-yellow);
      margin-top: -0.55rem;
    }

    & p {
      margin: 0;
      font-size: 0.92rem;
      color: #c8d8f0;
    }
  }

  .spec-table {
    margin-top: auto;
    display: grid;
    gap: 0.48rem;
    border-top: 1px solid var(--border-hud);
    padding-top: 0.85rem;
  }

  .spec-row {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.8rem;

    & span {
      color: var(--zx-muted);
    }

    & strong {
      color: var(--zx-white);
    }
  }

  /* Bento сетка боевых систем */
  .systems-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1.1rem;
  }

  .system-card {
    padding: 1.25rem;
    display: grid;
    gap: 0.55rem;
    align-content: start;
    transition: border-color 0.16s ease, transform 0.16s ease;

    &:hover {
      border-color: var(--zx-cyan);
      transform: translateY(-2px);
    }

    & .sys-code {
      font-family: var(--font-mono);
      font-size: 0.72rem;
      color: var(--zx-yellow);
      letter-spacing: 0.12em;
    }

    & h3 {
      margin: 0;
      font-family: var(--font-mono);
      font-size: 1.02rem;
      color: var(--zx-cyan);
    }

    & p {
      margin: 0;
      font-size: 0.92rem;
      color: var(--zx-muted);
    }
  }

  /* Галерея скриншотов */
  .gallery-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
  }

  .gallery-card {
    margin: 0;
    padding: 0.65rem;
    cursor: zoom-in;
    transition: border-color 0.16s ease, transform 0.16s ease;

    &.is-wide {
      grid-column: span 2;
    }

    &:hover {
      border-color: var(--zx-yellow);
      transform: translateY(-2px);
    }

    & img {
      width: 100%;
      aspect-ratio: 16 / 9;
      object-fit: cover;
      border-radius: 2px;
      border: 1px solid rgba(40, 255, 255, 0.2);
    }

    & figcaption {
      margin-top: 0.55rem;
      font-family: var(--font-mono);
      font-size: 0.78rem;
      color: var(--zx-muted);
    }
  }

  /* Сервер + Управление + Загрузка */
  .steps-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1.1rem;
  }

  .step-card {
    padding: 1.2rem;

    & h3 {
      margin: 0 0 0.5rem;
      font-family: var(--font-mono);
      font-size: 1rem;
      color: var(--zx-green);
    }

    & p {
      margin: 0 0 0.85rem;
      font-size: 0.92rem;
      color: var(--zx-muted);
    }

    & pre {
      margin: 0;
      padding: 0.65rem 0.75rem;
      background: rgba(0, 8, 22, 0.9);
      border: 1px solid var(--border-hud);
      border-radius: var(--radius);
      font-family: var(--font-mono);
      font-size: 0.76rem;
      color: var(--zx-cyan);
      overflow-x: auto;
    }
  }

  .controls-table-wrap {
    overflow-x: auto;
    padding: 0.2rem;
  }

  .controls-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;

    & th, & td {
      padding: 0.72rem 1rem;
      text-align: left;
      border-bottom: 1px solid rgba(40, 140, 255, 0.2);
    }

    & th {
      font-family: var(--font-mono);
      font-size: 0.78rem;
      text-transform: uppercase;
      letter-spacing: 0.08em;
      color: var(--zx-yellow);
    }

    & kbd {
      display: inline-block;
      padding: 0.16rem 0.48rem;
      font-family: var(--font-mono);
      font-size: 0.8rem;
      color: var(--zx-cyan);
      background: rgba(0, 48, 120, 0.35);
      border: 1px solid var(--border-hud);
      border-radius: 3px;
    }
  }

  .dl-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1.1rem;
  }

  .dl-card {
    padding: 1.3rem;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;

    & h3 {
      margin: 0;
      font-family: var(--font-mono);
      color: var(--zx-cyan);
      font-size: 1.05rem;
    }

    & p {
      margin: 0;
      color: var(--zx-muted);
      font-size: 0.92rem;
    }

    & pre {
      margin: 0;
      padding: 0.65rem;
      background: rgba(0, 8, 22, 0.9);
      border: 1px solid var(--border-hud);
      font-family: var(--font-mono);
      font-size: 0.75rem;
      color: var(--zx-yellow);
      overflow-x: auto;
    }

    & .btn-primary, & .btn-secondary {
      margin-top: auto;
      justify-content: center;
    }
  }

  /* Футер */
  .site-footer {
    border-top: 1px solid var(--border-hud);
    padding-block: 1.6rem;
    text-align: center;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--zx-muted);
  }

  /* Лайтбокс и уведомление о копировании */
  .lightbox {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: none;
    place-items: center;
    padding: 1.5rem;
    background: rgba(1, 4, 16, 0.92);
    backdrop-filter: blur(8px);

    &.is-open {
      display: grid;
    }

    & figure {
      margin: 0;
      max-width: min(1080px, 95vw);
      position: relative;
    }

    & img {
      max-height: 80vh;
      width: auto;
      margin-inline: auto;
      border: 1px solid var(--zx-cyan);
    }

    & figcaption {
      margin-top: 0.75rem;
      text-align: center;
      font-family: var(--font-mono);
      font-size: 0.86rem;
      color: var(--zx-cyan);
    }
  }

  .lightbox-close {
    position: fixed;
    top: 1.2rem;
    right: 1.4rem;
    background: rgba(0, 30, 80, 0.8);
    border: 1px solid var(--zx-cyan);
    color: var(--zx-cyan);
    font-family: var(--font-mono);
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius);
  }

  .copy-toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 80;
    padding: 0.7rem 1.1rem;
    background: rgba(4, 24, 16, 0.95);
    border: 1px solid var(--zx-green);
    color: var(--zx-green);
    font-family: var(--font-mono);
    font-size: 0.84rem;
    border-radius: var(--radius);
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;

    &.is-visible {
      opacity: 1;
      transform: translateY(0);
    }
  }
}

@layer utilities {
  @media (max-width: 1020px) {
    .hero-grid {
      grid-template-columns: 1fr;
    }
    .hangar-layout {
      grid-template-columns: 1fr;
    }
    .ship-list {
      grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }
    .systems-grid,
    .steps-grid,
    .dl-grid,
    .gallery-grid {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .gallery-card.is-wide {
      grid-column: span 2;
    }
  }

  @media (max-width: 640px) {
    .hero-specs {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .systems-grid,
    .steps-grid,
    .dl-grid,
    .gallery-grid {
      grid-template-columns: 1fr;
    }
    .gallery-card.is-wide {
      grid-column: span 1;
    }
    .hud-nav {
      display: none;
    }
  }
}
