:root {
  color-scheme: dark;
  --bg: #0c100f;
  --surface: #111716;
  --surface-2: #151d1b;
  --ink: #eef0e8;
  --muted: #89938d;
  --line: rgba(225, 235, 225, 0.1);
  --glow: #d7f879;
  --glow-soft: rgba(215, 248, 121, 0.18);
  --shadow: 0 30px 90px rgba(0, 0, 0, 0.42);
  font-family: "Noto Sans SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  margin: 0;
  min-width: 320px;
  min-height: 100svh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }

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

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(110px);
  opacity: .16;
  animation: drift 12s ease-in-out infinite alternate;
}

.orb-a { width: 36rem; height: 36rem; right: -13rem; top: -15rem; background: #d7f879; }
.orb-b { width: 28rem; height: 28rem; left: -12rem; bottom: -12rem; background: #4e8d76; animation-delay: -4s; }

.grain {
  position: absolute;
  inset: 0;
  opacity: .035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.7'/%3E%3C/svg%3E");
}

.topbar {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(22px, 5vw, 72px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  color: var(--ink);
  text-decoration: none;
  font-family: "Noto Serif SC", serif;
  font-weight: 700;
  letter-spacing: .08em;
}

.brand-mark { width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; filter: drop-shadow(0 0 8px rgba(255, 233, 160, .35)); }
.glow-sprout { width: 100%; height: 100%; display: block; }

.top-actions { display: flex; align-items: center; gap: 10px; }
.text-button, .icon-button { border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.text-button { padding: 10px 12px; }
.text-button:hover { color: var(--ink); }
.icon-button { width: 38px; height: 38px; border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 50%; }
.sound-off { display: none; }
.icon-button[aria-pressed="false"] .sound-on { display: none; }
.icon-button[aria-pressed="false"] .sound-off { display: inline; }

.shell {
  width: min(1320px, calc(100% - 44px));
  min-height: calc(100svh - 130px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: clamp(34px, 5vw, 76px);
  align-items: center;
  padding: 42px 0 48px;
}

.game-stage { min-width: 0; }
.game-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 20px; }
.eyebrow { margin: 0 0 8px; color: var(--glow); font-family: "DM Mono", monospace; font-size: 11px; letter-spacing: .2em; text-transform: uppercase; }
.game-heading h1 { margin: 0; font-family: "Noto Serif SC", serif; font-size: clamp(25px, 3vw, 42px); line-height: 1.25; font-weight: 600; letter-spacing: -.02em; }

.mode-switch { display: inline-flex; gap: 4px; padding: 4px; border: 1px solid rgba(255, 255, 255, 0.06); border-radius: 99px; background: rgba(255,255,255,.02); }
.mode { border: 0; border-radius: 99px; padding: 9px 15px; background: transparent; color: var(--muted); font-size: 13px; cursor: pointer; transition: .2s ease; }
.mode.active { background: var(--ink); color: #111512; }

.game-frame { border-top: 0; padding-top: 10px; }
.status-line { display: grid; grid-template-columns: 110px 1fr 130px; align-items: center; margin-bottom: 14px; }
.stat { display: flex; align-items: baseline; gap: 9px; }
.stat span { color: var(--muted); font-size: 12px; }
.stat strong { font-family: "DM Mono", monospace; font-size: 20px; font-weight: 500; }
.align-right { justify-content: flex-end; }
.status-copy { text-align: center; color: #bbc2bd; font-size: 13px; transition: color .2s; }
.status-copy.lit { color: var(--glow); }

.board-wrap { position: relative; width: min(100%, 680px); margin: 0 auto; }
.board {
  --size: 5;
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(var(--size), 1fr);
  gap: clamp(6px, 1vw, 10px);
  padding: clamp(10px, 1.6vw, 18px);
  border: 0;
  background: rgba(15, 20, 19, .68);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  border-radius: 12px;
}

.tile {
  position: relative;
  border: 0;
  padding: 0;
  background: rgba(255, 255, 255, 0.022);
  border-radius: 6px;
  cursor: pointer;
  overflow: hidden;
  outline: none;
  transition: background .2s ease, box-shadow .2s ease;
}

.tile:hover {
  background: rgba(255, 255, 255, 0.055);
}

.tile.keyboard-focused, .tile:focus-visible {
  outline: 2px solid var(--glow);
  outline-offset: -2px;
  box-shadow: 0 0 18px rgba(215, 248, 121, 0.5);
  z-index: 10;
}

.tile-rotator {
  position: absolute;
  inset: 0;
  transition: transform 0.24s cubic-bezier(0.34, 1.35, 0.64, 1);
  pointer-events: none;
}

.tile .node { position: absolute; left: 50%; top: 50%; width: 10px; height: 10px; margin: -5px; border-radius: 50%; background: #4a5650; z-index: 2; transition: background .25s ease, box-shadow .25s ease; }
.tile .arm { position: absolute; background: #323b37; transition: background .25s ease, box-shadow .25s ease; border-radius: 1px; }
.tile .arm.n, .tile .arm.s { left: calc(50% - 2px); width: 4px; height: 50%; }
.tile .arm.e, .tile .arm.w { top: calc(50% - 2px); height: 4px; width: 50%; }
.tile .arm.n { top: 0; }
.tile .arm.s { bottom: 0; }
.tile .arm.e { right: 0; }
.tile .arm.w { left: 0; }

.tile.powered { background: rgba(215, 248, 121, 0.045); }
.tile.powered .node { background: #ffffff; box-shadow: 0 0 8px var(--glow), 0 0 20px rgba(215,248,121,.7); }
.tile.powered .arm { background: var(--glow); box-shadow: 0 0 10px rgba(215, 248, 121, 0.75), 0 0 18px rgba(215, 248, 121, 0.35); }

.tile.wave-active {
  background: rgba(215, 248, 121, 0.22) !important;
  box-shadow: 0 0 24px rgba(215, 248, 121, 0.75), inset 0 0 12px rgba(215, 248, 121, 0.35) !important;
  transform: scale(1.06);
  z-index: 6;
  transition: transform 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}

.tile.wave-active .node {
  background: #ffffff !important;
  box-shadow: 0 0 14px var(--glow), 0 0 32px var(--glow) !important;
}

.tile.wave-active .arm {
  background: #ffffff !important;
  box-shadow: 0 0 14px var(--glow), 0 0 28px var(--glow) !important;
}

.tile.source .node {
  width: 16px;
  height: 16px;
  margin: -8px;
  background: #ffffff;
  box-shadow: 0 0 12px var(--glow), 0 0 28px rgba(215, 248, 121, 0.9);
}

.tile.source .node::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 1px solid var(--glow);
  animation: sourcePulse 2s cubic-bezier(0.2, 0.8, 0.4, 1) infinite;
  pointer-events: none;
}

@keyframes sourcePulse {
  0% { transform: scale(0.6); opacity: 1; }
  100% { transform: scale(1.85); opacity: 0; }
}

.tile.hint-flash { animation: hintPulse .7s ease; }

.completion-glow { position: absolute; inset: 5%; opacity: 0; pointer-events: none; border: 1px solid var(--glow); box-shadow: 0 0 90px var(--glow-soft), inset 0 0 70px var(--glow-soft); transition: opacity .5s ease; border-radius: 8px; }
.completion-glow.show { opacity: .75; animation: completionBreath 1.8s ease; }

.controls { display: flex; justify-content: center; gap: 10px; margin-top: 16px; }
.control { display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 4px; background: rgba(255, 255, 255, 0.02); color: var(--muted); padding: 10px 16px; cursor: pointer; transition: .2s ease; font-size: 13px; }
.control:hover:not(:disabled) { border-color: rgba(215,248,121,.4); color: var(--ink); background: rgba(215, 248, 121, 0.05); }
.control:disabled { opacity: .35; cursor: default; }
.control.accent { color: var(--glow); border-color: rgba(215, 248, 121, 0.25); }
.control-icon { margin-right: 5px; }

.keycap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  margin-left: 7px;
  font-family: "DM Mono", monospace;
  font-size: 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
}
.control:hover .keycap {
  border-color: rgba(215, 248, 121, 0.45);
  color: var(--glow);
}

.keyboard-hints {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 12px;
  font-size: 11px;
  color: #68736d;
}
.keyboard-hints kbd {
  font-family: "DM Mono", monospace;
  font-size: 10px;
  padding: 1px 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--ink);
}

.side-panel { align-self: stretch; border-left: 1px solid var(--line); padding: 52px 0 10px clamp(28px, 4vw, 56px); display: flex; flex-direction: column; }
.challenge-copy h2 { margin: 0 0 18px; font-family: "Noto Serif SC", serif; font-size: clamp(27px, 2.8vw, 39px); line-height: 1.35; font-weight: 600; }
.challenge-copy > p:last-child { margin: 0; max-width: 280px; color: var(--muted); line-height: 1.8; font-size: 14px; }
.ranking { margin-top: 45px; }
.campaign-progress { margin-top: 45px; }
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; margin-top: 16px; }

.theme-grid { display: grid; gap: 8px; margin: 12px 0 14px; }
.theme-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, .025);
}
.theme-button strong { color: inherit; font-size: 13px; }
.theme-button span { font: 11px/1 var(--mono); opacity: .72; }
.theme-button.active {
  border-color: var(--glow);
  color: var(--glow);
  background: rgba(207, 255, 59, .07);
}
.theme-button:disabled { cursor: not-allowed; opacity: .45; }
.level-pager { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; margin-top: 10px; color: #68736d; font: 10px var(--mono); }
.level-pager button { border: 0; padding: 7px 0; background: transparent; color: #a8b7ae; font: inherit; cursor: pointer; }
.level-pager button:last-child { text-align: right; }
.level-pager button:first-child { text-align: left; }
.level-pager button:disabled { color: #39433e; cursor: default; }
.level-button { aspect-ratio: 1; border: 1px solid var(--line); background: rgba(255,255,255,.02); color: #6f7a74; font-family: "DM Mono", monospace; font-size: 12px; cursor: pointer; transition: .2s ease; }
.level-button:not(:disabled):hover { border-color: rgba(215,248,121,.45); color: var(--ink); }
.level-button.current { border-color: var(--glow); color: #10140f; background: var(--glow); box-shadow: 0 0 22px rgba(215,248,121,.13); }
.level-button.completed:not(.current) { color: var(--glow); border-color: rgba(215,248,121,.24); }
.level-button:disabled { opacity: .28; cursor: not-allowed; }
.level-button.final { border-style: double; }
.difficulty-note { margin: 13px 0 0; color: #68736d; font-size: 11px; }
.section-title { display: flex; justify-content: space-between; align-items: center; padding-bottom: 13px; border-bottom: 1px solid var(--line); font-size: 13px; }
.live-dot { color: var(--glow); font-family: "DM Mono", monospace; font-size: 10px; }
.profile-button { display: flex; align-items: center; gap: 8px; border: 0; padding: 0; background: transparent; color: var(--ink); cursor: pointer; }
.profile-button:hover { color: var(--glow); }
.profile-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--glow); box-shadow: 0 0 10px rgba(215,248,121,.7); }
.rank-scopes { display: flex; gap: 18px; padding: 13px 0 2px; }
.rank-scope { position: relative; border: 0; padding: 0 0 8px; background: transparent; color: #68736d; font-size: 11px; cursor: pointer; }
.rank-scope::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 1px; background: var(--glow); transform: scaleX(0); transform-origin: left; transition: transform .2s ease; }
.rank-scope.active { color: #cdd3ce; }
.rank-scope.active::after { transform: scaleX(1); }
.rank-list { list-style: none; margin: 0; padding: 0; }
.rank-item { display: grid; grid-template-columns: 30px 1fr auto; gap: 10px; align-items: center; padding: 13px 0; border-bottom: 1px solid rgba(255,255,255,.055); font-size: 13px; }
.rank-number { color: #616c66; font-family: "DM Mono", monospace; }
.rank-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-score { color: #aab2ad; font-family: "DM Mono", monospace; }
.rank-item.me { color: var(--glow); }
.rank-item.me .rank-number, .rank-item.me .rank-score { color: inherit; }
.rank-empty { color: #66706b; font-size: 12px; line-height: 1.7; padding: 18px 0; display: none; }
.share-quiet { margin-top: auto; width: 100%; border: 0; border-bottom: 1px solid var(--glow); padding: 18px 0 12px; background: transparent; color: var(--ink); display: flex; justify-content: space-between; cursor: pointer; text-align: left; }
.share-quiet .arrow { color: var(--glow); transition: transform .2s; }
.share-quiet:hover .arrow { transform: translate(3px, -3px); }

.footer { width: min(1320px, calc(100% - 44px)); margin: 0 auto; padding: 16px 0 25px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; color: #56605b; font-size: 10px; letter-spacing: .08em; }

.modal { border: 0; padding: 0; color: var(--ink); background: transparent; max-width: min(92vw, 520px); width: 100%; }
.modal::backdrop { background: rgba(3, 6, 5, .82); backdrop-filter: blur(12px); }
.modal-inner { position: relative; padding: 50px 48px 42px; background: #131917; border: 1px solid rgba(255,255,255,.11); box-shadow: var(--shadow); text-align: center; animation: modalIn .35s cubic-bezier(.2,.8,.2,1); }
.modal-inner.compact { text-align: left; }
.modal-inner h2 { margin: 0 0 24px; font-family: "Noto Serif SC", serif; font-size: 28px; line-height: 1.45; }
.modal-close { position: absolute; right: 16px; top: 14px; width: 34px; height: 34px; border: 0; background: transparent; color: var(--muted); font-size: 24px; cursor: pointer; }
.rules { margin: 30px 0; }
.rules p { display: grid; grid-template-columns: 38px 1fr; margin: 0; padding: 15px 0; border-top: 1px solid var(--line); color: #b7beb9; line-height: 1.6; }
.rules p:last-child { border-bottom: 1px solid var(--line); }
.rules span { color: var(--glow); font-family: "DM Mono", monospace; }
.primary-button, .secondary-button { min-height: 48px; border: 0; padding: 0 20px; cursor: pointer; transition: .2s ease; }
.primary-button { background: var(--glow); color: #11150f; font-weight: 600; }
.primary-button:hover { background: #e4ff91; transform: translateY(-1px); }
.secondary-button { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.result-sprout { width: 76px; height: 76px; margin: 0 auto 14px; animation: sproutBreath 3.2s ease-in-out infinite; }
.result-score { margin: 28px 0 8px; display: flex; flex-direction: column; }
.result-score strong { font-family: "DM Mono", monospace; color: var(--glow); font-size: 64px; font-weight: 500; line-height: 1; }
.result-score span { margin-top: 8px; color: var(--muted); font-size: 12px; }
.percentile { color: #c0c7c2; font-size: 13px; }
.result-actions { margin-top: 30px; display: grid; grid-template-columns: 1.5fr 1fr; gap: 8px; }
.copy-state { min-height: 20px; margin: 13px 0 0; color: var(--glow); font-size: 12px; }
.profile-form label { display: block; margin: 24px 0 8px; color: var(--muted); font-size: 12px; }
.profile-form input { width: 100%; height: 52px; border: 1px solid rgba(255,255,255,.14); border-radius: 0; padding: 0 14px; outline: 0; background: rgba(255,255,255,.035); color: var(--ink); font: inherit; }
.profile-form input:focus { border-color: rgba(215,248,121,.65); box-shadow: 0 0 0 3px rgba(215,248,121,.07); }
.profile-form .field-note { margin: 9px 0 24px; color: #66706b; font-size: 11px; line-height: 1.6; }
.profile-form .primary-button { width: 100%; }

@keyframes drift { to { transform: translate3d(30px, 35px, 0) scale(1.08); } }
@keyframes hintPulse { 0%,100% { background: rgba(255,255,255,.025); } 45% { background: rgba(215,248,121,.2); } }
@keyframes completionBreath { 0% { opacity: 0; transform: scale(.96); } 35% { opacity: .85; } 100% { opacity: .5; transform: scale(1); } }
@keyframes modalIn { from { opacity: 0; transform: translateY(14px) scale(.98); } }
@keyframes sproutBreath { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-3px) scale(1.04); } }

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; width: min(760px, calc(100% - 32px)); padding-top: 28px; }
  .side-panel { border-left: 0; border-top: 1px solid var(--line); padding: 36px 0 10px; min-height: 520px; }
  .challenge-copy h2 br { display: none; }
  .challenge-copy > p:last-child { max-width: 560px; }
  .ranking { margin-top: 30px; }
  .campaign-progress { margin-top: 30px; }
  .share-quiet { margin-top: 34px; }
}

@media (max-width: 620px) {
  .topbar { height: 64px; padding: 0 18px; }
  .brand { font-size: 14px; }
  .brand-mark { width: 22px; height: 22px; }
  .shell { width: calc(100% - 24px); padding: 24px 0 36px; gap: 34px; }
  .game-heading { display: block; }
  .game-heading h1 { font-size: 26px; }
  .mode-switch { margin-top: 18px; }
  .mode { padding-inline: 12px; }
  .status-line { grid-template-columns: 72px 1fr 88px; }
  .stat { display: block; }
  .stat span { display: block; margin-bottom: 2px; font-size: 9px; }
  .stat strong { font-size: 17px; }
  .status-copy { font-size: 11px; }
  .board { gap: 4px; padding: 8px; }
  .tile .node { width: 8px; height: 8px; margin: -4px; }
  .tile .arm.n, .tile .arm.s { width: 3px; left: calc(50% - 1.5px); }
  .tile .arm.e, .tile .arm.w { height: 3px; top: calc(50% - 1.5px); }
  .controls { justify-content: stretch; }
  .control { flex: 1; padding: 10px 6px; font-size: 12px; }
  .side-panel { min-height: 470px; }
  .footer { width: calc(100% - 32px); display: block; line-height: 2; }
  .footer span { display: block; }
  .modal-inner { padding: 46px 24px 30px; }
  .modal-inner h2 { font-size: 23px; }
  .result-actions { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
