:root {
  --bg: #080808;
  --bg-panel: #111;
  --bg-code: #1a1a1a;
  --text: #ddd;
  --text-muted: #888;
  --heading: #eee;
  --accent: #6bbf8a;
  --link: #c9a962;
  --link-hover: #dfc07a;
  --border: rgba(255, 255, 255, 0.09);
  --kbd-fg: #d4a843;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-color: rgba(201, 169, 98, 0.4);
  text-underline-offset: 2px;
}
a:hover { color: var(--link-hover); }

code {
  background: var(--bg-code);
  padding: 0.12em 0.4em;
  border-radius: 4px;
  font-size: 0.86em;
  color: #e4e4e4;
}

/* Header */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 76rem;
  margin: 0 auto;
  padding: 1rem 1.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
.site-header h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--heading);
}
.site-header .tagline {
  margin: 0.2rem 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Language flags */
.lang-flags {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}
.lang-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.3rem 0.45rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.15s, border-color 0.15s, background 0.15s;
}
.lang-btn:hover {
  opacity: 0.85;
  background: var(--bg-panel);
}
.lang-btn.active {
  opacity: 1;
  border-color: var(--border);
  background: var(--bg-panel);
}
.lang-btn .flag {
  width: 22px;
  height: 15px;
  display: block;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}

/* Two-column layout */
.layout {
  display: grid;
  grid-template-columns: minmax(300px, 1.05fr) minmax(300px, 1fr);
  gap: 2rem 3rem;
  max-width: 76rem;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 3rem;
  align-items: start;
}

.col-game {
  position: sticky;
  top: 1rem;
}

.col-guide .lead {
  margin: 0;
  font-size: 0.98rem;
  color: var(--text);
  line-height: 1.65;
}
.col-guide .stack {
  margin: 0.75rem 0 0;
  font-size: 0.84rem;
  color: var(--text-muted);
  line-height: 1.6;
}
.col-guide .stack a {
  color: var(--link);
}
.col-guide .stack code {
  font-size: 0.92em;
  color: #b8dcc8;
  background: rgba(107, 191, 138, 0.08);
}

.col-guide h2 {
  margin: 1.75rem 0 0.75rem;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.07em;
  text-transform: uppercase;
}
.col-guide h2:first-of-type { margin-top: 1.25rem; }

.principle {
  margin-top: 0.85rem;
  padding: 0;
  background: none;
  border: none;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.55;
}
.principle strong { color: var(--text); }

.moment {
  padding: 0.8rem 0.95rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.moment-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.moment h3 {
  margin: 0 0 0.55rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--heading);
}
.moment--quantum {
  border-left: 3px solid var(--accent);
}
.moment-label {
  margin: 0.65rem 0 0.2rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  opacity: 0.75;
}
.moment h3 + .moment-label {
  margin-top: 0;
}
.moment-game {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text);
  line-height: 1.55;
}
.moment-quantum {
  margin: 0;
  font-size: 0.84rem;
  color: var(--text-muted);
  line-height: 1.55;
}
.moment-quantum code {
  font-size: 0.95em;
  color: #b8dcc8;
  background: rgba(107, 191, 138, 0.08);
}

/* Circuit diagram strip under each gameplay moment */
.circuit-fig {
  margin: 0.7rem 0 0;
  display: inline-block;
  max-width: 100%;
  padding: 0;
  line-height: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  overflow: hidden;
}
.circuit-fig img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 260px;
  object-fit: contain;
  object-position: left center;
  background: transparent;
}
.moment--quantum:hover .circuit-fig img {
  filter: brightness(1.06);
}
.circuit-fig--missing { display: none; }

.footer-dev {
  margin-top: 1.75rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: right;
}
.footer-dev p { margin: 0; }
.footer-dev a { text-decoration: none; }
.footer-dev a:hover { text-decoration: underline; }

/* Game frame */
#frame {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-panel);
}
#frame-inner {
  line-height: 0;
  background: #0c0c0c;
}
#frame canvas {
  display: block;
  width: 100% !important;
  height: auto !important;
  max-width: 100%;
  aspect-ratio: 900 / 720;
  touch-action: none;
}

#loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  min-height: 14rem;
  color: var(--text-muted);
  font-size: 0.86rem;
  text-align: center;
  padding: 1rem;
}
.loader-hint {
  max-width: 16rem;
  font-size: 0.75rem;
  line-height: 1.45;
  opacity: 0.75;
}
#loader.hidden { display: none; }

.spinner {
  width: 26px;
  height: 26px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#error {
  display: none;
  color: #c87070;
  font-size: 0.84rem;
  text-align: center;
  padding: 0.75rem;
  line-height: 1.5;
  white-space: pre-line;
}
#error.visible { display: block; }

@media (max-width: 880px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 2rem;
    padding: 1.25rem 1rem 2.5rem;
  }
  .col-game { position: static; }
  .site-header { padding: 0.85rem 1rem 0.65rem; }
}
