/* Ackerman Legion — the public console.
   A tiled terminal session: status bars above and below, workspaces made of panes,
   code rain in the gaps and a CRT glass over everything. Loaded after base.css. */

html { scroll-behavior: smooth; }
body { overflow-x: hidden; }

/* ---------- atmosphere ---------- */

#rain {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  opacity: .55;
}

.crt {
  position: fixed;
  inset: 0;
  z-index: 80;
  pointer-events: none;
  background:
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0) 0 2px, rgba(0, 0, 0, .2) 2px 3px),
    radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 58%, rgba(0, 0, 0, .62) 100%);
  overflow: hidden;
}
.crt::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: -22%;
  height: 20%;
  background: linear-gradient(to bottom, rgba(192, 132, 252, 0), rgba(192, 132, 252, .05), rgba(192, 132, 252, 0));
  animation: crt-sweep 9s linear infinite;
}
@keyframes crt-sweep { to { transform: translateY(640%); } }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- boot ---------- */

.boot {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #000;
  animation: boot-fallback 0s linear 8s forwards;      /* never traps the page if the script fails */
}
.boot-inner { width: min(35rem, 100%); }
.boot-seal { display: block; margin-bottom: 18px; filter: drop-shadow(0 0 14px rgba(192, 132, 252, .55)); }
.boot-log { margin: 0; min-height: 12em; font: 400 .8125rem/1.75 var(--mono); color: var(--ink); white-space: pre-wrap; }
.boot-log .hot { color: var(--white); font-weight: 700; }
.boot-log .grant {
  display: inline-block;
  margin-top: .5em;
  padding: 2px 10px;
  background: var(--g);
  color: #000;
  font-weight: 800;
  letter-spacing: .12em;
}
.boot-skip { margin: 18px 0 0; font-size: .72rem; color: var(--g-dim); }
.boot.is-done { animation: boot-out .55s steps(7) forwards; pointer-events: none; }
@keyframes boot-out {
  0% { clip-path: inset(0 0 0 0); }
  30% { clip-path: inset(12% 0 0 0); transform: translateX(-8px); }
  55% { clip-path: inset(12% 0 34% 0); transform: translateX(10px); }
  80% { clip-path: inset(44% 0 44% 0); transform: translateX(-4px); }
  100% { clip-path: inset(50% 0 50% 0); opacity: 0; visibility: hidden; }
}
@keyframes boot-fallback { to { visibility: hidden; } }

/* ---------- status bars ---------- */

.bar {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 50;
  height: var(--bar);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 var(--pad);
  background: #000;
  font-size: .75rem;
  color: var(--mute);
  white-space: nowrap;
}
.bar-top { top: 0; border-bottom: 1px solid var(--line); }
.bar-bottom { bottom: 0; border-top: 1px solid var(--line); }
.bar-id { display: flex; align-items: center; gap: 8px; color: var(--g); font-weight: 700; text-decoration: none; }
.bar-id img { display: block; }
.tabs { display: flex; align-self: stretch; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
  border-left: 1px solid var(--line-soft);
  color: var(--mute);
  text-decoration: none;
}
.tabs a:last-child { border-right: 1px solid var(--line-soft); }
.tabs a b { color: var(--g-mid); font-weight: 700; }
.tabs a:hover { color: var(--g); }
.tabs a[aria-current='true'] { background: var(--g); color: #000; font-weight: 700; }
.tabs a[aria-current='true'] b { color: #000; }
.bar-meta { margin-left: auto; display: flex; align-items: center; gap: 16px; }
.live::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 7px;
  background: var(--g);
  box-shadow: 0 0 8px var(--g);
  animation: blink 1.6s steps(2) infinite;
}
.mode {
  height: 22px;
  padding: 0 10px;
  border: 0;
  background: var(--g);
  color: #000;
  font-weight: 800;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  cursor: pointer;
}
.mode:hover { background: var(--white); }
.path { color: var(--g); }
kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 5px;
  border: 1px solid var(--line);
  color: var(--g);
  font: 400 .72rem/1.5 var(--mono);
  text-align: center;
}

/* ---------- workspaces ---------- */

main { position: relative; z-index: 1; padding: var(--bar) 0; }

