:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #20262d;
  --muted: #59636d;
  --glass: rgba(244, 247, 249, 0.72);
}

@font-face {
  font-family: "Mario64";
  src: url("./Mario64.ttf") format("truetype");
  font-display: swap;
}

* { box-sizing: border-box; }

html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }

body {
  background: #000;
  color: var(--ink);
  font-family: "Mario64", Inter, ui-sans-serif, system-ui, sans-serif;
  touch-action: none;
  overscroll-behavior: none;
}

#game, #scene { width: 100%; height: 100%; display: block; }

#game:fullscreen .screen {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  border: 0;
  border-radius: 0;
}

#viewport { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }

.screen {
  position: relative;
  width: min(100vw, calc(100vh * 4 / 3));
  height: auto;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 2px solid #000;
  border-radius: 4px;
  background: #000;
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  cursor: grab;
  touch-action: none;
  background: #000;
}
#scene.dragging { cursor: grabbing; }

#intro {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  background: #000;
}
#intro[hidden] { display: none; }

#intro-skip {
  position: absolute;
  left: 50%;
  bottom: 12px;
  z-index: 3;
  cursor: pointer;
  pointer-events: auto;
  padding: 6px 9px;
  border: 1px solid rgba(255,255,255,.5);
  border-radius: 6px;
  background: rgba(0,0,0,.4);
  color: #fff;
  font: 10px "Mario64", sans-serif;
  letter-spacing: .1em;
  -webkit-tap-highlight-color: transparent;
  opacity: 0;
  transform: translate(-50%, 6px);
  transition: opacity .3s ease, transform .3s ease;
}
#intro-skip:hover { background: rgba(0,0,0,.7); }
#intro-skip:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
#intro-skip.show { opacity: 1; transform: translate(-50%, 0); }

.menu {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  justify-content: center;
  transform: translateY(60px);
  pointer-events: none;
  transition: opacity .4s ease;
}
.menu.is-hidden { opacity: 0; pointer-events: none; }
.menu-start {
  pointer-events: auto;
  cursor: pointer;
  padding: 12px 36px;
  border: 2px solid rgba(255,255,255,.85);
  border-radius: 8px;
  background: rgba(0,0,0,.35);
  color: #fff;
  font: 18px "Mario64", sans-serif;
  letter-spacing: .18em;
  transition: background .15s ease, transform .1s ease;
}
.menu-start:hover { background: rgba(255,255,255,.2); }
.menu-start:active { transform: translateY(2px) scale(.98); }
.menu-install {
  pointer-events: auto;
  cursor: pointer;
  padding: 8px 18px;
  border: 1px solid rgba(255,255,255,.56);
  border-radius: 7px;
  background: rgba(0,0,0,.26);
  color: rgba(255,255,255,.9);
  font: 10px "Mario64", sans-serif;
  letter-spacing: .12em;
  transition: background .15s ease, transform .1s ease;
}
.menu-install:hover { background: rgba(255,255,255,.18); }
.menu-install:active { transform: translateY(2px) scale(.98); }
.menu-install[hidden], .install-hint[hidden] { display: none; }
.install-hint {
  max-width: min(280px, calc(100vw - 40px));
  color: #fff;
  font: 9px/1.5 "Mario64", sans-serif;
  letter-spacing: .04em;
  text-align: center;
  text-shadow: 0 1px 5px #000;
}

#death-flash {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  background: radial-gradient(circle at center, rgba(255,70,50,0) 30%, #a01510 130%);
  opacity: 0;
}
#death-flash.flash { animation: death-flash .7s ease-out; }
@keyframes death-flash { 0% { opacity: 0; } 15% { opacity: .85; } 100% { opacity: 0; } }

