:root {
  color-scheme: dark;
  --bg: #050607;
  --panel: #101315;
  --panel-2: #171b1e;
  --line: #b72a2a;
  --line-soft: rgba(183, 42, 42, 0.35);
  --amber: #e7b94d;
  --cyan: #51d6d6;
  --text: #f0f2ea;
  --muted: #9aa29a;
  --danger: #ff3030;
  --ok: #62d484;
  font-family: "Bahnschrift", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    linear-gradient(135deg, rgba(183, 42, 42, 0.16) 0 1px, transparent 1px 48px),
    radial-gradient(circle at 50% 12%, rgba(231, 185, 77, 0.08), transparent 34%),
    var(--bg);
  color: var(--text);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(255,255,255,0.035) 0 1px, transparent 1px 5px);
  mix-blend-mode: screen;
  opacity: 0.35;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(255, 48, 48, 0.18), transparent 18%, transparent 82%, rgba(255, 48, 48, 0.18)),
    radial-gradient(circle at 50% 50%, transparent 34%, rgba(255, 48, 48, 0.18));
  opacity: 0;
}

body[data-condition="alert"]::after {
  animation: alertWash 0.82s steps(2, end) infinite;
}

.shell {
  height: 100vh;
  min-height: 640px;
  padding: 8px;
}

.command {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  max-width: 1440px;
  height: 100%;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid var(--line);
  background: rgba(5, 6, 7, 0.86);
  box-shadow: 0 0 0 6px rgba(183, 42, 42, 0.08), inset 0 0 45px rgba(183, 42, 42, 0.12);
}

body[data-condition="alert"] .command {
  animation: alertFrame 0.82s steps(2, end) infinite;
}

.topbar,
.alert-panel,
.grid-main,
.lower-grid {
  border-bottom: 1px solid var(--line-soft);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 10px clamp(12px, 1.8vw, 20px);
  align-items: center;
  background: linear-gradient(90deg, rgba(183, 42, 42, 0.18), transparent 55%);
}

.eyebrow,
.alert-code span,
.threat-head span,
.module h2,
.field span,
.evidence span,
.signal-tile span {
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 2px 0 0;
  font-size: clamp(1.6rem, 3.6vw, 3.4rem);
  line-height: 0.95;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.status-lock {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: max-content;
  color: var(--cyan);
  font-weight: 700;
}

.pulse {
  width: 12px;
  height: 12px;
  background: var(--danger);
  box-shadow: 0 0 16px var(--danger);
  animation: pulse 1.2s infinite;
}

body[data-condition="alert"] .pulse {
  width: 16px;
  height: 16px;
  animation: alertBeacon 0.52s steps(2, end) infinite;
}

.alert-panel {
  display: grid;
  grid-template-columns: minmax(230px, 0.42fr) minmax(0, 1fr);
  gap: 8px 16px;
  padding: 10px clamp(12px, 1.8vw, 20px);
  align-items: center;
}

.alert-code {
  border-left: 8px solid var(--line);
  padding-left: 10px;
}

.alert-code strong {
  display: block;
  color: var(--amber);
  font-size: clamp(1.6rem, 3.5vw, 3.25rem);
  line-height: 0.95;
  max-width: 100%;
}

body[data-condition="alert"] .alert-code strong,
body[data-condition="alert"] .threat-head strong {
  color: #fff;
  text-shadow: 0 0 12px var(--danger), 0 0 28px var(--danger);
  animation: alertTextPulse 0.82s steps(2, end) infinite;
}

.threat-block {
  display: grid;
  min-width: 0;
  gap: 6px;
}

.threat-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: baseline;
}

.threat-head strong {
  color: var(--amber);
  font-size: 1.45rem;
  line-height: 1;
}

.threat-meter {
  height: 14px;
  background: #23282a;
  border: 1px solid var(--line-soft);
  overflow: hidden;
}

body[data-condition="alert"] .threat-meter,
body[data-condition="alert"] .alert-panel,
body[data-condition="alert"] .signal-tile {
  border-color: rgba(255, 48, 48, 0.82);
  box-shadow: inset 0 0 18px rgba(255, 48, 48, 0.18);
}