.ws {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--gap);
  align-content: start;
  padding: var(--pad);
  scroll-margin-top: var(--bar);
}
.ws + .ws { padding-top: clamp(26px, 5vw, 60px); }
.ws-title {
  margin: 0 0 4px;
  font: 700 clamp(1rem, .85rem + .7vw, 1.4rem)/1.3 var(--mono);
  color: var(--white);
  text-shadow: 0 0 16px rgba(192, 132, 252, .35);
}
.ws-title .ps1 { margin-right: .3em; }

/* panes switch on one after another when their workspace comes into view */
.js .ws .pane, .js .ws .ws-title { transition: opacity .45s ease, transform .6s var(--ease), border-color .15s linear, box-shadow .25s ease; transition-delay: calc(var(--i, 0) * 70ms); }
.js .ws:not(.is-in) .pane, .js .ws:not(.is-in) .ws-title { opacity: 0; transform: translateY(14px); }

/* ---------- 1: root ---------- */

.pane-title .pane-body { position: relative; display: flex; flex-direction: column; padding: 16px clamp(16px, 2.4vw, 34px) 16px; overflow: hidden; }
/* the seal stands behind the session like a watermark on a document */
.pane-title .pane-body::before {
  content: '';
  position: absolute;
  top: 50%;
  right: -7%;
  width: min(62%, 78vh);
  aspect-ratio: 1;
  transform: translateY(-50%);
  background: url(emblem-720.png) center / contain no-repeat;
  opacity: .075;
  pointer-events: none;
}
.pane-title .pane-body > * { position: relative; }
/* the ritual seal turns slowly around the emblem */
.pane-title .pane-body > .sigil {
  position: absolute;
  top: 50%;
  right: -7%;
  width: min(62%, 78vh);
  aspect-ratio: 1;
  transform: translateY(-50%);
  color: var(--g);
  opacity: .3;
  pointer-events: none;
}
.sigil svg { display: block; width: 100%; height: 100%; animation: sigil-turn 160s linear infinite; filter: drop-shadow(0 0 6px rgba(192, 132, 252, .6)); }
@keyframes sigil-turn { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .sigil svg { animation: none; } }
.cmd { margin: 0 0 auto; color: var(--ink); }
.title {
  position: relative;
  margin: 22px 0 0;
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(2.9rem, 13.5vw, 6rem);
  line-height: .88;
  letter-spacing: -.005em;
  text-transform: uppercase;
  color: var(--white);
  text-shadow: 0 0 34px rgba(192, 132, 252, .38);
}
.title > span { display: block; }
.title > span:last-child { color: var(--g); }
.glitch::before, .glitch::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  white-space: pre-line;
  pointer-events: none;
  opacity: 0;
  text-shadow: none;
  mix-blend-mode: screen;
}
.glitch::before { color: var(--red); animation: glitch-a 5.5s steps(1) infinite; }
.glitch::after { color: #35f2ff; animation: glitch-b 5.5s steps(1) infinite; }
.glitch:hover::before, .glitch:hover::after { animation-duration: 1.1s; }
@keyframes glitch-a {
  0%, 89%, 100% { opacity: 0; transform: none; clip-path: inset(0 0 0 0); }
  90% { opacity: .95; transform: translate(-6px, 0); clip-path: inset(8% 0 66% 0); }
  92% { opacity: .95; transform: translate(5px, -1px); clip-path: inset(52% 0 22% 0); }
  94% { opacity: .95; transform: translate(-3px, 1px); clip-path: inset(76% 0 4% 0); }
  96% { opacity: .95; transform: translate(4px, 0); clip-path: inset(30% 0 48% 0); }
  97% { opacity: 0; }
}
@keyframes glitch-b {
  0%, 89%, 100% { opacity: 0; transform: none; clip-path: inset(0 0 0 0); }
  90% { opacity: .9; transform: translate(6px, 1px); clip-path: inset(60% 0 12% 0); }
  92% { opacity: .9; transform: translate(-5px, 0); clip-path: inset(14% 0 58% 0); }
  94% { opacity: .9; transform: translate(3px, -1px); clip-path: inset(40% 0 36% 0); }
  96% { opacity: .9; transform: translate(-4px, 0); clip-path: inset(84% 0 0 0); }
  97% { opacity: 0; }
}
.tagline { margin: 18px 0 22px; min-height: 1.7em; font-size: clamp(.9rem, .8rem + .55vw, 1.2rem); color: var(--white); }
.caret {
  display: inline-block;
  width: .62em;
  height: 1.15em;
  margin-left: 3px;
  background: var(--g);
  vertical-align: text-bottom;
  box-shadow: 0 0 10px rgba(192, 132, 252, .7);
  animation: blink 1s steps(2) infinite;
}
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.keys { margin: auto 0 0; padding-top: 22px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-size: .75rem; color: var(--mute); }
.keys kbd + kbd { margin-left: -4px; }

.globe-wrap { position: relative; padding: 0; min-height: 250px; overflow: hidden; }
#globe { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: pan-y; }
#globe.is-dragging { cursor: grabbing; }
.no-gl #globe { display: none; }
.no-gl .globe-wrap::after { content: 'webgl недоступен — глобус отключён'; position: absolute; inset: 0; display: grid; place-items: center; color: var(--mute); font-size: .78rem; }
.globe-tags { position: absolute; inset: 0; pointer-events: none; }
.globe-tags span {
  position: absolute;
  left: 0;
  top: 0;
  padding: 0 5px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, .78);
  color: var(--g);
  font-size: .66rem;
  line-height: 1.5;
  white-space: nowrap;
  will-change: transform;
}
.globe-tags span.is-hq { border-color: var(--g); color: #000; background: var(--g); font-weight: 700; }
.globe-read { position: absolute; left: 12px; bottom: 10px; display: grid; grid-template-columns: auto auto; gap: 0 10px; margin: 0; font-size: .72rem; }
.globe-read dt { color: var(--mute); }
.globe-read dd { margin: 0; color: var(--g); min-width: 5.5em; }

.ident { display: flex; align-items: center; gap: clamp(12px, 2vw, 22px); overflow: hidden; }
.ascii {
  flex: none;
  margin: 0;
  font: 400 6px/1 var(--mono);
  letter-spacing: 0;
  white-space: pre;
  color: var(--g);
  text-shadow: 0 0 6px rgba(192, 132, 252, .55);
  user-select: none;
  -webkit-user-select: none;
}
.ident .kv { flex: 1; min-width: 0; }

.pane-log .pane-body { overflow: hidden; padding: 10px 14px; }
.log { display: flex; flex-direction: column; justify-content: flex-end; height: 100%; min-height: 8.5em; margin: 0; padding: 0; list-style: none; overflow: hidden; font-size: .75rem; line-height: 1.6; }
.log li { flex: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--mute); }
.log time { color: var(--g-dim); margin-right: .6em; }
.log li.is-real { color: var(--ink); }
.log li.is-real::after { content: ' <'; color: var(--g); }

