:root {
  color-scheme: dark;
  --bg: oklch(0.105 0.012 25);
  --surface: oklch(0.15 0.021 25);
  --surface-raised: oklch(0.195 0.032 25);
  --ink: oklch(0.95 0.012 25);
  --muted: oklch(0.7 0.025 25);
  --line: oklch(0.34 0.055 25);
  --primary: oklch(0.68 0.215 25);
  --primary-deep: oklch(0.43 0.145 25);
  --accent: oklch(0.64 0.235 25);
  --accent-dark: oklch(0.45 0.18 25);
  --signal: oklch(0.76 0.15 158);
  --warning: oklch(0.79 0.15 83);
  --focus: oklch(0.8 0.16 25);
  --z-dialog: 30;
  --z-toast: 40;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 22% 4%, color-mix(in oklch, var(--primary-deep) 42%, transparent), transparent 34rem),
    radial-gradient(circle at 92% 58%, color-mix(in oklch, var(--accent-dark) 20%, transparent), transparent 30rem),
    linear-gradient(132deg, var(--bg) 0 58%, color-mix(in oklch, var(--surface) 78%, var(--bg)) 100%);
  color: var(--ink);
  font-family: "Bahnschrift", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
}

button,
dialog {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 4px;
}

.ambient {
  position: fixed;
  pointer-events: none;
  opacity: 0.12;
  filter: blur(1px);
}

.ambient-a {
  width: 30rem;
  height: 1px;
  top: 18%;
  right: -7rem;
  background: var(--primary);
  transform: rotate(-36deg);
  box-shadow: 0 22px 0 var(--primary), 0 44px 0 var(--primary);
}

.ambient-b {
  width: 18rem;
  height: 18rem;
  bottom: -11rem;
  left: 8%;
  border: 1px solid var(--accent);
  transform: rotate(28deg);
}

.topbar,
.command-grid,
.footer {
  width: min(1440px, calc(100% - 48px));
  margin-inline: auto;
}

.topbar {
  min-height: 92px;
  display: flex;
  align-items: center;
  gap: 24px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 13px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  position: relative;
  width: 38px;
  height: 32px;
  display: inline-block;
}

.brand-mark i {
  position: absolute;
  top: 0;
  width: 18px;
  height: 30px;
  background: var(--accent);
  clip-path: polygon(0 0, 100% 0, 50% 100%, 0 68%);
}

.brand-mark i:first-child {
  left: 0;
}

.brand-mark i:last-child {
  right: 0;
  transform: scaleX(-1);
}

.brand-copy {
  display: grid;
  gap: 3px;
}

.brand-copy strong {
  font-size: 16px;
  letter-spacing: 0.06em;
}

.brand-copy small,
.system-state,
.protocol-id,
.stage-index,
.stage-mode,
.weapon-category,
.mission-code,
.threat-level,
.footer {
  font-family: "DIN Condensed", "Bahnschrift Condensed", "Aptos Narrow", sans-serif;
  letter-spacing: 0.14em;
}

.brand-copy small {
  color: var(--muted);
  font-size: 10px;
}

.system-state {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  color: var(--muted);
  font-size: 11px;
}

.online-dot {
  width: 7px;
  height: 7px;
  background: var(--signal);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  box-shadow: 0 0 8px var(--signal);
}

.system-clock {
  min-width: 62px;
  color: var(--ink);
}

.icon-button,
.dialog-close {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  transition: background 180ms ease, border-color 180ms ease;
}

.icon-button:hover,
.dialog-close:hover {
  border-color: var(--primary);
  background: color-mix(in oklch, var(--primary) 10%, transparent);
}

.icon-button svg,
.secondary-button svg,
.draw-button svg {
  width: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
}

.sound-off,
.icon-button[aria-pressed="false"] .sound-on {
  display: none;
}

.icon-button[aria-pressed="false"] .sound-off {
  display: block;
}

.command-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.72fr) minmax(340px, 0.78fr);
  gap: 1px;
  padding-block: 28px;
}

.draw-console,
.mission-panel {
  min-width: 0;
  background: color-mix(in oklch, var(--surface) 93%, transparent);
}

.draw-console {
  padding: clamp(24px, 3vw, 44px);
}

.mission-panel {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-left-width: 0;
}

.console-head,
.mission-head,
.dialog-head,
.history-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.protocol-id {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 10px;
}

h1,
h2,
h3,
p {
  text-wrap: pretty;
}

h1,
.mission-head h2,
.dialog-head h2 {
  margin: 0;
  text-wrap: balance;
}

h1 {
  font-size: clamp(22px, 2.3vw, 34px);
  font-weight: 650;
  letter-spacing: -0.025em;
}

