:root {
  color-scheme: light;
  font-family: "Trebuchet MS", "Avenir Next", system-ui, sans-serif;
  --gold: #ffd45c;
  --cyan: #63e8ec;
  --navy: #0d3954;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #73dce2;
  color: #fff;
  touch-action: none;
}

button { font: inherit; }

#game-shell {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  background: radial-gradient(circle at 50% 15%, #efffff, #79dfe5 42%, #287f9e 100%);
}
#game-shell:fullscreen,
#game-shell:-webkit-full-screen { width: 100vw; height: 100vh; min-height: 100vh; }

#game {
  display: block;
  width: 100%;
  height: 100%;
}

.hud {
  position: absolute;
  inset: max(12px, env(safe-area-inset-top)) 16px auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  pointer-events: none;
  color: #fff;
}

.hud-actions, .map-button, .artefact-meter {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 900;
  letter-spacing: .03em;
}
.hud-actions { justify-self: start; gap: 6px; }

.brand-star { color: var(--gold); font-size: 1.45rem; }
.map-button {
  justify-self: start;
  padding: 5px 12px;
  border: 1px solid #ffffff38;
  border-radius: 999px;
  color: white;
  background: #071d32ed;
  box-shadow: inset 0 1px 0 #ffffff35, 0 5px 16px #0009;
  cursor: pointer;
  pointer-events: auto;
}
.fullscreen-button { padding-inline: 10px; }
.fullscreen-button > span:first-child { font-size: 1.2rem; line-height: 1; }
#game-shell.standalone .fullscreen-button { display: none; }
.mission {
  min-width: 0;
  padding: 7px 14px 8px;
  border: 1px solid #8cf8ff55;
  border-radius: 16px;
  background: #06192ce8;
  box-shadow: inset 0 1px 0 #ffffff20, 0 5px 16px #0009;
  text-align: center;
}
.mission strong { display: block; color: #fff; font-size: clamp(.9rem, 2vw, 1.15rem); text-shadow: 0 2px 7px #000; }
.eyebrow { margin: 0 0 4px; color: var(--cyan); font-weight: 900; font-size: .7rem; letter-spacing: .16em; }
.artefact-meter {
  justify-self: end;
  flex-wrap: nowrap;
  justify-content: flex-end;
  padding: 7px 10px;
  border: 1px solid #ffffff38;
  border-radius: 16px;
  color: #fff;
  background: #06192ce8;
  box-shadow: inset 0 1px 0 #ffffff20, 0 5px 16px #0009;
  text-shadow: 0 2px 7px #000;
  white-space: nowrap;
}
.shards { display: flex; gap: 4px; }
.shards i { width: 11px; height: 18px; background: #ffffff2a; clip-path: polygon(50% 0,100% 70%,50% 100%,0 70%); }
.shards i.lit { background: var(--gold); filter: drop-shadow(0 0 7px var(--gold)); }

.modal {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(520px, calc(100% - 34px));
  padding: 26px;
  border: 1px solid #85f7ff66;
  border-radius: 28px;
  background: linear-gradient(150deg, #102b49f4, #071426f7);
  box-shadow: 0 24px 70px #000b, inset 0 1px 0 #ffffff30;
  text-align: center;
  color: #fff;
  backdrop-filter: blur(18px);
}

.intro-card {
  width: min(1040px, calc(100% - 34px));
  min-height: min(590px, calc(100% - 36px));
  padding: 24px;
  display: grid;
  grid-template-columns: minmax(250px, .72fr) minmax(430px, 1.45fr);
  gap: 22px;
  align-items: center;
  overflow: hidden;
  border: 3px solid #fff8cc;
  background: linear-gradient(145deg, #fffdf0f5, #c9f8f4f0);
  box-shadow: 0 24px 70px #07516d59, inset 0 2px 0 #fff;
  color: #123c54;
}
.intro-copy { position: relative; z-index: 2; text-align: left; padding-left: 10px; }
.intro-card .eyebrow { color: #087e91; }
.game-logo { position: relative; isolation: isolate; margin: 8px 0 24px !important; display: inline-flex; flex-direction: column; align-items: flex-start; transform: rotate(-2deg); font-family: Impact, Haettenschweiler, "Arial Black", sans-serif; font-weight: 950; line-height: .72 !important; letter-spacing: -.045em !important; }
.logo-times { position: relative; z-index: 2; margin-left: 7px; color: #fff8c8; font-size: .66em; letter-spacing: .12em; -webkit-text-stroke: 2px #155b79; paint-order: stroke fill; text-shadow: 0 5px 0 #0d6f87, 0 9px 15px #17546a80; }
.logo-impossible { position: relative; z-index: 1; display: block; color: #fff; font-size: .92em; -webkit-text-stroke: 3px #155b79; paint-order: stroke fill; text-shadow: 0 6px 0 #f0ae35, 0 11px 0 #d86b43, 0 16px 22px #174d6670; }
.logo-impossible::after { content: ""; position: absolute; z-index: -1; inset: -10% -5% -22%; transform: skew(-8deg); border-radius: 20px 12px 24px 11px; background: linear-gradient(105deg, #39cbd4, #4c8fe2 55%, #9b62d5); box-shadow: 0 0 0 4px #fff8c8, 0 10px 26px #12637965; }
.logo-spark { position: absolute; z-index: 3; right: -22px; top: -17px; color: #ffd24e; font-family: inherit; font-size: .52em; text-shadow: 0 0 12px #fff, 0 3px 0 #d8663e; animation: logoTwinkle 2.2s ease-in-out infinite; }
@keyframes logoTwinkle { 50% { transform: rotate(22deg) scale(1.18); } }
.intro-card p { margin: 22px 0 18px; font-size: 1.03rem; font-weight: 700; }
.intro-card small { color: #476d7d; font-weight: 700; }
.world-previews { position: relative; height: 510px; }
.world-preview {
  position: absolute;
  overflow: hidden;
  border: 4px solid #fff;
  border-radius: 28px;
  box-shadow: 0 18px 42px #084a6970;
  background: #1d7991;
}
.world-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.zero-preview { inset: 0 23% 38% 0; transform: rotate(-2deg); }
.one-preview { inset: 38% 0 0 18%; transform: rotate(2deg); }
.world-preview::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, #06182b1c, transparent 45%, #06243a9e); }
.world-tag, .preview-name, .equation { position: absolute; z-index: 1; color: white; text-shadow: 0 2px 7px #001f31; }
.world-tag { top: 14px; left: 16px; padding: 5px 10px; border-radius: 999px; background: #08364fa8; font-size: .68rem; font-weight: 900; letter-spacing: .13em; }
.preview-name { left: 18px; bottom: 15px; font-size: 1.15rem; font-weight: 900; }
.equation { padding: 7px 12px; border: 2px solid #ffffffc7; border-radius: 999px; background: #fff7d5e8; color: #143b55; text-shadow: none; box-shadow: 0 6px 16px #001b2e75; font-size: clamp(1rem, 2.1vw, 1.5rem); }
.equation-a { top: 16px; right: 14px; }
.equation-b { right: 15px; bottom: 17px; }
.intro-frogo { position: absolute; z-index: 3; width: 180px; left: -30px; bottom: 16px; filter: drop-shadow(0 15px 16px #06304770); }

.teaching-card { width: min(620px, calc(100% - 34px)); color: white; }
.teaching-card h2 { margin: 8px 0; color: #fff5bd; font-size: clamp(1.65rem, 5vw, 2.5rem); }
.teach-progress { display: flex; justify-content: center; gap: 7px; margin-bottom: 15px; }
.teach-progress i { width: 32px; height: 6px; border-radius: 99px; background: #ffffff35; }
.teach-progress i.active { background: #ffd45c; box-shadow: 0 0 10px #ffd45c; }
.teach-visual { min-height: 104px; display: flex; align-items: center; justify-content: center; gap: 12px; }
.teach-group { min-width: 74px; min-height: 70px; display: grid; grid-template-columns: repeat(3, 13px); place-content: center; gap: 5px; padding: 10px; border: 2px dashed #8ffaff; border-radius: 18px; background: #0c4561; }
.teach-group b { width: 13px; height: 13px; border-radius: 50%; background: #ffd45c; box-shadow: 0 0 8px #ffd45c; }
.teach-group.empty::after { content: "empty"; grid-column: 1 / -1; color: #bdfcff; font-size: .7rem; font-style: normal; font-weight: 900; }
.teach-arrow { color: #ffd45c; font-size: 2rem; font-weight: 900; }
.teach-visual .giant-number { color: #fff; font-size: 5rem; font-weight: 950; text-shadow: 0 5px 0 #196c83, 0 0 20px #65edf0; }
.teach-equation { min-height: 50px; margin: 13px auto 18px; display: grid; place-items: center; color: #14384e; background: #fff7cf; border: 3px solid white; border-radius: 18px; font-size: clamp(1.45rem, 6vw, 2.2rem); font-weight: 950; box-shadow: 0 7px 0 #d8902e; }

.modal h1 { margin: 4px 0 12px; font-size: clamp(2.2rem, 8vw, 4.5rem); line-height: .9; color: #fff6ce; text-shadow: 0 5px 0 #8e4f24; }
.modal p { line-height: 1.5; }
.modal small { display: block; margin-top: 14px; color: #bad0dd; }
.portal-mark {
  width: 82px;
  height: 82px;
  margin: -68px auto 10px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 5px solid var(--gold);
  background: #1c6580;
  color: white;
  font-size: 3rem;
  font-weight: 900;
  box-shadow: 0 0 30px var(--cyan), inset 0 0 20px #041527;
}

.primary, .answers button {
  border: 0;
  border-radius: 999px;
  padding: 14px 24px;
  color: #092027;
  background: linear-gradient(#fff18b, #ffc84d);
  font-weight: 900;
  box-shadow: 0 6px 0 #a7591d, 0 10px 24px #0007;
  cursor: pointer;
}
.primary:active, .answers button:active { transform: translateY(4px); box-shadow: 0 2px 0 #a7591d; }

.lesson-card {
  color: #12384f;
  border: 3px solid #fff6c7;
  background: linear-gradient(155deg, #fffdf0f7, #c9f8f4f5);
  box-shadow: 0 24px 70px #000b, inset 0 2px 0 #fff;
}
.lesson-card .eyebrow { color: #087e91; }
.lesson-card.practice-question { border-color: #8cf8ff; }
.lesson-card.challenge-question { border-color: #ffe073; }
.lesson-card.challenge-question .eyebrow { color: #9a5700; }
.lesson-card h2 {
  margin: 12px 0 4px;
  color: #092f48;
  font-size: clamp(2.2rem, 8vw, 3.5rem);
  line-height: 1;
  text-shadow: 0 2px 0 #fff;
}
.lesson-card > p:not(.eyebrow) {
  max-width: 36ch;
  margin: 14px auto 4px;
  color: #17445b;
  font-size: clamp(1rem, 3.8vw, 1.25rem);
  font-weight: 800;
  line-height: 1.35;
}
.wrong-feedback {
  width: max-content;
  margin: 10px auto 2px;
  padding: 8px 18px;
  border-radius: 999px;
  color: #fff;
  background: #c72f45;
  font-size: 1.05rem;
  font-weight: 950;
  letter-spacing: .08em;
  box-shadow: 0 5px 0 #761627;
}
.lesson-card.wrong {
  border-color: #ff5870;
  animation: wrongFlash .42s ease both;
  box-shadow: 0 0 0 8px #ff385544, 0 24px 70px #000b, inset 0 2px 0 #fff;
}
.answers button.wrong-choice {
  color: #fff;
  background: linear-gradient(#ef5c70, #bd263d);
  box-shadow: 0 6px 0 #701325, 0 10px 24px #0007;
}
@keyframes wrongFlash {
  0%, 100% { transform: translate(-50%, -50%); }
  20% { transform: translate(calc(-50% - 10px), -50%); }
  40% { transform: translate(calc(-50% + 10px), -50%); }
  60% { transform: translate(calc(-50% - 6px), -50%); }
  80% { transform: translate(calc(-50% + 6px), -50%); }
}
.visual-groups { min-height: 54px; display: flex; justify-content: center; gap: 8px; align-items: center; }
.visual-groups i { width: 34px; height: 42px; clip-path: polygon(50% 0,95% 34%,76% 100%,24% 100%,5% 34%); background: linear-gradient(135deg, #dcffff, #41dfe9 48%, #1682ad); filter: drop-shadow(0 0 10px #65f8ff); }
.answers { display: flex; justify-content: center; gap: 10px; margin-top: 17px; }
.answers button { min-width: 72px; font-size: 1.2rem; }

.world-map {
  position: absolute;
  z-index: 4;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  overflow: auto;
  color: #10384d;
  background-image: linear-gradient(#e9ffffb8, #ffffff12 35%, #0a4a687d), url("assets/time-map-worlds-v2.webp");
  background-size: cover;
  background-position: center;
}
.map-heading { text-align: center; flex: 0 0 auto; }
.map-heading { width: max-content; max-width: 100%; margin: 0 auto; padding: 8px 24px; border-radius: 22px; background: #f7ffffdc; box-shadow: 0 8px 24px #15576c38; }
.map-heading h2 { margin: 0; color: #155675; font-size: clamp(1.7rem, 5vw, 3rem); }
.map-heading p { margin: 5px 0; }
.map-stage { position: relative; width: min(1100px, 100%); min-height: 390px; margin: 0 auto; flex: 1 0 390px; }
.map-path { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.map-path path { fill: none; stroke: #fff1a8dd; stroke-width: 9; stroke-linecap: round; stroke-dasharray: 9 16; filter: drop-shadow(0 0 8px #fff) drop-shadow(0 3px 2px #93621a); }
.map-nodes { position: absolute; inset: 0; }
.world-node {
  position: absolute;
  width: 104px;
  transform: translate(-50%, -50%);
  border: 0;
  color: #d1dbe0;
  background: transparent;
  text-align: center;
  cursor: default;
}
.world-node .node-orb {
  width: 58px;
  height: 58px;
  margin: 0 auto 5px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 3px solid #8295a1;
  background: #152536;
  font-size: 1.45rem;
  font-weight: 900;
  box-shadow: 0 5px 16px #0008;
}
.map-equation { display: inline-block; margin-bottom: 4px; padding: 4px 7px; border: 2px solid #fff; border-radius: 999px; background: #fff8dceb; color: #17445b; font-size: .65rem; font-weight: 900; box-shadow: 0 4px 10px #154a6173; white-space: nowrap; }
.world-node strong { display: block; padding: 3px 5px; border-radius: 8px; background: #10394dd4; color: white; font-size: .68rem; line-height: 1.08; text-shadow: 0 2px 4px #000; }
.world-node small { color: #94a6b2; font-size: .58rem; }
.world-node.unlocked { color: white; cursor: pointer; }
.world-node.unlocked .node-orb { border-color: var(--gold); background: linear-gradient(145deg, #267891, #0c334c); box-shadow: 0 0 20px #68f2f0aa, inset 0 0 12px #05111c; }
.world-node.completed .node-orb { border-color: #9ff59e; background: #22664c; }
.world-node.completed .node-orb::after { content: "✓"; position: absolute; margin: 43px 0 0 43px; width: 20px; height: 20px; border-radius: 50%; background: #72df8d; color: #082413; font-size: .7rem; line-height: 20px; }
.world-node.locked .node-orb::before { content: "◆"; color: #6e7c85; font-size: .75rem; }
.map-help { margin: 4px auto 0; padding: 7px 14px; border-radius: 999px; background: #f8ffffdc; color: #184d65; text-align: center; font-size: .75rem; font-weight: 800; }

@media (max-width: 760px), (max-height: 650px) {
  .intro-card { grid-template-columns: .65fr 1.35fr; min-height: 0; padding: 16px; gap: 12px; }
  .game-logo { font-size: clamp(2.4rem, 7vw, 4rem) !important; }
  .intro-card p { margin: 14px 0; font-size: .86rem; }
  .world-previews { height: min(430px, calc(100vh - 60px)); }
  .intro-frogo { width: 120px; left: -12px; }
}

@media (max-width: 560px) and (orientation: portrait) {
  .intro-card { top: 49%; grid-template-columns: 1fr; gap: 10px; max-height: calc(100% - 20px); overflow-y: auto; }
  .intro-copy { text-align: center; padding: 0; }
  .game-logo { font-size: 3.4rem !important; align-items: center; }
  .intro-card p { margin: 14px auto; max-width: 34ch; }
  .world-previews { height: 330px; }
  .zero-preview { inset: 0 13% 42% 0; }
  .one-preview { inset: 38% 0 0 13%; }
  .intro-frogo { width: 105px; left: -8px; bottom: 3px; }
}

.completed-artefact {
  width: 90px;
  height: 90px;
  margin: -67px auto 12px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 6px solid var(--gold);
  color: white;
  background: #164b64;
  font-size: 3.4rem;
  font-weight: 900;
  box-shadow: 0 0 32px var(--cyan);
}
.completion-card h2 { margin: 7px 0; font-size: 2rem; color: #fff3be; }
.completion-card.final-ending {
  border-color: #fff1a4;
  background: radial-gradient(circle at 50% 15%, #237b83f5, #102b49f7 55%, #071426fa);
  box-shadow: 0 0 0 7px #ffe06d33, 0 24px 70px #000b, inset 0 1px 0 #fff6;
}
.completion-card.final-ending h2 { font-size: clamp(2rem, 7vw, 3.3rem); text-shadow: 0 3px 0 #93631e, 0 0 18px #ffe66d; }
.visual-groups.zero-groups i { clip-path: none; border-radius: 50%; background: #e7ffff; border: 3px dashed #258da5; filter: none; opacity: 1; }
.visual-groups.zero-groups i::after { content: "0"; display: grid; place-items: center; height: 100%; color: #12667d; font-weight: 900; }

.hidden { display: none !important; }
#game-shell:not(.playing) .hud,
#game-shell:not(.playing) .touch-controls,
#game-shell:not(.playing) .toast { display: none; }

.toast {
  position: absolute;
  left: 50%;
  bottom: 110px;
  transform: translateX(-50%);
  width: min(620px, calc(100% - 40px));
  padding: 11px 16px;
  border-radius: 999px;
  background: #041522c9;
  border: 1px solid #ffffff2c;
  color: #fff;
  text-align: center;
  font-size: .85rem;
  opacity: 0;
  transition: opacity .25s;
  pointer-events: none;
}
.toast.show { opacity: 1; }

.touch-controls {
  position: absolute;
  z-index: 3;
  inset: auto max(14px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}
.touch-controls > div { display: flex; gap: 10px; }
.touch-controls button {
  pointer-events: auto;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid #ffffff55;
  background: #09243dc9;
  color: white;
  font-weight: 900;
  box-shadow: inset 0 1px 0 #fff4, 0 8px 20px #0008;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.touch-controls button.pressed { transform: scale(.92); background: #20778c; }
.touch-controls .tongue-button { width: 78px; height: 78px; color: #cffff4; font-size: .68rem; border-color: #64e8d6aa; }
.touch-controls .jump-button { width: 78px; height: 78px; color: #fff2a8; font-size: .72rem; border-color: #ffd45c88; }

@media (hover: hover) and (pointer: fine) {
  .touch-controls { opacity: .5; }
  .touch-controls:hover { opacity: 1; }
}

@media (max-height: 520px) {
  .hud { top: 8px; }
  .map-button { font-size: .68rem; }
  .artefact-meter span { display: none; }
  .touch-controls button { width: 52px; height: 52px; }
  .touch-controls .tongue-button, .touch-controls .jump-button { width: 62px; height: 62px; }
  .toast { bottom: 82px; }
  .modal { padding: 20px; }
  .modal h1 { font-size: 2.6rem; }
  .modal p { margin: 8px 0; }
  .map-heading p:not(.eyebrow), .map-help { display: none; }
  .map-stage { min-height: 310px; flex-basis: 310px; }
  .world-node { width: 88px; }
  .world-node .node-orb { width: 48px; height: 48px; font-size: 1.15rem; }
  .world-node strong { font-size: .58rem; }
}

@media (max-width: 620px) {
  .hud {
    left: 10px;
    right: 10px;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 7px;
  }
  .map-button { padding: 6px 10px; font-size: .82rem; }
  .fullscreen-button { width: 37px; padding: 6px; justify-content: center; }
  .fullscreen-button > span:last-child { display: none; }
  .brand-star { font-size: 1.1rem; }
  .mission { padding: 6px 8px 7px; }
  .mission .eyebrow { margin-bottom: 2px; font-size: .56rem; letter-spacing: .1em; }
  .mission strong { overflow: hidden; font-size: .75rem; line-height: 1.12; text-overflow: ellipsis; white-space: nowrap; }
  .artefact-meter { padding: 7px; }
  .artefact-meter > span { display: none; }
  .shards { gap: 2px; }
  .shards i { width: 8px; height: 14px; }
}
