:root {
  --ink: #182235;
  --muted: #617089;
  --paper: #edf7fa;
  --panel: rgba(255, 255, 255, 0.94);
  --line: #cbd7e8;
  --blue: #2f6fed;
  --blue-dark: #1d54bb;
  --green: #17875a;
  --red: #c2413c;
  --yellow: #ffd166;
  --pink: #ff7ab6;
  --mint: #57dfc0;
  --space: #151d32;
  --shadow: 0 26px 70px rgba(4, 10, 24, 0.34);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(10, 18, 37, 0.88), rgba(33, 42, 63, 0.74)),
    url("../assets/yuri/extra/backgrounds/space_cockpit_stage.png") center / cover fixed,
    var(--space);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  display: grid;
  min-height: 100vh;
  padding: 24px;
  place-items: center;
}

.game-panel {
  width: min(100%, 900px);
  min-height: 620px;
  padding: 28px;
  background: var(--panel);
  border: 1px solid rgba(217, 222, 231, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.app-header {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 24px;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
}

.app-header > :not(.title-reward-display) {
  position: relative;
  z-index: 1;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 6px;
  font-size: clamp(2.2rem, 6vw, 4.6rem);
  line-height: 1.12;
}

.brand-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.18em;
  padding-bottom: 0.04em;
}

.brand-yuri {
  color: var(--pink);
  font-size: 0.72em;
  font-weight: 950;
  text-shadow: 0 8px 20px rgba(255, 122, 182, 0.25);
}

.brand-main {
  color: var(--ink);
  font-weight: 950;
}

.title-reward-display {
  position: absolute;
  inset: -10px 0 -8px;
  z-index: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 220ms ease;
}

body.screen-start .title-reward-display {
  opacity: 1;
}

body:not(.screen-start) .title-reward-display {
  display: none;
}

.title-reward-item {
  position: absolute;
  left: var(--reward-x);
  top: var(--reward-y);
  width: var(--reward-size);
  height: var(--reward-size);
  object-fit: contain;
  object-position: center;
  opacity: 0.56;
  filter: drop-shadow(0 8px 12px rgba(18, 34, 62, 0.18));
  transform: translate(-50%, -50%) rotate(var(--reward-rotate));
  animation: reward-float 4.2s ease-in-out infinite;
  animation-delay: var(--reward-delay);
}

.title-reward-item.is-grand {
  opacity: 0.78;
  filter:
    drop-shadow(0 0 14px rgba(255, 122, 182, 0.34))
    drop-shadow(0 10px 18px rgba(47, 111, 237, 0.2));
}

h2 {
  margin-bottom: 14px;
  font-size: clamp(1.7rem, 4vw, 2.7rem);
  line-height: 1.08;
}

h3 {
  margin-bottom: 12px;
  font-size: 1rem;
}

.level-badge {
  display: grid;
  min-width: 92px;
  min-height: 84px;
  padding: 12px;
  place-items: center;
  background: linear-gradient(145deg, #1a2844, #3f2c57);
  border-radius: 8px;
  color: #fff;
  text-align: center;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.level-badge span {
  color: #c9d3e2;
  font-size: 0.76rem;
  font-weight: 700;
}

.level-badge strong {
  font-size: 2rem;
  line-height: 1;
}

.bgm-control {
  display: grid;
  gap: 8px;
  width: min(240px, 30vw);
}

.bgm-toggle-button,
.bgm-select,
.bgm-volume-control {
  min-height: 38px;
  border: 1px solid rgba(87, 223, 192, 0.28);
  border-radius: 8px;
  background: rgba(31, 44, 70, 0.92);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 850;
}

.bgm-toggle-button {
  cursor: pointer;
}

.bgm-toggle-button.is-on {
  background: linear-gradient(90deg, var(--pink), var(--blue));
}

.bgm-select {
  padding: 0 8px;
}

.bgm-volume-control {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 42px;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
}

.bgm-volume-control span,
.bgm-volume-control output {
  color: #d9e7f7;
  font-size: 0.72rem;
  font-weight: 900;
}

.bgm-volume-control input {
  width: 100%;
  accent-color: var(--mint);
}

.header-subtitle {
  margin-bottom: 0;
  color: var(--muted);
  font-weight: 800;
}

.station-strip {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  min-height: 148px;
  margin-top: 22px;
  padding: 18px 20px;
  overflow: hidden;
  background:
    linear-gradient(110deg, rgba(17, 24, 44, 0.94), rgba(29, 54, 77, 0.72)),
    url("../assets/yuri/extra/backgrounds/space_cockpit_stage.png") center / cover;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  color: #fff;
}

.station-strip::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.05),
    rgba(255, 255, 255, 0.05) 1px,
    transparent 1px,
    transparent 8px
  );
  pointer-events: none;
}

.station-copy,
.crew-art {
  position: relative;
  z-index: 1;
}

.station-copy span {
  display: block;
  margin-bottom: 8px;
  color: var(--mint);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
}

.station-copy strong {
  display: block;
  max-width: 560px;
  font-size: clamp(1.2rem, 3vw, 1.75rem);
  line-height: 1.35;
}

.crew-art {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  min-width: 230px;
}

