:root {
  color-scheme: dark;
  font-family: "Courier New", ui-monospace, monospace;
  --cyan: #25e9ff;
  --blue: #1684ff;
  --pink: #ff2ead;
  --gold: #ffc739;
  --ink: #0b110d;
  --panel: rgba(3, 12, 35, 0.86);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: #152b24;
  touch-action: none;
}

body {
  display: grid;
  place-items: center;
  min-height: 100dvh;
}

button { font: inherit; }

.game-shell {
  position: relative;
  width: min(100vw, calc(100dvh * 16 / 9));
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #1c382b;
  box-shadow: 0 0 80px rgba(81, 126, 93, .36);
  isolation: isolate;
  user-select: none;
  -webkit-user-select: none;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.fullscreen-button {
  position: absolute;
  z-index: 26;
  top: 12.5%;
  right: 2%;
  min-width: clamp(62px, 7.5vw, 124px);
  padding: clamp(5px, .55vw, 10px) clamp(7px, .75vw, 13px);
  color: #fff2d1;
  border: 2px solid rgba(244, 176, 184, .72);
  border-radius: 999px;
  background: rgba(24, 61, 42, .86);
  box-shadow: 0 4px 0 rgba(49, 69, 47, .8), 0 0 18px rgba(244, 176, 184, .2);
  font-family: Tahoma, sans-serif;
  font-size: clamp(7px, .72vw, 13px);
  font-weight: 900;
  cursor: pointer;
  backdrop-filter: blur(6px);
}
.fullscreen-button:hover { border-color: #ffe1a9; filter: brightness(1.1); }
.fullscreen-button:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(49, 69, 47, .8); }

.game-shell:fullscreen,
.game-shell:-webkit-full-screen {
  width: min(100vw, calc(100dvh * 16 / 9));
  height: min(100dvh, calc(100vw * 9 / 16));
  margin: auto;
  aspect-ratio: 16 / 9;
}
.game-shell::backdrop { background: #08130e; }

.panel {
  border: clamp(1px, .16vw, 3px) solid rgba(72, 205, 255, .7);
  background: linear-gradient(180deg, rgba(7, 23, 54, .94), rgba(2, 8, 27, .88));
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .45), 0 0 12px rgba(19, 181, 255, .22);
  clip-path: polygon(8px 0, calc(100% - 8px) 0, 100% 8px, 100% calc(100% - 8px), calc(100% - 8px) 100%, 8px 100%, 0 calc(100% - 8px), 0 8px);
}

.hud {
  position: absolute;
  z-index: 4;
  inset: 2.2% 2% auto;
  display: grid;
  grid-template-columns: 12% 24% 18% 30% 6%;
  gap: 1.3%;
  align-items: start;
  pointer-events: none;
}

.agent-card {
  display: flex;
  align-items: center;
  padding: 3%;
  min-height: clamp(52px, 6.7vw, 108px);
}

.agent-card img {
  width: 48%;
  aspect-ratio: 1;
  object-fit: contain;
  image-rendering: pixelated;
  background: radial-gradient(circle, rgba(37,233,255,.2), transparent 70%);
}

.agent-stats { display: grid; gap: .25em; font-size: clamp(6px, .74vw, 14px); }
.agent-stats strong { color: white; }
.agent-stats span { color: var(--gold); }

.status-stack { display: grid; gap: .7vw; padding-top: .35vw; }
.meter-row {
  display: grid;
  grid-template-columns: 20% 1fr auto;
  gap: 2%;
  align-items: center;
  padding: 2.5% 3%;
  font-weight: 900;
  font-size: clamp(6px, .76vw, 14px);
  background: rgba(1, 8, 25, .88);
  border: 2px solid #28486e;
  transform: skewX(-4deg);
}
.meter-row > * { transform: skewX(4deg); }
.meter { height: clamp(5px, .9vw, 15px); overflow: hidden; background: #10182c; border: 1px solid #4c6384; }
.meter i { display: block; height: 100%; width: 100%; transition: width .18s ease; }
.hp-row span { color: #ff6274; }
.hp-row i { background: linear-gradient(90deg, #ff2449, #ff6e8e); box-shadow: 0 0 9px #ff2449; }
.energy-row span { color: var(--cyan); }
.energy-row i { background: linear-gradient(90deg, #0968ff, #26efff); box-shadow: 0 0 9px #17bdff; }

.score-card {
  justify-self: center;
  min-width: 100%;
  padding: 4% 7%;
  text-align: center;
  line-height: 1;
}
.score-card span, .mission-card span { display: block; color: #bcd7f8; font-size: clamp(7px, .72vw, 14px); }
.score-card strong { display: block; margin: .15em 0; font-size: clamp(14px, 2vw, 38px); letter-spacing: .08em; text-shadow: 0 0 10px rgba(255,255,255,.45); }
.score-card em { color: var(--gold); font-size: clamp(8px, 1vw, 18px); font-style: normal; }

.mission-card { min-height: clamp(44px, 5.8vw, 92px); padding: 4% 6%; }
.mission-card strong { display: block; margin-top: .5em; color: white; font-size: clamp(7px, .9vw, 17px); }
.boss-meter { height: clamp(4px, .65vw, 10px); margin-top: .6em; background: #19051c; border: 1px solid #9b1c80; }
.boss-meter i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #ed167e, #ff66d8); }

.icon-button {
  pointer-events: auto;
  width: 100%;
  aspect-ratio: 1;
  color: white;
  font-weight: 900;
  cursor: pointer;
}

.ability-bar {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: 2.1%;
  display: flex;
  gap: .65vw;
  transform: translateX(-50%);
}
.ability-bar button {
  position: relative;
  min-width: clamp(74px, 8vw, 140px);
  padding: clamp(5px, .55vw, 11px) clamp(5px, .8vw, 14px);
  color: white;
  border: 2px solid #3477a7;
  background: linear-gradient(180deg, rgba(4,31,67,.94), rgba(2,12,30,.94));
  box-shadow: inset 0 0 12px rgba(0,194,255,.12), 0 3px 0 #020612;
  cursor: pointer;
}
.ability-bar button:active, .ability-bar button.active { transform: translateY(2px); border-color: var(--cyan); box-shadow: 0 0 14px rgba(37,233,255,.5); }
.ability-bar span { position: absolute; top: 2px; right: 4px; color: #7fa0c0; font-size: clamp(6px, .58vw, 11px); }
.ability-bar b { display: block; color: var(--cyan); font-size: clamp(7px, .72vw, 14px); }
.ability-bar small { font-size: clamp(7px, .9vw, 16px); }

.touch-controls {
  position: absolute;
  z-index: 5;
  inset: auto 2.8% 2.2%;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}
.move-controls, .action-controls { display: flex; gap: 1.2vw; align-items: end; }
.touch-controls button {
  pointer-events: auto;
  display: grid;
  place-items: center;
  width: clamp(48px, 7vw, 112px);
  aspect-ratio: 1;
  color: #d7e8ff;
  border: 3px solid rgba(198,224,255,.72);
  border-radius: 17%;
  background: rgba(8,24,49,.78);
  box-shadow: inset 0 0 18px rgba(126,194,255,.14), 0 0 0 3px rgba(3,8,20,.5);
  font-size: clamp(18px, 2.4vw, 44px);
  cursor: pointer;
}
.touch-controls .jump, .touch-controls .shoot { border-radius: 50%; }
.touch-controls .drop { color: #67f7ff; }
.touch-controls .shoot { width: clamp(58px, 8.3vw, 132px); }
.touch-controls button.pressed { color: white; border-color: var(--cyan); background: rgba(10,92,128,.72); transform: scale(.96); }
.touch-controls span { font-size: clamp(6px, .62vw, 12px); font-weight: 900; }

.overlay {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 4%;
  background: radial-gradient(circle at 50% 35%, rgba(103, 145, 99, .5), rgba(14, 35, 25, .94));
  backdrop-filter: blur(3px);
  font-family: Georgia, "Times New Roman", Tahoma, sans-serif;
}
.start-overlay {
  background:
    linear-gradient(90deg, rgba(20, 50, 35, .94) 0%, rgba(37, 69, 43, .76) 48%, rgba(255, 222, 210, .08) 100%),
    url('/assets/mushroom-forest-bg.png') center/cover;
  background-blend-mode: normal;
  place-items: center start;
}
.character-select-overlay {
  background:
    linear-gradient(180deg, rgba(34, 75, 51, .58), rgba(13, 37, 27, .9)),
    url('/assets/mushroom-forest-bg.png') center/cover;
}
.overlay[hidden] { display: none; }
.overlay-card {
  width: min(44%, 620px);
  margin-left: 4%;
  padding: clamp(18px, 3.2vw, 56px);
  border-left: clamp(4px, .5vw, 9px) solid var(--cyan);
  background: linear-gradient(135deg, rgba(3,12,34,.96), rgba(4,17,42,.82));
  box-shadow: 0 0 60px rgba(0,183,255,.2), inset 0 0 40px rgba(0,132,255,.09);
  clip-path: polygon(0 0, 92% 0, 100% 13%, 100% 100%, 8% 100%, 0 87%);
}
.overlay-card.compact { width: min(48%, 560px); margin: 0; text-align: center; }
.start-overlay .overlay-card {
  width: min(52%, 720px);
  padding: clamp(18px, 2.5vw, 42px);
}
.character-select-card {
  width: min(86%, 1080px);
  margin: 0;
  padding: clamp(14px, 2vw, 32px);
  text-align: center;
  clip-path: polygon(3% 0, 97% 0, 100% 12%, 100% 88%, 97% 100%, 3% 100%, 0 88%, 0 12%);
}
.character-select-card > p { margin-inline: auto; }
.eyebrow { margin: 0 0 .7em; color: var(--cyan); font-size: clamp(8px, 1vw, 17px); letter-spacing: .2em; }
.overlay h1 { margin: 0; font-size: clamp(30px, 5.7vw, 100px); line-height: .8; letter-spacing: -.07em; text-shadow: 4px 5px 0 #09142f, 0 0 25px rgba(38,235,255,.35); }
.overlay h1 span, .overlay h2 { color: var(--pink); }
.overlay h2 { margin: .15em 0 .45em; font-size: clamp(24px, 4vw, 66px); }
.overlay-card > p:not(.eyebrow) { max-width: 38em; font-size: clamp(8px, .9vw, 16px); line-height: 1.6; color: #b9cae4; }
.overlay-card > p strong { color: #ff55c8; }
.character-picker { margin: .7em 0 .25em; }
.character-picker-label {
  display: block;
  margin-bottom: .45em;
  color: #a9bdd8;
  font-size: clamp(7px, .72vw, 13px);
  font-weight: 900;
  letter-spacing: .08em;
}
.character-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(5px, .8vw, 14px); }
.character-option {
  position: relative;
  display: grid;
  grid-template-columns: minmax(42px, 36%) 1fr;
  align-items: center;
  gap: clamp(4px, .55vw, 10px);
  min-width: 0;
  padding: clamp(4px, .45vw, 8px);
  color: #dcecff;
  border: 2px solid #304e68;
  background: linear-gradient(145deg, rgba(10, 31, 51, .92), rgba(4, 15, 28, .94));
  box-shadow: inset 0 0 14px rgba(37, 233, 255, .05);
  text-align: left;
  cursor: pointer;
}
.character-option:hover { border-color: #6096b6; background-color: rgba(23, 67, 82, .85); }
.character-option.selected {
  border-color: var(--gold);
  background: linear-gradient(145deg, rgba(50, 49, 27, .96), rgba(7, 25, 35, .94));
  box-shadow: inset 0 0 18px rgba(255, 199, 57, .12), 0 0 12px rgba(255, 199, 57, .16);
}
.start-overlay .overlay-card,
.character-select-overlay .overlay-card {
  border: 1px solid rgba(255, 221, 178, .42);
  border-left: clamp(5px, .55vw, 10px) solid #f0a7b1;
  border-radius: 0 28px 28px 0;
  background: linear-gradient(135deg, rgba(22, 58, 39, .95), rgba(48, 82, 48, .83));
  box-shadow: 0 22px 70px rgba(24, 52, 36, .38), inset 0 0 42px rgba(255, 226, 177, .07);
  clip-path: none;
  backdrop-filter: blur(7px);
}
.start-overlay .eyebrow,
.character-select-overlay .eyebrow,
.character-select-overlay .character-picker-label { color: #ffe2a9; }
.start-overlay h1 {
  color: #fff8dc;
  letter-spacing: -.035em;
  text-shadow: 4px 5px 0 #21402d, 0 0 28px rgba(255, 231, 183, .25);
}
.start-overlay h1 span,
.character-select-overlay h2 { color: #f4adb7; }
.start-overlay .overlay-card > p,
.character-select-overlay .overlay-card > p { color: #ecf2db; }
.start-overlay .overlay-card > p strong { color: #ffe09c; }
.start-overlay .game-tagline {
  margin: .65em 0 .25em;
  color: #ffe2a9 !important;
  font-size: clamp(15px, 2vw, 34px) !important;
  font-weight: 900;
  letter-spacing: .04em;
  text-shadow: 0 2px 10px rgba(27, 54, 37, .75);
}
.start-overlay .game-description { margin: .2em 0 .7em; }
.character-select-overlay .character-option {
  border-color: rgba(255, 224, 178, .34);
  border-radius: 16px;
  background: linear-gradient(145deg, rgba(38, 75, 48, .94), rgba(20, 50, 35, .96));
  box-shadow: inset 0 0 16px rgba(255, 227, 184, .05);
}
.character-select-overlay .character-option:hover { border-color: #f1b8bd; }
.character-select-overlay .character-option.selected {
  border-color: #f3b0b8;
  background: linear-gradient(145deg, rgba(80, 91, 51, .96), rgba(31, 65, 41, .96));
  box-shadow: inset 0 0 18px rgba(255, 220, 166, .12), 0 0 16px rgba(242, 168, 180, .2);
}
.character-option img {
  width: 100%;
  height: clamp(50px, 6.4vw, 96px);
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(0 4px 4px rgba(0, 0, 0, .45));
}
.character-copy { display: grid; min-width: 0; gap: .35em; }
.character-copy b { color: white; font-size: clamp(7px, .78vw, 14px); white-space: nowrap; }
.character-copy small { color: #d8dbb5; font-size: clamp(5px, .55vw, 10px); white-space: nowrap; }
.select-mark {
  position: absolute;
  top: 4px;
  right: 5px;
  display: none;
  color: #ffd596;
  font-size: clamp(8px, .9vw, 16px);
  font-weight: 900;
}
.character-option.selected .select-mark { display: block; }
.selection-actions {
  display: flex;
  justify-content: center;
  gap: clamp(8px, 1vw, 18px);
  margin-top: clamp(8px, 1vw, 18px);
}
.primary-button {
  display: block;
  min-width: 70%;
  margin: 1.5em 0 .7em;
  padding: .9em 1.3em;
  color: #00121b;
  border: 0;
  background: linear-gradient(90deg, #20dcff, #37ffce);
  box-shadow: 0 5px 0 #077b91, 0 0 24px rgba(33,234,255,.42);
  font-weight: 900;
  font-size: clamp(10px, 1.1vw, 20px);
  cursor: pointer;
}
.start-overlay .primary-button { margin-top: .8em; }
.start-overlay .primary-button,
.character-select-overlay .primary-button {
  color: #3d3026;
  border-radius: 10px;
  background: linear-gradient(90deg, #f2acb6, #f6d693);
  box-shadow: 0 5px 0 #8a6553, 0 0 24px rgba(244, 174, 184, .3);
}
.compact .primary-button { margin-inline: auto; }
.selection-actions .primary-button { min-width: 42%; margin: 0; }
.secondary-button {
  min-width: 20%;
  padding: .9em 1.3em;
  color: #fff0d0;
  border: 2px solid #bd8d83;
  border-radius: 10px;
  background: rgba(30, 63, 43, .94);
  box-shadow: 0 4px 0 #173525;
  font-weight: 900;
  cursor: pointer;
}
.secondary-button:hover { color: white; border-color: #f3b0b8; }
.primary-button:hover { filter: brightness(1.14); }
.primary-button:active { transform: translateY(3px); box-shadow: 0 2px 0 #077b91; }
.start-overlay small, .character-select-overlay small { color: #e4e5c3; }
.overlay small { font-size: clamp(6px, .65vw, 12px); }
.result-score { display: grid; gap: .1em; color: #9db1cc; }
.result-score strong { color: var(--gold); font-size: clamp(24px, 4.5vw, 76px); }
.transition-overlay {
  z-index: 20;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(37, 75, 49, .58), rgba(15, 39, 28, .88)),
    url('/assets/mushroom-forest-bg.png') center/cover;
  backdrop-filter: none;
}
.transition-overlay::before,
.transition-overlay::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 25%, rgba(244, 177, 188, .22) 49%, transparent 72%);
  transform: translateX(-115%);
  animation: sector-sweep .72s ease-in-out forwards;
}
.transition-overlay::after { animation-delay: .12s; opacity: .55; }
.transition-core {
  position: relative;
  z-index: 1;
  display: grid;
  width: min(48%, 560px);
  gap: .8em;
  color: #fff2d1;
  text-align: center;
  font-size: clamp(14px, 2vw, 34px);
  font-weight: 900;
  letter-spacing: .16em;
  animation: transition-pulse .72s ease both;
}
.transition-core i {
  display: block;
  height: 5px;
  background: linear-gradient(90deg, transparent, #f2aab5, #f3d389, transparent);
  box-shadow: 0 0 20px rgba(242, 170, 181, .55);
}
@keyframes sector-sweep {
  0% { transform: translateX(-115%); }
  100% { transform: translateX(115%); }
}
@keyframes transition-pulse {
  0% { opacity: 0; transform: scale(.92); }
  35%, 70% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.05); }
}
.rotate-hint { display: none; }

@media (hover: hover) and (pointer: fine) {
  .touch-controls { opacity: .24; }
  .touch-controls:hover { opacity: 1; }
  .fullscreen-button { opacity: .72; }
  .fullscreen-button:hover { opacity: 1; }
}

@media (max-aspect-ratio: 1/1) and (orientation: portrait) {
  .game-shell { width: 100vw; height: 100dvh; aspect-ratio: auto; }
  #game, .hud, .ability-bar, .touch-controls, .overlay { filter: blur(7px) brightness(.4); }
  .rotate-hint {
    position: absolute;
    z-index: 30;
    inset: 0;
    display: grid;
    place-items: center;
    margin: 0;
    padding: 20vw;
    text-align: center;
    color: white;
    font-size: 5vw;
    background: rgba(0,4,16,.6);
  }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
  .transition-overlay::before, .transition-overlay::after, .transition-core { animation: none !important; }
}
