:root {
  color-scheme: dark;
  --bg: #030407;
  --surface: rgba(8, 14, 26, 0.86);
  --surface-solid: #080e1a;
  --line: rgba(157, 204, 255, 0.13);
  --line-strong: rgba(157, 204, 255, 0.25);
  --text: #f7fbff;
  --text-soft: #b5c0d5;
  --text-dim: #6f7d96;
  --cyan: #38bdf8;
  --cyan-bright: #95e9ff;
  --mint: #7de2b1;
  --gold: #f4c96c;
  --coral: #ff8678;
  --purple: #b4a0ff;
  --shadow: 0 28px 90px rgba(0, 0, 0, 0.5);
  --font-sans: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 50% -10%, rgba(25, 91, 177, 0.24), transparent 38%),
    linear-gradient(180deg, #040713 0%, var(--bg) 64%);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

button,
a {
  color: inherit;
  font: inherit;
}

a {
  text-decoration: none;
}

button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 4px;
}

[hidden] {
  display: none !important;
}

.ambient {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.ambient-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(119, 175, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(119, 175, 255, 0.05) 1px, transparent 1px);
  background-size: 64px 64px;
  opacity: 0.28;
  mask-image: linear-gradient(to bottom, #000, transparent 88%);
}

.ambient-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(1px);
}

.ambient-orb-a {
  top: -34vw;
  left: 13vw;
  width: 66vw;
  height: 58vw;
  background: radial-gradient(circle, rgba(41, 117, 241, 0.2), transparent 68%);
  animation: breathe 18s ease-in-out infinite alternate;
}

.ambient-orb-b {
  right: -22vw;
  bottom: -30vw;
  width: 60vw;
  height: 55vw;
  background: radial-gradient(circle, rgba(42, 219, 242, 0.1), transparent 68%);
  animation: breathe 22s ease-in-out infinite alternate-reverse;
}

.site-header {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(1240px, calc(100% - 56px));
  height: 84px;
  margin: 0 auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid rgba(149, 233, 255, 0.36);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 25%, rgba(149, 233, 255, 0.24), rgba(7, 11, 19, 0.94) 68%);
  color: var(--cyan-bright);
  font-size: 16px;
  font-weight: 700;
  box-shadow: inset 0 0 18px rgba(56, 189, 248, 0.12);
}

.brand-copy {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.brand-copy strong {
  font-size: 18px;
  letter-spacing: 0.04em;
}

.brand-copy small {
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.15em;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 26px;
}

.nav-link,
.sound-button,
.back-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
  font-size: 14px;
}

.nav-link:hover,
.back-button:hover {
  color: var(--text);
}

.nav-quiet {
  color: var(--text-dim);
}

.sound-button {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 11px;
}

.shell {
  position: relative;
  z-index: 1;
  width: min(1240px, calc(100% - 56px));
  min-height: calc(100vh - 168px);
  margin: 0 auto;
}

.screen {
  animation: reveal 480ms cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

.home-screen {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(380px, 0.92fr);
  gap: clamp(52px, 8vw, 110px);
  align-items: center;
  min-height: calc(100vh - 168px);
  padding: 58px 0 90px;
}

.eyebrow,
.micro-label {
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.eyebrow {
  margin: 0 0 26px;
}

.eyebrow span {
  color: var(--cyan);
}

.home-copy h1 {
  margin: 0;
  font-size: clamp(56px, 7.2vw, 96px);
  font-weight: 650;
  letter-spacing: -0.06em;
  line-height: 1.02;
}

.home-copy h1 em {
  background: linear-gradient(92deg, #ffffff 4%, #8fe7ff 48%, #b7c9ff 94%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-style: normal;
  white-space: nowrap;
}

.home-lede {
  max-width: 620px;
  margin: 32px 0 0;
  color: var(--text-soft);
  font-size: 17px;
  line-height: 1.9;
}

.home-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 36px;
}

.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 52px;
  padding: 0 19px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease, color 180ms ease;
}

.primary-button {
  min-width: 210px;
  border: 1px solid rgba(149, 233, 255, 0.5);
  background: linear-gradient(110deg, #7ee2ff, #46bcff 54%, #6fb9ff);
  color: #03101a;
  font-size: 15px;
  font-weight: 700;
}

.secondary-button {
  min-height: 47px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.02);
  color: var(--text-soft);
  font-size: 13px;
}

.primary-button:hover {
  transform: translateY(-2px);
}

.secondary-button:hover {
  border-color: rgba(149, 233, 255, 0.4);
  color: var(--text);
}

.home-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 28px;
}