#threatFill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--ok), var(--amber), var(--danger));
  transition: width 400ms ease;
}

.score-scale {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
}

.score-scale span {
  min-width: 0;
  border-top: 2px solid rgba(255,255,255,0.16);
  color: var(--muted);
  font-size: 0.74rem;
  padding-top: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.score-scale span:nth-child(1) {
  border-color: var(--ok);
}

.score-scale span:nth-child(2) {
  border-color: var(--amber);
}

.score-scale span:nth-child(3),
.score-scale span:nth-child(4) {
  border-color: var(--danger);
}

#alertText {
  grid-column: 2;
  margin: -4px 0 0;
  font-size: 0.92rem;
  color: var(--text);
}

.signal-strip {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.signal-tile {
  min-width: 0;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.035);
  padding: 7px 9px;
}

.signal-tile strong {
  display: block;
  margin-top: 3px;
  color: var(--text);
  font-size: 1.18rem;
  line-height: 1;
}

.signal-tile i {
  display: block;
  width: 0;
  height: 4px;
  margin-top: 6px;
  background: linear-gradient(90deg, var(--ok), var(--amber), var(--danger));
  transition: width 400ms ease;
}

.grid-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
  min-height: 0;
}

.radar-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(rgba(81, 214, 214, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(81, 214, 214, 0.08) 1px, transparent 1px),
    #080b0c;
  background-size: 44px 44px;
}

canvas {
  width: 100%;
  height: 100%;
  min-height: inherit;
  display: block;
}

.radar-label {
  position: absolute;
  color: var(--cyan);
  font-weight: 900;
  opacity: 0.72;
}

.north { top: 16px; left: 50%; }
.south { bottom: 16px; left: 50%; }
.west { left: 18px; top: 50%; }
.east { right: 18px; top: 50%; }

.side-stack {
  display: grid;
  align-content: start;
  border-left: 1px solid var(--line-soft);
}

.module {
  padding: 10px 12px;
  background: linear-gradient(180deg, rgba(255,255,255,0.035), transparent);
  border-bottom: 1px solid var(--line-soft);
}

.module h2 {
  color: var(--text);
  font-size: 0.92rem;
  margin-bottom: 6px;
}

.evidence {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  padding: 7px 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.evidence strong {
  color: var(--amber);
  font-size: 1.28rem;
  line-height: 1;
}

.evidence p {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--text);
  font-size: 0.8rem;
  line-height: 1.35;
}

.toggle,
.field {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.toggle {
  grid-template-columns: 20px 1fr;
  align-items: center;
  color: var(--text);
}

input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line-soft);
  background: #070909;
  color: var(--text);
  padding: 11px 12px;
  font: inherit;
}

select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line-soft);
  background: #070909;
  color: var(--text);
  padding: 11px 12px;
  font: inherit;
}

input[type="checkbox"] {
  accent-color: var(--danger);
}

button {
  width: 100%;
  border: 1px solid var(--danger);
  background: var(--danger);
  color: #fff;
  padding: 12px 14px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.scan-button {
  width: auto;
  min-width: 100px;
  padding: 7px 11px;
  font-size: 0.8rem;
  line-height: 1;
  white-space: nowrap;
}

button:hover {
  filter: brightness(1.12);
}

.secondary-button {
  margin-top: 8px;
  border-color: var(--cyan);
  background: transparent;
  color: var(--cyan);
}

button:disabled {
  cursor: wait;
  filter: grayscale(0.45) brightness(0.72);
}

.source-health {
  display: grid;
  gap: 8px;
  margin: 16px 0 0;
}

.source-health div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 8px;
}

.source-health dt,
.source-health dd {
  margin: 0;
  font-size: 0.82rem;
}

.source-health dt {
  color: var(--muted);
}

.source-health dd {
  color: var(--cyan);
  text-align: right;
  overflow-wrap: anywhere;
}

.lower-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(260px, 0.8fr);
  max-height: 104px;
  overflow: hidden;
}

