:root {
  --ink: #2b2538;
  --paper: #fff8f3;
  --rose: #f06f91;
  --coral: #ff9b78;
  --mint: #68c7b7;
  --navy: #26315f;
  --gold: #f5c45f;
  --shadow: 0 20px 60px rgba(31, 24, 52, 0.25);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Noto Sans JP", system-ui, sans-serif;
  background:
    linear-gradient(135deg, rgba(38, 49, 95, 0.2), rgba(104, 199, 183, 0.18)),
    #fff4ef;
}

button {
  font: inherit;
}

.game-shell {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
}

.title-screen,
.game-screen {
  display: none;
  min-height: 100vh;
}

.title-screen.is-active,
.game-screen.is-active {
  display: grid;
}

.title-screen {
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 28% 22%, rgba(245, 196, 95, 0.45), transparent 20%),
    linear-gradient(150deg, #26315f 0%, #4d5aa1 42%, #f1a58f 100%);
}

.star-field,
.star-field::before,
.star-field::after {
  position: absolute;
  inset: 0;
  content: "";
  background-image:
    radial-gradient(circle, rgba(255,255,255,0.95) 0 2px, transparent 3px),
    radial-gradient(circle, rgba(245,196,95,0.9) 0 1px, transparent 2px);
  background-position: 20px 30px, 90px 80px;
  background-size: 140px 120px, 190px 150px;
  opacity: 0.55;
  animation: twinkle 4s ease-in-out infinite alternate;
}

.star-field::after {
  animation-delay: 1.4s;
  transform: translateY(8px);
}

.title-content {
  position: relative;
  width: min(760px, 100%);
  color: white;
  text-align: center;
  text-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
}

.title-label {
  margin: 0 0 10px;
  color: #ffe4a5;
  font-weight: 700;
  letter-spacing: 0;
}

.title-content h1 {
  margin: 0;
  font-size: clamp(2.8rem, 8vw, 6.2rem);
  font-weight: 900;
  letter-spacing: 0;
}

.title-copy {
  margin: 18px auto 30px;
  max-width: 620px;
  font-size: 1.05rem;
  line-height: 1.8;
}

