:root {
  color-scheme: dark;
  font-family: "Trebuchet MS", ui-rounded, system-ui, sans-serif;
  color: #f7fbff;
  background: #6ecbf4;
  --ink: #102a46;
  --paper: #fffdf4;
  --sun: #ffe27a;
  --coral: #ff8c63;
  --teal: #4fe0c8;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: #6ecbf4;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: var(--ink);
  border: 0;
  border-radius: 14px;
  padding: 10px 16px;
  background: #eaf7ff;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

button:active { transform: translateY(1px) scale(.98); }
button:focus-visible { outline: 3px solid var(--sun); outline-offset: 3px; }
button:disabled { opacity: .45; cursor: default; }

#game {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
  outline: none;
}

body.playing #game { cursor: crosshair; }
body.playing.locked #game { cursor: none; }

#portal-flash {
  position: fixed;
  z-index: 40;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background:
    radial-gradient(circle at 50% 55%, #ffffff 0%, #c9fbff 18%, #7de7ff 42%, transparent 72%);
  mix-blend-mode: screen;
}
#portal-flash.active { animation: portal-flash .62s ease-out; }
@keyframes portal-flash {
  0% { opacity: 0; transform: scale(1.25); }
  22% { opacity: 0.95; }
  100% { opacity: 0; transform: scale(1); }
}

#hud {
  position: fixed;
  z-index: 5;
  top: calc(var(--safe-top) + 12px);
  left: calc(var(--safe-left) + 14px);
  right: calc(var(--safe-right) + 14px);
  display: grid;
  grid-template-columns: minmax(130px, auto) minmax(220px, 1fr) auto;
  grid-template-areas: "hearts objective actions";
  gap: 12px;
  align-items: start;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity .3s ease, transform .3s ease;
}

body.started #hud { opacity: 1; transform: none; }

#hearts-wrap { grid-area: hearts; display: flex; flex-direction: column; gap: 5px; }
#hearts { display: flex; gap: 3px; min-height: 25px; filter: drop-shadow(0 2px 2px #102a4670); }
.heart { width: clamp(19px, 3.3vw, 27px); height: auto; color: #ff5f7a; transition: color .2s, opacity .2s, transform .2s; }
.heart path { fill: currentColor; stroke: #7f1730; stroke-width: 1.6; }
.heart.empty { color: #26384c; opacity: .55; }
.heart.pop { animation: heart-pop .32s ease; }

#land-progress {
  width: max-content;
  padding: 3px 9px;
  border-radius: 999px;
  background: #0b2038b8;
  color: #ccefff;
  font-size: clamp(.62rem, 1.4vw, .78rem);
  font-weight: 700;
  letter-spacing: .02em;
  backdrop-filter: blur(4px);
}

#brick-supply {
  display: flex;
  align-items: center;
  gap: 7px;
  width: max-content;
  padding: 3px 9px 3px 7px;
  border-radius: 999px;
  background: #0b2038b8;
  color: #ffe3cf;
  font-size: clamp(.62rem, 1.4vw, .78rem);
  font-weight: 700;
  letter-spacing: .01em;
  backdrop-filter: blur(4px);
  transition: color .2s, background .2s;
}
#brick-supply.empty { color: #ffb8aa; background: #3b1717d6; }
.brick-mini {
  width: 17px;
  height: 9px;
  border-radius: 2px;
  background: linear-gradient(#da8255, #ab4d2b);
  box-shadow: inset 0 1px #ffc3a0, 0 1px 0 #5f2b19;
}

#objective-card {
  grid-area: objective;
  justify-self: center;
  width: min(440px, 100%);
  padding: 10px 14px 9px;
  border-radius: 18px;
  background: linear-gradient(180deg, #fffdf4ee, #e9f8ffee);
  color: var(--ink);
  box-shadow: 0 8px 24px #0b2d4c40, inset 0 1px 0 #fff;
  border: 2px solid #ffffffaa;
  text-align: center;
}

#zone-name {
  margin: 0 0 2px;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: #28749b;
}

#objective {
  margin: 0;
  font-size: clamp(.78rem, 1.6vw, .95rem);
  font-weight: 700;
  line-height: 1.25;
}