#console {
  position: fixed;
  left: 20px;
  top: 20px;
  z-index: 20;
  width: 236px;
  padding: 12px 14px;
  border: 1px solid rgba(255,255,255,.4);
  border-radius: 10px;
  background: rgba(0,0,0,.68);
  color: #e8ecef;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 28px rgba(0,0,0,.45);
}
#console h1 { margin: 0 0 8px; font: 12px "Mario64", sans-serif; letter-spacing: .12em; color: #fff; }
#console .section { display: flex; flex-direction: column; gap: 7px; margin-top: 9px; }
#console .section:first-of-type { margin-top: 0; }
#console label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
#console label:hover { color: #fff; }
#console button {
  pointer-events: auto;
  cursor: pointer;
  padding: 8px 10px;
  border: 1px solid rgba(255,255,255,.5);
  border-radius: 8px;
  background: rgba(255,255,255,.08);
  color: #fff;
  font-family: inherit;
  font-size: 11px;
  text-align: left;
}
#console button:hover { background: rgba(255,255,255,.18); }
#console[hidden] { display: none; }

#debug-hud {
  position: fixed;
  left: 20px;
  bottom: 20px;
  z-index: 19;
  pointer-events: none;
  color: #7effa0;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  text-shadow: 0 0 6px rgba(0,0,0,.85);
  white-space: pre;
}

#ntsc {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

#loading-screen { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; color: #fff; background: #000; transition: opacity .55s ease, visibility .55s ease; }
#loading-screen[hidden] { display: none; }
#loading-screen.is-done { opacity: 0; visibility: hidden; pointer-events: none; }
#loading-screen.is-success { background: transparent; }
.loading-panel { width: min(310px, calc(100vw - 48px)); text-align: center; text-shadow: 0 2px 8px rgba(0,0,0,.42); transition: opacity .18s ease, transform .18s ease; }
#loading-screen.is-success .loading-panel { opacity: 0; transform: scale(.96); }
.loading-success { position: absolute; inset: 0; width: 100%; height: 100%; display: block; opacity: 0; pointer-events: none; }
#loading-screen.is-success .loading-success { opacity: 1; }
.loading-star-hole, .loading-star-glow { transform-box: fill-box; transform-origin: center; transform: scale(.02); }
#loading-screen.is-success .loading-star-hole, #loading-screen.is-success .loading-star-glow { animation: loading-star-open 1.05s linear forwards; }
.loading-star-glow { opacity: .96; }
@keyframes loading-star-open { 0% { transform: scale(.02); } 100% { transform: scale(3.4); } }
.loading-title { margin-bottom: 10px; font: 22px/1 "Mario64", sans-serif; letter-spacing: .08em; }
.loading-text { margin-bottom: 13px; font: 11px/1 "Mario64", sans-serif; letter-spacing: .1em; }
.loading-track { width: 100%; height: 9px; overflow: hidden; border: 1px solid rgba(255,255,255,.85); border-radius: 8px; background: rgba(0,0,0,.3); box-shadow: 0 2px 10px rgba(0,0,0,.22); }
.loading-progress { width: 0%; height: 100%; border-radius: inherit; background: #fff; transition: width .2s ease; }
.loading-percent { margin-top: 8px; font: 10px/1 "Mario64", sans-serif; letter-spacing: .08em; }

#desktop-help, #mobile-controls { position: fixed; z-index: 2; pointer-events: none; }

.fullscreen-toggle {
  position: fixed;
  z-index: 8;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255,255,255,.5);
  border-radius: 10px;
  background: rgba(0,0,0,.48);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-tap-highlight-color: transparent;
}
.restart-toggle { right: auto; left: max(14px, env(safe-area-inset-left)); }
.fullscreen-toggle:hover { background: rgba(255,255,255,.17); }
.fullscreen-toggle:active { transform: scale(.94); }
.fullscreen-toggle:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
.fullscreen-toggle svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.restart-dialog {
  width: min(360px, calc(100vw - 40px));
  padding: 24px;
  border: 1px solid rgba(255,255,255,.58);
  border-radius: 12px;
  background: rgba(0,0,0,.88);
  color: #fff;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,.55);
  backdrop-filter: blur(12px);
}
.restart-dialog::backdrop { background: rgba(0,0,0,.62); backdrop-filter: blur(3px); }
.restart-dialog h2 { margin: 0; font: 14px/1.5 "Mario64", sans-serif; letter-spacing: .06em; }
.restart-dialog p { margin: 13px 0 22px; color: rgba(255,255,255,.8); font: 10px/1.7 "Mario64", sans-serif; }
.restart-dialog-actions { display: flex; justify-content: center; gap: 10px; }
.restart-dialog-actions form { margin: 0; }
.restart-dialog-button {
  min-height: 38px;
  padding: 9px 12px;
  border: 1px solid rgba(255,255,255,.5);
  border-radius: 7px;
  background: rgba(255,255,255,.08);
  color: #fff;
  cursor: pointer;
  font: 9px "Mario64", sans-serif;
  letter-spacing: .05em;
}
.restart-dialog-button:hover { background: rgba(255,255,255,.2); }
.restart-dialog-button.is-primary { background: rgba(255,255,255,.92); color: #111; }
.restart-dialog-button.is-primary:hover { background: #fff; }
.restart-dialog-button:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }

#rotate-notice { display: none; }
@media (orientation: portrait) and (pointer: coarse) {
  #game { visibility: hidden; }
  #game * { font-family: ui-sans-serif, system-ui, sans-serif !important; }
  #rotate-notice {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: flex;
    visibility: visible;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    background: #000;
    color: #fff;
    font: 16px ui-sans-serif, system-ui, sans-serif;
    letter-spacing: .1em;
    text-align: center;
  }
  #rotate-notice svg {
    width: 62px;
    height: 62px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
}