.title-actions,
.control-bar {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.primary-button,
.ghost-button,
.choice-button,
.icon-button,
.close-button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.primary-button,
.ghost-button {
  min-width: 160px;
  padding: 12px 22px;
  font-weight: 800;
}

.primary-button {
  color: #371c2a;
  background: linear-gradient(135deg, #fff0a8, #ff9b78);
  box-shadow: 0 12px 28px rgba(55, 28, 42, 0.25);
}

.ghost-button {
  color: white;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.ghost-dark-button {
  min-height: 44px;
  min-width: 140px;
  padding: 12px 20px;
  color: var(--navy);
  font-weight: 800;
  background: white;
  border: 1px solid rgba(38, 49, 95, 0.2);
  border-radius: 8px;
  cursor: pointer;
}

button:hover {
  transform: translateY(-2px);
}

.game-screen {
  grid-template-columns: minmax(0, 1fr) 250px;
  grid-template-rows: minmax(420px, 1fr) auto;
  gap: 18px;
  padding: 18px;
}

.scene-art {
  position: relative;
  grid-column: 1 / 2;
  grid-row: 1 / 2;
  overflow: hidden;
  min-height: 420px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  background: linear-gradient(#7bb6e7 0%, #ffd1b7 58%, #87c58c 58%);
}

.sky {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(0deg, rgba(255, 244, 197, 0.55), transparent 45%),
    repeating-linear-gradient(90deg, transparent 0 70px, rgba(255, 255, 255, 0.12) 70px 72px);
}

.sun {
  position: absolute;
  top: 54px;
  right: 10%;
  width: 86px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #ffe48b;
  box-shadow: 0 0 48px rgba(255, 228, 139, 0.8);
}

.school-building {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 0;
  height: 45%;
  background: #f2d9c9;
  border: 6px solid #d59682;
  border-bottom: 0;
}

.roof {
  position: absolute;
  left: -20px;
  right: -20px;
  top: -52px;
  height: 52px;
  background: #a8506f;
  clip-path: polygon(0 100%, 50% 0, 100% 100%);
}

.windows {
  position: absolute;
  inset: 34px 34px 78px;
  background-image:
    linear-gradient(#7db3cf 0 0),
    linear-gradient(#7db3cf 0 0),
    linear-gradient(#7db3cf 0 0),
    linear-gradient(#7db3cf 0 0),
    linear-gradient(#7db3cf 0 0),
    linear-gradient(#7db3cf 0 0);
  background-position: 0 0, 50% 0, 100% 0, 0 100%, 50% 100%, 100% 100%;
  background-size: 86px 44px;
  background-repeat: no-repeat;
}

.door {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 86px;
  height: 76px;
  transform: translateX(-50%);
  background: #77506a;
  border-radius: 8px 8px 0 0;
}

.character-stage {
  position: absolute;
  left: 50%;
  right: auto;
  bottom: 18px;
  display: flex;
  justify-content: center;
  align-items: end;
  gap: clamp(18px, 5vw, 58px);
  width: min(760px, 94%);
  transform: translateX(-50%);
  pointer-events: none;
}

.character-card {
  width: clamp(190px, 25vw, 310px);
  text-align: center;
  opacity: 0.42;
  transform: scale(0.94);
  transition: opacity 220ms ease, transform 220ms ease;
}

.character-card.is-active {
  opacity: 1;
  transform: scale(1);
}

.character-card p {
  display: inline-block;
  margin: 8px 0 0;
  padding: 4px 18px;
  color: white;
  font-weight: 800;
  background: rgba(38, 49, 95, 0.8);
  border-radius: 999px;
}

.portrait {
  display: block;
  width: 100%;
  height: clamp(270px, 42vh, 430px);
  margin: 0 auto;
  object-fit: contain;
  object-position: center bottom;
  filter: drop-shadow(0 18px 20px rgba(31, 24, 52, 0.3));
}

.portrait.ren {
  object-position: center bottom;
  transform: scale(1.08);
  transform-origin: center bottom;
}

.portrait.aoi {
  object-position: center bottom;
  transform: scale(0.86);
  transform-origin: center bottom;
}

.status-panel {
  grid-column: 2 / 3;
  grid-row: 1 / 2;
  display: grid;
  align-content: start;
  gap: 12px;
}

.status-card,
.dialogue-panel {
  border: 1px solid rgba(43, 37, 56, 0.1);
  border-radius: 8px;
  background: rgba(255, 248, 243, 0.94);
  box-shadow: var(--shadow);
}

.status-card {
  display: grid;
  grid-template-columns: 40px 1fr 34px;
  align-items: center;
  gap: 10px;
  padding: 16px;
  font-weight: 800;
}

.meter {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e9ddd9;
}

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

.dialogue-panel {
  grid-column: 1 / 3;
  grid-row: 2 / 3;
  min-height: 224px;
  padding: 18px;
}

.nameplate {
  display: inline-flex;
  min-width: 96px;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  padding: 4px 16px;
  color: white;
  font-weight: 800;
  background: linear-gradient(135deg, var(--navy), var(--rose));
  border-radius: 8px;
}

.ending-badge {
  display: grid;
  gap: 2px;
  margin-top: 12px;
  padding: 12px 14px;
  color: #371c2a;
  font-weight: 800;
  background: linear-gradient(135deg, #fff0a8, #ffd6e0);
  border: 1px solid rgba(240, 111, 145, 0.32);
  border-radius: 8px;
}

.ending-badge[hidden] {
  display: none;
}

.ending-badge span {
  font-size: 0.86rem;
}

.ending-badge strong {
  font-size: 1.08rem;
}

.dialogue-text {
  min-height: 56px;
  margin: 14px 0;
  font-size: 1.12rem;
  line-height: 1.8;
}

.choices {
  display: grid;
  gap: 10px;
  margin: 10px 0 16px;
}

.choice-button {
  width: 100%;
  padding: 12px 14px;
  color: var(--ink);
  font-weight: 700;
  text-align: left;
  background: white;
  border: 1px solid rgba(43, 37, 56, 0.15);
}

.choice-button:hover {
  background: #fff0e9;
  box-shadow: 0 8px 18px rgba(240, 111, 145, 0.16);
}

.icon-button {
  min-width: 78px;
  padding: 8px 12px;
  color: white;
  font-weight: 800;
  background: #394273;
}

.backlog-modal {
  width: min(680px, calc(100vw - 28px));
  max-height: 78vh;
  border: 0;
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.backlog-modal::backdrop {
  background: rgba(31, 24, 52, 0.45);
}

.ending-modal {
  width: min(420px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  background: transparent;
}

.ending-modal::backdrop {
  background: rgba(31, 24, 52, 0.58);
  backdrop-filter: blur(3px);
}

.ending-modal-content {
  padding: 26px;
  text-align: center;
  background:
    linear-gradient(135deg, rgba(255, 240, 168, 0.92), rgba(255, 214, 224, 0.96)),
    var(--paper);
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.ending-modal-label {
  margin: 0 0 8px;
  color: var(--rose);
  font-size: 0.86rem;
  font-weight: 900;
}

.ending-modal h2 {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.4;
}

.ending-modal p {
  line-height: 1.7;
}

#endingModalType {
  margin: 10px 0 20px;
  font-weight: 800;
}

.ending-modal-actions {
  display: grid;
  gap: 10px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  background: #fff0e9;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.close-button {
  width: 38px;
  min-height: 38px;
  color: white;
  font-size: 1.2rem;
  background: var(--rose);
}

#backlogList {
  margin: 0;
  padding: 18px 34px 24px;
  line-height: 1.8;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 5;
  min-width: 180px;
  padding: 10px 16px;
  color: white;
  text-align: center;
  background: rgba(38, 49, 95, 0.92);
  border-radius: 8px;
  opacity: 0;
  transform: translate(-50%, 12px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes twinkle {
  from {
    opacity: 0.35;
  }
  to {
    opacity: 0.75;
  }
}

@media (max-width: 760px) {
  .game-screen {
    grid-template-columns: 1fr;
    grid-template-rows: 52vh auto auto;
    padding: 10px;
    gap: 10px;
  }

  .scene-art,
  .status-panel,
  .dialogue-panel {
    grid-column: 1;
  }

  .scene-art {
    grid-row: 1;
    min-height: 320px;
  }

  .status-panel {
    grid-row: 2;
    grid-template-columns: 1fr 1fr;
  }

  .dialogue-panel {
    grid-row: 3;
    min-height: 260px;
  }

  .status-card {
    grid-template-columns: 34px 1fr;
  }

  .status-card strong {
    grid-column: 2;
  }

  .windows {
    background-size: 52px 34px;
  }

  .character-stage {
    bottom: 8px;
    gap: 4px;
    width: 100%;
  }

  .character-card {
    width: 49%;
  }

  .portrait {
    height: min(34vh, 250px);
  }

  .portrait.ren {
    transform: scale(1.06);
  }

  .portrait.aoi {
    transform: scale(0.88);
  }

  .dialogue-text {
    font-size: 1rem;
  }
}
