/* Хилл Core War: таблица, матрица, матч, арена, лаборатория (hill.js).
   Арена — тёмная сцена в любой теме сайта: свечение ядра читается только на
   тёмном. Цвета бойцов: A — бирюза, B — оранжевый (различимы и при
   нарушениях цветового зрения чаще, чем пара красный/зелёный). */

:root {
  --hill-a: rgb(46, 230, 214);
  --hill-b: rgb(255, 122, 47);
  --stage: #070b14;
  --stage-2: #0d1322;
  --stage-3: #151d31;
  --stage-ink: #dbe3f2;
  --stage-ink-2: #8d9ab3;
  --stage-line: #222c44;
}

body.hill-wide main { max-width: min(1380px, 100%); }
body.hill-wide .table-wrap { overflow-x: auto; max-width: 100%; }

.hill-title { margin-bottom: 0.3rem; }
.hill-crumbs { font-family: var(--font-mono); font-size: 0.8rem; color: var(--ink-3); margin-bottom: 0.8rem; }
.hill-rules { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; margin: 0.8rem 0 1.2rem; }
.hill-rules .chip { cursor: default; }
.hill-rules .chip:hover { background: var(--bg-elev); color: inherit; }
.hill-meta { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; color: var(--ink-2); }
.hill-in { background: var(--ok-bg); color: var(--ok); }
.hill-ok { color: var(--ok); font-family: var(--font-mono); font-size: 0.85rem; }
.btn.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.btn-primary:hover { filter: brightness(1.08); }

/* ---- король и таблица ---- */
.hill-king {
  position: relative; overflow: hidden;
  margin: 0.4rem 0 1.6rem; padding: 1.2rem 1.4rem 1.3rem;
  border-radius: 10px; color: var(--stage-ink);
  background:
    radial-gradient(120% 140% at 0% 0%, rgba(46, 230, 214, 0.22), transparent 55%),
    radial-gradient(120% 140% at 100% 100%, rgba(255, 122, 47, 0.2), transparent 55%),
    var(--stage);
  border: 1px solid var(--stage-line);
}
.hill-king a { color: inherit; }
.hill-king-label { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.18em; text-transform: uppercase; color: #f5c451; }
.hill-king-name { font-size: clamp(1.6rem, 4vw, 2.4rem); font-weight: 700; margin: 0.15rem 0 0.2rem; letter-spacing: -0.01em; }
.hill-king-meta { color: var(--stage-ink-2); font-family: var(--font-mono); font-size: 0.82rem; margin-bottom: 0.9rem; }
.hill-king .btn { background: rgba(255, 255, 255, 0.06); color: var(--stage-ink); border-color: var(--stage-line); }

.hill-table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
.hill-table th, .hill-table td { padding: 0.35rem 0.55rem; border-bottom: 1px solid var(--line); text-align: left; }
.hill-table th { font-family: var(--font-mono); font-size: 0.72rem; font-weight: 500; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.06em; }
.hill-table .num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--font-mono); }
.hill-table tr.hill-top td { font-weight: 600; }
.hill-table tr.lab-me td { background: var(--ok-bg); font-weight: 600; }
.hill-table tr.lab-out td { opacity: 0.55; text-decoration: line-through; }

/* ---- матрица ---- */
.mx-wrap { overflow-x: auto; padding-bottom: 0.4rem; }
.mx {
  display: grid; gap: 2px; align-items: stretch;
  grid-template-columns: minmax(9rem, 13rem) repeat(var(--n), minmax(18px, 30px));
  min-width: calc(10rem + var(--n) * 20px);
  font-family: var(--font-mono); font-size: 0.72rem;
}
.mx-corner, .mx-col { color: var(--ink-3); text-align: center; align-self: end; }
.mx-row { color: var(--ink); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 0.3rem; align-self: center; }
.mx-row:hover { color: var(--accent); }
.mx-place { color: var(--ink-3); display: inline-block; min-width: 1.6em; text-align: right; }
.mx-cell, .mx-self, .mx-none { aspect-ratio: 1; border-radius: 3px; min-height: 18px; }
.mx-cell { display: block; transition: transform var(--duration), box-shadow var(--duration); }
.mx-cell:hover, .mx-cell:focus-visible { transform: scale(1.35); box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--ink); position: relative; z-index: 1; }
.mx-self { background: repeating-linear-gradient(45deg, var(--line), var(--line) 2px, transparent 2px, transparent 5px); }
.mx-none { background: var(--bg-elev); }

