:root {
  color-scheme: light;
  --pink-50: #fff7fa; --pink-100: #ffe9f1; --pink-200: #f7bfd3; --pink-600: #cf3f73;
  --blue-50: #f2f8ff; --blue-100: #e4f1ff; --blue-300: #9bc8f2; --blue-600: #2878bd;
  --ink: #3d3036; --muted: #786c72; --line: #eadde2; --white: #fff;
  --shadow: 0 16px 44px rgba(78, 48, 60, .16);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: #f1ebee; }
body {
  margin: 0; min-height: 100svh; color: var(--ink);
  background: linear-gradient(145deg, #f7f1f4, #ebe5e8);
  font-family: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, a { font: inherit; }
button { touch-action: manipulation; }

.app-shell {
  width: min(100%, 460px); min-height: 100svh; margin: 0 auto;
  background: var(--pink-50); box-shadow: var(--shadow); overflow: hidden;
}
.screen { display: none; min-height: 100svh; }
.screen.is-active { display: flex; }

.start-screen, .result-screen {
  align-items: center; justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) 22px max(24px, env(safe-area-inset-bottom));
  background: radial-gradient(circle at 85% 14%, rgba(255,212,227,.9) 0 5rem, transparent 5.1rem),
    radial-gradient(circle at 5% 90%, rgba(255,233,241,.95) 0 7rem, transparent 7.1rem), var(--pink-50);
}
.start-card, .result-card { width: 100%; text-align: center; }
.game-number { margin: 0 0 12px; color: var(--pink-600); font-size: .74rem; font-weight: 800; letter-spacing: .18em; }
h1 { margin: 0; font-size: clamp(2.2rem, 11vw, 3.15rem); line-height: 1.18; letter-spacing: .04em; }
.lead { margin: 28px 0 0; font-size: 1rem; line-height: 1.85; }
.hint { margin: 12px 0 0; color: var(--muted); font-size: .82rem; }
.best { margin: 24px 0 0; color: var(--muted); font-size: .84rem; font-weight: 800; letter-spacing: .08em; }

.primary-button, .secondary-button {
  display: flex; align-items: center; justify-content: center; width: 100%; min-height: 56px;
  border-radius: 999px; font-weight: 800; text-decoration: none; cursor: pointer;
}
.primary-button { margin-top: 24px; border: 0; color: var(--white); background: var(--pink-600); box-shadow: 0 8px 22px rgba(207,63,115,.25); }
.primary-button:active { transform: translateY(1px); }

.game-screen { position: relative; flex-direction: column; overflow-y: auto; background: #f7e9ee; }
.stage {
  position: relative; display: flex; flex: 1; flex-direction: column; min-height: 100svh;
  isolation: isolate; overflow: hidden; background: linear-gradient(180deg, #f8dce6, #e9edf4);
}
.portrait-frame { position: absolute; inset: 0; z-index: -3; overflow: hidden; background: linear-gradient(160deg, #f9dce7, #e8edf5); }
.portrait-frame img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 38%; transform-origin: 50% 38%; }
.image-placeholder { display: grid; width: 100%; height: 100%; place-items: center; color: #aa8c98; font-size: .84rem; font-weight: 700; letter-spacing: .04em; }
.background-shade {
  position: absolute; inset: 0; z-index: -2; pointer-events: none;
  background: linear-gradient(180deg, rgba(255,255,255,.18), rgba(255,255,255,0) 34%, rgba(32,29,35,.04) 52%, rgba(255,248,251,.5) 72%, rgba(255,248,251,.82));
  transition: background .35s ease;
}
.stage.is-crying .background-shade { background: linear-gradient(180deg, rgba(24,20,24,.1), rgba(24,20,24,.22)); }

.game-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 58px;
  padding: max(12px, env(safe-area-inset-top)) 18px 10px; border-bottom: 1px solid rgba(234,221,226,.82);
  background: rgba(255,255,255,.86); backdrop-filter: blur(10px);
}
.mini-title, .conversation-count { margin: 0; font-size: .82rem; font-weight: 800; }
.conversation-count { white-space: nowrap; color: var(--pink-600); }

.conversation-ui {
  display: flex; flex: 1; flex-direction: column; justify-content: flex-end; gap: 15px; min-height: 0;
  padding: 34svh 14px max(28px, calc(env(safe-area-inset-bottom) + 18px));
}
.speech-bubble {
  position: relative; width: 100%; padding: 22px 17px 16px; border: 2px solid rgba(244,124,166,.72);
  border-radius: 18px; background: rgba(255,255,255,.94); box-shadow: 0 8px 24px rgba(63,45,53,.14); backdrop-filter: blur(8px);
}
.speaker-tab {
  position: absolute; top: -13px; left: 14px; padding: 5px 12px; border-radius: 999px;
  color: #fff; background: var(--pink-600); font-size: .72rem; font-weight: 800; letter-spacing: .04em;
}
.speech-bubble p { margin: 0; font-size: .98rem; font-weight: 700; line-height: 1.6; }
.response-area { min-height: 199px; }
.response-guide { margin: 0 0 8px 3px; color: var(--blue-600); font-size: .78rem; font-weight: 800; }
.choices { display: grid; gap: 8px; }

.choice-button {
  width: 100%; min-height: 52px; padding: 11px 14px; border: 2px solid var(--blue-300); border-radius: 14px;
  color: #293a49; background: rgba(255,255,255,.95); box-shadow: 0 4px 12px rgba(44,82,113,.09);
  font-size: .9rem; font-weight: 700; line-height: 1.4; text-align: left; cursor: pointer;
  opacity: 0; transform: translateX(14px); animation: choice-in .3s ease-out forwards; animation-delay: var(--choice-delay, 0ms);
}
.choice-button::before {
  content: attr(data-label); display: inline-grid; width: 24px; height: 24px; margin-right: 8px; place-items: center;
  border-radius: 50%; color: #fff; background: var(--blue-600); font-size: .72rem; vertical-align: 1px;
}
.choice-button:disabled { cursor: default; }
.choice-button.is-selected { border-color: var(--blue-600); color: #174f7d; background: var(--blue-100); box-shadow: 0 0 0 2px rgba(40,120,189,.14); opacity: 1; }
.choice-button.is-selected::after { content: "✓"; float: right; color: var(--blue-600); font-weight: 900; }
.choice-button.is-muted { border-color: #d4d7da; color: #8a8f93; background: rgba(242,242,243,.9); opacity: .5; filter: grayscale(.55); }

.inner-thought {
  display: flex; min-height: 199px; padding: 22px 18px; flex-direction: column; justify-content: center;
  border: 2px solid rgba(93,152,205,.68); border-radius: 16px;
  color: #315e82; background: rgba(242,248,255,.94); box-shadow: 0 5px 16px rgba(43,80,112,.1);
}
.inner-thought p { margin: 0; font-size: 1.02rem; font-style: italic; font-weight: 800; line-height: 1.55; }
.inner-thought span { display: block; margin-top: 12px; color: #6e8ca4; font-size: .74rem; font-weight: 700; }
.inner-thought[hidden] { display: none; }
.inner-thought.is-ready span { animation: hint-pulse 1.25s ease-in-out infinite; }

.doom-card {
  display: flex; min-height: 199px; padding: 22px 18px; flex-direction: column; justify-content: center;
  border: 2px solid rgba(72, 132, 188, .78); border-radius: 16px;
  color: #245d8a; background: rgba(232, 244, 255, .96); box-shadow: 0 5px 16px rgba(43,80,112,.13);
  cursor: pointer; user-select: none; touch-action: manipulation;
}
.doom-card[hidden] { display: none; }
.doom-card p { margin: 0; font-size: 1.08rem; font-weight: 800; line-height: 1.55; }
.doom-card span { display: block; margin-top: 12px; color: #6688a3; font-size: .74rem; font-weight: 700; }
.doom-card:focus-visible { outline: 3px solid rgba(40,120,189,.36); outline-offset: 3px; }
.doom-card.is-pressed { opacity: .68; pointer-events: none; }

.clear-banner {
  position: absolute; inset: 0; z-index: 5; align-items: center; justify-content: center; flex-direction: column;
  color: var(--white); background: rgba(207,63,115,.88); text-align: center; animation: clear-in .48s ease-out both;
}
.clear-banner:not([hidden]) { display: flex; }
.clear-banner span { font-size: 2.3rem; font-weight: 900; letter-spacing: .08em; }
.clear-banner strong { margin-top: 8px; font-size: 1rem; }

.result-screen { overflow-y: auto; }
.result-card { padding: 8px 0; }
.result-card h2 { margin: 0; font-size: 2.2rem; letter-spacing: .06em; }
.result-card.is-clear h2 { color: var(--pink-600); }
.result-score { display: grid; margin: 20px 0; }
.result-score strong { font-size: 2.7rem; line-height: 1.1; }
.result-score span { margin-top: 4px; color: var(--muted); font-size: .86rem; font-weight: 700; }
.medal { padding: 20px 18px; border: 1px solid var(--pink-200); border-radius: 20px; background: rgba(255,255,255,.8); }
.medal-icon { display: grid; width: 54px; height: 54px; margin: 0 auto 10px; place-items: center; border-radius: 50%; color: #fff6ce; background: var(--pink-600); box-shadow: inset 0 0 0 5px rgba(255,255,255,.25); font-size: 1.45rem; }
.medal h3 { margin: 0; font-size: 1.08rem; }
.medal p { margin: 8px 0 0; color: var(--muted); font-size: .86rem; line-height: 1.6; }
.result-actions { display: grid; gap: 10px; margin-top: 22px; }
.result-actions .primary-button { margin-top: 0; }
.secondary-button { border: 1px solid var(--line); color: var(--ink); background: var(--white); }

.stage[data-effect="soft"] .portrait-frame { animation: soft .58s ease-out; }
.stage[data-effect="impact-small"] .portrait-frame { animation: impact-small .44s ease-out; }
.stage[data-effect="impact-medium"] .portrait-frame { animation: impact-medium .5s ease-out; }
.stage[data-effect="impact-large"] .portrait-frame { animation: impact-large .62s ease-out; }
.stage[data-effect="impact-large"][data-expression="teary"] .portrait-frame { animation-name: teary; }
.stage[data-effect="cry"] .portrait-frame { animation: cry 1.05s ease-in-out infinite; }

@keyframes choice-in { to { opacity: 1; transform: translateX(0); } }
@keyframes soft { 45% { transform: scale(1.025) translateY(-2px); } }
@keyframes impact-small { 28% { transform: scale(1.045) translateX(-1px); } 48% { transform: scale(1.025) translateX(2px); } }
@keyframes impact-medium { 30% { transform: scale(1.085); } 48% { transform: scale(1.055) translateX(-2px); } }
@keyframes impact-large { 28% { transform: scale(1.12) translateX(-2px); } 44% { transform: scale(1.09) translateX(3px); } }
@keyframes teary { 28% { transform: scale(1.09) translateY(3px); } 42% { transform: scale(1.08) translate(1px,4px); } 56% { transform: scale(1.08) translate(-1px,4px); } }
@keyframes cry { 0%,100% { transform: scale(1.08) translateX(0); } 25% { transform: scale(1.1) translateX(-3px); } 75% { transform: scale(1.1) translateX(3px); } }
@keyframes clear-in { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: scale(1); } }
@keyframes hint-pulse { 50% { opacity: .5; } }

@media (min-width: 461px) {
  body { padding: 20px 0; }
  .app-shell, .screen, .stage { min-height: calc(100svh - 40px); }
  .app-shell { border-radius: 28px; }
}
@media (max-height: 720px) {
  .conversation-ui { gap: 12px; padding-top: 27svh; padding-bottom: max(24px, calc(env(safe-area-inset-bottom) + 14px)); }
  .speech-bubble { padding: 19px 14px 12px; }
  .speech-bubble p { font-size: .92rem; line-height: 1.48; }
  .choice-button { min-height: 48px; padding-block: 9px; font-size: .86rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .choice-button { opacity: 1; transform: none; }
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.start-thumbnail {
  width: 100%; aspect-ratio: 4 / 3; overflow: hidden;
  border-radius: 22px; background: linear-gradient(145deg, var(--pink-100), #f1edf0);
  box-shadow: 0 14px 34px rgba(91, 54, 69, .16);
}
.start-thumbnail img { display: block; width: 100%; height: 100%; object-fit: cover; }
.start-thumbnail img[hidden] { display: none; }
.start-card .lead { margin-top: 24px; }
.start-back-button { margin-top: 10px; }

.result-screen {
  position: relative; isolation: isolate; align-items: flex-start; overflow-y: auto;
  color: #fff; background: linear-gradient(160deg, #d96e95, #7d445a);
}
.result-background { position: absolute; inset: 0; z-index: -2; overflow: hidden; }
.result-background::after {
  content: ""; position: absolute; inset: 0;
  background: rgba(20, 13, 17, .34);
}
.result-background img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: 50% 38%; }
.result-background img[hidden] { display: none; }
.result-card { position: relative; z-index: 1; margin: auto 0; padding: 18px 0; text-shadow: 0 2px 12px rgba(0,0,0,.34); }
.result-card h2, .result-card.is-clear h2 { color: #fff; }
.result-score span { color: rgba(255,255,255,.86); }
.result-screen .medal {
  color: var(--ink); background: rgba(255,255,255,.86);
  border-color: rgba(255,255,255,.72); backdrop-filter: blur(8px); text-shadow: none;
}
.result-screen .medal p { color: #65585e; }
.result-screen .primary-button { text-shadow: none; }
.result-screen .secondary-button {
  color: #fff; border-color: rgba(255,255,255,.7); background: rgba(255,255,255,.18);
  backdrop-filter: blur(6px); text-shadow: 0 1px 6px rgba(0,0,0,.3);
}