.home-facts span {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 11px;
}

.home-facts b {
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
}

.level-panel {
  padding: 26px;
  border: 1px solid var(--line-strong);
  border-radius: 26px;
  background:
    linear-gradient(145deg, rgba(13, 24, 44, 0.9), rgba(6, 10, 18, 0.96) 68%),
    var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.micro-label {
  margin: 0;
}

.panel-heading h2 {
  margin: 8px 0 0;
  font-size: 26px;
}

.total-stars {
  text-align: right;
}

.total-stars span {
  display: block;
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 18px;
}

.total-stars small {
  display: block;
  margin-top: 4px;
  color: var(--text-dim);
  font-size: 10px;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 24px;
}

.level-card {
  min-height: 104px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.018);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: border-color 180ms ease, background 180ms ease, transform 180ms ease;
}

.level-card:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: rgba(149, 233, 255, 0.4);
  background: rgba(255, 255, 255, 0.032);
}

.level-card:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.level-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.level-card-top span {
  color: var(--cyan);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.08em;
}

.level-card-top small {
  color: var(--gold);
  font-size: 10px;
  letter-spacing: 0.06em;
}

.level-card strong {
  display: block;
  margin-top: 16px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.45;
}

.panel-note {
  margin: 18px 0 0;
  color: var(--text-dim);
  font-size: 11px;
  line-height: 1.7;
}

.game-screen {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: clamp(32px, 5vw, 64px);
  align-items: center;
  min-height: calc(100vh - 168px);
  padding: 46px 0 78px;
}

.game-status {
  align-self: start;
  padding-top: 18px;
}

.back-button {
  margin-bottom: 58px;
  color: var(--text-dim);
}

.micro-label {
  color: var(--cyan);
}

.game-status h1 {
  margin: 12px 0 8px;
  font-size: 38px;
  line-height: 1.22;
}

.level-subtitle {
  margin: 0;
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.75;
}

.star-row,
.result-stars {
  display: flex;
  gap: 6px;
  margin-top: 18px;
}

.star {
  color: rgba(244, 201, 108, 0.18);
  font-size: 18px;
}

.star.is-active {
  color: var(--gold);
  text-shadow: 0 0 14px rgba(244, 201, 108, 0.4);
}

.metric-stack {
  display: grid;
  gap: 8px;
  margin-top: 30px;
}

.metric-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.018);
}

.metric-card span {
  color: var(--text-dim);
  font-size: 11px;
}

.metric-card strong {
  font-family: var(--font-mono);
  font-size: 16px;
}

.metric-goal strong {
  color: var(--gold);
}

.legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px 16px;
  margin-top: 24px;
  color: var(--text-dim);
  font-size: 11px;
}

