:root {
  --cream: #fff8df;
  --ink: #173346;
  --ink-soft: #4b6672;
  --teal: #1d9b8f;
  --teal-deep: #126a6c;
  --mint: #75e1c4;
  --gold: #f3bd50;
  --plum: #774d84;
  --rose: #d9667f;
  --panel: rgba(255, 249, 226, 0.94);
  --panel-edge: rgba(255, 255, 255, 0.76);
  --shadow: rgba(20, 45, 57, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #0b1c2b;
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

button,
input,
select {
  font: inherit;
}

#app {
  display: grid;
  place-items: center;
  height: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background:
    radial-gradient(circle at 50% 34%, #315e75 0, #142b3d 48%, #07121f 100%);
}

#game-shell {
  position: relative;
  width: min(100vw, 177.78vh);
  max-height: 100vh;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  isolation: isolate;
  background: #76c9e8;
  box-shadow: 0 22px 90px #000a, 0 0 0 1px #ffffff24;
}

canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
}

.hidden {
  display: none !important;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
}

.screen.active {
  display: flex;
  animation: screen-enter 320ms cubic-bezier(0.2, 0.85, 0.25, 1) both;
}

@keyframes screen-enter {
  from { opacity: 0; }
  to { opacity: 1; }
}

#main-menu {
  align-items: center;
  justify-content: space-between;
  padding: 5% 6.5%;
  background:
    linear-gradient(90deg, rgba(10, 39, 47, 0.24), transparent 42%, transparent 62%, rgba(12, 38, 48, 0.14)),
    linear-gradient(0deg, rgba(9, 32, 36, 0.2), transparent 26%);
}

.brand {
  position: relative;
  width: 45%;
  max-width: 470px;
  padding: 2.4% 2.8% 2.7%;
  color: var(--cream);
  text-align: center;
  filter: drop-shadow(0 9px 14px rgba(20, 47, 56, 0.34));
}

.brand::before {
  position: absolute;
  z-index: -1;
  inset: 0;
  content: "";
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 34px 16px 34px 16px;
  background:
    linear-gradient(145deg, rgba(23, 92, 87, 0.72), rgba(50, 62, 92, 0.56)),
    radial-gradient(circle at 20% 10%, #ffffff32, transparent 42%);
  box-shadow: inset 0 1px #ffffff55, inset 0 -5px rgba(11, 53, 56, 0.25), 0 13px 28px rgba(19, 48, 53, 0.25);
  backdrop-filter: blur(4px);
}

.brand-kicker {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #fff1a8;
  font-size: clamp(8px, 1.02vw, 14px);
  font-weight: 900;
  letter-spacing: 0.25em;
}

.brand-kicker span {
  width: 26px;
  height: 1px;
  background: currentColor;
}

h1 {
  margin: 0.18em 0 0.22em;
  color: #fffdf1;
  font-size: clamp(44px, 6.4vw, 88px);
  font-weight: 900;
  letter-spacing: -0.055em;
  line-height: 0.73;
  text-shadow: 0 3px 0 #2a716e, 0 7px 16px rgba(16, 48, 55, 0.38);
}

h1 small,
h1 em {
  display: block;
}

h1 small {
  font-size: 0.54em;
  letter-spacing: 0.01em;
}

h1 em {
  color: #ffda6e;
  font-size: 0.68em;
  font-style: normal;
  line-height: 1.05;
  -webkit-text-stroke: 1px rgba(83, 73, 58, 0.12);
}

.brand p {
  margin: 0;
  color: #e9fff7;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: clamp(11px, 1.3vw, 18px);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand-rune {
  position: absolute;
  right: -13px;
  bottom: -13px;
  display: grid;
  width: 43px;
  height: 43px;
  place-items: center;
  border: 2px solid #fff6b8;
  border-radius: 50%;
  color: #fff8c3;
  background: #2b8e84;
  box-shadow: 0 5px 12px #16494e88, inset 0 2px #ffffff66;
}

.menu {
  display: flex;
  width: clamp(185px, 23vw, 280px);
  flex-direction: column;
  gap: clamp(6px, 1.1vh, 11px);
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.52);
  border-radius: 24px;
  background: rgba(244, 250, 232, 0.7);
  box-shadow: inset 0 1px #fff, 0 16px 35px rgba(23, 54, 59, 0.22);
  backdrop-filter: blur(7px) saturate(1.18);
}