.log ol {
  margin: 0;
  padding-left: 22px;
  color: var(--text);
  max-height: 62px;
  overflow: hidden;
}

.log li {
  padding: 2px 0;
  font-size: 0.82rem;
}

.doctrine p {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
}

@media (max-width: 1120px) {
  .grid-main {
    grid-template-columns: 1fr;
  }

  .side-stack {
    grid-template-columns: 1fr;
    border-left: 0;
    border-top: 1px solid var(--line-soft);
  }

  .side-stack .module {
    border-right: 0;
  }

  .side-stack .module:last-child {
    border-right: 0;
  }
}

@keyframes pulse {
  0%, 100% { opacity: 0.35; transform: scale(0.82); }
  50% { opacity: 1; transform: scale(1.12); }
}

@keyframes alertWash {
  0%, 100% { opacity: 0.1; }
  50% { opacity: 0.62; }
}

@keyframes alertFrame {
  0%, 100% {
    border-color: rgba(255, 48, 48, 0.7);
    box-shadow:
      0 0 0 6px rgba(255, 48, 48, 0.12),
      0 0 42px rgba(255, 48, 48, 0.18),
      inset 0 0 45px rgba(255, 48, 48, 0.14);
  }
  50% {
    border-color: #ff3030;
    box-shadow:
      0 0 0 10px rgba(255, 48, 48, 0.28),
      0 0 80px rgba(255, 48, 48, 0.42),
      inset 0 0 70px rgba(255, 48, 48, 0.26);
  }
}

@keyframes alertBeacon {
  0%, 100% {
    opacity: 0.38;
    transform: scale(0.82);
    box-shadow: 0 0 14px var(--danger);
  }
  50% {
    opacity: 1;
    transform: scale(1.22);
    box-shadow: 0 0 32px var(--danger), 0 0 56px var(--danger);
  }
}

@keyframes alertTextPulse {
  0%, 100% { opacity: 0.72; }
  50% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  body[data-condition="alert"]::after,
  body[data-condition="alert"] .command,
  body[data-condition="alert"] .pulse,
  body[data-condition="alert"] .alert-code strong,
  body[data-condition="alert"] .threat-head strong {
    animation: none;
  }

  body[data-condition="alert"]::after {
    opacity: 0.24;
  }
}

@media (max-width: 860px) {
  .shell {
    height: auto;
    min-height: 100vh;
    padding: 8px;
  }

  .command {
    height: auto;
    min-height: calc(100vh - 16px);
    grid-template-rows: auto;
  }

  .topbar,
  .alert-panel,
  .grid-main,
  .lower-grid {
    display: grid;
    grid-template-columns: 1fr;
    max-height: none;
  }

  .topbar {
    align-items: start;
    padding: 12px;
  }

  .status-lock {
    justify-self: start;
    flex-wrap: wrap;
  }

  .alert-panel {
    padding: 12px;
    gap: 12px;
  }

  .alert-code {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px 12px;
    align-items: end;
  }

  .alert-code strong {
    font-size: clamp(2rem, 15vw, 3.8rem);
  }

  #alertText {
    grid-column: auto;
    margin-top: 0;
    line-height: 1.7;
  }

  .score-scale {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .signal-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .signal-tile {
    padding: 10px;
  }

  .side-stack {
    grid-template-columns: 1fr;
    border-left: 0;
  }

  .side-stack .module {
    border-right: 0;
  }

  .radar-stage {
    min-height: clamp(300px, 70vw, 410px);
  }

  .log ol {
    max-height: none;
  }

  .module {
    padding: 12px;
  }
}

@media (max-width: 460px) {
  .topbar {
    gap: 12px;
  }

  .eyebrow {
    font-size: 0.68rem;
  }

  .scan-button {
    min-width: 96px;
    padding: 8px 10px;
  }

  .alert-code {
    grid-template-columns: 1fr;
  }

  .threat-head {
    gap: 10px;
  }

  .score-scale,
  .signal-strip {
    grid-template-columns: 1fr;
  }

  .score-scale span {
    white-space: normal;
  }

  .lower-grid {
    border-bottom: 0;
  }
}