.lock-state {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: max-content;
  color: var(--muted);
  font-size: 12px;
}

.lock-state span {
  width: 8px;
  height: 8px;
  border: 1px solid currentColor;
}

.lock-state.scanning {
  color: var(--warning);
}

.lock-state.scanning span {
  animation: state-pulse 680ms ease infinite alternate;
}

.lock-state.locked {
  color: var(--primary);
}

.lock-state.locked span {
  background: currentColor;
  box-shadow: 0 0 8px currentColor;
}

.weapon-stage {
  position: relative;
  min-height: 440px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin: 28px 0 30px;
  padding: 48px clamp(24px, 5vw, 76px) 38px;
  overflow: hidden;
  background:
    linear-gradient(115deg, transparent 0 20%, color-mix(in oklch, var(--primary) 4%, transparent) 20% 48%, transparent 48%),
    color-mix(in oklch, var(--bg) 75%, var(--surface));
  border: 1px solid var(--line);
}

.weapon-stage::before,
.weapon-stage::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.weapon-stage::before {
  inset: 50% auto auto 50%;
  width: 260px;
  height: 260px;
  border: 1px solid color-mix(in oklch, var(--primary) 20%, transparent);
  border-radius: 50%;
  transform: translate(-50%, -57%);
}

.weapon-stage::after {
  inset: 0;
  background: linear-gradient(90deg, transparent 49.8%, color-mix(in oklch, var(--primary) 16%, transparent) 50%, transparent 50.2%);
}

.bracket {
  position: absolute;
  z-index: 2;
  width: 32px;
  height: 32px;
  border-color: var(--primary);
  border-style: solid;
  opacity: 0.72;
}

.bracket-tl { top: 18px; left: 18px; border-width: 1px 0 0 1px; }
.bracket-tr { top: 18px; right: 18px; border-width: 1px 1px 0 0; }
.bracket-bl { bottom: 18px; left: 18px; border-width: 0 0 1px 1px; }
.bracket-br { right: 18px; bottom: 18px; border-width: 0 1px 1px 0; }

.scan-beam {
  position: absolute;
  z-index: 4;
  inset: 0 auto 0 -10%;
  width: 4px;
  opacity: 0;
  background: var(--primary);
  box-shadow: 0 0 20px var(--primary), 0 0 50px var(--primary);
}

.weapon-stage.scanning .scan-beam {
  opacity: 0.72;
  animation: scan 640ms linear infinite;
}

.stage-index,
.stage-mode {
  position: absolute;
  z-index: 3;
  top: 20px;
  color: var(--muted);
  font-size: 10px;
}

.stage-index { left: 24px; }
.stage-mode { right: 24px; }

.weapon-visual {
  position: relative;
  z-index: 3;
  min-height: 196px;
  display: grid;
  place-items: center;
}

.weapon-glow {
  position: absolute;
  width: min(68%, 460px);
  height: 62%;
  border-radius: 50%;
  background: color-mix(in oklch, var(--primary) 15%, transparent);
  filter: blur(44px);
  opacity: 0.3;
}

.weapon-visual img {
  position: relative;
  width: min(78%, 500px);
  max-height: 196px;
  object-fit: contain;
  filter: drop-shadow(0 4px 2px color-mix(in oklch, var(--bg) 72%, transparent));
  transition: filter 200ms ease;
  user-select: none;
}

.weapon-stage.scanning .weapon-visual img {
  animation: weapon-cycle 110ms steps(2, end) infinite;
  filter: contrast(1.2) drop-shadow(0 0 10px color-mix(in oklch, var(--primary) 34%, transparent));
}

.weapon-stage.just-locked .weapon-visual img {
  animation: lock-impact 520ms var(--ease-out);
}

.weapon-identity {
  position: relative;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  margin-top: 22px;
  text-align: center;
}

.weapon-identity > p {
  margin: 0;
  color: var(--primary);
  font-size: 12px;
  line-height: 1.6;
  letter-spacing: 0.12em;
}

.weapon-identity h2 {
  width: 100%;
  padding-block: 0.08em 0.1em;
  margin: 0;
  overflow: visible;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  font-size: clamp(48px, 5.1vw, 74px);
  font-weight: 700;
  line-height: 1.16;
  letter-spacing: -0.02em;
}

.weapon-specs {
  display: flex;
  justify-content: center;
  gap: 22px;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.weapon-specs b {
  color: var(--ink);
}

.mode-and-action {
  display: grid;
  grid-template-columns: minmax(280px, 0.94fr) minmax(290px, 1.06fr);
  gap: 18px;
}

.mode-control > span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  padding: 1px;
  background: var(--line);
}

