* {
  box-sizing: border-box;
}
html {
  background: #101c32;
  color: #e1eaf7;
  font-family: system-ui, sans-serif;
}
body {
  margin: 0;
  min-width: 300px;
  min-height: 100dvh;
  background:
    radial-gradient(ellipse at 15% 3%, #34456499, transparent 50%),
    radial-gradient(ellipse at 90% 95%, var(--sky, #163b4e), transparent 65%),
    #101c32;
  --accent: #eac794;
  --sky: #163b4e;
}
body[data-chapter="1"] {
  --accent: #a6dbcf;
  --sky: #164349;
}
body[data-chapter="2"] {
  --accent: #a5caf1;
  --sky: #223f69;
}
body[data-chapter="3"] {
  --accent: #d0b3ef;
  --sky: #3e305f;
}
body[data-chapter="4"] {
  --accent: #e5b0b8;
  --sky: #4c2d47;
}
body[data-chapter="5"] {
  --accent: #abe6d2;
  --sky: #235452;
}
button,
a {
  -webkit-tap-highlight-color: transparent;
}
button {
  color: inherit;
  background: #ffffff08;
  border: 1px solid #c0d4ea35;
  border-radius: 12px;
  font: inherit;
  padding: 10px 13px;
  min-height: 44px;
  cursor: pointer;
  transition: background 0.15s;
}
button:hover {
  background: #ffffff15;
}
button:active {
  background: #ffffff25;
}
button:disabled {
  opacity: 0.35;
  cursor: default;
}
button:focus-visible,
a:focus-visible,
[role="button"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}
[hidden] {
  display: none !important;
}
#app {
  max-width: 1080px;
  padding: 28px 38px 18px;
  margin: auto;
}
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 24px;
  border-bottom: 1px solid #c7d5e21a;
}
.brand {
  display: flex;
  align-items: center;
  gap: 15px;
  color: #e6eefa;
  text-decoration: none;
  font-size: 23px;
  font-weight: 300;
  letter-spacing: 5px;
}
.brand svg {
  width: 36px;
  height: 36px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
}
.brand small {
  display: block;
  font-size: 7px;
  letter-spacing: 2.4px;
  color: #b1c0d1;
  margin-top: 6px;
}
nav {
  display: flex;
  gap: 8px;
}
nav button {
  width: 44px;
  padding: 7px;
  font-size: 20px;
}
.intro {
  margin: 26px 0 0;
}
.eyebrow {
  color: var(--accent);
  letter-spacing: 2.4px;
  font-size: 10px;
  font-weight: 600;
  margin: 0 0 9px;
}
.heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
h1 {
  font:
    normal 35px/1.2 Georgia,
    serif;
  margin: 0;
}
#counter {
  border: 0;
  background: none;
  font:
    28px Georgia,
    serif;
  padding: 0 8px;
}
#counter small {
  font: 12px system-ui;
  color: #a5b9cb;
}
.rule {
  font-size: 13px;
  color: #b8c9dc;
  margin: 13px 0 18px;
}
.journey {
  height: 2px;
  background: #e8eff715;
}
.journey span {
  display: block;
  background: var(--accent);
  height: 100%;
  transition: width 0.3s;
}
.play {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 265px;
  gap: 28px;
  align-items: center;
  padding-top: 26px;
}
.constellation {
  min-width: 0;
  position: relative;
}
.board-frame {
  padding: 14px 0;
  background: radial-gradient(ellipse, #bddcff07, transparent 66%);
  border: 1px solid #d2e5f014;
  border-radius: 28px;
}
#board {
  width: 100%;
  display: block;
  overflow: visible;
  touch-action: pan-y;
  user-select: none;
  min-height: 300px;
  max-height: 560px;
}
#board .tile {
  cursor: pointer;
  outline: none;
}
#board .tile .surface {
  transition:
    fill 0.2s,
    stroke 0.2s;
  fill: #233c59;
  stroke: #8aabc05c;
  stroke-width: 1.4;
}
#board .tile:nth-child(3n) .surface {
  fill: #2b405d;
}
#board .tile:hover .surface {
  fill: #3b5576;
}
#board .tile.selected .surface {
  fill: #3a526d;
  stroke: var(--accent);
  stroke-width: 2;
}
#board .tile.related .surface {
  fill: #355974;
  stroke: #a4cadb;
}
#board .tile:focus-visible .surface {
  stroke: var(--accent);
  stroke-width: 3;
}
#board text {
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: middle;
  font-family: system-ui;
}
#board .digit {
  font-size: 19px;
  fill: #ebf2fb;
  font-weight: 600;
}
#board .rotor {
  fill: #9fb7c8;
  font-size: 14px;
}
#board .node {
  cursor: pointer;
}
#board .node circle {
  fill: #112a40;
  stroke: #718fa4;
  stroke-width: 1.5;
}
#board .node.good circle {
  fill: #275758;
  stroke: #a8d7bd;
}
#board .node.active circle {
  stroke: var(--accent);
  stroke-width: 3;
}
#board .node text {
  font-size: 14px;
  fill: #d5e6ef;
}
#board .node.good text {
  fill: #e1f8e6;
}
#board .node .goal {
  font-weight: 750;
  font-size: 19px;
}
#board .beam {
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 3 4;
  pointer-events: none;
}
#board.won .surface {
  fill: #315354;
  stroke: #a0cabe;
}
#board.won {
  filter: drop-shadow(0 0 15px #9dddcb18);
}
.legend {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin: 15px 3px 0;
  font-size: 9px;
  letter-spacing: 0.7px;
  color: #9db4c8;
}
.dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  background: #a8d7bd;
  border-radius: 50%;
  margin-right: 5px;
}
.card {
  padding: 22px;
  border-radius: 22px;
  border: 1px solid #d2dfed21;
  background: #ffffff04;
  box-shadow: 0 14px 35px #00111c12;
}
.card .eyebrow {
  font-size: 8px;
  letter-spacing: 1.6px;
}
.motif {
  text-align: center;
  font:
    30px Georgia,
    serif;
  color: var(--accent);
  margin: 24px 0;
}
.motif span {
  font: 19px system-ui;
  color: #8ba7bc;
  padding: 0 5px;
}
#status {
  font-size: 13px;
  line-height: 1.6;
  margin: 15px 0;
  min-height: 62px;
}
.muted {
  font-size: 12px;
  line-height: 1.6;
  color: #a5bbce;
}
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 20px;
}
.actions button {
  font-size: 11px;
  padding: 10px 5px;
}
.lesson {
  font-size: 11px;
  color: #90a9bf;
  line-height: 1.65;
  padding: 0 12px;
}
.win {
  text-align: center;
  margin: 14px 0;
}
.star {
  color: var(--accent);
  font-size: 40px;
}
.win h2 {
  font:
    24px Georgia,
    serif;
  margin: 0 0 8px;
}
.win p {
  font-size: 12px;
  color: #a5bbce;
}
.primary {
  background: var(--accent);
  color: #182d3e;
  border-color: transparent;
  width: 100%;
  font-size: 12px;
  font-weight: 650;
}
.primary:hover {
  background: #fff0ca;
}
.win .primary {
  margin-top: 8px;
}
footer {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: #839eb6;
  margin: 30px 0 0;
  gap: 10px;
}
dialog {
  background: #15263d;
  color: #e2edf8;
  border: 1px solid #8ea5bc4f;
  border-radius: 24px;
  width: min(92vw, 480px);
  padding: 30px;
  max-height: 90dvh;
  box-shadow: 0 20px 100px #0007;
}
dialog::backdrop {
  background: #050e22bb;
  backdrop-filter: blur(5px);
}
dialog h2 {
  font:
    30px/1.2 Georgia,
    serif;
  margin: 15px 0 18px;
}
dialog ol {
  padding-left: 20px;
}
dialog li,
dialog p {
  font-size: 13px;
  line-height: 1.65;
}
dialog li {
  padding-bottom: 8px;
}
.close {
  position: absolute;
  right: 10px;
  top: 10px;
  border: 0;
  font-size: 24px;
  background: none;
}
.demo {
  width: 100%;
  max-height: 135px;
}
.demo text {
  fill: #e6cd9f;
  text-anchor: middle;
  font: 22px Georgia;
}
.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
}
.level-grid button {
  font-size: 13px;
  padding: 8px 3px;
}
.level-grid .done {
  background: #275758;
}
.level-grid .current {
  border-color: var(--accent);
}
#levels h3 {
  font-size: 12px;
  letter-spacing: 1px;
  margin: 25px 0 10px;
}
#update {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: #263c53;
  padding: 9px 13px;
  border: 1px solid #9aaebd;
  border-radius: 12px;
  font-size: 12px;
  z-index: 10;
}
@media (max-width: 700px) {
  #app {
    padding: 15px 17px;
  }
  header {
    padding-bottom: 16px;
  }
  .brand {
    font-size: 20px;
    gap: 10px;
  }
  .brand svg {
    width: 29px;
  }
  .brand small {
    font-size: 6px;
  }
  nav {
    gap: 5px;
  }
  .intro {
    margin-top: 20px;
  }
  h1 {
    font-size: 29px;
  }
  .rule {
    font-size: 12px;
    line-height: 1.5;
  }
  .play {
    display: block;
    padding-top: 12px;
  }
  .board-frame {
    padding: 10px 0;
  }
  #board {
    min-height: 210px;
    max-height: 410px;
  }
  .legend {
    font-size: 8px;
    margin-top: 10px;
  }
  .card {
    margin-top: 18px;
    padding: 13px 15px;
  }
  .card .eyebrow,
  .motif {
    display: none;
  }
  #status {
    margin: 0;
    min-height: 36px;
    font-size: 12px;
  }
  #selection {
    font-size: 11px;
    margin: 6px 0;
  }
  .actions {
    display: flex;
    gap: 6px;
    margin-top: 12px;
  }
  .actions button {
    flex: 1;
    font-size: 10px;
    padding: 7px 3px;
  }
  .lesson {
    font-size: 10px;
    margin-bottom: 0;
  }
  .win {
    margin: 15px 0;
  }
  .star {
    display: none;
  }
  footer {
    font-size: 9px;
    margin-top: 18px;
  }
  dialog {
    padding: 26px 22px;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}

