:root {
  color-scheme: dark;
  --bg: #090b11;
  --panel: #0e1119;
  --line: #232936;
  --muted: #70798d;
  --text: #f0f3f8;
  --acid: #b8ff3d;
  --cyan: #46e5ff;
  --danger: #ff526b;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background:
    radial-gradient(circle at 50% 10%, rgba(70, 229, 255, 0.07), transparent 35%),
    var(--bg);
}

body {
  min-height: 100svh;
  color: var(--text);
  overscroll-behavior: none;
}

button {
  color: inherit;
  font: inherit;
}

.top-nav {
  padding: 0 2px 12px;
  display: flex;
  align-items: center;
}

.back-link {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color 0.2s ease, transform 0.2s ease;
}

.back-link:hover, .back-link:focus {
  color: var(--acid);
  transform: translateX(-2px);
  outline: none;
}

.shell {
  width: min(100%, 540px);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 20px max(18px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 4px 2px 18px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--acid);
  font-size: 0.67rem;
  font-weight: 800;
  letter-spacing: 0.22em;
}

h1,
h2 {
  margin: 0;
  font-weight: 800;
  letter-spacing: -0.055em;
  line-height: 0.88;
}

h1 {
  font-size: clamp(2.25rem, 11vw, 3.7rem);
  text-transform: uppercase;
}

h2 {
  font-size: 2.4rem;
  line-height: 0.95;
}

.icon-button,
.dialog-close {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.hud {
  display: grid;
  grid-template-columns: 1fr 1fr 1.25fr;
  border-block: 1px solid var(--line);
  padding: 12px 2px 11px;
}

.metric {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.metric-center {
  align-items: center;
}

.metric-right {
  align-items: flex-end;
}

.metric-label {
  color: var(--muted);
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.metric strong {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 1.05rem;
  letter-spacing: 0.08em;
}

.fractures {
  display: flex;
  gap: 6px;
  height: 20px;
  align-items: center;
}

.fracture {
  width: 15px;
  height: 5px;
  border: 1px solid #454d5e;
  transform: skewX(-20deg);
}

.fracture.active {
  border-color: var(--danger);
  background: var(--danger);
  box-shadow: 0 0 10px rgba(255, 82, 107, 0.55);
}

.board-wrap {
  position: relative;
  flex: 1;
  min-height: 430px;
  margin: 16px 0 12px;
  border: 1px solid #1d2330;
  background:
    linear-gradient(rgba(255, 255, 255, 0.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.015) 1px, transparent 1px),
    #0b0e15;
  background-size: 24px 24px;
  overflow: hidden;
  touch-action: none;
}

.board-wrap::before,
.board-wrap::after {
  content: "";
  position: absolute;
  z-index: 2;
  width: 22px;
  height: 22px;
  pointer-events: none;
}

.board-wrap::before {
  top: -1px;
  left: -1px;
  border-top: 2px solid var(--acid);
  border-left: 2px solid var(--acid);
}

.board-wrap::after {
  right: -1px;
  bottom: -1px;
  border-right: 2px solid var(--acid);
  border-bottom: 2px solid var(--acid);
}

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

.status-chip-container {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: -24px;
  margin-bottom: 12px;
  position: relative;
  z-index: 10;
  pointer-events: none;
}

.status-chip {
  padding: 7px 10px;
  color: #8992a5;
  border: 1px solid #252c3a;
  background: rgba(9, 11, 17, 0.95);
  backdrop-filter: blur(8px);
  font-size: 0.56rem;
  font-weight: 800;
  letter-spacing: 0.17em;
  white-space: nowrap;
  transition: color 180ms, border-color 180ms;
  pointer-events: auto;
}

.status-chip.alert {
  color: var(--danger);
  border-color: rgba(255, 82, 107, 0.55);
}

.status-chip.success {
  color: var(--acid);
  border-color: rgba(184, 255, 61, 0.55);
}

.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.4;
}

.footer p {
  margin: 0;
}

.pulse-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--acid);
  box-shadow: 0 0 9px var(--acid);
}

.text-button {
  flex: none;
  padding: 0;
  border: 0;
  color: #aeb6c6;
  background: transparent;
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  cursor: pointer;
}

dialog {
  width: min(calc(100% - 36px), 480px);
  padding: 0;
  color: var(--text);
  border: 1px solid #303747;
  background: #10141d;
  box-shadow: 0 25px 90px rgba(0, 0, 0, 0.7);
}

dialog::backdrop {
  background: rgba(3, 5, 9, 0.82);
  backdrop-filter: blur(7px);
}

.dialog-inner {
  position: relative;
  padding: 32px;
}

.dialog-close {
  position: absolute;
  top: 18px;
  right: 18px;
  color: #9ba4b6;
  font-size: 1.35rem;
}

.dialog-inner ol {
  margin: 28px 0;
  padding-left: 20px;
  color: #aeb6c6;
  line-height: 1.65;
}

.dialog-inner li {
  padding-left: 7px;
  margin-bottom: 9px;
}

.primary-button,
.secondary-button {
  min-height: 48px;
  padding: 0 18px;
  border: 1px solid var(--acid);
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.13em;
  cursor: pointer;
}

.primary-button {
  color: #11160a;
  background: var(--acid);
}

.secondary-button {
  color: var(--text);
  border-color: #394152;
  background: transparent;
}

.result-inner pre {
  margin: 24px 0;
  padding: 18px;
  overflow: auto;
  color: #dce2ed;
  border: 1px solid #292f3d;
  background: #090c12;
  font: 0.72rem/1.65 "SFMono-Regular", Consolas, monospace;
  white-space: pre-wrap;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  padding: 10px 14px;
  color: var(--text);
  border: 1px solid #343c4d;
  background: #151a25;
  font-size: 0.7rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms, transform 180ms;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-height: 720px) {
  .shell {
    padding-top: 12px;
  }

  .masthead {
    padding-bottom: 10px;
  }

  h1 {
    font-size: 2rem;
  }

  .board-wrap {
    min-height: 350px;
    margin-top: 10px;
  }
}
