/* ═══════════════════════════════════════════
   フロガクDAYS — Frogaku Days
   Japanese school dating sim · Visual novel UI
   ═══════════════════════════════════════════ */

:root {
  --bg-deep: #1a1028;
  --bg-panel: rgba(18, 12, 32, 0.88);
  --bg-panel-solid: #1e1435;
  --pink: #ff6b9d;
  --pink-soft: #ffb3c9;
  --pink-glow: rgba(255, 107, 157, 0.45);
  --lavender: #c4a1ff;
  --lavender-soft: #e8d9ff;
  --gold: #ffd56b;
  --cream: #fff8f0;
  --text: #fff8f5;
  --text-muted: rgba(255, 248, 245, 0.65);
  --speaker-kero: #7ecf8a;
  --speaker-chad: #7eb8ff;
  --speaker-feller: #e8b86d;
  --speaker-monkiti: #9b8cff;
  --speaker-level6: #ffb07a;
  --speaker-narrator: #e8d9ff;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --font-jp: "M PLUS Rounded 1c", "Hiragino Sans", "Hiragino Kaku Gothic ProN", sans-serif;
  --font-en: "Nunito", "M PLUS Rounded 1c", sans-serif;
  --text-speed: 28ms;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --app-height: 100dvh;
  --dialogue-h: clamp(7.5rem, 22vh, 11rem);
  --hud-h: 3.25rem;
  --touch-min: 44px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
  height: -webkit-fill-available;
}

html, body {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg-deep);
  color: var(--text);
  font-family: var(--font-jp);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body {
  /* Prefer dynamic viewport on mobile browsers (address bar show/hide) */
  min-height: 100%;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  height: var(--app-height, 100dvh);
  position: fixed;
  inset: 0;
}

body.lang-en {
  font-family: var(--font-en);
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 1200px;
  margin: 0 auto;
  overflow: hidden;
  background: #0d0818;
}

/* Tap targets & form controls stay finger-friendly */
button,
.menu-btn,
.choice-btn,
.mg-btn,
.mg-monkey,
.icon-btn,
.lang-toggle,
.hearts-btn {
  min-height: var(--touch-min);
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

select,
input[type="range"],
input[type="checkbox"] {
  min-height: var(--touch-min);
  font-size: 16px; /* prevents iOS focus zoom */
}

/* ── Screens ── */
.screen {
  position: absolute;
  inset: 0;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.45s ease, visibility 0.45s;
  pointer-events: none;
}

.screen.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* ── Title Screen ── */
.title-bg {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(26, 16, 40, 0.35) 0%, rgba(26, 16, 40, 0.75) 70%, rgba(26, 16, 40, 0.95) 100%),
    url("../assets/backgrounds/school_gate.jpg") center / cover no-repeat;
  transform: scale(1.05);
  animation: titleKenBurns 24s ease-in-out infinite alternate;
}

@keyframes titleKenBurns {
  from { transform: scale(1.05) translateY(0); }
  to { transform: scale(1.12) translateY(-2%); }
}

.sakura-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 1;
}

.sakura-petal {
  position: absolute;
  width: 12px;
  height: 10px;
  background: radial-gradient(ellipse at 30% 30%, #ffd0e0, #ff8fb3);
  border-radius: 100% 0 100% 0;
  opacity: 0.85;
  animation: fall linear infinite;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.15));
}

@keyframes fall {
  0% { transform: translateY(-10vh) rotate(0deg) translateX(0); opacity: 0; }
  10% { opacity: 0.9; }
  100% { transform: translateY(110vh) rotate(360deg) translateX(40px); opacity: 0.2; }
}

.title-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 0;
  padding: max(1rem, var(--safe-top)) 1.25rem max(5.5rem, calc(4.5rem + var(--safe-bottom)));
  text-align: center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.title-subtitle {
  font-size: clamp(0.85rem, 2.5vw, 1.05rem);
  color: var(--pink-soft);
  letter-spacing: 0.15em;
  margin-bottom: 0.75rem;
  font-weight: 500;
  text-shadow: 0 2px 12px rgba(0,0,0,0.5);
}

.title-logo {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-bottom: 0.85rem;
}

.logo-jp {
  font-size: clamp(2.4rem, 9vw, 4rem);
  font-weight: 800;
  background: linear-gradient(135deg, #fff 0%, var(--pink-soft) 45%, var(--lavender) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 20px var(--pink-glow));
  letter-spacing: 0.04em;
  line-height: 1.15;
}

.logo-en {
  font-family: var(--font-en);
  font-size: clamp(0.95rem, 3vw, 1.25rem);
  font-weight: 700;
  color: var(--lavender-soft);
  letter-spacing: 0.35em;
  text-transform: uppercase;
  opacity: 0.9;
}

.title-tagline {
  font-size: clamp(0.85rem, 2.4vw, 1.05rem);
  color: var(--text-muted);
  margin-bottom: 1.1rem;
  max-width: 32rem;
  line-height: 1.6;
  text-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.title-cast {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0.45rem;
  margin-bottom: 1.6rem;
  flex-wrap: wrap;
}

.cast-icon {
  width: 52px;
  height: 52px;
  object-fit: contain;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  border: 2px solid rgba(255,182,210,0.35);
  padding: 4px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
  transition: transform 0.2s;
}

.cast-icon:hover {
  transform: translateY(-4px) scale(1.08);
}

.cast-icon:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

.cast-icon.pixel {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.title-cast-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 0.15rem 0 1.15rem;
  letter-spacing: 0.02em;
  text-align: center;
  min-height: 1.1em;
  opacity: 0.9;
}

/* Never flash a missing i18n key on title */
.title-cast-hint:empty {
  display: none;
}

.title-menu {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  width: min(280px, 85vw);
}

.menu-btn {
  appearance: none;
  border: 2px solid rgba(255, 255, 255, 0.18);
  background: rgba(30, 20, 50, 0.72);
  color: var(--text);
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  padding: 0.85rem 1.25rem;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s, border-color 0.2s, box-shadow 0.2s;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  letter-spacing: 0.06em;
}

.menu-btn:hover:not(:disabled),
.menu-btn:focus-visible:not(:disabled) {
  transform: translateY(-2px) scale(1.02);
  border-color: var(--pink-soft);
  background: rgba(50, 28, 60, 0.85);
  box-shadow: 0 8px 24px var(--pink-glow);
  outline: none;
}

.menu-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.menu-btn.primary {
  background: linear-gradient(135deg, #ff6b9d 0%, #c44dff 100%);
  border-color: transparent;
  box-shadow: 0 6px 24px var(--pink-glow);
}

.menu-btn.primary:hover:not(:disabled) {
  box-shadow: 0 10px 32px rgba(255, 107, 157, 0.55);
}

.menu-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.title-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem max(0.85rem, var(--safe-bottom));
  background: linear-gradient(transparent, rgba(10, 6, 18, 0.75) 40%);
  pointer-events: none;
}

.title-footer > * {
  pointer-events: auto;
}

.lang-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: var(--text);
  font-family: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.lang-toggle:hover {
  background: rgba(255,255,255,0.18);
  border-color: var(--pink-soft);
}

.version {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-en);
}

/* ── Game Screen ── */
.scene-bg {
  position: absolute;
  inset: 0;
  background: center / cover no-repeat;
  transition: opacity 0.5s ease, transform 0.8s ease;
  transform: scale(1.02);
}

.scene-bg.fade {
  opacity: 0;
}

.scene-overlay {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(10, 6, 18, 0.25) 0%, transparent 30%, transparent 55%, rgba(10, 6, 18, 0.55) 100%);
  pointer-events: none;
}