.yuri-avatar {
  width: clamp(138px, 20vw, 196px);
  filter: drop-shadow(0 18px 24px rgba(0, 0, 0, 0.34));
  animation: hover-yuri 2.7s ease-in-out infinite;
}

.pet-avatar {
  width: clamp(68px, 10vw, 96px);
  margin-left: -30px;
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.32));
  animation: hover-pet 2.2s ease-in-out infinite;
}

.screen {
  display: none;
  padding-top: 26px;
}

.screen.is-active {
  display: block;
}

.intro-copy {
  max-width: 560px;
  margin-bottom: 32px;
}

.intro-copy p,
#resultSummary {
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.7;
}

.primary-button,
.secondary-button {
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
}

.primary-button {
  background: linear-gradient(90deg, var(--pink), var(--blue));
  color: #fff;
  box-shadow: 0 10px 24px rgba(47, 111, 237, 0.22);
}

.primary-button:hover,
.primary-button:focus-visible {
  background: linear-gradient(90deg, #ee5aa0, var(--blue-dark));
}

.secondary-button {
  background: #22314a;
  color: #fff;
}

.stage-test-button {
  background:
    linear-gradient(90deg, rgba(87, 223, 192, 0.18), rgba(255, 122, 182, 0.18)),
    #243653;
  border: 1px solid rgba(87, 223, 192, 0.28);
}

.stage-progress-button {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  padding-right: 58px;
  text-align: center;
}

.stage-progress-button::before {
  position: absolute;
  inset: 0 auto 0 0;
  z-index: 0;
  width: var(--stage-progress, 0%);
  background: linear-gradient(90deg, rgba(87, 223, 192, 0.42), rgba(255, 122, 182, 0.26));
  content: "";
  transition: width 180ms ease;
}

.stage-progress-button::after {
  position: absolute;
  top: 50%;
  right: 12px;
  z-index: 1;
  color: rgba(255, 255, 255, 0.82);
  content: attr(data-progress-label);
  font-size: 0.72rem;
  font-weight: 900;
  transform: translateY(-50%);
}

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

.save-data-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.save-data-button {
  min-height: 42px;
  background: rgba(34, 49, 74, 0.92);
  border: 1px solid rgba(87, 223, 192, 0.22);
  font-size: 0.9rem;
}

.resume-card,
.growth-panel {
  margin-bottom: 16px;
  padding: 16px;
  background:
    linear-gradient(145deg, rgba(19, 30, 54, 0.9), rgba(36, 47, 74, 0.82)),
    rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(124, 184, 244, 0.24);
  border-radius: 8px;
  color: #f5f9ff;
  box-shadow: inset 0 0 0 1px rgba(87, 223, 192, 0.08);
}

.resume-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.resume-card[hidden] {
  display: none;
}

.resume-card span,
.growth-hero span {
  display: block;
  margin-bottom: 5px;
  color: var(--mint);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0;
}

.resume-card strong,
.growth-hero strong {
  display: block;
  font-size: 1.12rem;
}

.resume-card p,
.growth-hero p,
.next-reward-text {
  margin: 5px 0 0;
  color: #c9d6ea;
  line-height: 1.55;
}

.resume-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.growth-hero {
  display: flex;
  align-items: center;
  gap: 12px;
}

.growth-hero img {
  flex: 0 0 58px;
  width: 58px;
  height: 58px;
  object-fit: contain;
  object-position: center;
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.28));
}

.growth-meter {
  height: 10px;
  margin-top: 14px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
}

.growth-meter span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--pink), var(--mint));
  border-radius: inherit;
  transition: width 180ms ease;
}

.next-reward-text {
  font-weight: 700;
}

.reward-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 8px;
  max-height: min(36vh, 320px);
  overflow: auto;
  padding: 0;
  margin: 12px 0 0;
  list-style: none;
  scrollbar-color: rgba(87, 223, 192, 0.62) rgba(255, 255, 255, 0.08);
  scrollbar-width: thin;
}

.reward-list li {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 7px 9px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: #ecf5ff;
  font-size: 0.82rem;
  font-weight: 800;
}

.reward-list li.is-locked {
  opacity: 0.46;
}

.reward-list li.is-next {
  border-color: rgba(87, 223, 192, 0.48);
  background:
    linear-gradient(135deg, rgba(87, 223, 192, 0.16), rgba(255, 122, 182, 0.1)),
    rgba(255, 255, 255, 0.09);
}

.reward-list li.is-grand {
  border-color: rgba(255, 209, 102, 0.48);
  background:
    linear-gradient(135deg, rgba(255, 209, 102, 0.18), rgba(255, 122, 182, 0.12)),
    rgba(255, 255, 255, 0.08);
}

.reward-list img {
  justify-self: center;
  width: 30px;
  height: 30px;
  object-fit: contain;
  object-position: center;
}

.reward-list span {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.reward-list strong,
.reward-list small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reward-list strong {
  color: #f8fbff;
  font-size: 0.8rem;
}

.reward-list small {
  color: #b6c5da;
  font-size: 0.68rem;
  font-weight: 700;
}

.guide-list {
  display: grid;
  gap: 6px;
  margin-bottom: 22px;
}

.quiz-actions {
  display: flex;
  justify-content: stretch;
  margin-top: 18px;
}

.quiz-actions .secondary-button {
  width: 100%;
}

.stats-grid,
.result-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 22px;
}

