:root {
  color-scheme: dark;
  --ink: #effaf5;
  --muted: #adc6ba;
  --accent: #9de2bb;
  --line: #40665a;
  --font-ui: system-ui, sans-serif;
  font-family: var(--font-ui);
  background: #111c19;
  color: var(--ink);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at 50% 5%, #263f35 0%, #15231e 55%, #0e1714 100%);
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  width: min(1120px, calc(100% - 48px), max(760px, calc((100svh - 155px) * 16 / 9)));
  padding: 18px 0;
}
.topbar, .frame, .mirror-room, .controls { grid-column: 1; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 15px; }
.brand { font: 600 1.22rem var(--font-ui); }
button { font: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid #eafff3; outline-offset: 4px; }
.utility { color: var(--muted); background: #20322a; border: 1px solid var(--line); border-radius: 6px; padding: 8px 13px; font-size: .875rem; }
.utility:hover { color: var(--ink); border-color: var(--accent); }

.frame { position: relative; overflow: hidden; aspect-ratio: 16 / 9; isolation: isolate; border: 1px solid var(--line); border-radius: 12px; background: #12282a; box-shadow: 0 24px 70px #07120eb3; }
canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  text-align: center;
  padding: 26px;
  background: radial-gradient(ellipse at center, #101714aa 0%, #11191720 72%), linear-gradient(#10171842, #10171815 28%, #10171855);
}
.chapter { display: flex; align-items: center; gap: 10px; color: var(--accent); font-size: .875rem; font-weight: 650; text-transform: uppercase; letter-spacing: .19em; }
h1 { margin: 13px 0 9px; font: 750 clamp(2.2rem, 6.3vw, 5.3rem)/1.01 var(--font-ui); letter-spacing: -.05em; text-shadow: 0 4px 24px #08070b; text-wrap: balance; }
.overlay p { max-width: 425px; margin: 10px 0 25px; color: #ebf5ef; line-height: 1.6; text-wrap: balance; }
.primary { border: 1px solid #c3efda; border-radius: 6px; padding: 12px 20px; background: var(--accent); color: #112b20; font-weight: 720; box-shadow: 0 6px 25px #091a1455; }
.primary:hover { background: #b8efce; }

.hud { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; padding: 21px 25px 28px; background: linear-gradient(#0b1014c5, transparent); pointer-events: none; }
.health { display: grid; align-content: start; gap: 5px; font-size: .9rem; font-weight: 650; }
.enemy-health { justify-items: end; }
.hearts { display: flex; gap: 3px; font-size: 1.4rem; line-height: 1; }
.heart { color: var(--accent); }
.heart.empty { color: #78978a66; }
progress { appearance: none; width: clamp(100px, 16vw, 180px); height: 9px; border: 1px solid #9de2bb66; border-radius: 2px; overflow: hidden; background: #13221c; }
progress::-webkit-progress-bar { background: #13221c; }
progress::-webkit-progress-value { background: var(--accent); }
progress::-moz-progress-bar { background: var(--accent); }

.controls { display: flex; align-items: center; gap: clamp(12px, 2.4vw, 28px); padding: 15px 3px 0; color: var(--muted); font-size: .875rem; flex-wrap: wrap; }
.controls-heading { color: #c2e0d1; font-weight: 700; }
.control { display: inline-flex; align-items: center; gap: 4px; }
.control span { margin-left: 4px; }
.controls kbd { display: inline-grid; place-items: center; min-width: 28px; min-height: 28px; padding: 0 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; background: #233a30; color: #e0f6ea; font: 650 .85rem var(--font-ui); }
@media (max-width: 720px) {
  .shell { width: calc(100% - 24px); grid-template-columns: minmax(0, 1fr); }
  .frame { aspect-ratio: auto; min-height: 350px; }
  canvas { position: absolute; inset: 0; object-fit: cover; }
}

.nightmare-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }

.mirror-room {
  position: relative;
  display: grid;
  grid-template-columns: 1fr minmax(295px, 36%);
  min-height: 0;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  isolation: isolate;
  border: 1px solid #567b6c;
  background: #39413b;
  box-shadow: 0 24px 70px #07120eb3;
}

.mirror-art {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.mirror-art img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  image-rendering: pixelated;
  pointer-events: none;
  user-select: none;
}

.mirror-art .duel-cleared-image,
.is-cleared #duel-image { display: none; }
.is-cleared .duel-cleared-image { display: block; }

.is-dueling .mirror-art { cursor: crosshair; }
.sauron-target {
  position: absolute;
  z-index: 1;
  width: clamp(42px, 5.2%, 62px);
  aspect-ratio: 2 / 1;
  transform: translate(-50%, -50%);
  pointer-events: none;
  filter: drop-shadow(0 2px 0 #361912) drop-shadow(0 0 7px #ffae46);
}
.sauron-label, .sauron-window {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 6px;
  background: #202a23;
  color: #fff0b0;
  font: 800 .8rem/1.1 var(--font-ui);
  text-transform: uppercase;
  white-space: nowrap;
}
.sauron-label { bottom: calc(100% + 6px); }
.sauron-window { top: calc(100% + 6px); color: #ffe3d1; font-size: .68rem; }
.sauron-target.is-open .sauron-window { background: #ffe5a0; color: #272c20; }
.sauron-eye {
  position: absolute;
  inset: 0;
  background: linear-gradient(#e9bd7a 0 27%, #c78954 27% 68%, #96553d 68%);
  clip-path: polygon(0 40%, 12% 40%, 12% 23%, 27% 23%, 27% 7%, 73% 7%, 73% 23%, 88% 23%, 88% 40%, 100% 40%, 100% 60%, 88% 60%, 88% 77%, 73% 77%, 73% 93%, 27% 93%, 27% 77%, 12% 77%, 12% 60%, 0 60%);
}
.sauron-target.is-open .sauron-eye { background: linear-gradient(#fff5ad 0 27%, #ffbf52 27% 68%, #dc733e 68%); }
.sauron-eye::after {
  content: '';
  position: absolute;
  inset: 14% 42%;
  background: #202a23;
  clip-path: polygon(35% 0, 65% 0, 65% 16%, 100% 16%, 100% 84%, 65% 84%, 65% 100%, 35% 100%, 35% 84%, 0 84%, 0 16%, 35% 16%);
}

.gaze-reticle {
  --reticle-color: #fff1df;
  position: absolute;
  z-index: 2;
  width: 9%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  pointer-events: none;
  background:
    linear-gradient(var(--reticle-color), var(--reticle-color)) top left / 28% 2px,
    linear-gradient(var(--reticle-color), var(--reticle-color)) top left / 2px 28%,
    linear-gradient(var(--reticle-color), var(--reticle-color)) top right / 28% 2px,
    linear-gradient(var(--reticle-color), var(--reticle-color)) top right / 2px 28%,
    linear-gradient(var(--reticle-color), var(--reticle-color)) bottom left / 28% 2px,
    linear-gradient(var(--reticle-color), var(--reticle-color)) bottom left / 2px 28%,
    linear-gradient(var(--reticle-color), var(--reticle-color)) bottom right / 28% 2px,
    linear-gradient(var(--reticle-color), var(--reticle-color)) bottom right / 2px 28%;
  background-repeat: no-repeat;
  filter: drop-shadow(0 1px 2px #202021);
}

.gaze-reticle.is-tracking { --reticle-color: #a9f0c7; }
.gaze-reticle.is-centered { --reticle-color: #fff3a9; filter: drop-shadow(0 0 5px #fff3a9); }

.mirror-panel {
  z-index: 3;
  grid-column: 2;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  align-self: stretch;
  padding: clamp(19px, 3vw, 40px);
  border-left: 1px solid #78a38e;
  background: linear-gradient(140deg, #284237fa, #172820fc);
}

.mirror-panel .chapter { margin-bottom: 10px; font-family: var(--font-ui); }
.mirror-panel h1 {
  margin: 0 0 14px;
  font: 750 clamp(1.7rem, 3.05vw, 3rem)/1.07 var(--font-ui);
  letter-spacing: -.055em;
  text-shadow: 2px 2px #122419;
}

.mirror-panel p { margin: 0; max-width: 39ch; line-height: 1.45; }
.duel-hud { display: grid; width: 100%; gap: 7px; margin-top: 26px; }
.duel-hud .duel-round { color: var(--accent); font: 800 .875rem var(--font-ui); }
.duel-captures { display: flex; align-items: center; gap: 7px; margin-bottom: 8px; color: #c6ead5; font: 650 .875rem var(--font-ui); }
.duel-captures span { width: 10px; height: 10px; margin-left: 4px; border: 1px solid #82b99f; rotate: 45deg; }
.duel-captures .is-filled { background: #9de2bb; }
.duel-hud label { color: #b8d7c8; font-size: .875rem; }
.duel-hud progress { width: 100%; height: 10px; }
.duel-hud .duel-status { min-height: 3em; padding-top: 6px; color: #e7faef; font-weight: 650; }
.duel-actions { display: grid; gap: 10px; margin-top: 18px; }
.duel-actions:not(:has(> button:not([hidden]))) { display: none; }
.is-cleared .mirror-panel { background: linear-gradient(140deg, #335345fa, #1c3025fc); }

@media (max-width: 720px) {
  .mirror-room { grid-template-columns: 1fr; aspect-ratio: auto; }
  .mirror-art { position: relative; aspect-ratio: 16 / 9; }
  .mirror-panel { grid-column: 1; border-left: none; border-top: 1px solid #78a38e; }
}


.gym {
  background: #303e3b url('assets/gym-background.png') center / cover;
  min-height: 390px;
}
.gym-lifter {
  position: absolute;
  bottom: 8%;
  left: 9%;
  width: 42%;
}
.gym-lifter img {
  display: block;
  width: 100%;
  image-rendering: pixelated;
}
.gym-card {
  position: absolute;
  top: 12%;
  right: 4%;
  width: min(41%, 375px);
  padding: clamp(14px, 2.5vw, 32px);
  background: #20382cf2;
  border: 1px solid var(--line);
}
.gym-card h1 { font-size: clamp(1.6rem, 3.3vw, 3rem); }
.gym-card p { line-height: 1.5; }
.gym-meter { position: relative; height: 18px; border: 1px solid var(--line); background: #101d18; }
.gym-phase { color: var(--accent); font-weight: 750; }
.gym-meter span { position: absolute; inset: 0 auto 0 var(--zone-start); width: var(--zone-width); background: var(--accent); }
.gym-meter.is-release span { background: #f9d793; }
.gym-meter i { position: absolute; top: -4px; bottom: -4px; left: 0; width: 4px; background: white; }

.gym-actions,
.invitation-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.invitation {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  place-items: center;
  gap: clamp(16px, 3vw, 36px);
  padding: clamp(18px, 3vw, 38px);
  background: radial-gradient(ellipse at 50% 12%, #345748, #192e28 58%, #101a17);
}
.invitation-art {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  object-fit: cover;
  image-rendering: pixelated;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.invitation-card {
  width: min(100%, 520px);
  padding: clamp(22px, 4vw, 44px);
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #192b25;
}
.invitation-card .chapter,
.invitation-actions { justify-content: center; }
.invitation-card h1 {
  margin-bottom: 16px;
  font-size: clamp(2rem, 5vw, 3.5rem);
}
.invitation-card p {
  margin: 0 auto 24px;
  max-width: 35ch;
  line-height: 1.55;
}
.invitation-actions .primary { min-width: 132px; }
@media (max-width: 720px) {
  .invitation { grid-template-columns: minmax(0, 1fr); }
  .invitation-art { aspect-ratio: 4 / 3; }
}

.invitation-ending {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 24px;
  border: 0;
  overflow: hidden;
}
.invitation-ending[open] { display: grid; place-items: center; }
.invitation-ending::backdrop { background: transparent; }
.invitation-ending p {
  position: relative;
  margin: 0;
  font-weight: 750;
  text-align: center;
  outline: none;
}
.invitation-smile {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  color: var(--ink);
  font-size: clamp(5rem, 22vmin, 14rem);
  font-weight: 750;
  line-height: 1;
  outline: none;
}
.invitation-ending.is-wipe { background: transparent; color: #141414; }
.invitation-ending.is-wipe::before {
  content: '';
  position: absolute;
  inset: 0;
  background: #fff;
  animation: ending-wipe .95s ease-in-out both;
}
.invitation-ending.is-wipe p {
  font-size: clamp(2rem, 7vmin, 6rem);
  animation: ending-text .2s .95s both;
}
.ending-paw {
  display: none;
  position: absolute;
  z-index: 1;
  left: 0;
  top: 50%;
  width: clamp(95px, 17vmin, 170px);
  aspect-ratio: 1;
  color: #ca9b77;
  filter: drop-shadow(2px 3px 0 #493322);
}
.is-wipe .ending-paw { display: block; animation: ending-paw .95s ease-in-out both; }
.ending-paw i, .ending-paw b { position: absolute; display: block; background: currentColor; }
.ending-paw i { width: 19%; height: 29%; border-radius: 48%; }
.ending-paw i:nth-child(1) { left: 3%; top: 31%; rotate: -26deg; }
.ending-paw i:nth-child(2) { left: 24%; top: 10%; rotate: -12deg; }
.ending-paw i:nth-child(3) { right: 24%; top: 10%; rotate: 12deg; }
.ending-paw i:nth-child(4) { right: 3%; top: 31%; rotate: 26deg; }
.ending-paw b { inset: 43% 17% 5%; border-radius: 45% 45% 36% 36%; }
@keyframes ending-wipe { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0); } }
@keyframes ending-text { from { opacity: 0; } to { opacity: 1; } }
@keyframes ending-paw {
  from { transform: translate(-100%, -50%) rotate(53deg); }
  to { transform: translate(100vw, -50%) rotate(74deg); }
}
@media (prefers-reduced-motion: reduce) {
  .invitation-ending.is-wipe::before, .invitation-ending.is-wipe p { animation: none; }
  .is-wipe .ending-paw { display: none; }
}