.legend span {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.legend-start {
  background: var(--mint);
  box-shadow: 0 0 10px rgba(125, 226, 177, 0.45);
}

.legend-evidence {
  border-radius: 2px;
  background: var(--gold);
  transform: rotate(45deg);
}

.legend-goal {
  background: var(--cyan-bright);
  box-shadow: 0 0 10px rgba(149, 233, 255, 0.45);
}

.legend-noise {
  border-radius: 1px;
  background: var(--coral);
}

.status-message {
  min-height: 40px;
  margin-top: 26px;
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.65;
}

.status-message.is-error {
  color: var(--coral);
}

.game-controls {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.game-controls .secondary-button {
  flex: 1;
  justify-content: center;
  padding: 0 12px;
}

.board-shell {
  position: relative;
  width: min(100%, 760px);
  justify-self: end;
}

.board-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 10px;
}

.board-frame {
  position: relative;
  padding: clamp(14px, 2vw, 24px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 30px;
  background:
    radial-gradient(circle at 50% 38%, rgba(31, 83, 143, 0.12), transparent 58%),
    linear-gradient(145deg, rgba(11, 20, 37, 0.9), rgba(4, 7, 13, 0.97));
  box-shadow: var(--shadow);
}

.game-board {
  --grid-size: 7;
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--grid-size), minmax(0, 1fr));
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid rgba(145, 198, 255, 0.16);
  border-radius: 18px;
  background:
    linear-gradient(rgba(125, 179, 255, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(125, 179, 255, 0.06) 1px, transparent 1px),
    #030813;
  background-size: calc(100% / var(--grid-size)) calc(100% / var(--grid-size));
  touch-action: none;
  user-select: none;
}

.grid-cell {
  position: relative;
  display: grid;
  place-items: center;
  border-right: 1px solid rgba(145, 198, 255, 0.06);
  border-bottom: 1px solid rgba(145, 198, 255, 0.06);
}

.grid-cell.is-path {
  background: radial-gradient(circle, rgba(56, 189, 248, 0.18), transparent 68%);
}

.grid-cell.is-head {
  background: radial-gradient(circle, rgba(149, 233, 255, 0.24), transparent 70%);
}

.grid-cell.is-noise::before {
  position: absolute;
  inset: 24%;
  border: 1px solid rgba(255, 134, 120, 0.34);
  border-radius: 5px;
  background:
    repeating-linear-gradient(135deg, rgba(255, 134, 120, 0.17) 0 2px, rgba(255, 134, 120, 0.03) 2px 7px),
    rgba(255, 134, 120, 0.03);
  content: "";
}

.node {
  position: relative;
  z-index: 2;
  display: grid;
  width: clamp(24px, 4.2vw, 36px);
  height: clamp(24px, 4.2vw, 36px);
  place-items: center;
  border-radius: 50%;
  font-family: var(--font-mono);
  font-size: clamp(8px, 1vw, 10px);
  font-weight: 700;
}

.node-start {
  border: 1px solid rgba(125, 226, 177, 0.75);
  background: #0a251d;
  color: var(--mint);
  box-shadow: 0 0 22px rgba(125, 226, 177, 0.18);
}

.node-goal {
  border: 1px solid rgba(149, 233, 255, 0.72);
  background: #071e2a;
  color: var(--cyan-bright);
  box-shadow: 0 0 22px rgba(56, 189, 248, 0.2);
}

.node-evidence {
  border: 1px solid rgba(244, 201, 108, 0.7);
  border-radius: 8px;
  background: #241d0c;
  color: var(--gold);
  transform: rotate(45deg);
}

.node-evidence span {
  transform: rotate(-45deg);
}

.grid-cell.is-collected .node-evidence {
  background: var(--gold);
  color: #201704;
  box-shadow: 0 0 22px rgba(244, 201, 108, 0.32);
}

.grid-cell.is-goal-hit .node-goal {
  background: var(--cyan-bright);
  color: #041019;
  box-shadow: 0 0 34px rgba(149, 233, 255, 0.55);
}

.route-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.route-glow,
.route-line {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.route-glow {
  stroke: rgba(56, 189, 248, 0.28);
  stroke-width: 2.4;
  filter: blur(1.2px);
}

.route-line {
  stroke: url("#route-gradient");
  stroke: var(--cyan);
  stroke-width: 0.9;
  filter: drop-shadow(0 0 1.1px rgba(149, 233, 255, 0.9));
}

.game-board.is-invalid {
  animation: shake 300ms ease;
}

.game-board.is-won {
  border-color: rgba(125, 226, 177, 0.34);
}

.keyboard-help {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 12px;
  color: var(--text-dim);
  font-size: 10px;
}

.result-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(2, 6, 13, 0.58);
  backdrop-filter: blur(5px);
}

.result-card {
  width: min(430px, 100%);
  padding: 28px;
  border: 1px solid rgba(149, 233, 255, 0.25);
  border-radius: 23px;
  background:
    linear-gradient(145deg, rgba(13, 25, 45, 0.98), rgba(5, 9, 16, 0.99)),
    var(--surface-solid);
  box-shadow: var(--shadow);
  animation: result-in 360ms cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

.result-stars {
  margin-top: 12px;
}

.result-stars .star {
  font-size: 30px;
}

.result-card h2 {
  margin: 16px 0 6px;
  font-size: 36px;
}

.result-stat {
  margin: 0;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 11px;
}

.principle-label {
  margin: 26px 0 8px;
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.12em;
}

.principle-text {
  margin: 0;
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1.8;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 24px;
}

.result-actions .primary-button {
  min-width: 150px;
}

.site-footer {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(1240px, calc(100% - 56px));
  min-height: 84px;
  margin: 0 auto;
  border-top: 1px solid rgba(157, 204, 255, 0.08);
  color: var(--text-dim);
  font-size: 11px;
}

.site-footer p {
  margin: 0;
}

.site-footer div {
  display: flex;
  gap: 20px;
}

.site-footer a:hover {
  color: var(--text);
}

.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  z-index: 80;
  padding: 11px 17px;
  border: 1px solid rgba(149, 233, 255, 0.3);
  border-radius: 999px;
  background: rgba(7, 15, 27, 0.96);
  color: var(--text);
  font-size: 12px;
  box-shadow: var(--shadow);
  transform: translateX(-50%);
}

.noscript {
  position: fixed;
  right: 20px;
  bottom: 20px;
  padding: 12px;
  border-radius: 10px;
  background: var(--surface-solid);
}

@keyframes reveal {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes breathe {
  from {
    transform: scale(0.96);
    opacity: 0.74;
  }
  to {
    transform: scale(1.06);
    opacity: 1;
  }
}

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

@keyframes result-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 980px) {
  .home-screen,
  .game-screen {
    grid-template-columns: 1fr;
  }

  .home-screen {
    align-items: start;
    gap: 52px;
    padding-top: 46px;
  }

  .level-panel {
    max-width: 680px;
  }

  .game-screen {
    gap: 36px;
  }

  .game-status {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0 30px;
    padding-top: 0;
  }

  .game-status .back-button,
  .game-status > .micro-label,
  .game-status > h1,
  .game-status > .level-subtitle {
    grid-column: 1;
  }

  .back-button {
    margin-bottom: 28px;
  }

  .game-status .star-row {
    grid-column: 2;
    grid-row: 2 / span 2;
    align-self: center;
  }

  .metric-stack {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .legend,
  .status-message,
  .game-controls {
    grid-column: 1 / -1;
  }

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

  .board-shell {
    width: 100%;
    max-width: 720px;
    justify-self: center;
  }
}

@media (max-width: 720px) {
  .site-header,
  .shell,
  .site-footer {
    width: min(100% - 32px, 1240px);
  }

  .site-header {
    height: 74px;
  }

  .brand-copy small,
  .nav-quiet,
  .site-nav .nav-link:nth-child(2) {
    display: none;
  }

  .site-nav {
    gap: 14px;
  }

  .sound-button {
    padding: 7px 9px;
  }

  .home-screen {
    min-height: auto;
    padding: 44px 0 70px;
  }

  .home-copy h1 {
    font-size: clamp(43px, 13vw, 70px);
  }

  .home-copy h1 em {
    white-space: normal;
  }

  .home-actions {
    display: grid;
  }

  .home-actions .primary-button,
  .home-actions .secondary-button {
    width: 100%;
  }

  .level-panel {
    padding: 20px;
  }

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

  .game-screen {
    padding-top: 24px;
  }

  .game-status h1 {
    font-size: 32px;
  }

  .metric-stack {
    gap: 7px;
    margin-top: 22px;
  }

  .metric-card {
    display: grid;
    gap: 6px;
    padding: 11px;
  }

  .metric-card strong {
    font-size: 14px;
  }

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

  .board-frame {
    padding: 11px;
    border-radius: 22px;
  }

  .game-board {
    border-radius: 14px;
  }

  .node {
    width: clamp(22px, 7vw, 31px);
    height: clamp(22px, 7vw, 31px);
    font-size: 8px;
  }

  .keyboard-help {
    display: none;
  }

  .result-overlay {
    position: fixed;
    inset: 0;
    padding: 12px;
    overflow-y: auto;
    border-radius: 0;
    background: rgba(2, 6, 13, 0.8);
    backdrop-filter: blur(9px);
  }

  .result-card {
    padding: 22px;
  }

  .result-card h2 {
    font-size: 31px;
  }

  .result-actions {
    display: grid;
  }

  .result-actions .primary-button,
  .result-actions .secondary-button {
    width: 100%;
  }

  .site-footer {
    display: grid;
    gap: 12px;
    padding: 22px 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