.tele { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 18px; margin: 0; }
.tele div { min-width: 0; }
.tele dt { font-size: .68rem; color: var(--mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tele dd { margin: 0; font: 700 1.2rem/1.25 var(--display); color: var(--white); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.spark { font: 400 .72rem/1 var(--mono); color: var(--g); letter-spacing: -1px; }

/* ---------- 2: manifest ---------- */

.pane-doc .pane-body { padding: clamp(16px, 2.4vw, 30px) clamp(14px, 2.6vw, 34px); }
.pane-doc .doc { max-width: 82ch; }
.hex { margin: 0; font-size: .68rem; line-height: 1.7; color: var(--ink); white-space: pre; overflow-x: auto; }
.hex b { color: var(--g-dim); font-weight: 400; }
.hex i { color: var(--g); font-style: normal; }

/* ---------- 3: operatives ---------- */

.tree { margin: 0; font-size: .8125rem; line-height: 1.75; color: var(--ink); white-space: pre; overflow-x: auto; }
.tree b { color: var(--g); font-weight: 700; }
.tree i { color: var(--mute); font-style: normal; }

/* ---------- 4: uplink ---------- */

.pane-links .pane-body { padding: clamp(16px, 2.2vw, 26px); }
.target-hint { margin: 14px 0 0; font-size: .75rem; color: var(--mute); }
.eof { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 18px; padding: 16px 2px 6px; color: var(--mute); }
.eof img { display: block; filter: drop-shadow(0 0 10px rgba(192, 132, 252, .45)); }
.eof p { flex: 1; margin: 0; min-width: 12em; }

/* ---------- terminal drawer ---------- */

.term {
  position: fixed;
  left: var(--pad);
  right: var(--pad);
  bottom: calc(var(--bar) + 8px);
  z-index: 55;
  height: min(58vh, 500px);
  max-width: 1000px;
  margin: 0 auto;
  background: #08030f;
  box-shadow: 0 0 0 1px var(--g), 0 0 70px rgba(192, 132, 252, .2), 0 30px 90px #000;
  animation: term-in .22s var(--ease);
}
@keyframes term-in { from { opacity: 0; transform: translateY(18px); } }
.term-close { border: 0; background: none; color: var(--mute); font-size: .75rem; cursor: pointer; }
.term-close:hover { color: var(--g); }
.term-out { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 14px; font-size: .8125rem; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.term-out p { margin: 0; }
.term-out .in { color: var(--white); }
.term-out .in::before { content: 'guest@legion:~$ '; color: var(--g); font-weight: 700; }
.term-out a { color: var(--g); }
.term-out b { color: var(--g); }
.term-quick { display: flex; gap: 6px; padding: 6px 14px; overflow-x: auto; border-top: 1px solid var(--line-soft); scrollbar-width: none; }
.term-quick button { flex: none; padding: 3px 9px; border: 1px solid var(--line); background: none; color: var(--g); font-size: .75rem; cursor: pointer; }
.term-quick button:hover { background: var(--g); color: #000; }
.term-in { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-top: 1px solid var(--line); }
.term-in label { flex: none; font-size: .8125rem; }
.term-in input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--white); font: 400 16px/1.4 var(--mono); caret-color: var(--g); }

.noscript { position: relative; z-index: 2; padding: 1rem var(--pad); }

/* ---------- wide screens: tiled layout ---------- */

@media (min-width: 1000px) {
  .title { font-size: clamp(3.4rem, 7.4vw, 8.2rem); }

  .ws-root {
    height: calc(100vh - var(--bar) * 2);
    height: calc(100svh - var(--bar) * 2);
    min-height: 640px;
    grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1.25fr) minmax(0, 1fr) 176px;
    grid-template-areas: 'title globe' 'title ident' 'log stats';
    align-content: stretch;
  }
  .pane-title { grid-area: title; }
  .pane-globe { grid-area: globe; }
  .pane-ident { grid-area: ident; }
  .pane-log { grid-area: log; }
  .pane-stats { grid-area: stats; }
  .pane-stats .pane-body { display: grid; align-content: center; }
  .globe-wrap { min-height: 0; }

  .ws-manifest, .ws-ops, .ws-uplink { grid-template-columns: minmax(0, 1fr) clamp(250px, 24vw, 330px); }
  .ws-manifest { grid-template-areas: 'title title' 'doc stat' 'doc tags' 'doc hex'; grid-template-rows: auto auto auto 1fr; }
  .ws-ops { grid-template-areas: 'title title' 'cards tree'; }
  .ws-uplink { grid-template-areas: 'title title' 'links target' 'eof eof'; }
  .ws-title { grid-area: title; }
  .pane-doc { grid-area: doc; }
  .pane-stat { grid-area: stat; }
  .pane-tags-box { grid-area: tags; }
  .pane-hex { grid-area: hex; align-self: start; }
  .cards { grid-area: cards; }
  .pane-tree { grid-area: tree; align-self: start; }
  .pane-links { grid-area: links; }
  .pane-target { grid-area: target; align-self: start; }
  .eof { grid-area: eof; }
}

@media (max-width: 999px) {
  .globe-wrap { height: 320px; }
  .pane-log .pane-body { height: 150px; }
  .bar-bottom .hint { display: none; }
}
@media (max-width: 700px) {
  .bar { gap: 8px; }
  .bar-id span { display: none; }
  .tabs a { padding: 0 9px; gap: 5px; }
  .bar-top .live { display: none; }
  .tele { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ident { flex-direction: column; align-items: flex-start; }
  .tagline { min-height: 3.4em; margin-bottom: 14px; }      /* room for two lines, so typing never shifts the page */
}
@media (max-width: 520px) {
  .bar-top .bar-meta { display: none; }
  .bar-bottom #bPing { display: none; }
  .term-in label { display: none; }
  .term { height: min(64vh, 520px); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .boot { display: none; }
  .crt::after, .glitch::before, .glitch::after, .caret, .live::before, .term { animation: none; }
  .js .ws .pane, .js .ws .ws-title { transition: none; }
  .js .ws:not(.is-in) .pane, .js .ws:not(.is-in) .ws-title { opacity: 1; transform: none; }
}
