:root {
  color-scheme: dark;
  --ink: #173451;
  --cream: #fff8db;
  --yellow: #ffd83d;
  --orange: #ff8a38;
  --blue: #4ab6ff;
  --deep-blue: #1767ad;
  --pink: #ff6f91;
  --panel: rgba(255, 255, 255, .91);
  --display: "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: #75cef5;
  color: var(--ink);
  font-family: "Trebuchet MS", system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

button { font: inherit; }

#game, #world {
  width: 100%;
  height: 100%;
}

#game { position: relative; overflow: hidden; }

#world {
  position: absolute;
  inset: 0;
  display: block;
  outline: none;
}

.damage-flash { position: absolute; z-index: 18; inset: 0; opacity: 0; pointer-events: none; background: radial-gradient(circle, transparent 28%, rgba(255,48,80,.55) 100%); }
.damage-flash.hit { animation: damage-flash .42s ease-out; }

.curtain {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 20px;
  color: white;
  background: linear-gradient(150deg, #52c3ff, #8adbf3 50%, #ffc66b);
  transition: opacity .55s ease, visibility .55s;
}

.curtain.done { opacity: 0; visibility: hidden; }
.curtain p { margin: 0; font-weight: 800; letter-spacing: .04em; }

.loading-mark { position: relative; width: 82px; height: 82px; animation: bob 1s ease-in-out infinite; }
.loading-mark span {
  position: absolute; inset: 13px; border-radius: 21px 21px 30px 30px;
  background: #ff754f; box-shadow: inset -8px -7px 0 rgba(147, 47, 57, .18), 0 10px 20px rgba(31, 91, 130, .2);
}
.loading-mark span::before, .loading-mark span::after {
  content: ""; position: absolute; top: -13px; width: 23px; height: 28px; background: #ff754f;
}
.loading-mark span::before { left: 2px; border-radius: 5px 24px 4px 10px; transform: rotate(-17deg); }
.loading-mark span::after { right: 2px; border-radius: 24px 5px 10px 4px; transform: rotate(17deg); }
.loading-mark i { position: absolute; left: 30px; top: 40px; width: 8px; height: 8px; border-radius: 50%; background: white; box-shadow: 20px 0 white; }

.overlay {
  position: absolute;
  z-index: 30;
  left: clamp(24px, 7vw, 110px);
  top: 50%;
  transform: translateY(-50%);
}

.title-card {
  width: min(520px, calc(100vw - 48px));
  padding: clamp(26px, 4vw, 50px);
  border: 4px solid rgba(255,255,255,.86);
  border-radius: 40px 14px 40px 14px;
  background: rgba(255, 251, 227, .89);
  box-shadow: 0 26px 70px rgba(31, 84, 115, .25), inset 0 0 0 3px rgba(255, 192, 73, .15);
  backdrop-filter: blur(14px);
}

.eyebrow {
  margin-bottom: 12px;
  color: #da5d47;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.title-card h1 {
  margin: 0;
  color: #284f71;
  font-family: var(--display);
  font-size: clamp(48px, 7vw, 86px);
  line-height: .76;
  letter-spacing: -.06em;
  text-shadow: 0 4px 0 white;
}

.title-card h1 span { color: #ff765b; font-size: .68em; letter-spacing: -.03em; }
.title-card > p { max-width: 400px; margin: 24px 0; color: #49677d; font-weight: 700; line-height: 1.5; }
.title-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.tool-button {
  min-height: 36px; padding: 0 13px; border: 1px solid rgba(48,83,105,.14); border-radius: 11px;
  color: #527084; background: rgba(255,255,255,.62); cursor: pointer; font-size: 11px; font-weight: 900;
}

.primary, .secondary {
  min-width: 210px;
  min-height: 52px;
  padding: 0 22px;
  border: 0;
  border-radius: 18px;
  cursor: pointer;
  font-weight: 900;
  transition: transform .16s, box-shadow .16s;
}
.primary {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  color: white;
  background: linear-gradient(180deg, #ff8a51, #f25c4c);
  box-shadow: 0 7px 0 #bd403d, 0 13px 22px rgba(158, 54, 52, .2);
}
.secondary { color: #47677d; background: #e9f1f1; box-shadow: 0 5px 0 #c4d4d4; }
.primary:hover, .secondary:hover { transform: translateY(-2px); }
.primary:active, .secondary:active { transform: translateY(4px); box-shadow: 0 2px 0 #bd403d; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 4px solid #ffe15d; outline-offset: 3px; }

kbd {
  display: inline-grid;
  min-width: 28px;
  height: 26px;
  padding: 0 7px;
  place-items: center;
  border: 1px solid rgba(27, 65, 92, .18);
  border-radius: 8px;
  color: #36566e;
  background: rgba(255,255,255,.7);
  box-shadow: 0 2px 0 rgba(27, 65, 92, .14);
  font-family: inherit;
  font-size: 10px;
  font-weight: 900;
}

.controls-preview { display: flex; flex-wrap: wrap; gap: 14px 18px; margin-top: 27px; }
.controls-preview span { display: flex; align-items: center; gap: 7px; color: #7390a2; font-size: 11px; font-weight: 800; }

.hud {
  position: absolute;
  z-index: 12;
  top: 22px;
  left: 24px;
  right: 24px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 16px;
  pointer-events: none;
}

.hud[hidden], [hidden] { display: none !important; }
.hud-pill, .collectible-count, .timer {
  border: 2px solid rgba(255,255,255,.85);
  background: var(--panel);
  box-shadow: 0 7px 22px rgba(31, 76, 103, .16);
  backdrop-filter: blur(8px);
}
.hud-pill { width: max-content; padding: 10px 15px; border-radius: 17px; }
.level-pill strong { display: block; font-family: var(--display); font-size: 14px; }
.mini-label { display: block; color: #6f8b9d; font-size: 9px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.hud-center { display: flex; align-items: stretch; gap: 8px; }
.collectible-count, .timer { display: flex; align-items: center; min-height: 48px; padding: 0 17px; border-radius: 17px; }
.collectible-count strong { margin-left: 8px; font-family: var(--display); font-size: 21px; }
.collectible-count small { margin-left: 4px; color: #8298a6; font-weight: 900; }
.shard-icon { color: #ffc923; font-size: 20px; filter: drop-shadow(0 2px 0 #e59623); }
.timer { min-width: 85px; justify-content: center; color: #426176; font-size: 13px; font-weight: 900; }
.hearts { justify-self: end; display: flex; gap: 4px; min-height: 48px; align-items: center; }
.heart { color: #ff5f71; font-size: 22px; filter: drop-shadow(0 2px 0 #ca4059); transition: transform .2s; }
.heart.empty { color: #c8d4d7; filter: none; transform: scale(.85); }

.objective {
  position: absolute;
  z-index: 12;
  top: 92px;
  left: 24px;
  width: min(260px, calc(100vw - 48px));
  padding: 12px 15px;
  border-left: 4px solid #ffc73d;
  border-radius: 4px 15px 15px 4px;
  background: rgba(255,255,255,.86);
  box-shadow: 0 7px 20px rgba(31, 76, 103, .13);
  backdrop-filter: blur(8px);
}
.objective strong { display: block; margin-top: 2px; font-size: 12px; }
.objective-track { height: 5px; margin-top: 8px; overflow: hidden; border-radius: 5px; background: #dce5e5; }
.objective-track i { display: block; width: 0; height: 100%; background: linear-gradient(90deg, #ffc530, #ff7d4b); transition: width .35s; }

.powerup-hud {
  position: absolute;
  z-index: 12;
  top: 174px;
  left: 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 13px 9px 9px;
  border: 2px solid rgba(255,255,255,.88);
  border-radius: 17px;
  color: #594482;
  background: rgba(246, 232, 255, .92);
  box-shadow: 0 7px 20px rgba(73, 45, 111, .16);
  backdrop-filter: blur(8px);
}
.powerup-orb { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 50%; color: white; background: linear-gradient(145deg, #a681ed, #5fcce2); box-shadow: 0 4px 9px rgba(100,85,170,.26); }
.powerup-hud small, .powerup-hud strong { display: block; line-height: 1.1; }
.powerup-hud small { color: #907aa9; font-size: 8px; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; }
.powerup-hud strong { margin-top: 3px; font-family: var(--display); font-size: 14px; }

.boss-hud {
  position: absolute;
  z-index: 13;
  top: 86px;
  left: 50%;
  width: min(390px, calc(100vw - 32px));
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 13px;
  padding: 10px 14px;
  border: 2px solid rgba(255,255,255,.88);
  border-radius: 18px;
  color: #49385f;
  background: rgba(248, 237, 255, .93);
  box-shadow: 0 8px 24px rgba(48, 29, 78, .2);
  backdrop-filter: blur(9px);
}
.boss-hud strong { display: block; font-family: var(--display); font-size: 15px; }
.boss-track { height: 9px; overflow: hidden; border-radius: 9px; background: #d7cbe2; }
.boss-track i { display: block; width: 100%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #8064cb, #e468b0); transition: width .35s; }
.boss-hearts { color: #a16cdf; font-size: 13px; letter-spacing: 2px; white-space: nowrap; }

.toast {
  position: absolute;
  z-index: 20;
  left: 50%;
  bottom: 42px;
  transform: translate(-50%, 24px) scale(.96);
  padding: 11px 20px;
  border: 2px solid white;
  border-radius: 16px;
  opacity: 0;
  color: #34566f;
  background: rgba(255,255,255,.92);
  box-shadow: 0 8px 25px rgba(27, 67, 93, .2);
  font-size: 12px;
  font-weight: 900;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }

.tutorial {
  position: absolute; z-index: 22; left: 50%; bottom: 30px; width: min(620px, calc(100vw - 34px));
  transform: translateX(-50%); display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 14px;
  padding: 13px 15px; border: 3px solid white; border-radius: 20px; color: #36546a;
  background: rgba(255,250,226,.95); box-shadow: 0 13px 35px rgba(31,64,84,.24); backdrop-filter: blur(10px);
}
.tutorial-step { display: flex; align-items: center; gap: 4px; }
.tutorial-step span, .tutorial-step i { display: block; width: 9px; height: 9px; border-radius: 50%; background: #d3dfe1; }
.tutorial-step span { display: grid; width: 30px; height: 30px; place-items: center; color: white; background: #ff7959; font-size: 11px; font-weight: 900; }
.tutorial-step i.done { background: #ffb436; }
.tutorial strong { display: block; font-family: var(--display); font-size: 14px; }
.tutorial p { margin: 2px 0 0; color: #718b9a; font-size: 10px; }
.tutorial > kbd { min-width: 58px; background: white; }
.tutorial button { min-height: 32px; padding: 0 10px; border: 0; border-radius: 9px; color: #6f8795; background: #e8eeee; cursor: pointer; font-size: 9px; font-weight: 900; }

.dialog {
  left: 50%;
  width: min(440px, calc(100vw - 40px));
  padding: 38px;
  transform: translate(-50%, -50%);
  border: 4px solid white;
  border-radius: 30px;
  text-align: center;
  background: rgba(255, 250, 224, .94);
  box-shadow: 0 24px 80px rgba(25, 71, 100, .34);
  backdrop-filter: blur(16px);
}
.dialog::before { content: ""; position: fixed; inset: -100vh -100vw; z-index: -2; background: rgba(26, 76, 107, .2); }
.dialog h2 { margin: 0 0 22px; color: #2f5570; font-family: var(--display); font-size: 38px; }
.dialog button { display: flex; width: 100%; margin-top: 12px; justify-content: center; }
.dialog > p { margin: 20px 0 0; color: #77909f; font-size: 12px; }
.finish-card { width: min(550px, calc(100vw - 40px)); }
.victory-burst { color: #ffbf20; font-size: 70px; line-height: .8; filter: drop-shadow(0 6px 0 #f28245); animation: victory 1.5s ease-in-out infinite; }
.finish-card h2 { margin: 12px 0 8px; }
.finish-card > p { margin: 0 0 22px; }
.score-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 22px 0; }
.score-row div { padding: 12px 6px; border-radius: 14px; background: rgba(72, 171, 213, .1); }
.score-row span { display: block; color: #7991a0; font-size: 9px; font-weight: 900; text-transform: uppercase; letter-spacing: .08em; }
.score-row strong { font-family: var(--display); font-size: 20px; }
.best-time { margin: -8px 0 18px !important; color: #d4684e !important; font-weight: 900; }

.wide-dialog { width: min(850px, calc(100vw - 34px)); max-height: calc(100vh - 36px); overflow: auto; }
.wide-dialog h2, .settings-dialog h2 { margin-bottom: 18px; }
.course-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; text-align: left; }
.course-card {
  position: relative; overflow: hidden; min-height: 246px; padding: 20px; border: 3px solid rgba(255,255,255,.8);
  border-radius: 22px; color: white; box-shadow: inset 0 -70px 70px rgba(37,56,75,.13);
}
.course-card::before { content: ""; position: absolute; right: -26px; top: -28px; width: 110px; height: 110px; border: 22px solid rgba(255,255,255,.14); border-radius: 50%; }
.course-card.meadow { background: linear-gradient(145deg, #55bf70, #42a9be); }
.course-card.summit { background: linear-gradient(145deg, #ef9b59, #d36ea6); }
.course-card.citadel { background: linear-gradient(145deg, #6878c5, #7050a2); }
.course-card.locked { filter: saturate(.25); color: rgba(255,255,255,.72); }
.course-card.locked::after { content: "LOCKED"; position: absolute; inset: 0; display: grid; place-items: center; background: rgba(39,45,63,.42); font-size: 12px; font-weight: 900; letter-spacing: .16em; }
.course-card h3 { position: relative; margin: 9px 0 7px; font-family: var(--display); font-size: 24px; line-height: 1; }
.course-card p { position: relative; min-height: 38px; margin: 0; color: rgba(255,255,255,.8); font-size: 11px; }
.course-number { position: relative; font-size: 9px; font-weight: 900; letter-spacing: .13em; text-transform: uppercase; }
.course-record { position: relative; display: block; margin: 18px 0 4px; font-size: 11px; }
.course-card button { position: relative; z-index: 2; min-height: 40px; border: 0; border-radius: 12px; color: #38526a; background: rgba(255,255,255,.9); cursor: pointer; font-size: 11px; font-weight: 900; }
.course-card button:disabled { cursor: not-allowed; opacity: .3; }
.wide-dialog > .close-panel, .settings-dialog > .close-panel { width: min(230px, 100%); margin: 20px auto 0; }

.badge-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; text-align: left; }
.badge-grid article { display: flex; align-items: center; gap: 12px; min-height: 82px; padding: 12px; border: 2px solid #e2e7e4; border-radius: 16px; opacity: .46; background: rgba(255,255,255,.6); }
.badge-grid article.unlocked { opacity: 1; border-color: #ffd260; background: #fff9dd; box-shadow: 0 5px 14px rgba(143,104,39,.11); }
.badge-grid i { display: grid; flex: 0 0 40px; height: 40px; place-items: center; border-radius: 50%; color: white; background: #a9b5bb; font-style: normal; font-size: 19px; }
.badge-grid article.unlocked i { background: linear-gradient(145deg, #ffca3e, #ff7b56); }
.badge-grid strong, .badge-grid small { display: block; }
.badge-grid strong { color: #405e74; font-size: 12px; }
.badge-grid small { margin-top: 3px; color: #8295a1; font-size: 9px; line-height: 1.25; }
.panel-note { margin: 14px 0 0 !important; font-weight: 900; }

.settings-dialog { width: min(570px, calc(100vw - 34px)); max-height: calc(100vh - 34px); overflow: auto; }
.settings-list { display: grid; gap: 8px; text-align: left; }
.settings-list label { display: flex; align-items: center; justify-content: space-between; gap: 20px; min-height: 58px; padding: 10px 14px; border-radius: 14px; background: rgba(84,137,166,.08); }
.settings-list label > span strong, .settings-list label > span small { display: block; }
.settings-list label > span strong { color: #3f5e73; font-size: 12px; }
.settings-list label > span small { margin-top: 2px; color: #8195a2; font-size: 9px; }
.settings-list input[type="checkbox"] { width: 40px; height: 22px; accent-color: #ff765b; cursor: pointer; }
.settings-list select { min-height: 34px; border: 1px solid #cbd9df; border-radius: 9px; color: #405f72; background: white; font: inherit; font-size: 11px; font-weight: 900; }
.setting-range { align-items: stretch !important; flex-direction: column; gap: 8px !important; }
.setting-range > span { display: flex; justify-content: space-between; }
.setting-range input { width: 100%; accent-color: #7a72d1; }
.binding-section { margin-top: 12px; padding: 13px; border-radius: 15px; background: rgba(84,137,166,.08); text-align: left; }
.binding-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.binding-heading strong, .binding-heading small { display: block; }
.binding-heading strong { color: #3f5e73; font-size: 12px; }
.binding-heading small { margin-top: 2px; color: #8195a2; font-size: 9px; }
.binding-heading button { width: auto; min-height: 30px; margin: 0; padding: 0 11px; border: 0; border-radius: 8px; color: #5d7483; background: #dce7e9; cursor: pointer; font-size: 9px; font-weight: 900; }
.binding-grid { display: grid; grid-template-columns: 1fr auto 1fr auto; align-items: center; gap: 7px 10px; margin-top: 12px; }
.binding-grid span { color: #698190; font-size: 10px; font-weight: 800; }
.binding-grid button { width: 74px; min-height: 32px; margin: 0; padding: 0 7px; border: 2px solid white; border-radius: 9px; color: #425e71; background: #f7fbfa; cursor: pointer; font-size: 9px; font-weight: 900; box-shadow: 0 2px 0 #ccdadd; }
.binding-grid button.listening { color: white; background: #ff765b; box-shadow: 0 2px 0 #c54e43; }
.replay-tutorial { width: 100%; margin-top: 12px !important; }

.high-contrast .hud-pill, .high-contrast .collectible-count, .high-contrast .timer, .high-contrast .objective,
.high-contrast .powerup-hud, .high-contrast .boss-hud { border-color: #173451; background: #fff; box-shadow: 0 0 0 2px white, 0 7px 20px rgba(0,0,0,.3); }
.high-contrast .mini-label, .high-contrast .objective strong { color: #102e47; }
.reduced-motion .toast, .reduced-motion .hud *, .reduced-motion .overlay { transition: none !important; }

.crosshair { position: absolute; z-index: 10; left: 50%; top: 50%; width: 8px; height: 8px; transform: translate(-50%, -50%); border: 2px solid rgba(255,255,255,.55); border-radius: 50%; pointer-events: none; }

.mobile-controls { position: absolute; z-index: 16; inset: 0; pointer-events: none; }
.stick { position: absolute; left: 28px; bottom: 28px; width: 112px; height: 112px; border: 3px solid rgba(255,255,255,.7); border-radius: 50%; background: rgba(39, 89, 114, .18); pointer-events: auto; touch-action: none; }
.stick i { position: absolute; left: 31px; top: 31px; width: 44px; height: 44px; border-radius: 50%; background: rgba(255,255,255,.78); box-shadow: 0 5px 14px rgba(31,70,90,.2); }
.action { position: absolute; bottom: 33px; width: 72px; height: 72px; border: 3px solid rgba(255,255,255,.7); border-radius: 50%; color: white; font-size: 26px; font-weight: 900; pointer-events: auto; touch-action: manipulation; }
.jump { right: 28px; background: rgba(255, 107, 78, .8); }
.dash { right: 112px; bottom: 91px; width: 56px; height: 56px; background: rgba(255, 193, 41, .84); }
.rotate-notice { display: none; }

@keyframes bob { 50% { transform: translateY(-8px) rotate(2deg); } }
@keyframes victory { 50% { transform: rotate(10deg) scale(1.08); } }
@keyframes damage-flash { 0% { opacity: .8; } 100% { opacity: 0; } }

@media (pointer: coarse) { .mobile-controls:not([hidden]) { display: block; } .controls-preview { display: none; } }

@media (max-width: 700px) {
  .overlay { left: 18px; }
  .overlay.dialog { left: 50%; }
  .title-card { padding: 28px; border-radius: 30px 12px; }
  .hud { top: 12px; left: 12px; right: 12px; grid-template-columns: auto 1fr auto; }
  .level-pill { display: none; }
  .hud-center { grid-column: 2; justify-self: center; }
  .hearts { grid-column: 3; padding: 7px 10px; }
  .objective { top: 72px; left: 12px; }
  .powerup-hud { top: 154px; left: 12px; }
  .heart { font-size: 17px; }
  .course-grid, .badge-grid { grid-template-columns: 1fr; }
  .wide-dialog { padding: 24px; }
  .course-card { min-height: 190px; }
  .binding-grid { grid-template-columns: 1fr auto; }
  .tutorial { bottom: 18px; grid-template-columns: auto 1fr auto; }
  .tutorial > kbd { display: none; }
  .tutorial button { grid-column: 3; grid-row: 1; }
}

@media (pointer: coarse) { .tutorial { bottom: 150px; } }

@media (orientation: portrait) and (pointer: coarse) {
  .rotate-notice { display: block; position: absolute; z-index: 80; inset: 0; padding-top: 58vh; text-align: center; color: white; background: #4aaee1; font-weight: 900; }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
