:root {
  --stage-w: min(100vw, 520px, calc(100vh * 9 / 16));
  --ink: #f8fbff;
  --muted: #a9c6e8;
  --cyan: #7df9ff;
  --cyan-dark: #17698d;
  --gold: #ffd45c;
  --red: #ff5261;
  --green: #59f29b;
  --blue-black: #071126;
  --window: rgba(8, 17, 42, .92);
  --window-2: rgba(15, 34, 70, .94);
  --outline: #020611;
  --pixel: 4px;
  font-family: "Trebuchet MS", "Arial Rounded MT Bold", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(circle at 50% 10%, #132a53, #02040b 72%);
  color: var(--ink);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.game-stage {
  position: relative;
  width: var(--stage-w);
  aspect-ratio: 9 / 16;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
  margin: 0 auto;
  background-color: #111b3a;
  background-size: cover;
  background-position: center center;
  image-rendering: pixelated;
  box-shadow: 0 0 0 4px #040713, 0 0 36px rgba(0, 0, 0, .75);
}

.game-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(255,255,255,.04) 50%, rgba(0,0,0,.05) 50%) 0 0 / 100% 4px,
    radial-gradient(circle at 50% 18%, rgba(125,249,255,.18), transparent 38%),
    linear-gradient(180deg, rgba(0,0,0,.08), rgba(0,0,0,.38));
  mix-blend-mode: screen;
  opacity: .74;
}