button {
  position: relative;
  min-height: 42px;
  padding: 0.64em 1.1em 0.64em 3.15em;
  overflow: hidden;
  border: 1px solid #b4c9b9;
  border-radius: 13px 9px 13px 9px;
  color: #244455;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.85), rgba(234, 240, 216, 0.9)),
    #eef4df;
  box-shadow: inset 0 1px #fff, inset 0 -3px rgba(61, 100, 87, 0.12), 0 4px 0 #718e80, 0 8px 13px rgba(28, 64, 66, 0.17);
  cursor: pointer;
  font-weight: 900;
  letter-spacing: 0.015em;
  text-align: left;
  transition: transform 140ms ease, box-shadow 140ms ease, filter 140ms ease;
}

button::before {
  position: absolute;
  top: 50%;
  left: 10px;
  display: grid;
  width: 28px;
  height: 28px;
  content: attr(data-icon);
  transform: translateY(-50%);
  place-items: center;
  border: 1px solid #ffffffaa;
  border-radius: 50%;
  color: #fff8d1;
  background: linear-gradient(145deg, #57b59d, #277e7a);
  box-shadow: inset 0 2px #ffffff55, 0 2px 5px #235d5d44;
  font-size: 15px;
}

button::after {
  position: absolute;
  inset: 2px 6px auto;
  height: 1px;
  content: "";
  background: linear-gradient(90deg, transparent, #fff, transparent);
  opacity: 0.6;
}

button:hover,
button:focus-visible {
  z-index: 1;
  outline: 3px solid #fff6a3;
  outline-offset: 2px;
  filter: brightness(1.04) saturate(1.05);
  transform: translate(-3px, -2px) rotate(-0.35deg);
  box-shadow: inset 0 1px #fff, inset 0 -3px rgba(61, 100, 87, 0.12), 0 6px 0 #658779, 0 12px 18px rgba(28, 64, 66, 0.2);
}

button:active {
  transform: translateY(3px);
  box-shadow: inset 0 2px rgba(35, 67, 70, 0.16), 0 1px 0 #688276;
}

button.primary {
  border-color: #3f9384;
  color: #fffdf0;
  background: linear-gradient(180deg, #47b9a4, #217f7a);
  box-shadow: inset 0 1px #b9fff1aa, inset 0 -3px #0e6666, 0 4px 0 #11565c, 0 9px 14px #194f5244;
  text-shadow: 0 1px #14535a;
}

button.primary::before {
  color: #634e2f;
  background: linear-gradient(145deg, #fff4a5, #edb747);
}

button.danger {
  color: #8e3852;
}

button.danger::before {
  background: linear-gradient(145deg, #e78aa0, #b64c70);
}

button:disabled {
  cursor: not-allowed;
  filter: grayscale(0.7);
  opacity: 0.48;
  transform: none;
}

.menu-footer {
  position: absolute;
  right: 5%;
  bottom: 2.6%;
  display: flex;
  gap: 8px;
  color: #e8fff7;
  font-size: clamp(8px, 0.9vw, 12px);
  font-weight: 800;
  text-shadow: 0 2px 5px #174349;
}

.menu-footer span {
  padding: 4px 10px;
  border: 1px solid #ffffff55;
  border-radius: 99px;
  background: rgba(21, 79, 75, 0.5);
  backdrop-filter: blur(4px);
}

.panel-screen {
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 50% 40%, transparent, rgba(10, 29, 39, 0.27)),
    rgba(8, 25, 34, 0.42);
  backdrop-filter: blur(4px) saturate(0.9);
}

.panel {
  position: relative;
  display: flex;
  width: min(450px, 88%);
  max-height: 89%;
  flex-direction: column;
  gap: 11px;
  padding: clamp(24px, 3.4vw, 38px);
  overflow: auto;
  border: 2px solid #fff7d5;
  border-radius: 29px 17px 29px 17px;
  background:
    linear-gradient(145deg, rgba(255, 253, 237, 0.97), rgba(226, 239, 218, 0.94)),
    var(--panel);
  box-shadow: inset 0 1px #fff, inset 0 -6px #7d998d22, 0 20px 60px #091b28aa, 0 0 0 5px #4a7d7466;
  scrollbar-color: #60a995 transparent;
  animation: panel-enter 380ms cubic-bezier(0.17, 0.87, 0.24, 1.16) both;
}

@keyframes panel-enter {
  from { opacity: 0; transform: translateY(25px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

.panel.wide {
  width: min(730px, 91%);
}

.panel::before,
.panel::after {
  position: absolute;
  width: 35px;
  height: 35px;
  content: "";
  border-color: #d2b765;
  opacity: 0.65;
}

.panel::before {
  top: 9px;
  left: 9px;
  border-top: 2px solid;
  border-left: 2px solid;
  border-radius: 13px 0 0;
}

.panel::after {
  right: 9px;
  bottom: 9px;
  border-right: 2px solid;
  border-bottom: 2px solid;
  border-radius: 0 0 13px;
}

.panel-crest {
  display: grid;
  width: 45px;
  height: 45px;
  margin: -12px auto 0;
  place-items: center;
  border: 2px solid #fff5b0;
  border-radius: 50%;
  color: #fff4ae;
  background: linear-gradient(145deg, #4eb89e, #286e73);
  box-shadow: inset 0 2px #ffffff77, 0 5px 10px #215d5e55;
  font-size: 20px;
}

.panel-kicker {
  margin: 0;
  color: #4b8b7c;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.26em;
  text-align: center;
}

h2 {
  margin: 0 0 5px;
  color: #2e5e62;
  font-size: clamp(28px, 4vw, 46px);
  font-weight: 900;
  letter-spacing: -0.04em;
  line-height: 1;
  text-align: center;
  text-shadow: 0 2px #fff;
}

.panel label:not(.toggle) {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  align-items: center;
  gap: 15px;
  padding: 10px 13px;
  border: 1px solid #bed1bd;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.5);
  color: #31565e;
  font-weight: 800;
}

.panel input[type="range"] {
  width: 100%;
  accent-color: var(--teal);
}

.panel select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #9cb9a8;
  border-radius: 8px;
  color: #244b54;
  background: #fbffe9;
  font-weight: 700;
}

.toggle {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: 10px;
  color: #426168;
  cursor: pointer;
  font-weight: 700;
}

.toggle input {
  position: absolute;
  opacity: 0;
}

.toggle i {
  position: relative;
  width: 34px;
  height: 19px;
  border: 1px solid #91a99b;
  border-radius: 99px;
  background: #c5d2c5;
  box-shadow: inset 0 2px 4px #43625433;
  transition: background 150ms;
}

.toggle i::after {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  content: "";
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px #23443d66;
  transition: transform 150ms;
}

.toggle input:checked + i {
  background: #48b39c;
}

.toggle input:checked + i::after {
  transform: translateX(15px);
}

.toggle input:focus-visible + i {
  outline: 3px solid #f5d66b;
  outline-offset: 2px;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.level-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 11px;
}

.atlas-panel {
  width: min(790px, 92%);
}

.level-card {
  min-height: 205px;
  padding: 0;
  overflow: hidden;
  border: 2px solid #f7efd0;
  border-radius: 16px;
  background: #d8ead6;
  box-shadow: inset 0 1px #fff, 0 5px 0 #718b7d, 0 8px 12px #375c5844;
  text-align: left;
}

.level-card::before,
.level-card::after {
  display: none;
}

.level-card:hover,
.level-card:focus-visible {
  transform: translateY(-4px) rotate(-0.5deg);
}

.realm-number {
  position: absolute;
  z-index: 2;
  top: 9px;
  left: 9px;
  display: grid;
  width: 29px;
  height: 29px;
  place-items: center;
  border: 1px solid #ffffffaa;
  border-radius: 50%;
  color: #fff;
  background: #285f65cc;
  font-size: 10px;
}

.realm-art {
  position: relative;
  display: block;
  height: 105px;
  overflow: hidden;
  background: linear-gradient(#65bce9, #d9efbf);
}

.realm-art::before,
.realm-art::after {
  position: absolute;
  content: "";
}

.realm-meadow .realm-art::before {
  right: 12px;
  bottom: -11px;
  left: 12px;
  height: 54px;
  border-radius: 50% 50% 0 0;
  background: linear-gradient(#73c263 0 25%, #6b4d3d 26% 100%);
  box-shadow: inset 0 5px #a7de72;
}

.realm-meadow .realm-art::after {
  top: 19px;
  left: 20px;
  width: 65px;
  height: 25px;
  border-radius: 50%;
  background: #fffbdcdd;
  box-shadow: 34px 4px 0 4px #fffbdcdd;
}

.realm-cavern .realm-art {
  background: linear-gradient(#10172f, #344266);
}

.realm-cavern .realm-art::before {
  right: 0;
  bottom: 0;
  left: 0;
  height: 48px;
  background: #1c253d;
  box-shadow: inset 0 7px #4e5c78;
}

.realm-cavern .realm-art::after {
  bottom: 13px;
  left: 30px;
  width: 18px;
  height: 54px;
  background: linear-gradient(135deg, #d5ffff, #64e8e5 45%, #6851b8);
  clip-path: polygon(50% 0, 100% 78%, 70% 100%, 0 89%);
  filter: drop-shadow(37px 6px 5px #725ad9) drop-shadow(75px -2px 4px #49d8db);
}

.realm-fortress .realm-art {
  background: linear-gradient(#283256, #e57b76);
}

.realm-fortress .realm-art::before {
  right: 22px;
  bottom: 0;
  left: 22px;
  height: 75px;
  background: #344157;
  clip-path: polygon(0 100%, 0 36%, 15% 36%, 15% 12%, 30% 12%, 30% 50%, 55% 50%, 55% 0, 75% 0, 75% 35%, 100% 35%, 100% 100%);
}

.realm-fortress .realm-art::after {
  top: 19px;
  right: 19px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #ffdf9a;
  box-shadow: 0 0 22px #ffc274;
}

.realm-copy {
  display: block;
  padding: 10px 11px 2px;
}

.realm-copy b,
.realm-copy small,
.realm-status {
  display: block;
}

.realm-copy b {
  color: #2c565d;
  font-size: 15px;
}

.realm-copy small {
  margin-top: 2px;
  color: #678078;
  font-size: 10px;
}

.realm-status {
  padding: 5px 11px 10px;
  color: #829086;
  font-size: 8px;
  text-transform: uppercase;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.guide-grid > div {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 11px;
  padding: 13px;
  border: 1px solid #c5d7bf;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.5);
}

.guide-icon {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 50%;
  color: #fff4bb;
  background: linear-gradient(145deg, #55b99e, #28777a);
  box-shadow: inset 0 2px #ffffff55, 0 3px 6px #255c5e44;
  font-size: 18px;
}

.guide-grid h3,
.guide-grid p {
  margin: 5px 0 0;
}

.guide-grid h3 {
  color: #315d61;
}

.guide-grid p {
  color: #60756e;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 11px;
}

kbd {
  display: inline-block;
  min-width: 25px;
  margin-right: 3px;
  padding: 3px 6px;
  border: 1px solid #7d9a8c;
  border-bottom-width: 3px;
  border-radius: 5px;
  color: #31535b;
  background: #fbffed;
  font-size: 10px;
  text-align: center;
}

.tip {
  margin: 2px 0;
  padding: 8px 12px;
  border-left: 3px solid var(--gold);
  color: #49726c;
  background: #fff3b94a;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.hud {
  position: absolute;
  z-index: 3;
  inset: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  padding: 11px 14px;
  pointer-events: none;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: clamp(9px, 1.08vw, 14px);
}

.hud-cluster {
  display: flex;
  align-items: flex-start;
  gap: 7px;
}

.hud-center {
  justify-self: center;
}

.hud-right {
  justify-self: end;
}

.hud-widget {
  display: flex;
  min-height: 37px;
  align-items: center;
  gap: 7px;
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, 0.66);
  border-radius: 12px 8px 12px 8px;
  color: #f8fff4;
  background:
    linear-gradient(145deg, rgba(28, 90, 85, 0.88), rgba(27, 61, 71, 0.86));
  box-shadow: inset 0 1px #ffffff55, inset 0 -3px rgba(10, 43, 51, 0.3), 0 4px 10px rgba(12, 40, 48, 0.28);
  text-shadow: 0 1px 2px #153b42;
  backdrop-filter: blur(5px);
}

.hud-widget small,
.widget-label {
  color: #bde9dc;
  font-size: 8px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.health-widget {
  display: grid;
  min-width: 123px;
  grid-template-columns: auto 1fr;
}

.health-track {
  display: flex;
  gap: 3px;
}

.health-shard {
  display: block;
  width: 13px;
  height: 18px;
  transform: rotate(8deg);
  border: 1px solid #cce9e4;
  background: #3d6168;
  clip-path: polygon(50% 0, 100% 36%, 75% 100%, 25% 100%, 0 36%);
  filter: drop-shadow(0 2px 1px #173a43);
}

.health-shard.full {
  border-color: #ecffff;
  background: linear-gradient(135deg, #edffff, #64eee4 45%, #2cb0b1);
  box-shadow: inset 2px 2px #ffffffaa;
}

.luma-emblem {
  width: 22px;
  height: 22px;
  border: 2px solid #fff2a5;
  border-radius: 50%;
  background: linear-gradient(135deg, #79d78b 0 45%, #594267 46% 100%);
  box-shadow: inset 0 2px #ffffff77;
}

.sun-token,
.gem-token,
.charm-icon {
  display: block;
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
}

.sun-token {
  border: 2px solid #fff1a0;
  border-radius: 50%;
  background: radial-gradient(circle, #fff3a1 0 18%, #f3bd4d 20% 58%, #a96434 60% 100%);
  box-shadow: 0 0 8px #ffd36b88;
}

.gem-token {
  transform: rotate(45deg) scale(0.7);
  border: 2px solid #e5ffff;
  border-radius: 4px;
  background: linear-gradient(135deg, #eaffff, #55e8e3 45%, #5667bd);
  box-shadow: 0 0 8px #64e8e7;
}

.charm-icon {
  border: 2px solid #ffe99b;
  border-radius: 50% 50% 45% 45%;
  background: conic-gradient(#f5c85c, #65e2ca, #9874d5, #f5c85c);
  box-shadow: inset 0 0 0 4px #315b63, 0 0 7px #fff09a66;
}

.charm-widget {
  max-width: 195px;
}

.realm-widget,
.high-widget,
.timer-badge {
  display: grid;
  min-width: 68px;
  justify-items: center;
  gap: 0;
  padding-block: 4px;
}

.timer-badge {
  min-width: 57px;
  border-color: #fff0a6;
  color: #fff4b1;
  background: linear-gradient(145deg, rgba(118, 78, 114, 0.92), rgba(60, 54, 88, 0.9));
}

.timer-badge.warning {
  color: #fff;
  background: linear-gradient(145deg, #e26976, #9e3b63);
  animation: timer-warning 700ms ease-in-out infinite alternate;
}

@keyframes timer-warning {
  to { transform: scale(1.06); box-shadow: 0 0 16px #ff6f82; }
}

.value-pop {
  animation: value-pop 260ms cubic-bezier(0.2, 1.8, 0.4, 1);
}

@keyframes value-pop {
  50% { transform: scale(1.24); color: #fff3a0; }
}

.boss-wrap {
  position: absolute;
  top: 61px;
  left: 26%;
  width: 48%;
  color: #fff3d7;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-align: center;
  text-shadow: 0 2px 3px #2a233f;
}

.boss-track {
  height: 15px;
  margin-top: 4px;
  padding: 3px;
  overflow: hidden;
  border: 1px solid #ffe7be;
  border-radius: 99px;
  background: #222942cc;
  box-shadow: inset 0 2px 4px #111526, 0 3px 9px #12192c66;
}

.boss-track i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #e85579, #ffbd58 65%, #fff19c);
  box-shadow: inset 0 2px #ffffff77;
  transition: width 170ms ease;
}

.result {
  text-align: center;
}

.result-icon {
  display: grid;
  width: 72px;
  height: 72px;
  margin: -14px auto 0;
  place-items: center;
  border: 3px solid #fff4ad;
  border-radius: 50%;
  color: #fff8bf;
  background: linear-gradient(145deg, #66cbae, #5570a4);
  box-shadow: inset 0 3px #ffffff77, 0 7px 18px #315f6266, 0 0 25px #fff09a66;
  font-size: 36px;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 7px 0 11px;
}

.result-stats span {
  display: grid;
  gap: 2px;
  padding: 9px;
  border: 1px solid #c0d3be;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.52);
}

.result-stats small {
  color: #6a8279;
  font-size: 9px;
  text-transform: uppercase;
}

.result-stats b {
  color: #2c6164;
}

#toast {
  position: absolute;
  z-index: 8;
  top: 15%;
  left: 50%;
  max-width: 70%;
  padding: 9px 21px;
  transform: translate(-50%, -18px) scale(0.96);
  border: 1px solid #fff5b0;
  border-radius: 18px 9px 18px 9px;
  color: #fffbe4;
  background: linear-gradient(145deg, rgba(47, 132, 117, 0.94), rgba(57, 68, 98, 0.94));
  box-shadow: inset 0 1px #ffffff55, 0 7px 18px #173d4966;
  font-size: 13px;
  font-weight: 900;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: 230ms ease;
}

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

#touch-controls {
  position: absolute;
  z-index: 4;
  inset: 0;
  display: none;
  pointer-events: none;
}

#game-shell:has(.screen.active) #touch-controls {
  display: none;
}

#touch-controls button {
  width: 60px;
  height: 60px;
  min-height: 0;
  padding: 0;
  border: 2px solid #f7ffdbbb;
  border-radius: 50%;
  color: #f9ffe9;
  background: linear-gradient(145deg, rgba(66, 167, 145, 0.78), rgba(32, 89, 96, 0.86));
  box-shadow: inset 0 3px #ffffff55, 0 5px 0 #174d5588, 0 8px 15px #112d3866;
  font-size: 19px;
  text-align: center;
  text-shadow: 0 2px #174a51;
  touch-action: none;
  pointer-events: auto;
  opacity: 0.82;
}

#touch-controls button::before,
#touch-controls button::after {
  display: none;
}

.touch-left,
.touch-right {
  position: absolute;
  bottom: calc(18px + env(safe-area-inset-bottom));
  display: flex;
  gap: 12px;
}

.touch-left {
  left: calc(18px + env(safe-area-inset-left));
}

.touch-right {
  right: calc(18px + env(safe-area-inset-right));
}

.touch-pause {
  position: absolute;
  top: calc(58px + env(safe-area-inset-top));
  right: calc(16px + env(safe-area-inset-right));
  width: 42px !important;
  height: 42px !important;
}

.touch-right .jump {
  width: 72px !important;
  height: 72px !important;
  margin-top: -12px;
  border-color: #fff3a9cc;
  background: linear-gradient(145deg, rgba(239, 186, 79, 0.88), rgba(191, 105, 74, 0.88));
}

@media (max-width: 760px), (pointer: coarse) {
  #touch-controls {
    display: block;
  }

  #main-menu {
    padding: 3% 4%;
  }

  .brand {
    width: 48%;
    padding: 3%;
  }

  .menu {
    width: 41%;
    gap: 5px;
    padding: 8px;
    border-radius: 16px;
  }

  .menu button {
    min-height: 31px;
    padding: 0.35em 0.55em 0.35em 2.5em;
    border-radius: 9px;
    font-size: 10px;
  }

  .menu button::before {
    left: 6px;
    width: 21px;
    height: 21px;
    font-size: 10px;
  }

  .hud {
    gap: 3px;
    padding: 4px 5px;
    font-size: 8px;
  }

  .hud-cluster {
    gap: 3px;
  }

  .hud-widget {
    min-height: 28px;
    gap: 4px;
    padding: 3px 5px;
    border-radius: 7px;
  }

  .health-widget {
    min-width: auto;
    grid-template-columns: 1fr;
  }

  .widget-label,
  .high-widget,
  .realm-widget small,
  .charm-widget {
    display: none;
  }

  .health-shard {
    width: 9px;
    height: 13px;
  }

  .sun-token,
  .gem-token,
  .luma-emblem {
    width: 15px;
    height: 15px;
  }

  .realm-widget,
  .timer-badge {
    min-width: 45px;
  }

  .boss-wrap {
    top: 38px;
    left: 27%;
    width: 46%;
    font-size: 8px;
  }

  .boss-track {
    height: 10px;
    padding: 2px;
  }

  .panel {
    gap: 6px;
    padding: 19px;
  }

  .panel-crest {
    width: 34px;
    height: 34px;
    font-size: 14px;
  }

  .panel-kicker {
    font-size: 7px;
  }

  h2 {
    font-size: 25px;
  }

  .level-card {
    min-height: 125px;
  }

  .realm-art {
    height: 60px;
  }

  .realm-copy {
    padding: 5px 6px 0;
  }

  .realm-copy b {
    font-size: 10px;
  }

  .realm-copy small,
  .realm-status {
    font-size: 6px;
  }

  .realm-status {
    padding: 3px 6px 5px;
  }

  .guide-grid {
    gap: 5px;
  }

  .guide-grid > div {
    gap: 6px;
    padding: 7px;
  }

  .guide-icon {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }

  .guide-grid h3 {
    font-size: 11px;
  }

  .guide-grid p {
    display: none;
  }

  #toast {
    top: 12%;
    font-size: 9px;
  }
}

@media (max-aspect-ratio: 1 / 1) {
  #game-shell {
    width: 100vw;
    max-height: none;
  }
}

@media (orientation: portrait) and (max-width: 760px) {
  #game-shell {
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    aspect-ratio: auto;
  }

  canvas {
    left: 50%;
    width: 177.78vh;
    max-width: none;
    height: 100%;
    transform: translateX(-50%);
  }

  #main-menu {
    flex-direction: column;
    justify-content: center;
    gap: 18px;
    padding: max(24px, env(safe-area-inset-top)) 8% max(34px, env(safe-area-inset-bottom));
    background: linear-gradient(rgba(12, 54, 59, 0.12), rgba(10, 35, 45, 0.3));
  }

  .brand {
    width: 100%;
    max-width: 420px;
    padding: 22px 18px 24px;
  }

  h1 {
    font-size: clamp(48px, 16vw, 68px);
  }

  .brand p {
    font-size: 13px;
  }

  .menu {
    width: 100%;
    max-width: 350px;
    gap: 8px;
    padding: 12px;
  }

  .menu button {
    min-height: 42px;
    padding: 0.6em 0.9em 0.6em 3.2em;
    font-size: 13px;
  }

  .menu button::before {
    left: 9px;
    width: 27px;
    height: 27px;
    font-size: 13px;
  }

  .menu-footer {
    right: 50%;
    bottom: calc(10px + env(safe-area-inset-bottom));
    transform: translateX(50%);
  }

  .panel {
    width: min(440px, 89%);
    max-height: 88vh;
  }

  .atlas-panel,
  .panel.wide {
    width: 91%;
  }

  .level-cards {
    grid-template-columns: 1fr;
  }

  .level-card {
    min-height: 90px;
    display: grid;
    grid-template-columns: 115px 1fr;
  }

  .realm-art {
    grid-row: 1 / 3;
    width: 115px;
    height: 100%;
  }

  .realm-copy {
    align-self: end;
    padding: 10px 10px 0;
  }

  .realm-copy b {
    font-size: 13px;
  }

  .realm-copy small,
  .realm-status {
    font-size: 8px;
  }

  .realm-status {
    padding: 5px 10px 10px;
  }

  .guide-grid {
    grid-template-columns: 1fr;
  }

  .guide-grid p {
    display: block;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