/* ── Scene mood FX (christmas, kraftskiva, etc.) ── */
.scene-mood {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  opacity: 0;
  transition: opacity 0.45s ease;
}

.scene-mood.active {
  opacity: 1;
}

.scene-mood::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.45s ease;
}

.scene-mood.active::before {
  opacity: 1;
}

.scene-mood.mood-xmas::before {
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(255, 220, 160, 0.35), transparent 55%),
    radial-gradient(ellipse 60% 40% at 80% 20%, rgba(255, 80, 80, 0.12), transparent 50%),
    linear-gradient(180deg, rgba(20, 40, 70, 0.2), transparent 40%, rgba(10, 20, 40, 0.35));
  box-shadow: inset 0 0 80px rgba(255, 200, 120, 0.15);
}

.scene-mood.mood-kraft::before {
  background:
    repeating-linear-gradient(
      -12deg,
      transparent,
      transparent 18px,
      rgba(255, 40, 40, 0.04) 18px,
      rgba(255, 40, 40, 0.04) 36px
    ),
    radial-gradient(ellipse 70% 50% at 50% 40%, rgba(255, 60, 40, 0.22), transparent 65%),
    linear-gradient(180deg, rgba(80, 10, 10, 0.25), transparent 45%);
  animation: kraftPulse 1.4s ease-in-out infinite;
}

@keyframes kraftPulse {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 1; filter: brightness(1.08); }
}

.scene-mood.mood-sweets::before {
  background:
    radial-gradient(ellipse 70% 55% at 50% 70%, rgba(255, 140, 180, 0.28), transparent 60%),
    radial-gradient(circle at 20% 30%, rgba(255, 210, 230, 0.2), transparent 40%);
}

.scene-mood.mood-envelope::before {
  background:
    radial-gradient(ellipse 60% 50% at 50% 40%, rgba(90, 60, 160, 0.3), transparent 65%),
    linear-gradient(180deg, rgba(20, 10, 40, 0.35), transparent 50%);
}

.scene-mood.mood-sumo::before {
  background:
    radial-gradient(ellipse 55% 35% at 50% 75%, rgba(255, 160, 60, 0.28), transparent 60%),
    linear-gradient(180deg, transparent 40%, rgba(60, 30, 10, 0.25));
}

.scene-mood.mood-trueend::before {
  background:
    radial-gradient(ellipse 80% 60% at 50% 40%, rgba(255, 180, 210, 0.35), transparent 65%),
    radial-gradient(circle at 30% 20%, rgba(255, 220, 140, 0.2), transparent 40%);
}

.scene-mood.mood-chaos::before {
  background:
    radial-gradient(circle at 20% 30%, rgba(255, 100, 160, 0.2), transparent 40%),
    radial-gradient(circle at 80% 40%, rgba(120, 180, 255, 0.18), transparent 40%),
    radial-gradient(circle at 50% 70%, rgba(255, 210, 80, 0.18), transparent 45%);
  animation: chaosHue 3s linear infinite;
}

@keyframes chaosHue {
  0% { filter: hue-rotate(0deg); }
  100% { filter: hue-rotate(360deg); }
}

.mood-particles {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.mood-flake {
  position: absolute;
  top: -8%;
  color: rgba(255, 255, 255, 0.85);
  animation: moodFall linear infinite;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  will-change: transform;
}

.mood-xmas .mood-flake { color: rgba(220, 240, 255, 0.9); }
.mood-kraft .mood-flake { color: rgba(255, 90, 70, 0.9); top: 10%; animation-name: moodDrift; }
.mood-sweets .mood-flake { color: rgba(255, 150, 190, 0.9); }
.mood-envelope .mood-flake { color: rgba(200, 170, 255, 0.85); }
.mood-sumo .mood-flake { color: rgba(255, 190, 100, 0.85); top: 30%; animation-name: moodDrift; }
.mood-trueend .mood-flake { color: rgba(255, 200, 220, 0.9); }
.mood-chaos .mood-flake { color: rgba(255, 230, 150, 0.9); }

@keyframes moodFall {
  0% { transform: translateY(0) rotate(0deg); }
  100% { transform: translateY(110vh) rotate(360deg); }
}

@keyframes moodDrift {
  0%, 100% { transform: translate(0, 0) scale(1); opacity: 0.3; }
  50% { transform: translate(12px, -18px) scale(1.15); opacity: 0.85; }
}

.mood-banner {
  position: absolute;
  top: max(3.6rem, calc(var(--safe-top) + 3.1rem));
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  max-width: min(92vw, 28rem);
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  animation: bannerPop 0.45s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.mood-kraft .mood-banner {
  background: rgba(120, 15, 15, 0.88);
  border: 1px solid rgba(255, 100, 80, 0.65);
  color: #ffe0d8;
  box-shadow: 0 6px 20px rgba(180, 20, 20, 0.4);
  animation: bannerPop 0.45s cubic-bezier(0.34, 1.4, 0.64, 1), kraftBannerBlink 1.2s ease-in-out infinite;
}

.mood-xmas .mood-banner {
  background: rgba(30, 50, 80, 0.88);
  border: 1px solid rgba(255, 210, 140, 0.55);
  color: #ffe8c8;
  box-shadow: 0 6px 20px rgba(40, 60, 100, 0.4);
}

@keyframes bannerPop {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px) scale(0.92); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

@keyframes kraftBannerBlink {
  0%, 100% { box-shadow: 0 6px 20px rgba(180, 20, 20, 0.4); }
  50% { box-shadow: 0 6px 28px rgba(255, 60, 40, 0.65); }
}

.game-hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50; /* above tap layer / dialogue so lang & menu always clickable */
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: max(0.55rem, var(--safe-top)) max(0.65rem, var(--safe-right)) 0.4rem max(0.65rem, var(--safe-left));
  gap: 0.45rem;
  pointer-events: none;
}

.game-hud .hud-left,
.game-hud .hud-right,
.game-hud button {
  pointer-events: auto;
  position: relative;
  z-index: 51;
}

.icon-btn.lang-chip {
  font-size: 0.72rem;
  font-weight: 800;
  font-family: var(--font-en);
  letter-spacing: 0.04em;
  min-width: 40px;
}

.hud-left, .hud-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  min-width: 0;
  max-width: 52%;
}

