:root {
  color-scheme: light;
  --ink: #1f2528;
  --muted: #627075;
  --paper: #fffaf4;
  --line: rgba(31, 37, 40, 0.16);
  --shadow: 0 22px 60px rgba(29, 44, 51, 0.18);
  --mio: #e86f61;
  --rin: #3c8d93;
  --hina: #d7a441;
  --soft-blue: #b9d9e5;
  --soft-green: #d9e7ca;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #e8edf0;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", Meiryo, system-ui, sans-serif;
  letter-spacing: 0;
  background:
    linear-gradient(135deg, rgba(238, 191, 172, 0.65), rgba(185, 217, 229, 0.55) 45%, rgba(217, 231, 202, 0.6)),
    #edf1ef;
}

button {
  font: inherit;
}

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

.stage {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1120px, 100%);
  height: min(760px, calc(100vh - 40px));
  min-height: 620px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 8px;
  background:
    linear-gradient(rgba(255, 250, 244, 0.18), rgba(255, 250, 244, 0.52)),
    linear-gradient(150deg, #f8c9b9 0%, #f4e7ca 38%, #b9d9e5 66%, #7898a5 100%);
  box-shadow: var(--shadow);
}

.skyline {
  position: absolute;
  inset: auto 0 0;
  display: none;
  align-items: end;
  height: 34%;
  opacity: 0.34;
  pointer-events: none;
}

.skyline span {
  display: block;
  width: 20%;
  border: 1px solid rgba(31, 37, 40, 0.14);
  border-bottom: 0;
  background: rgba(255, 250, 244, 0.58);
}

.skyline span:nth-child(1) { height: 44%; }
.skyline span:nth-child(2) { height: 70%; }
.skyline span:nth-child(3) { height: 52%; }
.skyline span:nth-child(4) { height: 82%; }
.skyline span:nth-child(5) { height: 62%; }

.topbar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 20px;
  padding: 28px;
}

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

.eyebrow {
  margin: 0 0 6px;
  color: #56666b;
  font-size: 0.85rem;
  font-weight: 700;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.75rem, 4vw, 3rem);
  line-height: 1.05;
}

.day-card {
  display: grid;
  width: 76px;
  height: 76px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 244, 0.82);
}

.day-card span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
}

.day-card strong {
  margin-top: -14px;
  font-size: 2rem;
  line-height: 1;
}

.play-area {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 20px;
  min-height: 0;
  padding: 0 28px 28px;
}

.status-panel,
.scene-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 244, 0.86);
  backdrop-filter: blur(16px);
}

.status-panel {
  align-self: stretch;
  padding: 20px;
}

.status-panel h2 {
  margin-bottom: 18px;
  font-size: 1rem;
}

.stats {
  display: grid;
  gap: 16px;
}

.stat-name {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
  font-size: 0.9rem;
  font-weight: 700;
}

.stat-name span:last-child {
  color: var(--muted);
  font-weight: 600;
}

.meter {
  height: 10px;
  overflow: hidden;
  border: 1px solid rgba(31, 37, 40, 0.08);
  border-radius: 999px;
  background: rgba(31, 37, 40, 0.08);
}

.meter-fill {
  height: 100%;
  border-radius: inherit;
  transition: width 240ms ease;
}

.tools {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 24px;
}

.tools button,
.choices button {
  min-height: 44px;
  white-space: nowrap;
  border: 1px solid rgba(31, 37, 40, 0.18);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.74);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.tools button:hover,
.choices button:hover,
.tools button:focus-visible,
.choices button:focus-visible {
  border-color: rgba(31, 37, 40, 0.36);
  background: #fff;
  outline: 3px solid rgba(60, 141, 147, 0.22);
  transform: translateY(-1px);
}

.tools button:disabled,
.choices button:disabled {
  color: rgba(31, 37, 40, 0.46);
  border-color: rgba(31, 37, 40, 0.1);
  background: rgba(255, 255, 255, 0.42);
  cursor: not-allowed;
  transform: none;
}

.tools button[aria-pressed="true"] {
  color: #fff;
  border-color: rgba(31, 37, 40, 0.16);
  background: #2f6f74;
}

.tools button[aria-pressed="true"]:hover,
.tools button[aria-pressed="true"]:focus-visible {
  background: #255d61;
}

.scene-panel {
  display: grid;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  position: relative;
  background:
    linear-gradient(90deg, rgba(18, 26, 30, 0.34), rgba(18, 26, 30, 0.08) 44%, rgba(255, 250, 244, 0.22)),
    var(--scene-bg) center / cover no-repeat,
    rgba(255, 250, 244, 0.86);
}

.scene-panel::before {
  position: absolute;
  inset: 0;
  content: "";
  background:
    linear-gradient(180deg, rgba(255, 250, 244, 0.14), rgba(31, 37, 40, 0.18)),
    radial-gradient(circle at 78% 28%, rgba(255, 250, 244, 0.28), transparent 38%);
  pointer-events: none;
}