.mode-button {
  min-height: 62px;
  display: grid;
  gap: 3px;
  align-content: center;
  border: 0;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: background 180ms ease, color 180ms ease;
}

.mode-button:hover {
  background: var(--surface-raised);
  color: var(--ink);
}

.mode-button.active {
  background: color-mix(in oklch, var(--primary) 17%, var(--surface));
  color: var(--ink);
}

.mode-button span {
  font-weight: 700;
}

.mode-button small {
  color: currentColor;
  opacity: 0.7;
}

.draw-button {
  align-self: end;
  min-height: 78px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  border: 0;
  background: var(--accent);
  color: var(--ink);
  cursor: pointer;
  clip-path: polygon(0 0, calc(100% - 16px) 0, 100% 16px, 100% 100%, 0 100%);
  transition: background 180ms ease, transform 180ms var(--ease-out);
}

.draw-button:hover {
  background: color-mix(in oklch, var(--accent) 86%, var(--ink));
  transform: translateY(-2px);
}

.draw-button:active {
  transform: translateY(0) scale(0.99);
}

.draw-button.is-scanning {
  background: var(--warning);
  color: var(--bg);
}

.button-key {
  padding: 7px 8px;
  border: 1px solid color-mix(in oklch, currentColor 50%, transparent);
  font-family: "DIN Condensed", "Bahnschrift Condensed", sans-serif;
  font-size: 9px;
  letter-spacing: 0.08em;
}

.button-copy {
  display: grid;
  gap: 2px;
  text-align: left;
}

.button-copy strong {
  font-size: 15px;
}

.button-copy small {
  opacity: 0.78;
  font-size: 11px;
}

.draw-button svg {
  margin-left: auto;
}

.keyboard-hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

kbd {
  padding: 2px 6px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font: inherit;
}

.mission-head {
  padding: 30px 28px 24px;
  border-bottom: 1px solid var(--line);
}

.mission-head h2,
.dialog-head h2 {
  font-size: 22px;
}

.threat-level {
  min-width: max-content;
  padding: 7px 9px;
  background: color-mix(in oklch, var(--primary) 12%, transparent);
  color: color-mix(in oklch, var(--primary) 75%, var(--ink));
  font-size: 9px;
}

.mission-body {
  position: relative;
  min-height: 272px;
  padding: 35px 28px 30px;
  overflow: hidden;
}

.mission-body::after {
  content: "";
  position: absolute;
  right: -48px;
  bottom: -76px;
  width: 180px;
  height: 180px;
  border: 1px solid color-mix(in oklch, var(--primary) 25%, transparent);
  transform: rotate(45deg);
}

.mission-body.rule-refresh {
  animation: directive-refresh 360ms var(--ease-out);
}

.mission-code {
  display: block;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 10px;
}

.mission-body h3 {
  max-width: 12ch;
  margin: 0 0 14px;
  font-size: clamp(30px, 3vw, 43px);
  line-height: 1.04;
  letter-spacing: -0.025em;
}

.mission-body p {
  position: relative;
  z-index: 1;
  max-width: 48ch;
  margin: 0;
  color: color-mix(in oklch, var(--ink) 78%, var(--muted));
  font-size: 14px;
  line-height: 1.72;
}

.rule-tags {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 22px;
}

.rule-tags span {
  padding: 6px 9px;
  background: color-mix(in oklch, var(--primary) 11%, transparent);
  color: color-mix(in oklch, var(--primary) 72%, var(--ink));
  font-size: 10px;
}

.mission-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line);
  border-block: 1px solid var(--line);
}

.secondary-button {
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  transition: background 180ms ease, color 180ms ease;
}

.secondary-button:hover {
  background: var(--surface-raised);
  color: var(--ink);
}

.secondary-button svg {
  width: 16px;
}

.history-block {
  padding: 26px 28px 30px;
}

.history-title {
  align-items: center;
}

.history-title h3 {
  margin: 0;
  font-size: 14px;
}

.history-title button {
  border: 0;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  font-size: 11px;
}

.history-list {
  display: grid;
  gap: 1px;
  margin: 14px 0 0;
  padding: 0;
  background: var(--line);
  list-style: none;
}

.history-list li {
  min-height: 54px;
  display: grid;
  grid-template-columns: 58px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  background: var(--surface);
}

.history-list img {
  width: 56px;
  height: 32px;
  object-fit: contain;
}

.history-name {
  display: grid;
  gap: 2px;
}

.history-name b {
  font-size: 12px;
}

.history-name small,
.history-time {
  color: var(--muted);
  font-size: 9px;
}