#waypoint {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 7px;
  margin: 5px 0 0;
  min-height: 13px;
  color: #a0491e;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
}

#waypoint-arrow {
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 10px solid #e87532;
  transform-origin: 50% 65%;
  transition: transform .12s linear;
}

#top-actions {
  grid-area: actions;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: auto;
}

#tool-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border-radius: 15px;
  background: #0b2038c7;
  box-shadow: 0 4px 14px #071a2e55;
  backdrop-filter: blur(5px);
  color: #d9f6ff;
  border: 1px solid #ffffff30;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}
#tool-chip:hover, #tool-chip:focus-visible { background: #173e61e6; outline: 2px solid #8ff7ff99; outline-offset: 2px; }

#tool-chip small { display: block; font-size: .52rem; letter-spacing: .08em; text-transform: uppercase; opacity: .7; }
#tool-chip strong { display: block; font-size: .8rem; line-height: 1.05; }
#tool-dot {
  flex: none;
  width: 19px;
  height: 19px;
  border-radius: 5px;
  background: #66efff;
  box-shadow: 0 0 12px currentColor;
  transform: rotate(45deg);
  border: 2px solid #ffffffbb;
}

.hud-buttons { display: flex; gap: 6px; }
.icon-btn {
  padding: 6px 10px;
  border-radius: 10px;
  background: #0b2038c7;
  color: #e3f8ff;
  font-size: .68rem;
  border: 1px solid #ffffff38;
  backdrop-filter: blur(5px);
}
.icon-btn:hover { background: #173e61d9; }

#crosshair {
  position: fixed;
  z-index: 6;
  left: 50%;
  top: 50%;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  border: 2px solid #ffffffb8;
  border-radius: 50%;
  box-shadow: 0 0 0 2px #123d5c68, 0 0 8px #ffffffb0;
  pointer-events: none;
  opacity: 0;
}

#crosshair::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  margin: -2px 0 0 -2px;
  border-radius: 50%;
  background: #fff;
}

body.playing #crosshair { opacity: 1; }
body.playing.gliding #crosshair { border-color: #ffe27a; }

#bossbar {
  position: fixed;
  z-index: 6;
  top: calc(var(--safe-top) + 108px);
  left: 50%;
  transform: translateX(-50%);
  width: min(360px, 64vw);
  padding: 8px 12px 10px;
  border-radius: 14px;
  background: #102a46d9;
  border: 1px solid #ffffff45;
  box-shadow: 0 7px 20px #081c31a0;
  pointer-events: none;
}

#bossbar-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 5px;
  color: #ffe9b0;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}

#bossbar-count { color: #d8f7ff; }
#bossbar-track { height: 9px; border-radius: 99px; background: #071a2e; overflow: hidden; box-shadow: inset 0 1px 3px #00000088; }
#bossbar-fill { height: 100%; width: 100%; border-radius: inherit; background: var(--bar-color, #ff8c63); transition: width .2s ease; box-shadow: 0 0 10px var(--bar-color, #ff8c63); }

#toast {
  position: fixed;
  z-index: 9;
  top: 24%;
  left: 50%;
  transform: translate(-50%, -10px);
  max-width: min(500px, 86vw);
  padding: 11px 16px;
  border-radius: 16px;
  background: #0b2038e8;
  color: #f7fcff;
  border: 1px solid #ffffff40;
  box-shadow: 0 8px 28px #04172870;
  font-size: clamp(.8rem, 1.8vw, 1rem);
  font-weight: 700;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
}

#toast.show { opacity: 1; transform: translate(-50%, 0); }

#touch-controls { display: none; }

body.touch.started #touch-controls { display: block; }
body.touch:not(.playing) #touch-controls { display: none; }