.hud-right {
  justify-content: flex-end;
}

.day-badge {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  background: rgba(18, 12, 32, 0.72);
  border: 1px solid rgba(255,255,255,0.12);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  backdrop-filter: blur(8px);
  font-weight: 700;
}

.day-label {
  font-size: 0.7rem;
  color: var(--pink-soft);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.day-num {
  font-size: 1.1rem;
  color: var(--gold);
  font-family: var(--font-en);
}

.location-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: rgba(18, 12, 32, 0.55);
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  backdrop-filter: blur(6px);
  max-width: 40vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.comedy-badge {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  background: rgba(18, 12, 32, 0.72);
  border: 1px solid rgba(255, 213, 107, 0.35);
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  backdrop-filter: blur(8px);
  font-weight: 700;
  font-size: 0.85rem;
  font-family: var(--font-en);
  color: var(--gold);
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
}

.comedy-badge:hover {
  border-color: var(--gold);
  transform: scale(1.04);
}

.hearts-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(18, 12, 32, 0.72);
  border: 1px solid rgba(255, 107, 157, 0.35);
  color: var(--text);
  font-family: inherit;
  font-weight: 700;
  font-size: 0.8rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: transform 0.15s, border-color 0.2s;
}

.hearts-btn:hover {
  transform: scale(1.05);
  border-color: var(--pink);
}

.heart-icon {
  color: var(--pink);
  font-size: 0.95rem;
  animation: heartPulse 1.6s ease-in-out infinite;
}

@keyframes heartPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.hearts-preview {
  font-family: var(--font-en);
  color: var(--pink-soft);
  min-width: 3em;
}

.fx-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 40;
}

.icon-btn.active-toggle {
  border-color: var(--pink);
  background: rgba(255, 107, 157, 0.25);
  box-shadow: 0 0 12px var(--pink-glow);
}

/* Backlog */
.log-card {
  width: min(480px, 100%);
  max-height: min(85dvh, 640px);
  display: flex;
  flex-direction: column;
}

.log-list {
  flex: 1;
  min-height: 200px;
  max-height: min(55dvh, 420px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0.35rem 0 0.85rem;
  padding: 0.35rem 0.25rem;
  text-align: left;
}

.log-empty {
  color: var(--text-muted);
  text-align: center;
  padding: 2rem 1rem;
}

.log-entry {
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.log-speaker {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--pink-soft);
  margin-bottom: 0.2rem;
}

.log-text {
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--cream);
  white-space: pre-wrap;
}

/* Achievements */
.achievements-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin: 0.5rem 0 1rem;
  max-height: min(50dvh, 400px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.achieve-row {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  padding: 0.7rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(0,0,0,0.25);
  text-align: left;
}

.achieve-row.unlocked {
  border-color: rgba(255, 213, 107, 0.4);
  background: rgba(50, 30, 20, 0.45);
}

.achieve-row.locked {
  opacity: 0.55;
  filter: grayscale(0.6);
}

.achieve-row-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.achieve-row-title {
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--gold);
  margin-bottom: 0.15rem;
}

.achieve-row.locked .achieve-row-title {
  color: var(--text-muted);
}

.achieve-row-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.achieve-toast {
  position: absolute;
  top: calc(var(--hud-h) + max(0.75rem, var(--safe-top)) + 0.5rem);
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  z-index: 210;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  background: rgba(24, 14, 40, 0.96);
  border: 2px solid var(--gold);
  border-radius: 14px;
  padding: 0.7rem 1rem;
  box-shadow: 0 10px 28px rgba(255, 213, 107, 0.25);
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  max-width: calc(100% - 1.5rem);
}

.achieve-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.achieve-icon {
  font-size: 1.6rem;
}

.achieve-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.06em;
}

.achieve-name {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text);
}

.ending-actions {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  width: min(280px, 100%);
  margin: 0 auto;
}

.ending-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
  margin: 0.35rem 0 0.75rem;
}

.ending-chip {
  display: inline-block;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 213, 107, 0.35);
  color: var(--gold);
}

.ending-chip.rank {
  border-color: rgba(255, 107, 157, 0.4);
  color: var(--pink-soft);
}

.ending-epi {
  font-size: 0.92rem !important;
  max-width: 26rem;
  margin: 0 auto 1.1rem !important;
  line-height: 1.55 !important;
  color: var(--cream) !important;
}

.comedy-rank-line {
  text-align: center;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--gold);
  margin-top: 0.35rem;
  padding: 0.45rem;
  border-radius: 10px;
  background: rgba(255, 213, 107, 0.08);
}

/* Floating comedy reactions */
.react-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 35;
  overflow: hidden;
}

.react-bubble {
  position: absolute;
  font-weight: 800;
  font-size: clamp(1rem, 3.5vw, 1.35rem);
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  opacity: 0;
  transform: translateY(12px) scale(0.85);
  transition: opacity 0.25s, transform 0.45s cubic-bezier(0.34, 1.4, 0.64, 1);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  white-space: nowrap;
}

.react-bubble.pop {
  opacity: 1;
  transform: translateY(-28px) scale(1);
}

.react-comedy {
  color: #ffe08a;
  background: rgba(40, 20, 10, 0.75);
  border: 2px solid rgba(255, 213, 107, 0.55);
}

.react-heart {
  color: #ffb3c9;
  background: rgba(40, 10, 25, 0.75);
  border: 2px solid rgba(255, 107, 157, 0.5);
}

.react-angry {
  color: #ff8a8a;
  background: rgba(40, 10, 10, 0.75);
  border: 2px solid rgba(255, 100, 100, 0.45);
}

.react-win {
  color: #9ee8a8;
  background: rgba(10, 30, 15, 0.75);
  border: 2px solid rgba(126, 207, 138, 0.5);
}

.react-lose {
  color: #c4b8ff;
  background: rgba(20, 15, 40, 0.75);
  border: 2px solid rgba(155, 140, 255, 0.45);
}

.gag-banner {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%) translateY(-12px) scale(0.96);
  z-index: 45;
  max-width: min(92vw, 420px);
  padding: 0.75rem 1.15rem;
  border-radius: 14px;
  background: rgba(20, 12, 32, 0.94);
  border: 2px solid rgba(255, 213, 107, 0.55);
  box-shadow: 0 12px 36px rgba(255, 213, 107, 0.2);
  color: var(--cream);
  font-weight: 700;
  font-size: clamp(0.88rem, 2.6vw, 1.05rem);
  text-align: center;
  line-height: 1.45;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s, transform 0.35s cubic-bezier(0.34, 1.3, 0.64, 1);
}

.gag-banner.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
}

/* Choice number hotkeys */
.choice-btn {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
}

