:root {
  color-scheme: dark;
  --bg: #04060f;
  --line: #18233a;
  --muted: #70798d;
  --text: #f0f3f8;
  --cyan: #5cc8ff;
  --green: #5be4b0;
  --red: #ff5d6c;
  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% 6%, rgba(92, 200, 255, 0.12), transparent 40%),
    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(--cyan);
  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(--cyan);
  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.2rem;
  line-height: 0.95;
}

.icon-button,
.dialog-close {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, background-color 0.2s;
}

.icon-button:hover,
.dialog-close:hover {
  border-color: var(--cyan);
  background: rgba(92, 200, 255, 0.05);
}

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

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

.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.2rem;
  letter-spacing: 0.08em;
  color: var(--cyan);
}

.board-wrap {
  position: relative;
  flex: 1;
  min-height: 420px;
  margin: 16px 0 12px;
  border: 1px solid #112033;
  overflow: hidden;
  touch-action: none;
  background: #04060f;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.start-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 6, 15, 0.72);
  backdrop-filter: blur(3px);
  text-align: center;
  cursor: pointer;
  z-index: 5;
}

.start-overlay.hidden {
  display: none;
}

.start-inner {
  padding: 0 28px;
  max-width: 320px;
}

.start-kicker {
  margin: 0 0 12px;
  color: var(--green);
  font-size: 1.4rem;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.start-sub {
  margin: 0 0 22px;
  color: #aeb6c6;
  font-size: 0.85rem;
  line-height: 1.5;
}

.start-cta {
  margin: 0;
  color: var(--cyan);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

.footer {
  display: flex;
  justify-content: center;
  align-items: center;
  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(--green);
  box-shadow: 0 0 9px var(--green);
}

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

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

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

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

.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(--cyan);
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.13em;
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s, color 0.2s;
}

.primary-button {
  color: #04090f;
  background: var(--cyan);
}

.primary-button:hover {
  background: #7ad4ff;
  border-color: #7ad4ff;
}

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

.secondary-button:hover {
  border-color: var(--cyan);
  background: rgba(92, 200, 255, 0.03);
}

.result-inner pre {
  margin: 24px 0;
  padding: 18px;
  overflow: auto;
  color: #dce2ed;
  border: 1px solid #222d3d;
  background: #060910;
  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 #273447;
  background: #111721;
  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: 340px;
    margin-top: 10px;
  }
}
