:root {
  --bg: #0d1117;
  --panel: #132034;
  --panel-2: #0f1a29;
  --line: #2b3f5d;
  --line-strong: #40618c;
  --text: #e7eef8;
  --muted: #9bb0c8;
  --accent: #59c9ff;
  --accent-2: #93f7cd;
  --danger: #ff7f96;
  --warn: #ffd166;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  color: var(--text);
  background:
    radial-gradient(900px 460px at 15% -10%, #153a67 0%, transparent 52%),
    radial-gradient(700px 420px at 100% 0%, #214f42 0%, transparent 50%),
    var(--bg);
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  padding: 16px;
}

button {
  touch-action: manipulation;
}

canvas {
  touch-action: none;
}

.shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(19, 32, 52, 0.98), rgba(16, 28, 45, 0.98));
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 14px;
}

.breadcrumb a {
  color: var(--accent);
  text-decoration: none;
}

.breadcrumb a:hover {
  text-decoration: underline;
}

.top {
  margin-bottom: 16px;
}

.top h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.05;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 8px 0 0;
  color: var(--muted);
}

.hud {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.14);
}

.stat span {
  display: block;
  font-size: 12px;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.stat strong {
  display: block;
  margin-top: 7px;
  font-size: 16px;
  line-height: 1.2;
}

.stat-seed {
  grid-column: 1 / -1;
}

.stat-seed strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 14px;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}

.stat-seed strong::-webkit-scrollbar {
  display: none;
}

.controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 272px;
  gap: 12px;
  margin-bottom: 16px;
  align-items: stretch;
}

.control-panel,
.mini-panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.12);
  padding: 14px;
}

.control-group + .control-group {
  margin-top: 14px;
}

.control-label,
.mini-title {
  display: block;
  margin-bottom: 10px;
  font-size: 12px;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.toggle-btn,
.btn-ghost,
.btn-primary {
  appearance: none;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 10px 14px;
  background: linear-gradient(180deg, rgba(27, 45, 70, 0.98), rgba(17, 30, 49, 0.98));
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition:
    transform 120ms ease,
    border-color 120ms ease,
    background 120ms ease,
    box-shadow 120ms ease;
}

.btn-primary,
.toggle-btn.active {
  border-color: var(--accent);
  background: linear-gradient(180deg, rgba(33, 79, 123, 0.98), rgba(23, 53, 84, 0.98));
  box-shadow: inset 0 0 0 1px rgba(89, 201, 255, 0.28), 0 0 0 1px rgba(89, 201, 255, 0.08);
}

.toggle-btn:hover,
.btn-ghost:hover,
.btn-primary:hover,
.toggle-btn:focus-visible,
.btn-ghost:focus-visible,
.btn-primary:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.toggle-btn:active,
.btn-ghost:active,
.btn-primary:active {
  transform: translateY(1px);
}

.control-note {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.mini-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mini-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.mini-title {
  margin-bottom: 0;
}

.mini-legend {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.swatch-direct {
  background: var(--accent);
}

.swatch-flip {
  background: var(--accent-2);
}

#diagramCanvas {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid rgba(64, 97, 140, 0.65);
  border-radius: 12px;
  background: linear-gradient(180deg, #0c1624, #09111b);
  cursor: pointer;
}

.canvas-wrap {
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  background:
    radial-gradient(140% 120% at 50% -12%, rgba(96, 160, 235, 0.08), transparent 38%),
    linear-gradient(180deg, #09111b, #081019);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 960 / 640;
  cursor: grab;
}

#gameCanvas.dragging {
  cursor: grabbing;
}

.message {
  margin: 14px 0 0;
  color: var(--muted);
}

.footer-nav {
  margin-top: 18px;
}

.link-btn {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.link-btn:hover {
  text-decoration: underline;
}

@media (max-width: 980px) {
  .hud {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .controls {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  body {
    padding: 10px;
  }

  .shell {
    padding: 16px;
  }

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

  .toggle-btn,
  .btn-ghost,
  .btn-primary {
    flex: 1 1 150px;
    min-width: 0;
  }
}