:root {
  color-scheme: light;
  --ink: #20133d;
  --purple: #6a3bd1;
  --purple-dark: #40217f;
  --violet: #9f67ff;
  --cream: #fff9e9;
  --pink: #ff76b8;
  --orange: #ff9d33;
  --sky: #bfeeff;
  --shadow: 0 18px 50px rgba(45, 24, 88, 0.18);
}

* { box-sizing: border-box; }

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

body {
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 255, 255, .9) 0 5%, transparent 22%),
    linear-gradient(145deg, #c8f4ff 0%, #eadfff 45%, #fff2c7 100%);
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "Avenir Next", system-ui, sans-serif;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

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

.game-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  background: rgba(255, 255, 255, .72);
  border: 2px solid rgba(255, 255, 255, .85);
  border-radius: 28px;
  box-shadow: var(--shadow);
  overflow: hidden;
  backdrop-filter: blur(18px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px 12px;
}

.brand { display: flex; align-items: center; gap: 13px; }
.brand p { margin: 0 0 2px; color: var(--purple); font-size: 12px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.brand h1 { margin: 0; font-size: clamp(20px, 3vw, 30px); line-height: 1; }

.paw-mark { position: relative; display: block; width: 48px; height: 48px; border-radius: 16px; background: linear-gradient(145deg, #ffbc4d, #ff7c3f); box-shadow: inset 0 2px 5px rgba(255,255,255,.55), 0 7px 16px rgba(208,93,46,.25); }
.paw-mark i, .paw-mark b { position: absolute; display: block; background: #fff8e9; }
.paw-mark i { width: 9px; height: 12px; border-radius: 50%; top: 10px; }
.paw-mark i:nth-child(1) { left: 8px; transform: rotate(-25deg); }
.paw-mark i:nth-child(2) { left: 18px; top: 6px; }
.paw-mark i:nth-child(3) { right: 9px; transform: rotate(25deg); }
.paw-mark i:nth-child(4) { display: none; }
.paw-mark b { width: 24px; height: 19px; border-radius: 52% 52% 45% 45%; left: 12px; bottom: 8px; }

.small-button {
  border: 0;
  background: #efe7ff;
  color: var(--purple-dark);
  font-weight: 900;
  border-radius: 999px;
  padding: 10px 15px;
  cursor: pointer;
}
.small-button:active { transform: translateY(1px); }

.hud {
  display: grid;
  grid-template-columns: 1fr 1.35fr 1.15fr;
  gap: 10px;
  padding: 0 20px 12px;
}

.hud > div {
  min-width: 0;
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(255,255,255,.88);
  border: 1px solid rgba(75, 42, 131, .1);
}

.hud span, .hud small { display: block; color: #715b92; font-size: 11px; font-weight: 800; }
.hud strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.flight-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.flight-label span, .flight-label strong { display: inline; }
.flight-track { height: 10px; background: #e7dcff; border-radius: 999px; overflow: hidden; margin: 6px 0 4px; }
.flight-fill { height: 100%; width: 100%; border-radius: inherit; background: linear-gradient(90deg, #8856ff, #ff77ba); transition: width .12s linear; }

.progress { display: flex; gap: 5px; padding: 0 20px 11px; }
.progress span { flex: 1; height: 6px; border-radius: 999px; background: #ddd2ed; }
.progress span.done { background: linear-gradient(90deg, #7647df, #b06bf3); }
.progress span.current { background: #ff9c3e; box-shadow: 0 0 0 3px rgba(255,156,62,.16); }

.stage-wrap { position: relative; background: #8ddff2; }
canvas { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; outline: none; touch-action: none; }

.game-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: linear-gradient(rgba(37, 21, 70, .24), rgba(37, 21, 70, .5));
  z-index: 5;
}
.game-overlay[hidden] { display: none; }
.overlay-card { width: min(480px, 92%); text-align: center; background: rgba(255, 252, 243, .96); padding: 26px; border-radius: 24px; box-shadow: 0 18px 55px rgba(28,11,64,.3); }
.overlay-card .eyebrow { font-size: 11px; font-weight: 950; letter-spacing: .15em; color: var(--purple); }
.overlay-card h2 { margin: 8px 0; font-size: clamp(25px, 5vw, 38px); line-height: 1.05; }
.overlay-card p { margin: 0 auto 18px; max-width: 390px; color: #5e4e77; font-weight: 650; line-height: 1.45; }
.start-button { border: 0; color: white; background: linear-gradient(135deg, #6f3ad5, #aa56e9); box-shadow: 0 8px 18px rgba(101,53,193,.3); padding: 13px 22px; border-radius: 999px; font-weight: 950; cursor: pointer; }

.toast { position: absolute; left: 50%; top: 18px; translate: -50% -16px; opacity: 0; pointer-events: none; z-index: 4; background: rgba(33,20,60,.9); color: white; border-radius: 999px; padding: 9px 16px; font-size: 13px; font-weight: 900; transition: .2s ease; white-space: nowrap; max-width: calc(100% - 30px); overflow: hidden; text-overflow: ellipsis; }
.toast.show { translate: -50% 0; opacity: 1; }

.controls { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 16px 10px; background: rgba(255,255,255,.94); }
.move-controls, .action-controls, .dance-controls { display: flex; gap: 10px; }
.control-button, .dance-button { min-width: 62px; min-height: 52px; border: 0; border-radius: 17px; color: white; font-weight: 950; box-shadow: inset 0 -4px 0 rgba(0,0,0,.13), 0 5px 12px rgba(46,25,80,.15); cursor: pointer; user-select: none; }
.control-button:active, .control-button.pressed, .dance-button:active { transform: translateY(3px); box-shadow: inset 0 -1px 0 rgba(0,0,0,.13); }
.move-controls .control-button { background: #4b347b; font-size: 21px; }
.jump-button { background: linear-gradient(145deg, #ffac35, #f77b3f); }
.fly-button { background: linear-gradient(145deg, #8c58f4, #d257d6); }
.dance-button { background: linear-gradient(145deg, #ff55ad, #7b54f4); min-width: 86px; }
.dance-controls[hidden] { display: none; }

.keyboard-help { text-align: center; margin: 0; padding: 0 12px 13px; color: #66537f; font-size: 12px; font-weight: 700; background: rgba(255,255,255,.94); }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 700px) {
  body { padding: 0; background: white; }
  .game-shell { border-radius: 0; border: 0; min-height: 100vh; }
  .topbar { padding: 10px 12px 8px; }
  .paw-mark { width: 40px; height: 40px; border-radius: 13px; transform: scale(.88); }
  .brand p { font-size: 9px; }
  .brand h1 { font-size: 17px; }
  .small-button { padding: 8px 10px; font-size: 11px; }
  .hud { grid-template-columns: .85fr 1.15fr; padding: 0 10px 8px; gap: 6px; }
  .mission-card { display: none; }
  .hud > div { padding: 7px 9px; border-radius: 12px; }
  .hud strong { font-size: 12px; }
  .progress { padding: 0 10px 8px; }
  .controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    padding: 10px max(10px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }
  .move-controls { justify-self: start; }
  .action-controls { justify-self: end; }
  .dance-controls:not([hidden]) { grid-column: 1 / -1; justify-self: center; margin-top: 4px; }
  .control-button { min-width: 54px; min-height: 50px; border-radius: 15px; font-size: 12px; }
  .move-controls, .action-controls, .dance-controls { gap: 7px; }
  .dance-button { min-width: 69px; min-height: 48px; font-size: 11px; }
  .keyboard-help { display: none; }
}

@media (max-width: 430px) {
  .controls { gap: 6px; }
  .control-button { min-width: 48px; }
}
