:root {
  --bg: #0d1117;
  --surface: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #3fb950;
  --accent-dim: #238636;
  --focus-ring: #58a6ff;
  --danger: #f85149;
  --font-mono: ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, monospace;
}

[data-theme='light'] {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --border: #d0d7de;
  --text: #1f2328;
  --muted: #656d76;
  --accent: #1a7f37;
  --accent-dim: #116329;
  --focus-ring: #0969da;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--focus-ring);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.site-header__brand {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}

.site-header__brand span {
  color: var(--accent);
}

.site-header__nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-left: auto;
  margin-right: 0.75rem;
}

.site-header__link {
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: none;
}

.site-header__link:hover,
.site-header__link--active {
  color: var(--text);
  text-decoration: none;
}

.site-header__link--active {
  color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--accent-dim);
  color: #fff;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover {
  filter: brightness(1.08);
  text-decoration: none;
}

.btn--ghost {
  background: transparent;
  color: var(--text);
}

.hero {
  max-width: 42rem;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 1rem;
  text-align: center;
}

.hero h1 {
  margin: 0 0 0.5rem;
  font-size: 1.75rem;
  font-weight: 700;
}

.hero p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.level-grid {
  display: grid;
  gap: 1rem;
  max-width: 52rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

@media (min-width: 640px) {
  .level-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.level-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  transition: border-color 0.15s, transform 0.15s;
}

.level-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.level-card--done {
  border-color: var(--accent-dim);
}

.level-card__bucket {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.level-card__title {
  margin: 0;
  font-size: 1.1rem;
}

.level-card__meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.level-card__play {
  margin-top: auto;
}

.play-layout {
  max-width: 56rem;
  margin: 0 auto;
  padding: 1rem 1.25rem 2rem;
}

.play-header {
  margin-bottom: 1rem;
}

.play-header h1 {
  margin: 0 0 0.35rem;
  font-size: 1.25rem;
}

.play-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.terminal {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

.terminal--shake {
  animation: shake 0.32s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.terminal__board {
  min-height: 320px;
  height: 52vh;
  max-height: 480px;
  padding: 4px;
  gap: 3px;
}

.pane {
  position: relative;
  display: flex;
  align-items: flex-start;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.2);
  overflow: hidden;
  transition: border-color 0.12s, box-shadow 0.12s;
}

[data-theme='light'] .pane {
  background: rgba(0, 0, 0, 0.03);
}

.pane--focused {
  border-color: var(--focus-ring);
  box-shadow: inset 0 0 0 1px var(--focus-ring);
}

.pane--flash {
  animation: split-flash 0.28s ease;
}

@keyframes split-flash {
  0% { background: rgba(63, 185, 80, 0.35); }
  100% { background: rgba(0, 0, 0, 0.2); }
}

.pane__label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.pane__cursor {
  margin-left: 0.35rem;
  color: var(--accent);
  animation: blink 1s step-end infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

.status {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.25);
}

.status__prefix {
  min-width: 3.5rem;
  font-weight: 700;
  color: transparent;
}

.status__prefix--active {
  color: var(--accent);
  animation: pulse 0.8s ease infinite;
}

@keyframes pulse {
  50% { opacity: 0.6; }
}

.status__windows {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.status__window {
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  border: 1px solid transparent;
}

.status__window--active {
  border-color: var(--border);
  color: var(--text);
  background: var(--bg);
}

.status__hint {
  margin-left: auto;
  opacity: 0.85;
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.65);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 50;
}

.overlay--show {
  opacity: 1;
  pointer-events: auto;
}

.win-card {
  width: min(90vw, 22rem);
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  text-align: center;
  animation: win-in 0.35s ease;
}

@keyframes win-in {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(8px);
  }
}

.win-card__tag {
  margin: 0 0 0.35rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
}

.win-card__title {
  margin: 0 0 1rem;
  font-size: 1.35rem;
}

.win-card__stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin: 0 0 1.25rem;
  text-align: left;
}

.win-card__stats dt {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
}

.win-card__stats dd {
  margin: 0.15rem 0 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.win-card__keys {
  margin: 0 0 1rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.win-card__keys kbd {
  display: inline-block;
  padding: 0.1rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.75rem;
  background: var(--bg);
}

.win-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

/* --- Mobile touch mode --- */

.mode-mobile .mode-desktop-only {
  display: none;
}

.mode-desktop [data-touch-panel] {
  display: none !important;
}

.touch-panel {
  margin-top: 1rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.touch-panel__label {
  margin: 0 0 0.75rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-align: center;
}

.touch-panel__sequence {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  margin-bottom: 1rem;
  min-height: 2rem;
}

.seq-step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--bg);
}

.seq-step--active {
  border-color: var(--focus-ring);
  color: var(--text);
  box-shadow: 0 0 0 1px var(--focus-ring);
}

.seq-step--done {
  border-color: var(--accent-dim);
  color: var(--accent);
}

.seq-step__arrow {
  color: var(--muted);
  font-size: 0.8rem;
  user-select: none;
}

.touch-panel__keycaps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.keycap {
  min-width: 3.25rem;
  min-height: 3.25rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s, border-color 0.1s, background 0.1s;
}

.keycap:active {
  transform: scale(0.94);
  border-color: var(--focus-ring);
  background: rgba(88, 166, 255, 0.12);
}

@media (max-width: 480px) {
  .terminal__board {
    min-height: 240px;
    height: 38vh;
  }

  .keycap {
    min-width: 3.5rem;
    min-height: 3.5rem;
    font-size: 1.05rem;
  }
}

/* --- Cheat sheet --- */

.cheat-page {
  max-width: 46rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.cheat-hero {
  margin-bottom: 2rem;
}

.cheat-hero__eyebrow {
  margin: 0 0 0.35rem;
  color: var(--accent);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.cheat-hero h1 {
  margin: 0 0 0.5rem;
  font-size: 1.75rem;
}

.cheat-hero__lead {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.cheat-section {
  margin-bottom: 2rem;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.cheat-section h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

.cheat-section--appendix {
  opacity: 0.92;
}

.cheat-muted {
  color: var(--muted);
  line-height: 1.5;
}

.cheat-prefix {
  margin: 0 0 0.75rem;
}

.cheat-kbd {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
}

.cheat-kbd-gap {
  margin: 0 0.25rem;
  color: var(--muted);
}

.cheat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.cheat-table th,
.cheat-table td {
  padding: 0.5rem 0.35rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.cheat-table th {
  color: var(--muted);
  font-weight: 600;
}

.cheat-table__when {
  color: var(--muted);
}

.cheat-badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: rgba(63, 185, 80, 0.15);
  color: var(--accent);
  font-size: 0.7rem;
  white-space: nowrap;
}

.cheat-badge--muted {
  background: rgba(139, 148, 158, 0.12);
  color: var(--muted);
}

.cheat-path {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.cheat-path__step {
  padding: 1rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  background: var(--bg);
}

.cheat-path__head {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  margin-bottom: 0.5rem;
}

.cheat-path__num {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 1.75rem;
  height: 1.75rem;
  border-radius: 6px;
  background: var(--accent-dim);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
}

.cheat-path__step h3 {
  margin: 0;
  font-size: 1rem;
}

.cheat-path__keys {
  margin: 0.2rem 0 0;
  color: var(--focus-ring);
  font-size: 0.85rem;
}

.cheat-path__play {
  margin-top: 0.75rem;
  font-size: 0.8rem;
}

.cheat-layout {
  margin: 0;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--accent);
  font: inherit;
  font-size: 0.72rem;
  line-height: 1.35;
  overflow-x: auto;
  white-space: pre;
}

.cheat-appendix {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.cheat-appendix li {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
  align-items: baseline;
}

.golden-path {
  max-width: 52rem;
  margin: 0 auto;
  padding: 0 1.25rem 1rem;
}

.golden-path h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  text-align: center;
  color: var(--muted);
  font-weight: 600;
}

.golden-path__strip {
  display: grid;
  gap: 0.5rem;
}

@media (min-width: 640px) {
  .golden-path__strip {
    grid-template-columns: repeat(5, 1fr);
  }
}

.golden-path__step {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s;
}

.golden-path__step:hover {
  border-color: var(--accent);
  text-decoration: none;
}

.golden-path__step-num {
  font-size: 0.7rem;
  color: var(--accent);
  font-weight: 700;
}

.golden-path__step-title {
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.3;
}

.golden-path__step-keys {
  font-size: 0.72rem;
  color: var(--muted);
}

.level-card__agent-tip {
  margin: 0 0 0.75rem;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
  flex: 1;
}

.play-agent-tip {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: var(--accent);
}

.site-footer {
  max-width: 52rem;
  margin: 2rem auto 0;
  padding: 1.5rem 1.25rem 2.5rem;
  border-top: 1px solid var(--border);
}

.site-footer__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  margin-bottom: 1.25rem;
}

.site-footer__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  text-align: center;
}

.site-footer__links {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: center;
}

.site-footer__links a {
  font-size: 0.85rem;
  color: var(--muted);
  text-decoration: none;
}

.site-footer__links a:hover {
  color: var(--text);
  text-decoration: underline;
}

.site-footer__legal {
  margin: 0;
  max-width: 36rem;
  font-size: 0.72rem;
  line-height: 1.5;
  color: var(--muted);
}

.site-footer__credit {
  margin: 0.25rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.site-footer__credit a {
  color: var(--text);
  text-decoration: none;
}

.site-footer__credit a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.site-footer__heart {
  color: var(--accent);
}

.about-page .cheat-section p + p {
  margin-top: 0.75rem;
}

.site-header__badge {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-right: 0.5rem;
}

.learn-pillars {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
  max-width: 52rem;
  margin: 0 auto 1.5rem;
  padding: 0 1.25rem;
}

.learn-pillar {
  padding: 0.35rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--muted);
  text-decoration: none;
}

.learn-pillar--active,
.learn-pillar:hover {
  color: var(--text);
  border-color: var(--accent);
}

.section-lead {
  margin: -0.5rem 0 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.levelup-section {
  margin-top: 2.5rem;
}

.sim-hero {
  max-width: 52rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 0;
}

.sim-hero h1 {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
}

.sim-hero p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.pane--sim {
  align-items: stretch;
  justify-content: flex-start;
  padding: 0.35rem 0.5rem 0.5rem;
}

.pane__screen {
  margin: 1.25rem 0 0;
  flex: 1;
  width: 100%;
  font-size: 0.62rem;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: hidden;
  color: var(--text);
  opacity: 0.92;
}

.pane__proc {
  position: absolute;
  top: 0.35rem;
  right: 0.4rem;
  color: var(--accent);
  font-size: 0.55rem;
}

.pane--zoomed .pane__label::after {
  content: ' · zoomed';
  color: var(--muted);
}

.status__flair {
  margin-left: 0.5rem;
  font-size: 0.7rem;
  color: var(--accent);
}

.script-dock {
  display: none;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.mode-mobile .script-dock {
  display: flex;
}

.script-chip {
  padding: 0.4rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.72rem;
  cursor: pointer;
}

.script-chip:hover {
  border-color: var(--accent);
}

@media (max-width: 640px) {
  .site-header__nav {
    display: none;
  }

  .cheat-table {
    font-size: 0.78rem;
  }

  .cheat-table th:nth-child(4),
  .cheat-table td:nth-child(4) {
    display: none;
  }
}