.scene-panel::after {
  position: absolute;
  z-index: 2;
  inset: 0;
  content: "";
  opacity: 0;
  pointer-events: none;
  background: rgba(255, 250, 244, 0.34);
}

.scene-panel.is-transitioning::after {
  animation: scene-wash 360ms ease-out both;
}

.scene-panel.is-transitioning .location-strip,
.scene-panel.is-transitioning .scene-visual,
.scene-panel.is-transitioning .choices {
  animation: scene-content-in 320ms ease-out both;
}

.scene-panel[data-menu="true"] .scene-visual {
  grid-template-columns: 1fr;
  place-items: center;
  padding: 42px;
}

.scene-panel[data-menu="true"] .scene-copy {
  width: min(560px, 100%);
  text-align: center;
}

.scene-panel[data-menu="true"] .speaker {
  justify-content: center;
}

.scene-panel[data-menu="true"] .choices {
  grid-template-columns: repeat(2, minmax(0, 220px));
  justify-content: center;
}

.location-strip {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  color: #f8fbfa;
  font-size: 0.92rem;
  font-weight: 700;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.34);
  background: rgba(24, 33, 36, 0.2);
}

.location-strip span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.scene-visual {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(280px, 42%) minmax(0, 1fr);
  align-items: end;
  gap: 22px;
  min-height: 0;
  padding: 24px 28px 18px;
}

.portrait {
  display: grid;
  min-height: 0;
  height: 100%;
  place-items: end center;
  overflow: visible;
}

.portrait svg {
  width: min(100%, 250px);
  max-height: 340px;
  filter: drop-shadow(0 18px 24px rgba(31, 37, 40, 0.16));
}

.sprite {
  display: block;
  width: min(100%, 390px);
  max-height: 462px;
  object-fit: contain;
  object-position: bottom center;
  filter: drop-shadow(0 20px 22px rgba(0, 0, 0, 0.28));
  transform-origin: bottom center;
  animation:
    sprite-enter 340ms ease-out both,
    sprite-breathe 4s ease-in-out 460ms infinite;
}

.motion-happy {
  animation:
    sprite-enter 260ms ease-out both,
    reaction-happy-bounce 520ms ease-out 280ms both,
    sprite-breathe 4s ease-in-out 980ms infinite;
}

.motion-shy,
.motion-worried {
  animation:
    sprite-enter 260ms ease-out both,
    reaction-shy-dip 560ms ease-out 260ms both,
    sprite-breathe 4s ease-in-out 1020ms infinite;
}

.motion-determined {
  animation:
    sprite-enter 260ms ease-out both,
    reaction-determined-lean 520ms ease-out 280ms both,
    sprite-breathe 4s ease-in-out 980ms infinite;
}

.motion-surprised {
  animation:
    sprite-enter 220ms ease-out both,
    reaction-surprised-pop 440ms ease-out 220ms both,
    sprite-breathe 4s ease-in-out 900ms infinite;
}

.sprite-rin {
  width: min(100%, 420px);
}

.sprite-hina {
  width: min(100%, 430px);
}

.scene-copy {
  align-self: center;
  max-width: 650px;
  padding: 20px 22px;
  border: 1px solid rgba(255, 255, 255, 0.46);
  border-radius: 8px;
  background: rgba(255, 250, 244, 0.82);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.16);
  backdrop-filter: blur(12px);
}

.speaker {
  display: inline-flex;
  max-width: 100%;
  margin-bottom: 14px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 700;
  background: #52666b;
  overflow-wrap: anywhere;
}

.dialogue {
  margin-bottom: 0;
  font-size: clamp(1.12rem, 2vw, 1.55rem);
  line-height: 1.78;
  word-break: auto-phrase;
}

.name-entry {
  display: grid;
  grid-template-columns: auto minmax(0, 220px);
  align-items: center;
  gap: 10px;
  margin-top: 18px;
}

.name-entry[hidden] {
  display: none;
}

.name-entry label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.name-entry input {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(31, 37, 40, 0.18);
  border-radius: 8px;
  padding: 8px 11px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.82);
  font: inherit;
}

.name-entry input:focus {
  border-color: rgba(31, 37, 40, 0.36);
  outline: 3px solid rgba(60, 141, 147, 0.22);
  background: #fff;
}

.choices {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 18px;
  border-top: 1px solid var(--line);
  background: rgba(255, 250, 244, 0.78);
  backdrop-filter: blur(12px);
}

.choices button {
  padding: 11px 14px;
  text-align: left;
  line-height: 1.45;
  white-space: normal;
  overflow-wrap: anywhere;
}

.choices button.primary {
  color: #fff;
  border-color: rgba(31, 37, 40, 0.16);
  background: #2f6f74;
}