.choice-num {
  flex-shrink: 0;
  width: 1.55em;
  height: 1.55em;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-family: var(--font-en);
  font-size: 0.8rem;
  font-weight: 800;
  background: rgba(255, 107, 157, 0.2);
  border: 1px solid rgba(255, 182, 210, 0.35);
  color: var(--pink-soft);
  margin-top: 0.1em;
}

.choice-label {
  flex: 1;
  min-width: 0;
}

.title-progress {
  margin-top: 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: 0.04em;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.credits-card {
  width: min(420px, 100%);
  max-height: min(85dvh, 640px);
  overflow-y: auto;
}

.credits-body {
  text-align: left;
  margin: 0.25rem 0 1rem;
  line-height: 1.55;
}

.credits-line {
  font-size: 0.95rem;
  margin: 0.35rem 0;
  color: var(--cream);
}

.credits-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 0 0 0.5rem 0.15rem;
}

.credits-hr {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  margin: 0.75rem 0;
}

.credits-tips {
  font-size: 0.85rem;
  color: var(--pink-soft);
  line-height: 1.5;
}

.day-badge.saved-flash {
  box-shadow: 0 0 0 2px var(--gold), 0 0 16px rgba(255, 213, 107, 0.45);
  transition: box-shadow 0.3s;
}

/* Text size */
body.text-sm .dialogue-text {
  font-size: 0.9rem;
  line-height: 1.6;
}
body.text-md .dialogue-text {
  font-size: clamp(0.95rem, 2.8vw, 1.15rem);
}
body.text-lg .dialogue-text {
  font-size: clamp(1.08rem, 3.2vw, 1.3rem);
  line-height: 1.75;
}
body.text-lg .choice-btn {
  font-size: 1.02rem;
}
body.text-sm .choice-btn {
  font-size: 0.88rem;
}

/* Route forecast (high-impact finale UI) */
.forecast-panel {
  position: absolute;
  left: 50%;
  bottom: calc(var(--dialogue-h) + max(1rem, var(--safe-bottom)) + 0.65rem);
  transform: translateX(-50%);
  width: min(420px, calc(100% - 1rem));
  z-index: 27;
  animation: cardPop 0.3s cubic-bezier(0.34, 1.3, 0.64, 1);
}

.forecast-panel[hidden] {
  display: none !important;
}