#stick-zone {
  position: fixed;
  z-index: 7;
  left: calc(var(--safe-left) + 18px);
  bottom: calc(var(--safe-bottom) + 20px);
  width: clamp(108px, 24vw, 142px);
  height: clamp(108px, 24vw, 142px);
  touch-action: none;
}

#stick-base {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: radial-gradient(circle, #ffffff24 0 40%, #0b203878 70%);
  border: 2px solid #ffffff70;
  box-shadow: 0 4px 18px #04172855, inset 0 0 22px #ffffff12;
}

#stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 42%;
  height: 42%;
  margin: -21% 0 0 -21%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fffbe4, #77d9ef 60%, #2c9dbf);
  border: 2px solid #ffffffdd;
  box-shadow: 0 4px 12px #04172870;
  will-change: transform;
}

#action-pad {
  position: fixed;
  z-index: 7;
  right: calc(var(--safe-right) + 16px);
  bottom: calc(var(--safe-bottom) + 16px);
  display: grid;
  grid-template-columns: 60px minmax(72px, 92px);
  grid-template-rows: 38px minmax(72px, 92px);
  gap: 8px;
  align-items: end;
  justify-items: end;
  touch-action: none;
}

.action {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  padding: 0 6px;
  border: 2px solid #ffffffcc;
  box-shadow: 0 5px 14px #04172870, inset 0 -4px 0 #00000022;
  color: #102a46;
  font-weight: 800;
  line-height: 1.05;
}