.choices button.primary:hover,
.choices button.primary:focus-visible {
  background: #255d61;
}

.history-panel {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(31, 37, 40, 0.42);
}

.history-panel[hidden] {
  display: none;
}

.history-dialog {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(680px, 100%);
  max-height: min(680px, calc(100vh - 40px));
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background: rgba(255, 250, 244, 0.96);
  box-shadow: 0 24px 72px rgba(0, 0, 0, 0.24);
}

.history-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.history-header h2 {
  margin-bottom: 0;
  font-size: 1.25rem;
}

.history-header button {
  min-height: 40px;
  padding: 8px 13px;
  border: 1px solid rgba(31, 37, 40, 0.18);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.82);
  cursor: pointer;
}

.history-header button:hover,
.history-header button:focus-visible {
  border-color: rgba(31, 37, 40, 0.36);
  outline: 3px solid rgba(60, 141, 147, 0.22);
  background: #fff;
}

.history-list {
  display: grid;
  gap: 12px;
  min-height: 0;
  margin: 0;
  padding: 18px 20px;
  overflow: auto;
  list-style: none;
}

.history-item {
  padding: 13px 14px;
  border: 1px solid rgba(31, 37, 40, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
}

.history-meta {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.history-item strong {
  display: block;
  margin-bottom: 6px;
  font-size: 0.92rem;
}

.history-text {
  margin-bottom: 0;
  line-height: 1.68;
}

.history-empty {
  margin: 0;
  padding: 0 20px 20px;
  color: var(--muted);
  font-size: 0.94rem;
}

@media (max-width: 820px) {
  body {
    overflow: auto;
  }

  .game-shell {
    padding: 12px;
  }

  .stage {
    height: auto;
    min-height: calc(100vh - 24px);
  }

  .topbar {
    padding: 20px;
  }

  .play-area {
    grid-template-columns: 1fr;
    padding: 0 20px 20px;
  }

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

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

  .scene-visual {
    grid-template-columns: 1fr;
    gap: 6px;
    min-height: 0;
  }

  .portrait {
    min-height: 210px;
  }

  .portrait svg {
    max-height: 220px;
  }

  .sprite {
    max-height: 250px;
  }
}

@media (max-width: 560px) {
  .topbar {
    align-items: stretch;
    gap: 12px;
    padding: 16px;
  }

  h1 {
    font-size: 1.5rem;
    line-height: 1.16;
    overflow-wrap: anywhere;
  }

  .day-card {
    flex: 0 0 auto;
    width: 64px;
    height: 64px;
  }

  .play-area {
    padding: 0 12px 12px;
  }

  .status-panel {
    padding: 16px;
  }

  .stats,
  .choices {
    grid-template-columns: 1fr;
  }

  .scene-visual {
    padding: 18px;
  }

  .scene-copy {
    padding: 16px;
    overflow-wrap: anywhere;
  }

  .name-entry {
    grid-template-columns: 1fr;
  }

  .dialogue {
    font-size: 1.06rem;
    line-height: 1.7;
    overflow-wrap: anywhere;
  }

  .scene-panel[data-menu="true"] .scene-visual {
    padding: 22px 18px;
  }

  .scene-panel[data-menu="true"] .choices {
    grid-template-columns: 1fr;
  }

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

@keyframes sprite-enter {
  from {
    opacity: 0;
    transform: translate3d(-18px, 18px, 0) scale(0.985);
  }

  to {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }
}

@keyframes sprite-breathe {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }

  50% {
    transform: translateY(-5px) scale(1.006);
  }
}

@keyframes reaction-happy-bounce {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }

  35% {
    transform: translateY(-13px) scale(1.018);
  }

  68% {
    transform: translateY(2px) scale(0.996);
  }
}

@keyframes reaction-shy-dip {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
  }

  42% {
    transform: translateY(11px) rotate(-1.4deg);
  }

  72% {
    transform: translateY(5px) rotate(-0.7deg);
  }
}

@keyframes reaction-determined-lean {
  0%,
  100% {
    transform: translateX(0) rotate(0deg);
  }

  45% {
    transform: translateX(10px) rotate(1.4deg);
  }

  72% {
    transform: translateX(4px) rotate(0.6deg);
  }
}

@keyframes reaction-surprised-pop {
  0%,
  100% {
    transform: scale(1);
  }

  34% {
    transform: translateY(-7px) scale(1.026);
  }

  66% {
    transform: translateY(1px) scale(0.992);
  }
}

@keyframes scene-wash {
  0% {
    opacity: 0.72;
  }

  100% {
    opacity: 0;
  }
}

@keyframes scene-content-in {
  from {
    opacity: 0.64;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sprite,
  .scene-panel.is-transitioning::after,
  .scene-panel.is-transitioning .location-strip,
  .scene-panel.is-transitioning .scene-visual,
  .scene-panel.is-transitioning .choices {
    animation: none;
  }
}