.history-list .empty-history {
  display: block;
  min-height: auto;
  padding: 16px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.footer {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-block: 16px 24px;
  color: var(--muted);
  font-size: 9px;
}

.arsenal-dialog {
  width: min(1040px, calc(100% - 32px));
  max-height: min(820px, calc(100vh - 48px));
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  color: var(--ink);
}

.arsenal-dialog::backdrop {
  background: color-mix(in oklch, var(--bg) 80%, transparent);
  backdrop-filter: blur(5px);
}

.arsenal-dialog[open] {
  animation: dialog-in 260ms var(--ease-out);
}

.dialog-head {
  align-items: center;
  padding: 24px 28px;
  border-bottom: 1px solid var(--line);
}

.dialog-close {
  font-size: 24px;
}

.arsenal-filters {
  display: flex;
  gap: 1px;
  padding: 14px 28px;
  overflow-x: auto;
  background: var(--bg);
}

.filter-button {
  min-width: max-content;
  padding: 8px 12px;
  border: 0;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
}

.filter-button.active {
  background: var(--primary-deep);
  color: var(--ink);
}

.arsenal-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1px;
  max-height: 610px;
  overflow-y: auto;
  background: var(--line);
}

.arsenal-item {
  min-height: 152px;
  display: grid;
  grid-template-rows: 1fr auto;
  padding: 18px;
  background: var(--surface);
  cursor: pointer;
  transition: background 180ms ease;
}

.arsenal-item:hover {
  background: var(--surface-raised);
}

.arsenal-item img {
  width: 100%;
  height: 76px;
  object-fit: contain;
}

.arsenal-item-info {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 10px;
}

.arsenal-item-info b {
  display: block;
  margin-bottom: 2px;
  font-size: 14px;
}

.arsenal-item-info small,
.arsenal-cost {
  color: var(--muted);
  font-size: 9px;
}

.toast {
  position: fixed;
  z-index: var(--z-toast);
  right: 24px;
  bottom: 24px;
  max-width: min(360px, calc(100% - 48px));
  padding: 12px 16px;
  background: var(--primary-deep);
  color: var(--ink);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 180ms ease, transform 180ms var(--ease-out);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@keyframes scan {
  from { transform: translateX(0); }
  to { transform: translateX(900px); }
}

@keyframes weapon-cycle {
  0% { transform: translateX(-3px); opacity: 0.68; }
  100% { transform: translateX(3px); opacity: 1; }
}

@keyframes lock-impact {
  0% { transform: scale(1.12); filter: brightness(2) drop-shadow(0 0 26px var(--primary)); }
  100% { transform: scale(1); }
}

@keyframes state-pulse {
  to { background: currentColor; box-shadow: 0 0 8px currentColor; }
}

@keyframes directive-refresh {
  0% { opacity: 0.35; transform: translateY(5px); }
  100% { opacity: 1; transform: translateY(0); }
}

@keyframes dialog-in {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

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

  .mission-panel {
    border-left-width: 1px;
  }

  .weapon-stage {
    min-height: 410px;
  }

  .history-list {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 680px) {
  .topbar,
  .command-grid,
  .footer {
    width: min(100% - 28px, 1440px);
  }

  .topbar {
    min-height: 76px;
  }

  .system-state {
    display: none;
  }

  .icon-button {
    margin-left: auto;
  }

  .brand-copy strong {
    font-size: 14px;
  }

  .draw-console {
    padding: 22px 16px;
  }

  .lock-state {
    display: none;
  }

  .weapon-stage {
    min-height: 430px;
    margin-block: 22px;
    padding: 48px 14px 34px;
  }

  .weapon-stage::before {
    width: 210px;
    height: 210px;
  }

  .weapon-visual {
    min-height: 158px;
  }

  .weapon-visual img {
    width: 94%;
    max-height: 145px;
  }

  .weapon-identity h2 {
    padding-block: 0.1em 0.12em;
    font-size: clamp(48px, 14vw, 56px);
    line-height: 1.18;
  }

  .weapon-identity {
    gap: 10px;
    margin-top: 26px;
  }

  .weapon-specs {
    margin-top: 0;
    line-height: 1.5;
  }

  .mode-and-action {
    grid-template-columns: 1fr;
  }

  .keyboard-hint,
  .button-key {
    display: none;
  }

  .draw-button {
    min-height: 68px;
  }

  .mission-head,
  .mission-body,
  .history-block {
    padding-inline: 20px;
  }

  .history-list {
    grid-template-columns: 1fr;
  }

  .footer {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .arsenal-list {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }

  .scan-beam {
    display: none;
  }
}