.action.small { font-size: clamp(.62rem, 2vw, .72rem); background: #d9f7ffdd; }
.action.medium { font-size: clamp(.68rem, 2.2vw, .8rem); background: #a6eff0; }
.action.large { font-size: clamp(.76rem, 2.5vw, .9rem); background: #ffe27a; border-color: #fff9d4; }
.action.cool { filter: saturate(.25) brightness(.75); }
.action.pressed { transform: scale(.92); box-shadow: 0 2px 7px #04172870, inset 0 2px 5px #00000033; }

.overlay {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(14px, var(--safe-top)) max(14px, var(--safe-right)) max(14px, var(--safe-bottom)) max(14px, var(--safe-left));
  background:
    radial-gradient(ellipse at 50% 20%, #8be0ff33, transparent 55%),
    #071d34a8;
  overflow: auto;
  overscroll-behavior: contain;
}

#menu {
  background:
    radial-gradient(ellipse at 75% 10%, #ffe27a33, transparent 45%),
    radial-gradient(ellipse at 20% 85%, #31d2b02e, transparent 40%),
    linear-gradient(180deg, #0b2038b8, #071b30d9);
}

.menu-card, .card {
  width: min(560px, 100%);
  margin: auto;
  padding: clamp(18px, 4vw, 38px);
  border-radius: clamp(22px, 4vw, 34px);
  background: linear-gradient(160deg, #fffdf4f6, #dff8fff2);
  color: var(--ink);
  border: 3px solid #ffffffcc;
  box-shadow: 0 24px 70px #020f1faa, inset 0 1px 0 #fff;
  text-align: center;
}

.eyebrow {
  margin: 0 0 6px;
  color: #2c7f9f;
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .18em;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }

h1 {
  margin-bottom: 2px;
  font-size: clamp(3.2rem, 13vw, 6.4rem);
  line-height: .9;
  letter-spacing: -.055em;
  color: #123a5b;
  text-shadow: 0 4px 0 #ffffff, 0 8px 20px #5bbfe060;
}

h2 { margin-bottom: 8px; font-size: clamp(1.7rem, 5vw, 2.5rem); letter-spacing: -.02em; }
h3 { margin-bottom: 7px; font-size: .85rem; color: #2c7f9f; letter-spacing: .08em; text-transform: uppercase; }

.tagline {
  margin-bottom: 14px;
  color: #e46f42;
  font-size: clamp(1rem, 3vw, 1.4rem);
  font-weight: 800;
  letter-spacing: .01em;
}

.intro { margin-bottom: 14px; font-size: clamp(.9rem, 2vw, 1.05rem); line-height: 1.45; color: #32526f; }
.small-print { margin: 13px 0 0; font-size: .68rem; line-height: 1.4; color: #52708b; }

.feature-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 0 0 18px; }
.feature-row span {
  padding: 5px 10px;
  border-radius: 999px;
  background: #123a5b10;
  color: #2c7f9f;
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.primary { background: #ff9d45; color: #2a1a0a; box-shadow: 0 4px 0 #c75f17, 0 9px 20px #c75f1740; border: 2px solid #ffcf93; }
.primary:hover { background: #ffad5e; }
.primary:active { box-shadow: 0 2px 0 #c75f17; transform: translateY(2px); }
.primary.big { width: min(320px, 100%); padding: 14px 22px; font-size: clamp(1rem, 3vw, 1.18rem); }

.button-grid { display: grid; gap: 8px; margin-top: 10px; }
.button-grid button { background: #d9f2fb; color: #1b4c6c; }
.button-grid .quiet { background: transparent; color: #9a4e42; box-shadow: inset 0 0 0 1px #9a4e4230; }

.menu-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px; margin-top: 12px; }
.text-btn { padding: 4px 2px; background: transparent; color: #256d8f; text-decoration: underline; text-underline-offset: 3px; font-size: .78rem; }
.text-btn:hover { color: #12445f; }

.card { width: min(520px, 100%); }
.card h2 { margin-bottom: 10px; }
.card > p { color: #3f5d76; line-height: 1.4; }

.help-card { width: min(760px, 100%); }
.help-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; text-align: left; margin: 14px 0 16px; }
.help-columns section { padding: 12px; border-radius: 16px; background: #e7f7fd; }
dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; font-size: .8rem; }
dt { color: #256d8f; font-weight: 800; }
dd { margin: 0; color: #35536d; }
.help-tip { padding: 10px 12px; border-radius: 14px; background: #fff1ce; color: #6c4515 !important; font-size: .8rem; }
#help-close { margin-top: 2px; }
.help-card .primary { width: min(240px, 100%); }

.power-card { width: min(570px, 100%); }
.power-subtitle { margin: -4px 0 2px; font-size: .84rem; }
#power-options { position: relative; width: min(340px, 78vw); aspect-ratio: 1; margin: 6px auto 2px; }
.power-option {
  position: absolute;
  width: 84px;
  height: 84px;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 5px;
  border-radius: 50%;
  border: 2px solid #ffffff66;
  background: radial-gradient(circle at 35% 25%, #ffffff2e, transparent 42%), #183b5c;
  color: #effcff;
  box-shadow: 0 5px 14px #07182b66, inset 0 0 0 4px #ffffff0d;
  cursor: pointer;
  font-family: inherit;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.power-option:hover, .power-option:focus-visible { border-color: #ffffffcc; outline: none; transform: translate(-50%, -50%) scale(1.06); }
.power-option[aria-pressed="true"] {
  border-color: #ffe27a;
  box-shadow: 0 0 0 4px #ffe27a33, 0 0 22px #ffe27a88;
  transform: translate(-50%, -50%) scale(1.1);
}
.power-icon {
  width: 22px;
  height: 30px;
  background: var(--power-color);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  filter: drop-shadow(0 0 7px var(--power-color));
}
.power-label {
  max-width: 74px;
  font-size: .58rem;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: .02em;
  text-transform: uppercase;
  text-align: center;
  overflow-wrap: anywhere;
}
.power-hint {
  margin: 8px auto 13px;
  min-height: 2.4em;
  max-width: 430px;
  color: #3f5d76;
  font-size: .82rem;
  font-weight: 700;
  line-height: 1.3;
}
.power-card .primary { width: min(240px, 100%); }

@media (max-width: 420px) {
  #power-options { width: min(300px, 82vw); }
  .power-option { width: 72px; height: 72px; }
  .power-label { font-size: .52rem; max-width: 62px; }
  .power-icon { width: 18px; height: 25px; }
}

@media (max-width: 700px) {
  #hud {
    grid-template-columns: auto 1fr auto;
    grid-template-areas:
      "hearts . actions"
      "objective objective objective";
    gap: 7px;
  }
  #objective-card { align-self: start; padding: 8px 12px; }
  #top-actions { flex-direction: row; align-items: center; }
  #tool-chip { padding: 5px 8px; }
  #tool-chip small { display: none; }
  #tool-chip strong { font-size: .68rem; max-width: 84px; }
  #tool-dot { width: 14px; height: 14px; }
  .hud-buttons { gap: 4px; }
  .icon-btn { font-size: .6rem; padding: 5px 7px; }
  #bossbar { top: calc(var(--safe-top) + 126px); width: min(350px, 74vw); }
  #toast { top: 30%; }
  .help-columns { grid-template-columns: 1fr; gap: 10px; }
  .menu-card, .card { padding: 20px 18px; border-radius: 24px; }
}

@media (max-width: 420px) {
  #hearts { gap: 2px; }
  #land-progress { font-size: .58rem; }
  .feature-row span { font-size: .58rem; }
  #action-pad { grid-template-columns: 54px minmax(68px, 82px); grid-template-rows: 34px minmax(68px, 82px); }
}

@media (orientation: landscape) and (max-height: 520px) {
  #hud { top: calc(var(--safe-top) + 7px); left: calc(var(--safe-left) + 10px); right: calc(var(--safe-right) + 10px); }
  #hearts { min-height: 16px; }
  #land-progress { display: none; }
  #brick-supply { padding: 2px 7px 2px 5px; font-size: .55rem; gap: 5px; }
  .brick-mini { width: 13px; height: 7px; }
  #objective-card { padding: 5px 12px; border-radius: 12px; width: min(400px, 67vw); }
  #zone-name { font-size: .5rem; }
  #objective { font-size: .68rem; }
  #waypoint { margin-top: 2px; font-size: .55rem; }
  #waypoint-arrow { border-left-width: 4px; border-right-width: 4px; border-bottom-width: 7px; }
  #tool-chip { padding: 3px 7px; }
  #tool-chip strong { font-size: .58rem; }
  #tool-chip small { display: none; }
  #tool-dot { width: 12px; height: 12px; }
  #bossbar { top: calc(var(--safe-top) + 56px); width: min(300px, 48vw); padding: 5px 9px 7px; }
  #toast { top: 26%; padding: 8px 13px; font-size: .72rem; }
  .overlay { padding-top: 6px; padding-bottom: 6px; }
  .menu-card, .card { padding: 12px 18px; max-height: calc(100vh - 12px); overflow: auto; border-radius: 18px; }
  h1 { font-size: clamp(2.4rem, 9vh, 3.8rem); }
  .tagline { margin-bottom: 6px; font-size: .92rem; }
  .intro { display: none; }
  .feature-row { display: none; }
  .small-print { display: none; }
  .primary.big { padding: 9px 18px; width: min(280px, 100%); }
  .menu-links { margin-top: 5px; }
  .help-columns { grid-template-columns: 1fr 1fr; gap: 8px; margin: 6px 0 8px; }
  .help-columns section { padding: 8px; }
  dl { font-size: .68rem; gap: 3px 7px; }
  .help-tip { padding: 6px 8px; font-size: .68rem; margin-bottom: 7px; }
  #stick-zone { left: calc(var(--safe-left) + 13px); bottom: calc(var(--safe-bottom) + 10px); width: 104px; height: 104px; }
  #action-pad { right: calc(var(--safe-right) + 12px); bottom: calc(var(--safe-bottom) + 8px); grid-template-columns: 55px minmax(66px, 80px); grid-template-rows: 33px minmax(66px, 80px); gap: 6px; }
  #btn-jump, #btn-throw { padding: 0 4px; }
}

@media (pointer: coarse) {
  body.started #touch-controls { display: block; }
  body:not(.playing) #touch-controls { display: none; }
  #crosshair { width: 26px; height: 26px; margin: -13px 0 0 -13px; }
}

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

@keyframes heart-pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.3); }
  100% { transform: scale(1); }
}