.forecast-card {
  background: rgba(16, 10, 28, 0.96);
  border: 2px solid rgba(255, 182, 210, 0.35);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 0.9rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.forecast-card h3 {
  text-align: center;
  font-size: 1.15rem;
  margin-bottom: 0.25rem;
  background: linear-gradient(135deg, var(--pink-soft), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.forecast-sub {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.55rem;
}

.forecast-top {
  text-align: center;
  font-size: 0.9rem;
  color: var(--pink-soft);
  margin-bottom: 0.55rem;
}

.forecast-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.45rem;
}

.forecast-row {
  display: grid;
  grid-template-columns: 5.5rem 1fr 1.6rem;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
}

.forecast-row.top .forecast-name {
  color: var(--gold);
  font-weight: 800;
}

.forecast-row.comedy {
  margin-top: 0.35rem;
  padding-top: 0.45rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.forecast-name {
  font-weight: 700;
  color: var(--cream);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.forecast-bar {
  height: 9px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
}

.forecast-fill {
  height: 100%;
  background: linear-gradient(90deg, #ff6b9d, #ffd56b);
  border-radius: 999px;
  transition: width 0.5s ease;
}

.forecast-fill.comedy {
  background: linear-gradient(90deg, #ffd56b, #fff3c4);
}

.forecast-val {
  font-family: var(--font-en);
  font-weight: 800;
  text-align: right;
  color: var(--gold);
}

.forecast-hint {
  text-align: center;
  font-size: 0.8rem;
  color: var(--pink-soft);
  margin-top: 0.65rem;
  animation: blink 1.2s step-end infinite;
}

.ending-ng-hint {
  font-size: 0.78rem !important;
  color: var(--gold) !important;
  margin: -0.25rem 0 0.35rem !important;
  text-align: center;
}

@media (max-width: 640px) {
  .forecast-panel {
    width: calc(100% - 0.75rem);
    bottom: calc(var(--dialogue-h) + max(0.55rem, var(--safe-bottom)) + 0.45rem);
  }

  .forecast-row {
    grid-template-columns: 4.5rem 1fr 1.4rem;
    font-size: 0.8rem;
  }
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(18, 12, 32, 0.72);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: background 0.2s, transform 0.15s;
  display: grid;
  place-items: center;
}

.icon-btn:hover {
  background: rgba(50, 28, 60, 0.9);
  transform: scale(1.06);
}

/* ── Characters (portrait-style sprites) ── */
.character-stage {
  position: absolute;
  inset: 0 0 26% 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 9; /* above tap layer so sprites aren't blocked visually; still no pointer events */
  padding: 4% 4% 0;
  gap: 0.5rem;
}

.char-slot {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 340px;
  height: 100%;
  opacity: 0;
  transform: translateY(24px) scale(0.88);
  transition: opacity 0.4s ease, transform 0.45s cubic-bezier(0.34, 1.2, 0.64, 1), filter 0.3s;
  filter: brightness(0.72) saturate(0.85);
  position: relative;
}

.char-slot::before {
  content: "";
  position: absolute;
  width: min(72%, 220px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 182, 210, 0.35) 0%, rgba(196, 161, 255, 0.12) 45%, transparent 70%);
  z-index: 0;
  opacity: 0;
  transition: opacity 0.35s;
}

.char-slot.visible::before {
  opacity: 1;
}

.char-slot.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.char-slot.active {
  filter: brightness(1.05) saturate(1.1);
  z-index: 2;
  transform: translateY(-10px) scale(1.08);
}

.char-slot.visible.active {
  transform: translateY(-10px) scale(1.08);
}

.char-slot.active::before {
  background: radial-gradient(circle, rgba(255, 107, 157, 0.45) 0%, rgba(255, 213, 107, 0.15) 40%, transparent 70%);
  width: min(80%, 250px);
}

.char-sprite {
  position: relative;
  z-index: 1;
  width: min(52vw, 280px);
  height: min(52vw, 280px);
  max-height: min(48vh, 320px);
  object-fit: contain;
  image-rendering: auto;
  filter: drop-shadow(0 12px 24px rgba(0, 0, 0, 0.5));
  user-select: none;
  -webkit-user-drag: none;
  background: radial-gradient(circle at 50% 55%, rgba(255,255,255,0.12), transparent 65%);
  border-radius: 50%;
  padding: 8%;
}

/* Pixel-art characters stay crisp when scaled */
.char-sprite.pixel {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.char-slot.center {
  flex: 1.2;
}

.char-slot.center .char-sprite {
  width: min(58vw, 320px);
  height: min(58vw, 320px);
  max-height: min(52vh, 360px);
}

.char-slot.bounce .char-sprite {
  animation: charBounce 0.45s ease;
}

@keyframes charBounce {
  0% { transform: translateY(0); }
  40% { transform: translateY(-14px); }
  100% { transform: translateY(0); }
}

.char-slot.shake .char-sprite {
  animation: charShake 0.4s ease;
}

@keyframes charShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

/* Tap stage to advance (mobile VN feel). HUD / dialogue / choices sit above. */
.game-tap-layer {
  position: absolute;
  inset: 0;
  z-index: 8;
  width: 100%;
  height: 100%;
  background: transparent;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  min-height: 0;
}

/* ── Dialogue ── */
.dialogue-box {
  position: absolute;
  left: 50%;
  bottom: max(0.75rem, var(--safe-bottom));
  transform: translateX(-50%);
  width: min(920px, calc(100% - 1rem));
  min-height: var(--dialogue-h);
  max-height: min(42vh, 280px);
  z-index: 20;
  background: var(--bg-panel);
  border: 2px solid rgba(255, 182, 210, 0.25);
  border-radius: var(--radius);
  padding: 1.1rem 1.35rem 1.35rem;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,0.08);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.dialogue-box::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(255,107,157,0.08), transparent 50%, rgba(196,161,255,0.08));
  pointer-events: none;
}

.speaker-name {
  display: inline-block;
  font-weight: 800;
  font-size: 0.95rem;
  padding: 0.2rem 0.85rem;
  border-radius: 999px;
  margin-bottom: 0.55rem;
  background: rgba(255,255,255,0.08);
  color: var(--speaker-narrator);
  letter-spacing: 0.04em;
  min-height: 1.6em;
}

.speaker-name.kero { color: #0d1f12; background: linear-gradient(135deg, #9ee8a8, #7ecf8a); }
.speaker-name.chad { color: #0a1628; background: linear-gradient(135deg, #a8d4ff, #7eb8ff); }
.speaker-name.feller { color: #2a1808; background: linear-gradient(135deg, #f0d0a0, #e8b86d); }
.speaker-name.monkiti { color: #140f28; background: linear-gradient(135deg, #c8bfff, #9b8cff); }
.speaker-name.level6 { color: #2a1408; background: linear-gradient(135deg, #ffd0a8, #ffb07a); }
.speaker-name.player { color: #2a1830; background: linear-gradient(135deg, #ffd0e0, #ff9ec4); }
.speaker-name:empty { display: none; }

.dialogue-text {
  font-size: clamp(0.95rem, 2.8vw, 1.15rem);
  line-height: 1.7;
  font-weight: 500;
  color: var(--cream);
  min-height: 3.2em;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.continue-hint {
  position: absolute;
  right: 1.1rem;
  bottom: 0.7rem;
  color: var(--pink-soft);
  font-size: 0.75rem;
  animation: blink 1s step-end infinite;
  opacity: 0;
}

.continue-hint.show {
  opacity: 1;
}

@keyframes blink {
  50% { opacity: 0.25; }
}

/* ── Choices ── */
.choices-panel {
  position: absolute;
  left: 50%;
  bottom: calc(var(--dialogue-h) + max(1rem, var(--safe-bottom)) + 0.65rem);
  transform: translateX(-50%);
  width: min(560px, calc(100% - 1rem));
  max-height: min(42vh, 320px);
  z-index: 25;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0.15rem 0.1rem 0.35rem;
  /* Fade edge so scroll is obvious on small screens */
  mask-image: linear-gradient(to bottom, transparent 0, #000 8px, #000 calc(100% - 8px), transparent 100%);
}

.choices-panel[hidden] {
  display: none !important;
}

.choice-btn {
  appearance: none;
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  text-align: left;
  border: 2px solid rgba(255, 182, 210, 0.35);
  background: rgba(22, 14, 38, 0.94);
  color: var(--text);
  font-family: inherit;
  font-size: clamp(0.9rem, 2.4vw, 1.05rem);
  font-weight: 600;
  padding: 0.85rem 1rem;
  min-height: var(--touch-min);
  border-radius: var(--radius-sm);
  cursor: pointer;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
  line-height: 1.4;
  animation: choiceIn 0.35s ease backwards;
  flex-shrink: 0;
}

.choice-btn:nth-child(1) { animation-delay: 0.05s; }
.choice-btn:nth-child(2) { animation-delay: 0.12s; }
.choice-btn:nth-child(3) { animation-delay: 0.19s; }
.choice-btn:nth-child(4) { animation-delay: 0.26s; }
.choice-btn:nth-child(5) { animation-delay: 0.33s; }
.choice-btn:nth-child(6) { animation-delay: 0.4s; }
.choice-btn:nth-child(7) { animation-delay: 0.47s; }

@keyframes choiceIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* No translate/scale on hover — moving the hitbox under the cursor causes jitter */
.choice-btn:hover,
.choice-btn:focus-visible {
  border-color: var(--pink);
  background: rgba(60, 28, 55, 0.95);
  box-shadow: 0 0 0 1px rgba(255, 107, 157, 0.35), 0 6px 20px var(--pink-glow);
  outline: none;
}

.choice-btn:active {
  background: rgba(80, 36, 70, 0.98);
  border-color: var(--pink-soft);
}

/* ── Mini-games ── */
.minigame-panel {
  position: absolute;
  left: 50%;
  bottom: calc(var(--dialogue-h) + max(1rem, var(--safe-bottom)) + 0.65rem);
  transform: translateX(-50%);
  width: min(520px, calc(100% - 1rem));
  max-height: min(48vh, 360px);
  z-index: 28;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.minigame-panel[hidden] {
  display: none !important;
}

.mg-card {
  background: rgba(18, 12, 36, 0.96);
  border: 2px solid rgba(255, 213, 107, 0.4);
  border-radius: var(--radius);
  padding: 1rem 1rem 1.15rem;
  box-shadow: 0 12px 36px rgba(0,0,0,0.5), 0 0 24px rgba(255, 213, 107, 0.15);
  text-align: center;
  animation: cardPop 0.3s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.mg-card h3 {
  font-size: 1.15rem;
  margin-bottom: 0.35rem;
  background: linear-gradient(135deg, var(--gold), var(--pink-soft));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.mg-hint {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 0.85rem;
  line-height: 1.45;
}

/* Texas Sumo RPS — Feller's hybrid showdown */
.mg-card.mg-sumo {
  border-color: rgba(255, 180, 70, 0.55);
  background:
    radial-gradient(ellipse 70% 45% at 50% 100%, rgba(180, 90, 30, 0.35), transparent 70%),
    linear-gradient(165deg, rgba(40, 22, 18, 0.98), rgba(18, 12, 36, 0.96));
  box-shadow: 0 12px 36px rgba(0,0,0,0.5), 0 0 28px rgba(255, 160, 60, 0.22);
}

.mg-sumo-ring {
  position: relative;
  height: 3.2rem;
  margin: 0 auto 0.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mg-sumo-dohyo {
  font-size: 2.6rem;
  line-height: 1;
  color: rgba(255, 200, 120, 0.35);
  text-shadow: 0 0 18px rgba(255, 170, 60, 0.5);
  font-weight: 800;
}

.mg-sumo-hat {
  position: absolute;
  font-size: 1.45rem;
  top: 0.15rem;
  animation: sumoHatBob 1.4s ease-in-out infinite;
}

@keyframes sumoHatBob {
  0%, 100% { transform: translateY(0) rotate(-6deg); }
  50% { transform: translateY(-4px) rotate(6deg); }
}

.mg-sumo-sub {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: rgba(255, 200, 120, 0.85);
  margin: -0.15rem 0 0.45rem;
}

.mg-sumo-actions .mg-sumo-btn {
  border-color: rgba(255, 180, 80, 0.35);
  background: linear-gradient(160deg, rgba(70, 40, 20, 0.95), rgba(40, 24, 60, 0.9));
  font-size: 0.88rem;
  line-height: 1.25;
  padding: 0.7rem 0.65rem;
}

.mg-sumo-actions .mg-sumo-btn:hover {
  border-color: rgba(255, 200, 100, 0.85);
  box-shadow: 0 6px 18px rgba(255, 160, 60, 0.35);
}

.mg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.mg-actions .mg-btn {
  flex: 1 1 30%;
  min-width: 5.5rem;
}

.mg-btn {
  appearance: none;
  border: 2px solid rgba(255,255,255,0.2);
  background: rgba(40, 24, 60, 0.9);
  color: var(--text);
  font-family: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0.75rem 1rem;
  min-height: var(--touch-min);
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s, box-shadow 0.2s;
}

.mg-btn:hover {
  border-color: var(--gold);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(255, 213, 107, 0.3);
}

.mg-btn.primary {
  background: linear-gradient(135deg, #ff6b9d, #c44dff);
  border-color: transparent;
}

.mg-btn.big {
  width: 100%;
  margin-top: 0.5rem;
  font-size: 1.1rem;
  padding: 0.9rem;
}

.mg-btn.big.hit {
  transform: scale(0.96);
  filter: brightness(1.15);
}

.mg-monkeys {
  display: flex;
  gap: 0.55rem;
  justify-content: center;
}

.mg-monkey {
  flex: 1;
  max-width: 110px;
  appearance: none;
  border: 2px solid rgba(155, 140, 255, 0.45);
  background: rgba(30, 20, 55, 0.95);
  color: var(--text);
  font-family: inherit;
  font-weight: 800;
  font-size: 1.25rem;
  padding: 1rem 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s, background 0.2s;
}

.mg-monkey:hover {
  transform: scale(1.06) rotate(-2deg);
  border-color: var(--lavender);
  background: rgba(55, 35, 90, 0.95);
}

.stare-track {
  height: 14px;
  background: rgba(255,255,255,0.1);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 0.35rem;
}

.stare-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ffb07a, #ff6b9d, #ffd56b);
  transition: width 0.08s linear;
  border-radius: 999px;
}

.mg-timer {
  margin-top: 0.45rem;
  font-family: var(--font-en);
  font-weight: 800;
  color: var(--gold);
  font-size: 1.1rem;
}

/* Hearts overlay */
.hearts-card {
  width: min(400px, 100%);
}

.hearts-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin: 0.35rem 0 0.85rem;
}

.heart-row {
  display: grid;
  grid-template-columns: 4.5rem 1fr 2rem;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.heart-name {
  font-weight: 700;
  color: var(--pink-soft);
}

.heart-bar {
  height: 10px;
  background: rgba(255,255,255,0.1);
  border-radius: 999px;
  overflow: hidden;
}

.heart-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #ff6b9d, #ffd56b);
  border-radius: 999px;
  transition: width 0.4s ease;
}

.heart-bar-fill.comedy {
  background: linear-gradient(90deg, #ffd56b, #fff3c4);
}

.heart-num {
  font-family: var(--font-en);
  font-weight: 800;
  text-align: right;
  color: var(--gold);
}

/* ── Overlays ── */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 4, 16, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding:
    max(1rem, var(--safe-top))
    max(1rem, var(--safe-right))
    max(1rem, var(--safe-bottom))
    max(1rem, var(--safe-left));
  animation: fadeIn 0.25s ease;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.overlay[hidden] {
  display: none !important;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.overlay-card {
  background: var(--bg-panel-solid);
  border: 2px solid rgba(255, 182, 210, 0.25);
  border-radius: var(--radius);
  padding: 1.75rem 1.5rem;
  width: min(360px, 100%);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  animation: cardPop 0.3s cubic-bezier(0.34, 1.4, 0.64, 1);
}

@keyframes cardPop {
  from { opacity: 0; transform: scale(0.92) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.overlay-card h2 {
  text-align: center;
  font-size: 1.35rem;
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, var(--pink-soft), var(--lavender));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.settings-card .setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-size: 0.95rem;
}

.settings-card input[type="range"] {
  width: 120px;
  accent-color: var(--pink);
}

.settings-card .volume-row {
  align-items: center;
}

.volume-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.volume-control input[type="range"] {
  width: min(140px, 36vw);
  flex: 1;
}

.volume-pct {
  font-family: var(--font-en);
  font-weight: 800;
  font-size: 0.85rem;
  color: var(--gold);
  min-width: 2.6em;
  text-align: right;
}

.settings-card select {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  color: var(--text);
  font-family: inherit;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
}

.gallery-card {
  width: min(520px, 100%);
  max-height: min(85vh, 640px);
  overflow-y: auto;
}

.gallery-hint {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin: 0.5rem 0 1rem;
}

@media (min-width: 480px) {
  .gallery-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.gallery-item {
  min-height: 9.5rem;
  border-radius: var(--radius-sm);
  border: 2px solid rgba(255,255,255,0.12);
  background: rgba(0,0,0,0.35);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  position: relative;
  padding: 0.55rem 0.45rem 0.65rem;
  text-align: center;
}

.gallery-item.unlocked {
  border-color: rgba(255, 107, 157, 0.45);
  background: rgba(40, 20, 50, 0.6);
}

.gallery-item img {
  width: 56%;
  max-height: 4.5rem;
  object-fit: contain;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.4));
  margin-top: 0.2rem;
}

.gallery-item.locked img {
  filter: brightness(0) opacity(0.35);
}

.gallery-item .g-title {
  font-size: 0.75rem;
  font-weight: 700;
  margin-top: 0.4rem;
  color: var(--pink-soft);
}

.gallery-item.locked .g-title {
  color: var(--text-muted);
}

.gallery-item .g-tip {
  font-size: 0.62rem;
  line-height: 1.35;
  color: var(--text-muted);
  margin-top: 0.35rem;
  padding: 0 0.15rem;
}

/* ── Toast ── */
.toast {
  position: absolute;
  top: calc(var(--hud-h) + max(0.75rem, var(--safe-top)) + 0.35rem);
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  z-index: 200;
  background: rgba(30, 16, 40, 0.95);
  border: 1px solid var(--pink);
  color: var(--text);
  padding: 0.65rem 1.1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 8px 24px var(--pink-glow);
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  max-width: calc(100% - 1.5rem);
  white-space: normal;
  text-align: center;
  line-height: 1.35;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Transition ── */
.transition {
  position: absolute;
  inset: 0;
  z-index: 150;
  background: #0a0612;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.transition.active {
  opacity: 1;
  pointer-events: auto;
}

.transition-text {
  font-size: clamp(1.4rem, 5vw, 2rem);
  font-weight: 800;
  letter-spacing: 0.2em;
  background: linear-gradient(135deg, var(--pink-soft), var(--lavender), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-align: center;
  padding: 0 1.5rem;
}

/* ── Ending splash ── */
.ending-splash {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: rgba(10, 6, 18, 0.72);
  text-align: center;
  padding: max(1.25rem, var(--safe-top)) 1.25rem max(1.5rem, var(--safe-bottom));
  animation: fadeIn 0.6s ease;
}

.ending-splash.end-true {
  background:
    radial-gradient(ellipse 70% 50% at 50% 20%, rgba(255, 140, 180, 0.35), transparent 60%),
    rgba(18, 8, 28, 0.78);
}

.ending-splash.end-chaos {
  background:
    radial-gradient(circle at 20% 30%, rgba(255, 100, 160, 0.25), transparent 40%),
    radial-gradient(circle at 80% 40%, rgba(100, 180, 255, 0.22), transparent 40%),
    rgba(12, 8, 24, 0.8);
}

.ending-splash.end-xmas {
  background:
    radial-gradient(ellipse 80% 45% at 50% 0%, rgba(255, 210, 140, 0.3), transparent 55%),
    rgba(12, 20, 40, 0.82);
}

.ending-splash.end-kraft {
  background:
    radial-gradient(ellipse 60% 40% at 50% 30%, rgba(255, 70, 50, 0.22), transparent 60%),
    rgba(30, 8, 12, 0.82);
}

.ending-portrait-wrap {
  margin: 0.5rem auto 0.85rem;
  width: min(42vw, 11rem);
  height: min(42vw, 11rem);
  border-radius: 50%;
  padding: 4px;
  background: linear-gradient(135deg, var(--pink-soft), var(--gold), var(--lavender));
  box-shadow: 0 12px 36px rgba(255, 107, 157, 0.35);
  animation: cardPop 0.5s cubic-bezier(0.34, 1.3, 0.64, 1);
}

.ending-splash.end-true .ending-portrait-wrap {
  width: min(48vw, 13rem);
  height: min(48vw, 13rem);
  box-shadow: 0 16px 48px rgba(255, 140, 180, 0.5);
}

.ending-portrait {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 50%;
  background: rgba(18, 12, 32, 0.9);
  padding: 8%;
  display: block;
}

.ending-splash h2 {
  font-size: clamp(1.8rem, 6vw, 2.8rem);
  font-weight: 800;
  margin-bottom: 0.75rem;
  background: linear-gradient(135deg, #fff, var(--pink-soft), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 16px var(--pink-glow));
}

.ending-splash p {
  color: var(--text-muted);
  font-size: 1.05rem;
  max-width: 28rem;
  line-height: 1.7;
  margin-bottom: 1.5rem;
}

.ending-howto {
  max-width: 26rem;
  margin: 0 auto 0.85rem;
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 213, 107, 0.1);
  border: 1px solid rgba(255, 213, 107, 0.28);
  color: var(--cream);
  font-size: 0.88rem;
  line-height: 1.5;
  text-align: left;
}

.ending-howto.more {
  background: rgba(196, 161, 255, 0.1);
  border-color: rgba(196, 161, 255, 0.28);
}

.ending-howto ul {
  margin: 0.35rem 0 0 1.1rem;
  padding: 0;
}

.ending-howto li {
  margin-bottom: 0.25rem;
  color: var(--text-muted);
}

/* Cast bio card */
.cast-bio-card {
  max-width: 22rem;
  text-align: center;
}

.cast-bio-img {
  width: 96px;
  height: 96px;
  object-fit: contain;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  border: 2px solid rgba(255, 182, 210, 0.4);
  padding: 6px;
  margin: 0 auto 0.75rem;
  display: block;
  filter: drop-shadow(0 6px 16px rgba(0,0,0,0.4));
}

.cast-bio-img.pixel {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.cast-bio-role {
  color: var(--gold);
  font-weight: 700;
  font-size: 0.92rem;
  margin-bottom: 0.55rem;
}

.cast-bio-body {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.55;
  margin-bottom: 0.75rem;
  text-align: left;
}

.cast-bio-tip {
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--pink-soft);
  background: rgba(255, 107, 157, 0.12);
  border: 1px solid rgba(255, 107, 157, 0.28);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.75rem;
  margin-bottom: 1rem;
  text-align: left;
}

/* ── Responsive: phones ── */
@media (max-width: 640px) {
  :root {
    --dialogue-h: clamp(7.25rem, 26vh, 10.5rem);
    --radius: 14px;
  }

  .title-content {
    justify-content: flex-start;
    padding-top: max(1.5rem, calc(var(--safe-top) + 0.75rem));
  }

  .title-tagline {
    margin-bottom: 0.85rem;
    font-size: 0.88rem;
  }

  .title-cast {
    gap: 0.3rem;
    margin-bottom: 1.15rem;
  }

  .cast-icon {
    width: 44px;
    height: 44px;
  }

  .title-menu {
    width: min(300px, 92vw);
    gap: 0.55rem;
    padding-bottom: 0.5rem;
  }

  .menu-btn {
    font-size: 1rem;
    padding: 0.8rem 1rem;
  }

  .logo-jp {
    font-size: clamp(2.1rem, 11vw, 3rem);
  }

  .game-hud {
    padding-top: max(0.4rem, var(--safe-top));
  }

  .day-badge,
  .comedy-badge,
  .hearts-btn {
    padding: 0.28rem 0.55rem;
    font-size: 0.78rem;
  }

  .day-num {
    font-size: 1rem;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
    min-height: 36px;
    min-width: 36px;
    flex-shrink: 0;
    font-size: 0.9rem;
  }

  .hud-right {
    max-width: 62%;
    gap: 0.28rem;
  }

  .hearts-btn {
    padding: 0.25rem 0.45rem;
  }

  .hearts-preview {
    display: none;
  }

  .location-label {
    display: none;
  }

  .character-stage {
    inset: calc(var(--hud-h) + var(--safe-top)) 0 calc(var(--dialogue-h) + var(--safe-bottom) + 0.5rem) 0;
    align-items: center;
    padding: 0 2%;
    gap: 0.15rem;
  }

  .char-sprite {
    width: min(42vw, 168px);
    height: min(42vw, 168px);
    max-height: min(32vh, 190px);
    padding: 6%;
  }

  .char-slot.center .char-sprite {
    width: min(50vw, 200px);
    height: min(50vw, 200px);
    max-height: min(36vh, 220px);
  }

  /* Two side characters: shrink so three fit */
  .char-slot.left .char-sprite,
  .char-slot.right .char-sprite {
    width: min(34vw, 130px);
    height: min(34vw, 130px);
    max-height: min(28vh, 150px);
  }

  .char-slot.active {
    transform: translateY(-4px) scale(1.04);
  }

  .char-slot.visible.active {
    transform: translateY(-4px) scale(1.04);
  }

  .dialogue-box {
    width: calc(100% - 0.75rem);
    min-height: var(--dialogue-h);
    max-height: min(38vh, 240px);
    padding: 0.8rem 0.9rem 1.05rem;
    bottom: max(0.45rem, var(--safe-bottom));
    border-radius: 14px;
  }

  .speaker-name {
    font-size: 0.85rem;
    padding: 0.18rem 0.7rem;
    margin-bottom: 0.4rem;
  }

  .dialogue-text {
    font-size: 0.95rem;
    line-height: 1.65;
    min-height: 3em;
  }

  .continue-hint {
    right: 0.75rem;
    bottom: 0.45rem;
  }

  .choices-panel,
  .minigame-panel {
    width: calc(100% - 0.75rem);
    bottom: calc(var(--dialogue-h) + max(0.55rem, var(--safe-bottom)) + 0.45rem);
    max-height: min(40vh, 280px);
  }

  .choice-btn {
    padding: 0.75rem 0.85rem;
    font-size: 0.9rem;
  }

  .mg-card {
    padding: 0.85rem 0.75rem 1rem;
  }

  .mg-card h3 {
    font-size: 1.05rem;
  }

  .mg-hint {
    font-size: 0.82rem;
  }

  .mg-monkey {
    min-height: 56px;
    font-size: 1.1rem;
    padding: 0.85rem 0.35rem;
  }

  .mg-btn.big {
    min-height: 52px;
    font-size: 1.05rem;
  }

  .overlay-card {
    width: min(360px, 100%);
    padding: 1.35rem 1.1rem;
    max-height: min(88dvh, 640px);
    overflow-y: auto;
  }

  .gallery-card {
    width: min(100%, 520px);
  }

  .gallery-grid {
    grid-template-columns: 1fr 1fr;
  }

  .heart-row {
    grid-template-columns: 3.8rem 1fr 1.75rem;
    font-size: 0.85rem;
  }

  .ending-splash {
    padding: 1.25rem 1rem;
    padding-bottom: max(1.25rem, var(--safe-bottom));
  }

  .ending-splash h2 {
    font-size: clamp(1.35rem, 7vw, 2rem);
  }

  .ending-splash p {
    font-size: 0.95rem;
  }

  .toast {
    font-size: 0.8rem;
    padding: 0.55rem 0.9rem;
  }

  /* Prefer active states over hover on touch devices */
  .menu-btn:hover:not(:disabled),
  .mg-btn:hover,
  .mg-monkey:hover {
    transform: none;
  }

  .menu-btn:active:not(:disabled),
  .mg-btn:active,
  .mg-monkey:active {
    transform: scale(0.97);
  }
}

/* Very small phones */
@media (max-width: 380px) {
  .title-subtitle {
    font-size: 0.78rem;
    letter-spacing: 0.08em;
  }

  .cast-icon {
    width: 38px;
    height: 38px;
  }

  .hud-left {
    max-width: 48%;
  }

  .hearts-preview {
    max-width: 4.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .char-sprite {
    width: min(40vw, 140px);
    height: min(40vw, 140px);
  }
}

/* Landscape phones — prioritize dialogue + choices readability */
@media (max-height: 500px) and (orientation: landscape) {
  :root {
    --dialogue-h: clamp(5.5rem, 38vh, 8rem);
  }

  .title-content {
    justify-content: flex-start;
    padding: 0.75rem 1rem 3.5rem;
  }

  .title-cast {
    display: none;
  }

  .title-tagline {
    display: none;
  }

  .title-menu {
    flex-direction: row;
    flex-wrap: wrap;
    width: min(560px, 92vw);
    justify-content: center;
  }

  .title-menu .menu-btn {
    flex: 1 1 40%;
    min-width: 140px;
  }

  .character-stage {
    inset: 0 42% 0 0;
    align-items: center;
    padding: 0.5rem;
  }

  .dialogue-box {
    left: auto;
    right: max(0.5rem, var(--safe-right));
    transform: none;
    width: min(52%, 420px);
    max-height: calc(100% - 4.5rem);
    bottom: max(0.5rem, var(--safe-bottom));
    top: auto;
  }

  .choices-panel,
  .minigame-panel {
    left: auto;
    right: max(0.5rem, var(--safe-right));
    transform: none;
    width: min(52%, 420px);
    bottom: calc(var(--dialogue-h) + max(0.5rem, var(--safe-bottom)) + 0.35rem);
    max-height: min(48vh, 200px);
  }

  .char-sprite {
    width: min(28vh, 160px);
    height: min(28vh, 160px);
    max-height: 160px;
  }

  .char-slot.center .char-sprite {
    width: min(34vh, 190px);
    height: min(34vh, 190px);
    max-height: 190px;
  }

  .game-hud {
    padding-top: max(0.25rem, var(--safe-top));
  }
}

/* Short tall phones (notch + home bar) */
@media (max-width: 640px) and (max-height: 700px) {
  .character-stage {
    inset: calc(var(--hud-h) + var(--safe-top)) 0 calc(var(--dialogue-h) + var(--safe-bottom) + 0.25rem) 0;
  }

  .char-sprite {
    max-height: min(28vh, 170px);
  }

  .char-slot.center .char-sprite {
    max-height: min(32vh, 195px);
  }
}

@media (min-width: 900px) {
  #app {
    box-shadow: 0 0 80px rgba(0, 0, 0, 0.6);
  }

  .char-sprite {
    width: 300px;
    height: 300px;
    max-height: 340px;
  }

  .char-slot.center .char-sprite {
    width: 340px;
    height: 340px;
    max-height: 380px;
  }
}

/* Coarse pointer = phone/tablet finger */
@media (hover: none) and (pointer: coarse) {
  .menu-btn:hover:not(:disabled),
  .mg-btn:hover,
  .mg-monkey:hover,
  .cast-icon:hover {
    transform: none;
  }

  .menu-btn:active:not(:disabled) {
    border-color: var(--pink);
    background: rgba(60, 28, 55, 0.95);
  }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .title-bg {
    animation: none;
  }
}