.result-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stats-grid div,
.result-grid div {
  min-height: 82px;
  padding: 14px;
  background: #f3f8fb;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stats-grid span,
.result-grid span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.stats-grid strong,
.result-grid strong {
  font-size: 1.45rem;
}

.question-card {
  display: grid;
  min-height: 210px;
  margin-bottom: 22px;
  padding: 28px;
  place-items: center;
  background:
    linear-gradient(135deg, rgba(21, 29, 50, 0.96), rgba(34, 49, 74, 0.88)),
    url("../assets/yuri/extra/effects/20_magic_circle.png") center / 260px no-repeat;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  color: #fff;
  text-align: center;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.operation-label {
  display: none;
  margin-bottom: 12px;
  color: var(--mint);
  font-weight: 800;
}

.question-text {
  margin-bottom: 0;
  font-size: clamp(3.2rem, 12vw, 7rem);
  font-weight: 900;
  line-height: 1;
}

.answer-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-height: 30px;
  margin-bottom: 10px;
}

.answer-form label {
  flex: 0 0 auto;
  color: var(--muted);
  font-weight: 800;
}

.answer-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
}

.answer-display-wrap {
  position: relative;
  min-width: 0;
}

.answer-notation-help {
  margin: 8px 0 0;
  color: #65748c;
  font-size: 0.78rem;
  font-weight: 800;
}

.number-pad {
  display: none;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

body.touch-input .number-pad {
  display: grid;
}

.key-button {
  min-height: 66px;
  padding: 0;
  background: #eef3fb;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  font-size: 1.45rem;
  font-weight: 900;
  -webkit-tap-highlight-color: transparent;
}

.key-button[data-key-type="digit"] {
  background: #eef3fb;
  border-color: #c8d8ec;
  color: #14223a;
}

.key-button[data-key-type="symbol"] {
  background: #e8f6f3;
  border-color: rgba(49, 184, 156, 0.38);
  color: #18344d;
}

.key-button[data-key-type="action"] {
  background: #e9edf7;
  border-color: rgba(92, 113, 156, 0.28);
  color: #1f2f4b;
}

.key-button-zero {
  grid-column: span 1;
}

.key-button-submit {
  grid-column: span 2;
  background: linear-gradient(90deg, var(--blue), #39a6d9);
  color: #fff;
}

.key-button-submit[data-key-type="action"] {
  background: linear-gradient(90deg, var(--pink), var(--blue));
  color: #fff;
}

.key-button:active {
  transform: translateY(1px);
}

.key-button:hover,
.key-button:focus-visible {
  border-color: var(--blue);
  outline: 3px solid rgba(47, 111, 237, 0.14);
}

.answer-row input {
  width: 100%;
  min-height: 54px;
  padding: 0 16px;
  border: 2px solid var(--line);
  border-radius: 8px;
  color: transparent;
  caret-color: transparent;
  overflow: hidden;
  text-overflow: clip;
  white-space: nowrap;
  font-size: var(--answer-font-size, 1.25rem);
  font-weight: 800;
}

.answer-pretty-display {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 0 16px;
  overflow: hidden;
  color: var(--ink);
  font-size: var(--answer-font-size, 1.25rem);
  font-weight: 900;
  line-height: 1;
  pointer-events: none;
  white-space: nowrap;
}

.answer-pretty-display.is-placeholder {
  color: rgba(97, 112, 137, 0.45);
}

.sqrt-expression {
  display: inline-flex;
  align-items: baseline;
  min-width: 0;
}

.sqrt-symbol {
  display: inline-block;
  padding-right: 0.02em;
  line-height: 1;
}

.sqrt-radicand {
  display: inline-block;
  min-width: 0.25em;
  padding: 0.08em 0.03em 0;
  border-top: 0.075em solid currentColor;
  line-height: 0.95;
  transform: translateY(-0.02em);
}

.answer-row input::placeholder {
  color: transparent;
}

.answer-row input[readonly] {
  background: #fff;
  cursor: default;
}

.answer-row input:focus {
  border-color: var(--blue);
  outline: 3px solid rgba(47, 111, 237, 0.18);
}

.feedback {
  margin: 0;
  text-align: right;
  font-weight: 800;
}

.feedback.is-correct {
  color: var(--green);
}

.feedback.is-wrong {
  color: var(--red);
}

.result-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.result-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.result-yuri {
  width: clamp(96px, 18vw, 146px);
  flex: 0 0 auto;
  filter: drop-shadow(0 14px 20px rgba(0, 0, 0, 0.24));
}

.diagnosis-block {
  margin: 22px 0;
}

.skill-list {
  display: grid;
  gap: 10px;
  padding: 0;
  list-style: none;
}

.skill-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  padding: 12px 14px;
  background: #f3f8fb;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.skill-list span {
  color: var(--muted);
  font-weight: 700;
}

@keyframes hover-yuri {
  0%,
  100% {
    transform: translateY(0) rotate(-1deg);
  }
  50% {
    transform: translateY(-8px) rotate(1deg);
  }
}

@keyframes hover-pet {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-5px);
  }
}