#zoom {
  font-size: 10px;
  padding: 6px 8px;
  white-space: nowrap;
}
.board-frame.zoomed {
  overflow: auto;
  max-height: 600px;
  touch-action: pan-x pan-y;
}
.board-frame.zoomed #board {
  width: 160%;
  min-height: 0;
  max-height: none;
  touch-action: pan-x pan-y;
}
@media (max-width: 700px) {
  .board-frame.zoomed {
    max-height: 480px;
  }
  .legend {
    flex-wrap: wrap;
  }
}

/* Crystal edition: light belongs to the pieces, atmosphere stays behind them. */
body {
  background:
    radial-gradient(ellipse at 12% 0%, #54648355, transparent 48%),
    radial-gradient(ellipse at 100% 95%, var(--sky), transparent 65%), #0c172b;
}
header {
  border-bottom-color: #c2ddf021;
}
.brand {
  font-weight: 500;
}
.brand svg {
  filter: drop-shadow(0 0 6px #eac79444);
}
.board-frame {
  position: relative;
  background:
    radial-gradient(circle at 23% 19%, #deedff3d 0 0.7px, transparent 1.3px),
    radial-gradient(circle at 76% 72%, #d6ebff2e 0 0.8px, transparent 1.4px),
    radial-gradient(ellipse at 50% 35%, #55749c22, transparent 72%),
    linear-gradient(145deg, #ffffff05, #020c191a);
  background-size:
    83px 97px,
    107px 123px,
    auto,
    auto;
  border-color: #b9d3e226;
  box-shadow:
    inset 0 1px 0 #d5e7f010,
    0 16px 42px #000d1a22;
  border-radius: 26px;
}
#board .tile .surface,
#board .tile:nth-child(3n) .surface {
  fill: url(#facet);
  stroke: #96b9d087;
  stroke-width: 1.2;
  filter: drop-shadow(0 2px 1px #000a1e66);
}
#board .inlay {
  fill: none;
  stroke: #c4dcec12;
  stroke-width: 0.6;
  pointer-events: none;
}
#board .facet-shine {
  fill: none;
  stroke: #d5eeff65;
  stroke-width: 1;
  pointer-events: none;
}
#board .tile.selected .surface {
  fill: #3b607e;
  stroke: var(--accent);
  stroke-width: 2.3;
}
#board .tile.related .surface {
  fill: #355b73;
  stroke: #cce7f2;
}
#board .digit {
  font-weight: 650;
  fill: #f2f7ff;
  paint-order: stroke;
  stroke: #11294355;
  stroke-width: 0.6;
}
#board .rotor {
  fill: #97bbd0;
  font-size: 12px;
}
#board .node .lens {
  fill: url(#beacon);
  stroke: #96bfd2;
  stroke-width: 1.5;
  filter: drop-shadow(0 2px 2px #000a2255);
}
#board .node .aura {
  fill: none;
  stroke: #9bbbd71f;
  stroke-width: 0.8;
  pointer-events: none;
}
#board .node.good .lens {
  fill: #214e50;
  stroke: #b6e9cf;
  stroke-width: 1.8;
}
#board .node.good .aura {
  stroke: #a4f4d357;
  stroke-width: 1.1;
}
#board .node.active .lens {
  stroke: var(--accent);
  stroke-width: 2.7;
}
#board .node.good .goal {
  fill: #e0ffed;
}
#board .node .goal {
  font-weight: 750;
}
#board.won .tile .surface {
  fill: #2c535c;
  stroke: #b5e7d4;
}
.card {
  background: linear-gradient(140deg, #ffffff07, #ffffff02);
  border-color: #aec8e228;
  box-shadow:
    inset 0 1px 0 #f0f7ff07,
    0 14px 30px #00101d14;
}
.actions button {
  background: #11283d66;
  border-color: #b5d5e02b;
}
.actions button:not(:disabled):hover {
  background: #36536d;
}
.primary {
  box-shadow: 0 6px 23px #06142533;
  border-radius: 14px;
  min-height: 48px;
}
.legend {
  font-size: 9px;
  color: #bad0e0;
}
.lesson {
  color: #a6bbcf;
}
#status {
  color: #e1edf8;
}
.muted {
  color: #b5cadd;
}
.transfer {
  border-top: 1px solid #9bbbd733;
  margin-top: 22px;
  padding-top: 16px;
}
.transfer-actions {
  display: flex;
  gap: 8px;
}
.transfer-actions button {
  flex: 1;
  font-size: 12px;
}
.transfer p {
  font-size: 11px;
}
@media (max-width: 700px) {
  #app {
    padding: max(14px, env(safe-area-inset-top))
      max(15px, env(safe-area-inset-right))
      max(20px, env(safe-area-inset-bottom))
      max(15px, env(safe-area-inset-left));
  }
  header {
    padding-bottom: 13px;
  }
  .intro {
    margin-top: 17px;
  }
  h1 {
    font-size: clamp(25px, 6.8vw, 31px);
  }
  .rule {
    margin: 10px 0 14px;
  }
  .play {
    padding-top: 13px;
  }
  .board-frame {
    border-radius: 23px;
    padding: 14px 2px;
  }
  #board {
    max-height: min(490px, 58dvh);
    min-height: 220px;
  }
  .card {
    margin-top: 12px;
    padding: 13px 14px;
    border-radius: 19px;
  }
  #status {
    min-height: 34px;
    line-height: 1.5;
  }
  .actions {
    gap: 7px;
  }
  .actions button {
    min-height: 48px;
    font-size: 11px;
    padding: 8px 4px;
  }
  .legend {
    margin-top: 8px;
    font-size: 8px;
  }
  #zoom {
    min-height: 44px;
  }
  .lesson {
    margin-top: 11px;
    padding: 0 4px;
  }
  .win h2 {
    font-size: 26px;
  }
  footer {
    font-size: 9px;
    line-height: 1.5;
    margin-top: 16px;
  }
  .board-frame.zoomed {
    max-height: 65dvh;
  }
  dialog {
    padding-bottom: max(26px, env(safe-area-inset-bottom));
  }
}
@media (display-mode: standalone) {
  header {
    padding-top: 3px;
  }
  body {
    overscroll-behavior-y: contain;
  }
}