.bg-title {
  background-image:
    linear-gradient(180deg, rgba(9, 15, 38, 0), rgba(4, 5, 16, .16)),
    url("assets/images/bg-title-9x16.png"),
    radial-gradient(circle at 50% 18%, #385b9a 0 12%, #121d45 38%, #050713 100%);
}

.bg-setup {
  background-image:
    linear-gradient(180deg, rgba(8, 20, 42, .18), rgba(3, 7, 18, .86)),
    url("assets/images/bg-setup-9x16.png"),
    linear-gradient(160deg, #233f68, #101a3a 55%, #070916);
}

.bg-attempt {
  background-image:
    linear-gradient(180deg, rgba(4, 6, 14, .08), rgba(4, 5, 13, .92)),
    url("assets/images/bg-attempt-9x16.png"),
    radial-gradient(circle at 50% 12%, #5e4d93, #14224e 48%, #050711);
}

.bg-result {
  background-image:
    linear-gradient(180deg, rgba(11, 13, 26, .04), rgba(4, 5, 13, .9)),
    url("assets/images/bg-result-9x16.png"),
    radial-gradient(circle at 50% 20%, #5f336a, #172046 52%, #060712);
}

.bg-ranking {
  background-image:
    linear-gradient(180deg, rgba(5, 9, 23, .08), rgba(2, 3, 10, .93)),
    url("assets/images/bg-ranking-9x16.png"),
    linear-gradient(160deg, #22325c, #071127 62%, #02040b);
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}

.screen.active {
  display: block;
}

.safe-area {
  position: relative;
  z-index: 1;
  height: 100%;
  display: grid;
  gap: 12px;
  align-content: center;
}

.pixel-window,
.pixel-panel,
.result-card {
  position: relative;
  border: var(--pixel) solid var(--outline);
  background: var(--window);
  box-shadow:
    inset 0 0 0 3px var(--cyan),
    inset 0 0 0 7px rgba(255,255,255,.18),
    0 7px 0 rgba(0,0,0,.65);
}

.pixel-window {
  padding: 16px;
  text-align: center;
}

.pixel-panel {
  padding: 12px;
}

.kicker,
.subtitle,
.command-label,
.screen-header span,
.attempt-hud span {
  margin: 0;
  color: var(--muted);
  font-size: clamp(.68rem, 2.5vw, .82rem);
  font-weight: 900;
}

.pixel-title {
  margin: 4px 0;
  color: var(--gold);
  font-size: clamp(2rem, 10vw, 3.5rem);
  line-height: .9;
  letter-spacing: 0;
  text-shadow: 4px 0 0 var(--outline), -4px 0 0 var(--outline), 0 4px 0 var(--outline), 0 8px 0 #6d302f;
}

.pixel-title.small {
  font-size: clamp(2rem, 10vw, 3.4rem);
}

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

h2 {
  margin: 8px 0 0;
  font-size: clamp(1.2rem, 5vw, 1.6rem);
}

.pixel-button,
.mini-button {
  border: var(--pixel) solid var(--outline);
  color: #04101e;
  background: linear-gradient(180deg, #f9feff, var(--cyan) 55%, #29a9cf);
  font-weight: 900;
  box-shadow: 0 6px 0 rgba(0,0,0,.72);
  cursor: pointer;
}

.pixel-button {
  width: 100%;
  min-height: 52px;
  padding: 10px 12px;
  font-size: clamp(1rem, 4.2vw, 1.25rem);
}

.pixel-button.secondary {
  background: linear-gradient(180deg, #fff0a0, var(--gold) 58%, #bc7b22);
}

.pixel-button:disabled,
.mini-button:disabled {
  opacity: .55;
  filter: grayscale(1);
  cursor: not-allowed;
}

.screen-title .start-button {
  position: absolute;
  left: 18%;
  right: 18%;
  bottom: 38px;
  width: auto;
  min-height: 54px;
  opacity: 0;
}

.title-start-zone {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 50%;
  border: 0;
  padding: 0;
  background: transparent;
  color: transparent;
  cursor: pointer;
  z-index: 4;
}

.screen-title .pixel-button.secondary {
  position: absolute;
  right: 12px;
  top: 12px;
  width: auto;
  min-height: 34px;
  padding: 5px 10px;
  font-size: .78rem;
  opacity: .9;
  z-index: 5;
}

.blinking-text {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 28px;
  margin: 0;
  text-align: center;
  color: var(--cyan);
  font-size: clamp(1.5rem, 8vw, 2.45rem);
  font-weight: 900;
  opacity: 0;
  animation:
    titlePromptReady .24s steps(1, end) 2.05s forwards,
    blink 1s steps(2, end) 2.05s infinite;
  text-shadow:
    3px 0 0 var(--outline),
    -3px 0 0 var(--outline),
    0 3px 0 var(--outline),
    0 0 18px rgba(125,249,255,.95),
    0 0 34px rgba(125,249,255,.65);
  z-index: 7;
  pointer-events: none;
}

.title-credit {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 6px;
  margin: 0;
  color: rgba(248, 251, 255, .72);
  font-size: clamp(.52rem, 2.1vw, .68rem);
  font-weight: 900;
  line-height: 1;
  text-align: center;
  text-shadow: 2px 2px 0 var(--outline), 0 0 8px rgba(0,0,0,.85);
  pointer-events: none;
  z-index: 7;
}

@keyframes blink {
  50% { opacity: .15; }
}

@keyframes titlePromptReady {
  to { opacity: 1; }
}

.title-layout {
  align-content: end;
  padding: 26px 8px 26px;
}

.title-character-stage {
  position: absolute;
  left: -13%;
  right: -13%;
  bottom: -80px;
  height: 66%;
  pointer-events: none;
  z-index: 2;
}

.title-character {
  position: absolute;
  bottom: 0;
  left: var(--x);
  width: var(--w);
  height: var(--h);
  background-repeat: no-repeat;
  background-size: auto 100%;
  background-position: center bottom;
  image-rendering: pixelated;
  filter: drop-shadow(0 7px 0 rgba(0,0,0,.7)) drop-shadow(0 0 10px rgba(125,249,255,.24));
  opacity: 0;
  transform: translate(-50%, 118%) scale(.82);
  transform-origin: 50% 100%;
  animation: titleCharacterPop .62s cubic-bezier(.2, .9, .22, 1.18) var(--delay) forwards;
  z-index: var(--z);
}

.title-character-okada {
  --x: 18%;
  --w: 46%;
  --h: 85%;
  --delay: .08s;
  --z: 1;
}

.title-character-motty {
  --x: 39%;
  --w: 48%;
  --h: 81%;
  --delay: .48s;
  --z: 2;
}

.title-character-aichan {
  --x: 60%;
  --w: 43%;
  --h: 79%;
  --delay: .88s;
  --z: 3;
}

.title-character-rika {
  --x: 82%;
  --w: 46%;
  --h: 85%;
  --delay: 1.28s;
  --z: 4;
}

@keyframes titleCharacterPop {
  0% {
    opacity: 0;
    transform: translate(-50%, 118%) scale(.82);
  }
  58% {
    opacity: 1;
    transform: translate(-50%, -8%) scale(1.07);
  }
  76% {
    opacity: 1;
    transform: translate(-50%, 3%) scale(.97);
  }
  90% {
    opacity: 1;
    transform: translate(-50%, -2%) scale(1.02);
  }
  100% {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
}

.title-card-art {
  display: none;
}

.title-window {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.title-text-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.screen-header,
.attempt-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.screen-header strong,
.attempt-hud strong {
  color: var(--gold);
}

.setup-layout {
  align-content: start;
  padding-top: 8px;
}

.screen-setup.is-weight-only .character-panel {
  display: none;
}

.character-carousel {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.character-grid {
  min-width: 0;
}

.character-arrow {
  width: 42px;
  min-height: 148px;
  padding: 0;
  border: 3px solid var(--outline);
  background: linear-gradient(180deg, #eafcff, #7df9ff 52%, #17698d);
  color: var(--outline);
  font-size: 1.25rem;
  font-weight: 900;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.45), 0 4px 0 rgba(0,0,0,.65);
  cursor: pointer;
}

.character-card {
  min-width: 0;
  width: 100%;
  min-height: 282px;
  padding: 24px 12px 12px;
  border: 3px solid var(--outline);
  background: rgba(10, 25, 58, .94);
  color: var(--ink);
  display: none;
  grid-template-columns: minmax(142px, 1.05fr) minmax(0, 1fr);
  align-items: end;
  gap: 12px;
  box-shadow: inset 0 0 0 2px rgba(125,249,255,.25), 0 4px 0 rgba(0,0,0,.65);
  cursor: pointer;
  text-align: left;
  overflow: visible;
}

.character-card.is-current {
  display: grid;
}

.character-card.is-selected {
  background: rgba(31, 72, 111, .96);
  box-shadow: inset 0 0 0 3px var(--gold), 0 0 16px rgba(255,212,92,.65), 0 4px 0 rgba(0,0,0,.65);
}

.character-card.is-selected .character-portrait {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--outline), 0 0 14px rgba(255,212,92,.75);
}

.character-copy {
  min-width: 0;
  display: grid;
  gap: 9px;
  align-self: center;
  position: relative;
  z-index: 2;
}

.character-name {
  min-height: 0;
  width: 100%;
  padding: 7px 8px;
  border: 3px solid var(--outline);
  background: rgba(2,8,23,.9);
  display: block;
  text-align: left;
  font-size: clamp(.9rem, 3.8vw, 1.22rem);
  font-weight: 900;
  line-height: 1.12;
}

.character-flavor {
  color: var(--muted);
  font-size: clamp(.74rem, 2.9vw, .94rem);
  font-weight: 900;
  line-height: 1.42;
  overflow-wrap: anywhere;
}

.character-portrait,
.player-avatar {
  --shirt: #7df9ff;
  --hair: #303041;
  image-rendering: pixelated;
  border: 3px solid var(--outline);
  background:
    linear-gradient(var(--hair) 0 17%, transparent 17%),
    radial-gradient(circle at 50% 28%, #ffc08a 0 22%, transparent 23%),
    linear-gradient(90deg, transparent 0 20%, var(--shirt) 20% 80%, transparent 80%),
    linear-gradient(90deg, transparent 0 28%, #151515 28% 42%, transparent 42% 58%, #151515 58% 72%, transparent 72%);
  background-color: #ffc08a;
}

.character-portrait {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 184px;
  height: 224px;
  background-color: rgba(2, 8, 23, .45);
  background-image: none;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.22), 0 4px 0 rgba(0,0,0,.65);
  overflow: visible;
}

.character-portrait::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -40px;
  width: 160%;
  height: calc(100% + 42px);
  transform: translateX(-50%);
  background-image: var(--portrait-image);
  background-repeat: no-repeat;
  background-size: 165% auto;
  background-position: center top;
  image-rendering: pixelated;
  pointer-events: none;
  filter: drop-shadow(0 4px 0 rgba(0,0,0,.65));
}

.character-okada { --shirt: #7df9ff; --hair: #2d3747; --portrait-image: url("assets/characters/okada.png"); background-image: var(--portrait-image); }
.character-motty { --shirt: #ffda63; --hair: #4a2d20; --portrait-image: url("assets/characters/motty.png"); background-image: var(--portrait-image); }
.character-aichan { --shirt: #ff6ab1; --hair: #53306d; --portrait-image: url("assets/characters/aichan.png"); background-image: var(--portrait-image); }
.character-rika { --shirt: #67f09a; --hair: #263b2c; --portrait-image: url("assets/characters/rika.png"); background-image: var(--portrait-image); }

.weight-panel {
  display: grid;
  gap: 8px;
}

.weight-readout {
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 6px;
  color: var(--gold);
  text-shadow: 3px 3px 0 var(--outline);
}

.weight-readout span {
  font-size: clamp(2.4rem, 12vw, 4rem);
  line-height: .9;
  font-weight: 900;
}

.weight-readout small {
  padding-bottom: 6px;
  font-weight: 900;
}

.weight-input,
#playerName {
  width: 100%;
  min-width: 0;
  padding: 10px;
  border: 3px solid var(--outline);
  background: #020817;
  color: var(--ink);
  font-weight: 900;
  border-radius: 0;
}

.weight-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.mini-button {
  min-height: 38px;
  padding: 6px 4px;
  font-size: .82rem;
}

.attempt-layout {
  align-content: start;
  padding-top: 8px;
}

.attempt-hud {
  padding: 10px;
  text-align: left;
}

.attempt-hud > div {
  display: grid;
  gap: 2px;
}

.platform {
  position: relative;
  height: min(38vh, 250px);
  min-height: 210px;
  overflow: hidden;
  border: var(--pixel) solid var(--outline);
  background:
    linear-gradient(transparent 0 62%, #563866 62% 100%),
    repeating-linear-gradient(90deg, #162454 0 20px, #1e2e65 20px 40px);
  box-shadow: inset 0 0 0 3px rgba(125,249,255,.28), 0 6px 0 rgba(0,0,0,.65);
}

.arena-lights {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 5%, rgba(125,249,255,.55), transparent 26%),
    radial-gradient(circle at 80% 5%, rgba(255,212,92,.5), transparent 28%);
}

.rack span {
  position: absolute;
  bottom: 48px;
  width: 16px;
  height: 130px;
  background: #c7e6f4;
  border: 3px solid var(--outline);
}

.rack span:first-child { left: 12%; }
.rack span:last-child { right: 12%; }

.barbell {
  position: absolute;
  left: 12%;
  right: 12%;
  top: 50px;
  height: 36px;
  display: flex;
  align-items: center;
  transition: transform .14s ease;
}

.bar {
  flex: 1;
  height: 8px;
  border: 2px solid var(--outline);
  background: #ebf9ff;
}

.plate {
  width: 36px;
  height: 36px;
  border: 4px solid var(--outline);
  background: var(--red);
}

.bench {
  position: absolute;
  left: 24%;
  right: 24%;
  bottom: 58px;
  height: 18px;
  border: 3px solid var(--outline);
  background: var(--gold);
}

.player-avatar {
  position: absolute;
  width: 74px;
  height: 74px;
  left: calc(50% - 37px);
  bottom: 76px;
  background-color: rgba(2, 8, 23, .45);
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center bottom;
}

.meter-panel {
  display: grid;
  gap: 8px;
}

.step-label {
  min-height: 24px;
  color: var(--gold);
  font-weight: 900;
  text-align: center;
}

.timing-meter {
  position: relative;
  height: 38px;
  border: 3px solid var(--outline);
  background: linear-gradient(90deg, #df4054, #ffd45c, #59f29b, #ffd45c, #df4054);
  overflow: hidden;
}

.perfect-zone,
.timing-needle {
  position: absolute;
  top: 0;
  height: 100%;
}

.perfect-zone {
  left: 42%;
  width: 16%;
  background: rgba(255,255,255,.46);
  border-left: 3px solid #fff;
  border-right: 3px solid #fff;
}

.timing-needle {
  width: 6px;
  background: var(--outline);
  box-shadow: 0 0 0 2px var(--ink);
}

.message {
  min-height: 2.5em;
  margin: 0;
  color: var(--gold);
  font-size: .92rem;
  font-weight: 900;
  line-height: 1.25;
  text-align: center;
}

.action-button {
  min-height: 68px;
  background: linear-gradient(180deg, #ffb3b9, var(--red) 55%, #9a2635);
  color: var(--ink);
  text-shadow: 2px 2px 0 var(--outline);
}

.result-layout,
.submit-layout,
.ranking-layout {
  align-content: start;
  padding-top: 8px;
}

.result-layout {
  gap: 8px;
}

.result-list {
  display: grid;
  gap: 8px;
}

.result-row,
.ranking-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 7px;
  border: 3px solid var(--outline);
  background: rgba(4, 12, 29, .82);
}

.result-status-badge {
  width: 64px;
  height: 34px;
  object-fit: contain;
}

.result-row strong,
.ranking-row strong {
  color: var(--gold);
}

.success { color: var(--green); }
.failed { color: var(--red); }

.record-box {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  padding: 8px;
  border: 3px solid var(--outline);
  background: rgba(28, 61, 101, .86);
  font-weight: 900;
}

.record-box strong {
  color: var(--gold);
}

.grade-medal {
  width: 74px;
  height: 74px;
  margin: 8px auto 0;
  background: center / contain no-repeat;
  filter: drop-shadow(0 6px 0 rgba(0,0,0,.55));
}

.grade-c { background-image: url("assets/ui/grade-c.png"); }
.grade-b { background-image: url("assets/ui/grade-b.png"); }
.grade-a { background-image: url("assets/ui/grade-a.png"); }
.grade-s { background-image: url("assets/ui/grade-s.png"); }
.grade-ss { background-image: url("assets/ui/grade-ss.png"); }
.grade-sss { background-image: url("assets/ui/grade-sss.png"); }

.button-stack {
  display: grid;
  gap: 10px;
}

.rank-form {
  display: grid;
  gap: 10px;
}

.rank-in-effect {
  display: grid;
  place-items: center;
  min-height: 44%;
  border: var(--pixel) solid var(--outline);
  background: rgba(255, 212, 92, .94);
  color: #061126;
  text-align: center;
  font-weight: 900;
  box-shadow: 0 0 0 6px rgba(255,255,255,.5), 0 0 38px rgba(255,212,92,.9);
  animation: rankPulse 1.05s steps(4, end) infinite;
  padding: 18px;
}

.rank-in-effect img {
  width: min(86%, 310px);
  object-fit: contain;
  filter: drop-shadow(0 7px 0 rgba(0,0,0,.4));
}

.rank-in-effect p {
  margin: 0;
  font-size: clamp(2.4rem, 13vw, 4.2rem);
  text-shadow: 3px 3px 0 #fff;
}

.rank-in-effect strong {
  font-size: clamp(1.25rem, 6vw, 2rem);
}

@keyframes rankPulse {
  0%, 100% { transform: scale(.96); filter: brightness(1); }
  50% { transform: scale(1.04); filter: brightness(1.35); }
}

.ranking-table {
  display: grid;
  gap: 7px;
  max-height: 58vh;
  overflow: auto;
}

.ranking-head,
.ranking-row {
  grid-template-columns: 1.7em minmax(0, 1fr) 3.1em 4em 2.4em 3em;
  font-size: clamp(.68rem, 2.7vw, .82rem);
}

.ranking-head {
  display: grid;
  gap: 6px;
  padding: 6px;
  color: var(--cyan);
  font-weight: 900;
}

.ranking-row {
  display: grid;
  gap: 6px;
  padding: 7px 6px;
  line-height: 1.18;
}

.ranking-row span {
  overflow-wrap: anywhere;
}

@media (max-width: 360px), (max-height: 700px) {
  .screen {
    padding: 8px;
  }

  .safe-area {
    gap: 8px;
  }

  .pixel-window,
  .pixel-panel,
  .result-card {
    padding: 10px;
  }

  .character-card {
    min-height: 194px;
    grid-template-columns: 98px minmax(0, 1fr);
    gap: 7px;
    padding: 20px 8px 8px;
  }

  .character-carousel {
    grid-template-columns: 34px minmax(0, 1fr) 34px;
    gap: 6px;
  }

  .character-arrow {
    width: 34px;
    min-height: 194px;
    font-size: .95rem;
  }

  .character-portrait {
    width: 98px;
    height: 138px;
  }

  .character-portrait::after {
    top: -28px;
    width: 164%;
    height: calc(100% + 30px);
  }

  .character-flavor {
    font-size: .64rem;
    line-height: 1.28;
  }

  .platform {
    min-height: 178px;
  }

  .ranking-table {
    max-height: 52vh;
  }
}