@keyframes reward-float {
  0%,
  100% {
    transform: translate(-50%, -50%) rotate(var(--reward-rotate));
  }
  50% {
    transform: translate(-50%, calc(-50% - 5px)) rotate(var(--reward-rotate));
  }
}

@media (min-width: 641px) {
  html,
  body {
    height: 100%;
  }

  .app-shell {
    min-height: 100dvh;
    padding: 18px;
  }

  .game-panel {
    display: flex;
    flex-direction: column;
    width: min(100%, 1500px);
    min-height: calc(100dvh - 36px);
    padding: 18px;
    background:
      linear-gradient(135deg, rgba(244, 248, 255, 0.74), rgba(231, 240, 252, 0.56)),
      rgba(16, 25, 45, 0.2);
    border-color: rgba(255, 255, 255, 0.42);
    overflow: visible;
  }

  .app-header {
    flex: 0 0 auto;
    align-items: center;
    padding-bottom: 12px;
  }

  .eyebrow {
    margin-bottom: 4px;
  }

  h1 {
    font-size: clamp(2rem, 3.6vw, 3.6rem);
    line-height: 1.16;
  }

  .brand-title {
    gap: 0.24em;
  }

  .brand-yuri {
    padding: 0.08em 0.18em 0.1em;
    background: linear-gradient(120deg, rgba(255, 122, 182, 0.22), rgba(87, 223, 192, 0.18));
    border: 1px solid rgba(255, 122, 182, 0.28);
    border-radius: 8px;
    color: #e74791;
    font-size: 0.62em;
  }

  .brand-main {
    background: linear-gradient(90deg, #172238, #315b89 55%, #e85fa4);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    padding-bottom: 0.08em;
  }

  .header-subtitle {
    font-size: 0.95rem;
  }

  h2 {
    margin-bottom: 10px;
    font-size: clamp(1.35rem, 2.6vw, 2rem);
  }

  .level-badge {
    min-height: 62px;
    padding: 10px 12px;
    background: linear-gradient(145deg, rgba(26, 40, 68, 0.96), rgba(63, 44, 87, 0.92));
  }

  .level-badge strong {
    font-size: 1.75rem;
  }

  .bgm-control {
    width: min(190px, 18vw);
  }

  .station-strip {
    flex: 0 0 auto;
    min-height: 108px;
    margin-top: 10px;
    padding: 10px 14px;
  }

  .station-copy span {
    margin-bottom: 5px;
  }

  .station-copy strong {
    font-size: clamp(1rem, 1.9vw, 1.35rem);
  }

  .crew-art {
    min-width: 230px;
  }

  .yuri-avatar {
    width: clamp(122px, 10vw, 152px);
  }

  .pet-avatar {
    width: clamp(64px, 6vw, 82px);
  }

  body.screen-start .app-shell,
  body.screen-result .app-shell {
    padding: 8px;
  }

  body.screen-start .game-panel,
  body.screen-result .game-panel {
    min-height: calc(100dvh - 16px);
    padding: 12px 16px;
  }

  body.screen-start .app-header,
  body.screen-result .app-header {
    gap: 12px;
    padding-bottom: 6px;
  }

  body.screen-start .eyebrow,
  body.screen-start .header-subtitle,
  body.screen-result .eyebrow,
  body.screen-result .header-subtitle {
    display: none;
  }

  body.screen-start h1,
  body.screen-result h1 {
    margin-bottom: 0;
    font-size: clamp(1.35rem, 2.2vw, 2.25rem);
    line-height: 1.04;
  }

  body.screen-start .brand-title,
  body.screen-result .brand-title {
    gap: 0.16em;
  }

  body.screen-start .brand-yuri,
  body.screen-result .brand-yuri {
    padding: 0.04em 0.14em 0.06em;
    font-size: 0.58em;
  }

  body.screen-start .level-badge,
  body.screen-result .level-badge {
    min-width: 66px;
    min-height: 48px;
    padding: 7px 9px;
  }

  body.screen-start .level-badge span,
  body.screen-result .level-badge span {
    font-size: 0.62rem;
  }

  body.screen-start .level-badge strong,
  body.screen-result .level-badge strong {
    font-size: 1.35rem;
  }

  body.screen-start .bgm-control,
  body.screen-result .bgm-control {
    grid-template-columns: minmax(88px, auto) minmax(132px, 1fr) minmax(132px, 1fr);
    align-items: center;
    gap: 6px;
    width: min(520px, 37vw);
  }

  body.screen-start .bgm-toggle-button,
  body.screen-start .bgm-select,
  body.screen-start .bgm-volume-control,
  body.screen-result .bgm-toggle-button,
  body.screen-result .bgm-select,
  body.screen-result .bgm-volume-control {
    min-height: 34px;
    font-size: 0.72rem;
  }

  body.screen-start .bgm-volume-control,
  body.screen-result .bgm-volume-control {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 6px;
    padding: 0 7px;
  }

  body.screen-start .station-strip,
  body.screen-result .station-strip {
    min-height: 76px;
    margin-top: 8px;
    padding: 8px 14px;
  }

  body.screen-start .station-copy span,
  body.screen-result .station-copy span {
    margin-bottom: 2px;
    font-size: 0.68rem;
  }

  body.screen-start .station-copy strong,
  body.screen-result .station-copy strong {
    display: -webkit-box;
    overflow: hidden;
    font-size: clamp(0.92rem, 1.25vw, 1.08rem);
    line-height: 1.3;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  body.screen-start .crew-art,
  body.screen-result .crew-art {
    min-width: 166px;
  }

  body.screen-start .yuri-avatar,
  body.screen-result .yuri-avatar {
    width: clamp(88px, 7.2vw, 116px);
  }

  body.screen-start .pet-avatar,
  body.screen-result .pet-avatar {
    width: clamp(48px, 4.6vw, 62px);
  }

  body.screen-quiz .app-shell {
    padding: 8px;
  }

  body.screen-quiz .game-panel {
    min-height: calc(100dvh - 16px);
    padding: 12px 16px;
  }

  body.screen-quiz .app-header {
    gap: 12px;
    padding-bottom: 6px;
  }

  body.screen-quiz .eyebrow,
  body.screen-quiz .header-subtitle {
    display: none;
  }

  body.screen-quiz h1 {
    margin-bottom: 0;
    font-size: clamp(1.35rem, 2.2vw, 2.25rem);
    line-height: 1.04;
  }

  body.screen-quiz .brand-title {
    gap: 0.16em;
  }

  body.screen-quiz .brand-yuri {
    padding: 0.04em 0.14em 0.06em;
    font-size: 0.58em;
  }

  body.screen-quiz .level-badge {
    min-width: 66px;
    min-height: 48px;
    padding: 7px 9px;
  }

  body.screen-quiz .level-badge span {
    font-size: 0.62rem;
  }

  body.screen-quiz .level-badge strong {
    font-size: 1.35rem;
  }

  body.screen-quiz .bgm-control {
    grid-template-columns: minmax(88px, auto) minmax(132px, 1fr) minmax(132px, 1fr);
    align-items: center;
    gap: 6px;
    width: min(520px, 37vw);
  }

  body.screen-quiz .bgm-toggle-button,
  body.screen-quiz .bgm-select,
  body.screen-quiz .bgm-volume-control {
    min-height: 34px;
    font-size: 0.72rem;
  }

  body.screen-quiz .bgm-volume-control {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 6px;
    padding: 0 7px;
  }

  body.screen-quiz .station-strip {
    min-height: 76px;
    margin-top: 8px;
    padding: 8px 14px;
  }

  body.screen-quiz .station-copy span {
    margin-bottom: 2px;
    font-size: 0.68rem;
  }

  body.screen-quiz .station-copy strong {
    display: -webkit-box;
    overflow: hidden;
    font-size: clamp(0.92rem, 1.25vw, 1.08rem);
    line-height: 1.3;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  body.screen-quiz .crew-art {
    min-width: 166px;
  }

  body.screen-quiz .yuri-avatar {
    width: clamp(88px, 7.2vw, 116px);
  }

  body.screen-quiz .pet-avatar {
    width: clamp(48px, 4.6vw, 62px);
  }

  .screen {
    min-height: 0;
    padding-top: 12px;
  }

  .screen.is-active {
    flex: 1 1 auto;
  }

  .intro-copy {
    max-width: 680px;
    margin-bottom: 16px;
  }

  .intro-copy p,
  #resultSummary {
    font-size: 0.98rem;
    line-height: 1.55;
  }

  #startScreen .button-stack {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #startScreen.screen.is-active {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(340px, 430px);
    grid-template-areas:
      "intro growth"
      "resume growth"
      "buttons growth"
      "data growth";
    gap: 14px 18px;
    align-items: start;
  }

  #startScreen .intro-copy {
    grid-area: intro;
    margin-bottom: 0;
  }

  #startScreen .resume-card {
    grid-area: resume;
    margin-bottom: 0;
  }

  #startScreen .growth-panel {
    grid-area: growth;
    margin-bottom: 0;
  }

  #startScreen .button-stack {
    grid-area: buttons;
  }

  #startScreen .save-data-actions {
    grid-area: data;
    margin-top: 0;
  }

  #startScreen .reward-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: min(36vh, 360px);
    overflow: auto;
    padding-right: 0;
  }

  #quizScreen.screen.is-active {
    display: grid;
    grid-template-columns: minmax(172px, 220px) minmax(440px, 1fr) minmax(310px, 390px);
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas:
      "stats question form"
      "actions question form";
    gap: 14px;
    min-height: 0;
  }

  #quizScreen .stats-grid {
    grid-area: stats;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-bottom: 0;
    min-height: 0;
  }

  #quizScreen .stats-grid div {
    display: grid;
    align-content: center;
    min-height: 0;
    padding: 12px 14px;
    background: rgba(15, 26, 48, 0.76);
    border-color: rgba(124, 184, 244, 0.24);
    color: #f5f9ff;
    box-shadow: inset 0 0 0 1px rgba(87, 223, 192, 0.08);
  }

  #quizScreen .stats-grid span {
    margin-bottom: 3px;
    color: #95f1df;
    font-size: 0.74rem;
  }

  #quizScreen .stats-grid strong {
    font-size: clamp(1.2rem, 1.8vw, 1.7rem);
  }

  #quizScreen .question-card {
    grid-area: question;
    align-content: center;
    justify-items: center;
    height: 100%;
    min-height: 0;
    margin-bottom: 0;
    padding: 24px;
    background:
      linear-gradient(135deg, rgba(16, 25, 45, 0.97), rgba(38, 53, 80, 0.9)),
      url("../assets/yuri/extra/effects/20_magic_circle.png") center / min(48%, 320px) no-repeat;
  }

  #quizScreen .operation-label {
    display: none;
  }

  #quizScreen .question-text {
    font-size: clamp(5rem, 8.2vw, 8.8rem);
    text-shadow: 0 18px 36px rgba(0, 0, 0, 0.28);
  }

  #quizScreen .answer-form {
    grid-area: form;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 0;
    padding: 18px;
    background:
      linear-gradient(180deg, rgba(24, 34, 53, 0.98), rgba(35, 49, 74, 0.96)),
      url("../assets/yuri/extra/effects/17_twinkle_cluster.png") right 18px top 18px / 120px no-repeat;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 8px;
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(87, 223, 192, 0.08);
  }

  #quizScreen .answer-label-row {
    display: block;
    min-height: 0;
    margin-bottom: 14px;
  }

  #quizScreen .answer-form label {
    color: var(--mint);
    font-size: 0.82rem;
    letter-spacing: 0;
  }

  #quizScreen .feedback {
    min-height: 52px;
    margin-top: 10px;
    color: #dce7f7;
    text-align: left;
    line-height: 1.55;
  }

  #quizScreen .feedback.is-correct {
    color: #75f0c8;
  }

  #quizScreen .feedback.is-wrong {
    color: #ff9aa7;
  }

  #quizScreen .answer-row {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  #quizScreen .answer-row input {
    min-height: clamp(118px, 20vh, 190px);
    padding: 0 18px;
    background:
      linear-gradient(180deg, rgba(12, 20, 38, 0.92), rgba(22, 34, 56, 0.88)),
      rgba(255, 255, 255, 0.04);
    border: 3px solid rgba(87, 223, 192, 0.9);
    color: #fff8ff;
    font-size: var(--answer-font-size, clamp(3.3rem, 7vw, 6rem));
    font-weight: 950;
    line-height: 1;
    text-align: center;
    box-shadow:
      0 0 0 5px rgba(87, 223, 192, 0.12),
      0 18px 36px rgba(0, 0, 0, 0.22);
  }

  #quizScreen .answer-pretty-display {
    padding: 0 18px;
    color: #fff8ff;
    font-size: var(--answer-font-size, clamp(3.3rem, 7vw, 6rem));
    font-weight: 950;
  }

  #quizScreen .answer-pretty-display.is-placeholder {
    color: rgba(255, 248, 255, 0.2);
  }

  #quizScreen .answer-row input::placeholder {
    color: transparent;
  }

  #quizScreen .quiz-actions {
    grid-area: actions;
    margin-top: 0;
  }

  #quizScreen .quiz-actions .secondary-button {
    min-height: 54px;
  }

  .primary-button,
  .secondary-button {
    min-height: 44px;
  }

  .result-hero {
    margin-bottom: 12px;
  }

  #guideScreen.screen.is-active,
  #resultScreen.screen.is-active {
    overflow: auto;
    padding-right: 6px;
  }

  .guide-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .diagnosis-block {
    margin: 14px 0;
  }
}