.hill-free { display: flex; flex-wrap: wrap; gap: 0.5rem 0.8rem; align-items: center; margin-bottom: 1rem; }
.hill-free select, .hill-free input { font: inherit; padding: 0.3rem 0.4rem; border: 1px solid var(--line); border-radius: 5px; background: var(--bg-elev); color: var(--ink); max-width: 100%; }
.hill-free label { display: inline-flex; gap: 0.35rem; align-items: center; max-width: 100%; min-width: 0; }
.hill-free select { min-width: 0; width: 22rem; max-width: 100%; flex: 1 1 auto; }
.hill-free input[type=number] { width: 5.5em; }
.hill-free input[type=text] { width: 9em; }
.hill-free .muted { flex-basis: 100%; margin: 0; font-size: 0.85rem; }
.hill-vs { font-family: var(--font-mono); color: var(--ink-3); }
.hill-archive { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.hill-chip { text-decoration: none; }
.hill-gone { opacity: 0.6; }
.hill-seasons li { margin: 0.3rem 0; }
.hill-listing, .hill-source { font-family: var(--font-mono); font-size: 0.8rem; background: var(--bg-elev); border: 1px solid var(--line); border-radius: 6px; padding: 0.7rem 0.9rem; overflow-x: auto; line-height: 1.45; }

/* ---- матч ---- */
.hill-duel {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 1rem; align-items: end;
  padding: 1.2rem 1.4rem; margin: 0.6rem 0 0.8rem; border-radius: 10px;
  background: var(--stage); color: var(--stage-ink); border: 1px solid var(--stage-line);
}
.hill-duel a { color: inherit; }
.duel-side { min-width: 0; }
.duel-1 { text-align: right; }
.duel-mid { text-align: center; }
.duel-big { font-family: var(--font-mono); font-size: clamp(2rem, 6vw, 3.4rem); font-weight: 700; line-height: 1.05; font-variant-numeric: tabular-nums; }
.duel-0 .duel-big { color: var(--hill-a); text-shadow: 0 0 18px rgba(46, 230, 214, 0.45); }
.duel-1 .duel-big { color: var(--hill-b); text-shadow: 0 0 18px rgba(255, 122, 47, 0.45); }
.duel-author, .hill-duel .quiet { color: var(--stage-ink-2); font-size: 0.82rem; }
.hill-who { font-weight: 700; font-size: 1.1rem; overflow-wrap: anywhere; }
.hill-who-0 a { color: var(--hill-a); }
.hill-who-1 a { color: var(--hill-b); }
.duel-side .hill-who-0 a, .duel-side .hill-who-1 a { color: var(--stage-ink); }

.rounds-strip {
  display: flex; align-items: flex-end; gap: 1px; height: 120px;
  padding: 6px; border-radius: 8px; background: var(--stage); border: 1px solid var(--stage-line);
}
.rounds-strip .rb { flex: 1 1 0; min-width: 0; border-radius: 1px 1px 0 0; opacity: 0.85; transition: opacity var(--duration); }
.rounds-strip .rb:hover, .rounds-strip .rb:focus-visible { opacity: 1; outline: 1px solid #fff; }
.rb-0 { background: var(--hill-a); }
.rb-1 { background: var(--hill-b); }
.rb-t { background: #5b6478; }
.rounds-mini { height: 46px; margin-top: 0.5rem; }
.rounds-mini .rb { opacity: 0.55; }
.rounds-mini .rb-now { opacity: 1; box-shadow: 0 0 0 1px #fff, 0 0 10px #fff; }
.hill-highlights { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.8rem; }

/* ---- арена ---- */
.arena {
  --a: var(--hill-a); --b: var(--hill-b);
  background:
    radial-gradient(80% 60% at 0% 0%, rgba(46, 230, 214, 0.08), transparent 60%),
    radial-gradient(80% 60% at 100% 0%, rgba(255, 122, 47, 0.08), transparent 60%),
    var(--stage);
  color: var(--stage-ink); border: 1px solid var(--stage-line); border-radius: 12px;
  padding: 1rem clamp(0.6rem, 2vw, 1.2rem) 0.8rem; margin-top: 0.4rem;
}
.arena a { color: inherit; }
.arena .btn { background: var(--stage-3); color: var(--stage-ink); border-color: var(--stage-line); }
.arena .btn:hover { border-color: #56627f; }
.arena-top { display: grid; grid-template-columns: 1fr auto 1fr; gap: 0.8rem; align-items: start; }
.fighter { min-width: 0; padding: 0.55rem 0.8rem; border-radius: 8px; background: var(--stage-2); border: 1px solid var(--stage-line); transition: opacity 400ms, filter 400ms; }
.fighter.f0 { border-left: 3px solid var(--a); box-shadow: inset 12px 0 24px -18px var(--a); }
.fighter.f1 { border-right: 3px solid var(--b); text-align: right; box-shadow: inset -12px 0 24px -18px var(--b); }
.fighter.f-dead { opacity: 0.45; filter: grayscale(0.8); }
.f-name { font-weight: 700; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.f-letter { display: inline-block; min-width: 1.4em; padding: 0 0.3em; border-radius: 4px; text-align: center; font-family: var(--font-mono); font-size: 0.8rem; color: #041016; }
.f0 .f-letter { background: var(--a); }
.f1 .f-letter { background: var(--b); }
.f-author { color: var(--stage-ink-2); font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.f-stats { margin-top: 0.25rem; }
.f-procs { font-family: var(--font-mono); font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.f0 .f-procs { color: var(--a); text-shadow: 0 0 14px rgba(46, 230, 214, 0.55); }
.f1 .f-procs { color: var(--b); text-shadow: 0 0 14px rgba(255, 122, 47, 0.55); }
.f-label, .f-note { color: var(--stage-ink-2); font-size: 0.78rem; }
.arena-clock { text-align: center; font-family: var(--font-mono); padding-top: 0.1rem; }
.clock-round { font-size: 0.72rem; letter-spacing: 0.16em; text-transform: uppercase; color: #f5c451; }
.clock-cycle { font-size: clamp(1.7rem, 4.5vw, 2.6rem); font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.clock-of, .clock-sub { font-size: 0.72rem; color: var(--stage-ink-2); }

.tug { display: flex; height: 6px; margin: 0.7rem 0 0.8rem; border-radius: 3px; overflow: hidden; background: #1c2437; }
.tug-a { background: var(--a); box-shadow: 0 0 10px var(--a); transition: width 120ms linear; }
.tug-b { background: var(--b); box-shadow: 0 0 10px var(--b); margin-left: auto; transition: width 120ms linear; }

.arena-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(17rem, 23rem); gap: 1rem; align-items: start; }
.board-col { min-width: 0; }
.board-wrap { position: relative; line-height: 0; width: max-content; max-width: 100%; }
.board { display: block; border-radius: 4px; box-shadow: 0 0 0 1px var(--stage-line), 0 10px 40px rgba(0, 0, 0, 0.55); cursor: crosshair; touch-action: manipulation; }
.board-tip {
  position: absolute; z-index: 2; pointer-events: none; line-height: 1.3; white-space: nowrap;
  font-family: var(--font-mono); font-size: 0.75rem; padding: 0.2rem 0.45rem; border-radius: 4px;
  background: rgba(7, 11, 20, 0.92); border: 1px solid var(--stage-line); color: var(--stage-ink);
}
.board-banner {
  position: absolute; inset: 0; z-index: 3; line-height: 1.25;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.35rem;
  text-align: center; padding: 1rem; pointer-events: none;
}
.board-banner[hidden] { display: none; }
.banner-big { font-size: clamp(1.6rem, 5vw, 3.2rem); font-weight: 800; letter-spacing: -0.01em; text-shadow: 0 0 24px rgba(0, 0, 0, 0.9), 0 0 2px #000; }
.banner-sub { font-family: var(--font-mono); font-size: 0.85rem; color: var(--stage-ink-2); text-shadow: 0 0 8px #000; }
.banner-intro { background: radial-gradient(closest-side, rgba(7, 11, 20, 0.75), transparent); animation: hill-intro 1.4s ease-out forwards; }
.banner-intro .banner-big { color: #f5c451; }
.banner-end { background: rgba(4, 7, 14, 0.62); pointer-events: auto; animation: hill-fade 700ms ease-out both; }
.banner-w0 .banner-big { color: var(--a); text-shadow: 0 0 30px rgba(46, 230, 214, 0.8), 0 0 2px #000; }
.banner-w1 .banner-big { color: var(--b); text-shadow: 0 0 30px rgba(255, 122, 47, 0.8), 0 0 2px #000; }
.banner-tie .banner-big { color: #c8d0e0; }
.banner-cause { max-width: 38rem; font-size: 0.9rem; color: var(--stage-ink); text-shadow: 0 0 6px #000; }
.banner-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.4rem; margin-top: 0.4rem; }
@keyframes hill-intro {
  0% { opacity: 0; transform: scale(1.25); }
  18% { opacity: 1; transform: scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; }
}
@keyframes hill-fade { from { opacity: 0; } to { opacity: 1; } }

.timeline { display: block; margin-top: 0.55rem; border-radius: 4px; cursor: ew-resize; touch-action: none; box-shadow: 0 0 0 1px var(--stage-line); }
.arena-controls { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: center; margin-top: 0.6rem; font-size: 0.85rem; }
.ctl-group { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.arena-controls .btn-small { min-width: 2.3rem; }
.arena-controls select { font: inherit; background: var(--stage-3); color: var(--stage-ink); border: 1px solid var(--stage-line); border-radius: 5px; padding: 0.25rem 0.35rem; }
.arena-controls input[type=range] { width: 8.5rem; accent-color: #f5c451; vertical-align: middle; }
.speed-label { font-family: var(--font-mono); font-size: 0.78rem; color: var(--stage-ink-2); min-width: 7.5em; }
.hill-toggle { color: var(--stage-ink-2); white-space: nowrap; }
.hill-toggle input { accent-color: #f5c451; }

.arena-side { display: flex; flex-direction: column; gap: 0.7rem; min-width: 0; }
.ip-pane, .inspector, .pspace { background: var(--stage-2); border: 1px solid var(--stage-line); border-radius: 8px; padding: 0.5rem 0.6rem; }
.ip-pane.p0 { border-top: 2px solid var(--a); }
.ip-pane.p1 { border-top: 2px solid var(--b); }
.ip-dead { opacity: 0.5; }
.ip-title { font-family: var(--font-mono); font-size: 0.72rem; color: var(--stage-ink-2); margin-bottom: 0.3rem; }
.ip-list { font-family: var(--font-mono); font-size: 0.76rem; line-height: 1.5; }
.ip-line { display: grid; grid-template-columns: 4.6em 3.4em 1fr; gap: 0.3em; padding: 0 0.3em; border-radius: 3px; border-left: 2px solid transparent; white-space: nowrap; }
.ip-line.own-0 { border-left-color: var(--a); }
.ip-line.own-1 { border-left-color: var(--b); }
.ip-line.ip-focus { background: rgba(255, 255, 255, 0.1); }
.p0 .ip-line.ip-focus { background: rgba(46, 230, 214, 0.16); }
.p1 .ip-line.ip-focus { background: rgba(255, 122, 47, 0.16); }
.ip-line.ip-wrote .ip-text { color: #fff; text-shadow: 0 0 8px #fff; }
.ip-mark { color: #f5c451; overflow: hidden; text-overflow: ellipsis; }
.ip-addr { color: var(--stage-ink-2); }
.ip-text { overflow: hidden; text-overflow: ellipsis; }
.ip-next { font-family: var(--font-mono); font-size: 0.7rem; color: var(--stage-ink-2); margin-top: 0.3rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inspector .muted { color: var(--stage-ink-2); font-size: 0.8rem; margin: 0; }
.insp-text { font-family: var(--font-mono); font-size: 1.05rem; font-weight: 700; margin: 0.1rem 0 0.3rem; }
.insp-facts { list-style: none; margin: 0 0 0.4rem; padding: 0; font-size: 0.8rem; color: var(--stage-ink-2); }
.dot { display: inline-block; width: 0.65em; height: 0.65em; border-radius: 50%; }
.dot-0 { background: var(--a); }
.dot-1 { background: var(--b); }
.pspace summary { cursor: pointer; font-size: 0.8rem; color: var(--stage-ink-2); }
.ps { font-size: 0.8rem; margin-top: 0.35rem; }
.ps-cells { font-family: var(--font-mono); font-size: 0.72rem; color: var(--stage-ink-2); overflow-wrap: anywhere; }
.ps-0 strong { color: var(--a); }
.ps-1 strong { color: var(--b); }

.arena-nav { margin-top: 0.9rem; }
.arena-nav-row { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; font-size: 0.85rem; flex-wrap: wrap; }
.arena-keys { font-size: 0.72rem; color: var(--stage-ink-2); margin: 0.7rem 0 0; }

/* ---- лаборатория ---- */
.lab-src { width: 100%; font-family: var(--font-mono); font-size: 0.85rem; line-height: 1.45; padding: 0.7rem; border: 1px solid var(--line); border-radius: 6px; background: var(--bg-elev); color: var(--ink); resize: vertical; }
.lab-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.6rem 0 1rem; }
.lab-errors { font-family: var(--font-mono); font-size: 0.85rem; }
.lab-big { font-size: 1.15rem; font-weight: 600; font-family: var(--font-ui); }
.lab-run progress { width: min(20rem, 60%); vertical-align: middle; }

/* ---- карточка в треде машины ---- */
.hill-card {
  margin: 1.2rem 0 1.6rem; padding: 1rem 1.2rem 1.1rem; border-radius: 10px;
  color: var(--stage-ink); border: 1px solid var(--stage-line);
  background:
    radial-gradient(90% 120% at 0% 0%, rgba(46, 230, 214, 0.16), transparent 60%),
    radial-gradient(90% 120% at 100% 100%, rgba(255, 122, 47, 0.16), transparent 60%),
    var(--stage);
}
.hill-card[hidden] { display: none; }
.hill-card a { color: inherit; }
.hill-card h3 { margin: 0.1rem 0 0.4rem; font-size: 1.25rem; }
.hill-card p { color: var(--stage-ink-2); font-size: 0.9rem; margin: 0 0 0.6rem; }
.hill-card-kicker { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; color: #f5c451; }
.hill-card-top { margin: 0 0 0.8rem; padding-left: 1.4rem; font-size: 0.9rem; }
.hill-card-top .quiet { color: var(--stage-ink-2); }
.hill-card-actions { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.hill-card p.hill-card-past { margin: 0.7rem 0 0; font-size: 0.82rem; }
.hill-card-live { margin: 0.2rem 0 0.9rem; }
.hill-card-live .status { color: var(--stage-ink-2); }
.arena-compact { margin: 0; padding: 0.6rem; border-radius: 8px; }
.arena-compact .fighter { padding: 0.35rem 0.55rem; }
.arena-compact .f-procs { font-size: 1.25rem; }
.arena-compact .f-name { font-size: 0.92rem; }
.arena-compact .clock-cycle { font-size: 1.5rem; }
.arena-compact .tug { margin: 0.45rem 0 0.55rem; }
.arena-compact .board { cursor: pointer; }
.arena-compact .board-wrap { margin: 0 auto; }
.arena-compact .banner-big { font-size: clamp(1.2rem, 4vw, 2rem); }
.arena-compact .banner-cause { font-size: 0.8rem; }
.hill-card .btn { background: rgba(255, 255, 255, 0.06); color: var(--stage-ink); border-color: var(--stage-line); }
.hill-card .btn.btn-primary { background: #f5c451; color: #1b1405; border-color: #f5c451; }

@media (max-width: 900px) {
  .arena-body { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 600px) {
  .arena-top { grid-template-columns: 1fr 1fr; }
  .arena-clock { grid-column: 1 / -1; grid-row: 1; }
  .f-procs { font-size: 1.3rem; }
  .hill-duel { grid-template-columns: 1fr 1fr; }
  .duel-mid { grid-column: 1 / -1; grid-row: 2; }
  .arena-controls input[type=range] { width: 6.5rem; }
  .rounds-strip { gap: 0; padding: 4px; }
}
@media (prefers-reduced-motion: reduce) {
  .banner-intro, .banner-end { animation: none; }
  .tug-a, .tug-b, .mx-cell { transition: none; }
}
