:root {
  color-scheme: dark;
  --bg: #04030a;
  --line: #2b143c;
  --muted: #684675;
  --text: #dff9fb;
  --violet: #c05ab5;
  --green: #2ed573;
  --amber: #ff9f1c;
  --red: #ff4757;
  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% 4%, rgba(255, 71, 87, 0.15), transparent 42%),
    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(--amber);
  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;
}

.masthead-buttons {
  display: flex;
  gap: 8px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--amber);
  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(2rem, 10vw, 3.2rem);
  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(--amber);
  background: rgba(232, 163, 61, 0.06);
}

.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(--amber);
}

.metric-right strong {
  color: var(--green);
}

.board-wrap {
  position: relative;
  flex: 1;
  min-height: 420px;
  margin: 16px 0 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  overflow: hidden;
  touch-action: none;
  background: var(--bg);
}

canvas#game-canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  cursor: crosshair;
  background: var(--bg);
}

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

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

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

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

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

.start-cta {
  margin: 0;
  color: var(--amber);
  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 #3a3350;
  background: #120e1d;
  box-shadow: 0 25px 90px rgba(0, 0, 0, 0.7);
}

dialog::backdrop {
  background: rgba(8, 6, 13, 0.85);
  backdrop-filter: blur(7px);
}

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

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

.dialog-inner ol {
  margin: 24px 0;
  padding-left: 20px;
  color: #b3aec9;
  line-height: 1.6;
  font-size: 0.88rem;
}

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

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 20px;
  color: #b3aec9;
  font-size: 0.85rem;
  cursor: pointer;
}

.toggle-row input {
  accent-color: var(--green);
  width: 18px;
  height: 18px;
}

.primary-button,
.secondary-button {
  min-height: 48px;
  padding: 0 18px;
  border: 1px solid var(--green);
  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: #06110a;
  background: var(--green);
}

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

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

.secondary-button:hover {
  border-color: var(--green);
  background: rgba(82, 224, 90, 0.04);
}

.share-card {
  display: block;
  width: 100%;
  height: auto;
  margin: 20px 0 0;
  border: 1px solid #3a3350;
  image-rendering: pixelated;
}

.result-inner pre {
  margin: 16px 0 24px;
  padding: 18px;
  overflow: auto;
  color: #d5cfe6;
  border: 1px solid #3a3350;
  background: #0a0812;
  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 #453b5c;
  background: #191325;
  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: 1.9rem;
  }

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