@media (max-width: 640px) {
  html,
  body {
    min-height: 100dvh;
  }

  body {
    background-attachment: scroll;
  }

  .app-shell {
    width: 100%;
    max-width: 100vw;
    grid-template-columns: minmax(0, 1fr);
    min-height: 100dvh;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    place-items: stretch;
  }

  .game-panel {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    min-height: calc(100dvh - 16px);
    padding: 14px;
    background:
      linear-gradient(135deg, rgba(244, 248, 255, 0.82), rgba(231, 240, 252, 0.7)),
      rgba(16, 25, 45, 0.2);
    overflow-x: hidden;
  }

  .app-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    padding-bottom: 10px;
  }

  .title-reward-display {
    inset: -6px 0 -4px;
  }

  .title-reward-item {
    width: calc(var(--reward-size) * 0.72);
    height: calc(var(--reward-size) * 0.72);
    opacity: 0.42;
  }

  .app-header > div:first-child {
    min-width: 0;
  }

  .eyebrow {
    margin-bottom: 2px;
    font-size: 0.68rem;
  }

  h1 {
    font-size: clamp(1.8rem, 9vw, 2.7rem);
  }

  .brand-title {
    flex-wrap: wrap;
    gap: 0.16em;
  }

  .brand-yuri {
    padding: 0.04em 0.12em 0.06em;
    background: linear-gradient(120deg, rgba(255, 122, 182, 0.22), rgba(87, 223, 192, 0.18));
    border: 1px solid rgba(255, 122, 182, 0.28);
    border-radius: 8px;
    font-size: 0.66em;
  }

  .brand-main {
    overflow-wrap: anywhere;
  }

  .header-subtitle {
    font-size: 0.82rem;
  }

  .level-badge {
    display: none;
    width: auto;
    min-width: 58px;
    min-height: 52px;
    padding: 7px 9px;
    justify-self: end;
  }

  .level-badge span {
    font-size: 0.64rem;
  }

  .level-badge strong {
    font-size: 1.45rem;
  }

  .bgm-control {
    grid-template-columns: auto minmax(0, 1fr);
    width: 100%;
  }

  .bgm-toggle-button,
  .bgm-select,
  .bgm-volume-control {
    min-height: 36px;
    font-size: 0.78rem;
  }

  .bgm-volume-control {
    grid-column: 1 / -1;
  }

  .resume-card {
    align-items: stretch;
    flex-direction: column;
  }

  .resume-actions {
    flex-direction: column;
  }

  .station-strip {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    min-height: 86px;
    margin-top: 10px;
    padding: 10px 12px;
  }

  .station-copy span {
    margin-bottom: 4px;
    font-size: 0.68rem;
  }

  .station-copy strong {
    max-width: none;
    font-size: 0.95rem;
    line-height: 1.35;
  }

  .crew-art {
    justify-content: flex-end;
    min-width: 90px;
  }

  .yuri-avatar {
    width: 82px;
  }

  .pet-avatar {
    width: 42px;
    margin-left: -14px;
  }

  .screen {
    padding-top: 14px;
  }

  .intro-copy p {
    font-size: 0.92rem;
    line-height: 1.55;
  }

  .growth-panel {
    padding: 14px;
    overflow: hidden;
  }

  .reward-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: 230px;
  }

  .reward-list li {
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 6px;
    padding: 6px;
    font-size: 0.74rem;
  }

  .reward-list img {
    width: 24px;
    height: 24px;
  }

  .stats-grid,
  .result-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .answer-row {
    grid-template-columns: 1fr;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .result-hero {
    align-items: flex-start;
  }

  .result-yuri {
    width: 92px;
  }

  body.screen-quiz .app-shell {
    padding: 0;
  }

  body.screen-quiz .game-panel {
    min-height: 100vh;
    min-height: 100dvh;
    padding: 8px;
    border-width: 0;
    border-radius: 0;
  }

  body.screen-quiz .app-header {
    grid-template-columns: minmax(0, 1fr) auto minmax(88px, 24vw);
    padding-bottom: 6px;
    border-bottom-color: rgba(203, 215, 232, 0.5);
  }

  body.screen-quiz .eyebrow,
  body.screen-quiz .header-subtitle {
    display: none;
  }

  body.screen-quiz h1 {
    margin-bottom: 0;
    font-size: clamp(1.15rem, 5.5vw, 1.55rem);
    line-height: 1.05;
  }

  body.screen-quiz .brand-yuri {
    font-size: 0.72em;
  }

  body.screen-quiz .level-badge {
    display: grid;
    min-width: 50px;
    min-height: 40px;
    padding: 5px 7px;
  }

  body.screen-quiz .level-badge span {
    font-size: 0.58rem;
  }

  body.screen-quiz .level-badge strong {
    font-size: 1.16rem;
  }

  body.screen-quiz .bgm-control {
    display: grid;
    width: 100%;
    gap: 0;
  }

  body.screen-quiz .bgm-toggle-button,
  body.screen-quiz .bgm-select {
    display: none;
  }

  body.screen-quiz .bgm-volume-control {
    grid-template-columns: minmax(0, 1fr);
    min-height: 40px;
    padding: 0 6px;
  }

  body.screen-quiz .bgm-volume-control span,
  body.screen-quiz .bgm-volume-control output {
    display: none;
  }

  body.screen-quiz .station-strip {
    min-height: 58px;
    margin-top: 6px;
    padding: 7px 9px;
  }

  body.screen-quiz .station-copy span {
    display: none;
  }

  body.screen-quiz .station-copy strong {
    display: -webkit-box;
    overflow: hidden;
    font-size: 0.78rem;
    line-height: 1.35;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  body.screen-quiz .crew-art {
    min-width: 54px;
  }

  body.screen-quiz .yuri-avatar {
    width: 54px;
  }

  body.screen-quiz .pet-avatar {
    display: none;
  }

  body.screen-quiz #quizScreen.screen.is-active {
    display: grid;
    grid-template-rows: auto minmax(118px, 1fr) auto auto;
    gap: 7px;
    width: 100%;
    max-width: 100%;
    min-height: 0;
    padding-top: 7px;
  }

  body.screen-quiz #quizScreen > *,
  body.screen-quiz #quizScreen .stats-grid div,
  body.screen-quiz #quizScreen .key-button {
    min-width: 0;
    max-width: 100%;
  }

  body.screen-quiz #quizScreen > * {
    width: calc(100vw - 16px);
  }

  body.screen-quiz #quizScreen .stats-grid {
    display: flex;
    gap: 5px;
    width: 100%;
    margin-bottom: 0;
  }

  body.screen-quiz #quizScreen .stats-grid div {
    flex: 1 1 0;
    min-height: 45px;
    padding: 6px 4px;
    text-align: center;
  }

  body.screen-quiz #quizScreen .stats-grid span {
    margin-bottom: 2px;
    font-size: 0.63rem;
  }

  body.screen-quiz #quizScreen .stats-grid strong {
    font-size: clamp(0.98rem, 4.8vw, 1.22rem);
  }

  body.screen-quiz #quizScreen .question-card {
    min-height: clamp(124px, 27dvh, 210px);
    margin-bottom: 0;
    padding: 12px 8px;
    background-size: min(60%, 175px);
  }

  body.screen-quiz #quizScreen .question-text {
    overflow-wrap: anywhere;
    font-size: clamp(3.1rem, 18vw, 5.4rem);
    line-height: 0.95;
  }

  body.screen-quiz #quizScreen .answer-form {
    display: grid;
    gap: 7px;
  }

  body.screen-quiz #quizScreen .answer-label-row {
    align-items: center;
    min-height: 0;
    margin-bottom: 0;
  }

  body.screen-quiz #quizScreen .answer-form label {
    font-size: 0.78rem;
  }

  body.screen-quiz #quizScreen .feedback {
    max-width: 70%;
    font-size: 0.76rem;
    line-height: 1.25;
  }

  body.screen-quiz #quizScreen .answer-row {
    grid-template-columns: 1fr 88px;
    gap: 7px;
  }

  body.touch-input.screen-quiz #quizScreen .answer-row {
    grid-template-columns: 1fr;
  }

  body.touch-input.screen-quiz #quizScreen .answer-row .primary-button {
    display: none;
  }

  body.screen-quiz #quizScreen .answer-row input {
    min-height: 58px;
    padding: 0 12px;
    border: 3px solid rgba(87, 223, 192, 0.9);
    color: var(--ink);
    font-size: var(--answer-font-size, clamp(2rem, 13vw, 3.3rem));
    font-weight: 950;
    line-height: 1;
    text-align: center;
  }

  body.screen-quiz #quizScreen .answer-pretty-display {
    padding: 0 12px;
    color: var(--ink);
    font-size: var(--answer-font-size, clamp(2rem, 13vw, 3.3rem));
    font-weight: 950;
  }

  body.screen-quiz #quizScreen .answer-pretty-display.is-placeholder {
    color: rgba(97, 112, 137, 0.45);
  }

  body.screen-quiz #quizScreen .answer-notation-help {
    margin-top: -2px;
    font-size: 0.66rem;
    line-height: 1.2;
    text-align: center;
  }

  body.screen-quiz #quizScreen .number-pad {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
    width: 100%;
    margin-top: 0;
  }

  body.screen-quiz #quizScreen .key-button {
    min-height: clamp(34px, 6.8dvh, 46px);
    border-radius: 7px;
    font-size: clamp(1rem, 5.2vw, 1.2rem);
  }

  body.screen-quiz #quizScreen .key-button[data-key="7"] {
    order: 1;
  }

  body.screen-quiz #quizScreen .key-button[data-key="8"] {
    order: 2;
  }

  body.screen-quiz #quizScreen .key-button[data-key="9"] {
    order: 3;
  }

  body.screen-quiz #quizScreen .key-button[data-key="4"] {
    order: 5;
  }

  body.screen-quiz #quizScreen .key-button[data-key="5"] {
    order: 6;
  }

  body.screen-quiz #quizScreen .key-button[data-key="6"] {
    order: 7;
  }

  body.screen-quiz #quizScreen .key-button[data-key="1"] {
    order: 9;
  }

  body.screen-quiz #quizScreen .key-button[data-key="2"] {
    order: 10;
  }

  body.screen-quiz #quizScreen .key-button[data-key="3"] {
    order: 11;
  }

  body.screen-quiz #quizScreen .key-button[data-key="."] {
    order: 13;
  }

  body.screen-quiz #quizScreen .key-button[data-key="0"] {
    order: 14;
  }

  body.screen-quiz #quizScreen .key-button[data-key="/"] {
    order: 4;
  }

  body.screen-quiz #quizScreen .key-button-plus {
    order: 8;
  }

  body.screen-quiz #quizScreen .key-button-minus {
    order: 12;
  }

  body.screen-quiz #quizScreen #clearAnswerButton {
    order: 15;
  }

  body.screen-quiz #quizScreen #backspaceButton {
    order: 16;
  }

  body.screen-quiz #quizScreen .key-button-pi {
    order: 17;
  }

  body.screen-quiz #quizScreen .key-button-e {
    order: 18;
  }

  body.screen-quiz #quizScreen .key-button-x {
    order: 19;
  }

  body.screen-quiz #quizScreen .key-button-y {
    order: 20;
  }

  body.screen-quiz #quizScreen .key-button-root {
    order: 21;
  }

  body.screen-quiz #quizScreen .key-button-root-close {
    order: 22;
  }

  body.screen-quiz #quizScreen .key-button-submit {
    grid-column: span 2;
    order: 23;
  }

  body.screen-quiz #quizScreen .quiz-actions {
    margin-top: 0;
  }

  body.screen-quiz #quizScreen .quiz-actions .secondary-button {
    min-height: 38px;
    padding: 8px 12px;
    font-size: 0.86rem;
  }
}

@media (max-width: 640px) and (max-height: 700px) {
  body.screen-quiz .station-strip {
    display: none;
  }

  body.screen-quiz #quizScreen.screen.is-active {
    gap: 6px;
    padding-top: 6px;
  }

  body.screen-quiz #quizScreen .question-card {
    min-height: 112px;
  }

  body.screen-quiz #quizScreen .key-button {
    min-height: clamp(38px, 8dvh, 48px);
  }
}