.help-card {
  right: 24px;
  bottom: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,.5);
  border-radius: 10px;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(10px);
  box-shadow: 0 5px 18px rgba(0,0,0,.4);
  color: #c7cdd4;
  font-size: 10px;
  letter-spacing: .08em;
}
.help-content { display: flex; align-items: center; gap: 14px; }
.help-label { color: #fff; }
.help-card b { color: #fff; font-size: 10px; margin-right: 3px; }
.help-toggle {
  pointer-events: auto;
  cursor: pointer;
  width: 20px;
  height: 20px;
  margin-left: 2px;
  border: 1px solid rgba(255,255,255,.5);
  border-radius: 6px;
  background: transparent;
  color: #fff;
  font: 14px/1 "Mario64", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
.help-toggle:hover { background: rgba(255,255,255,.15); }
.help-card.is-collapsed { background: transparent; backdrop-filter: none; box-shadow: none; border: none; padding: 0; gap: 0; }
.help-card.is-collapsed .help-content { display: none; }
.help-card.is-collapsed .help-toggle { width: auto; height: auto; padding: 7px 12px; font-size: 10px; letter-spacing: .08em; border-radius: 10px; border: 1px solid rgba(255,255,255,.5); background: rgba(0,0,0,.55); }

#mobile-controls { display: none; inset: auto 0 max(20px, env(safe-area-inset-bottom)) 0; height: 170px; }
.joystick { position: absolute; left: 28px; bottom: 8px; width: 118px; height: 118px; border-radius: 50%; pointer-events: auto; }
.joystick-ring { position: absolute; inset: 0; border: 1px solid rgba(255,255,255,.54); border-radius: 50%; background: rgba(255,255,255,.16); box-shadow: inset 0 1px 8px rgba(55,65,72,.12); }
.joystick-knob { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px; border-radius: 50%; background: rgba(244,247,249,.72); border: 1px solid rgba(255,255,255,.78); box-shadow: 0 4px 12px rgba(44,53,61,.18); transition: transform .05s linear; }
.action-buttons { position: absolute; right: 27px; bottom: 4px; width: 140px; height: 126px; pointer-events: none; }
.action-button { position: absolute; width: 58px; height: 58px; border: 2px solid rgba(255,255,255,.8); border-radius: 50%; color: white; font: 800 19px/1 "Mario64", sans-serif; box-shadow: 0 4px 0 rgba(44,53,61,.3), inset 0 1px 0 rgba(255,255,255,.34); pointer-events: auto; -webkit-tap-highlight-color: transparent; }
.action-button:active { transform: translateY(2px) scale(.96); }
.action-button.jump { right: 0; top: 6px; background: #d94435; }
.action-button.dive { left: 4px; bottom: 4px; width: 48px; height: 48px; background: #3e78ad; font-size: 16px; }
.action-button.crouch { right: 8px; top: 72px; width: 42px; height: 42px; background: #59636d; font-size: 13px; }

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

@media (max-width: 380px) {
  .joystick { left: 18px; }
  .action-buttons { right: 17px; }
}
