:root {
  color-scheme: dark;
  --ink: #f9f6ef;
  --muted: #cfc5b7;
  --panel: rgba(25, 25, 31, 0.86);
  --panel-strong: rgba(17, 18, 24, 0.94);
  --line: rgba(255, 255, 255, 0.16);
  --accent: #ff9cc6;
  --accent-2: #72d7e7;
  --sunny: #ffd66e;
  --shadow: rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  width: 100vw;
  height: 100vh;
  min-height: 100vh;
  font-family: "Yu Gothic", "Hiragino Sans", "Meiryo", system-ui, sans-serif;
  background: #18171c;
  color: var(--ink);
}

button {
  font: inherit;
}

.game-shell {
  position: relative;
  width: min(100vw, 1280px, calc(100vh * 16 / 9));
  height: min(100vh, 720px, calc(100vw * 9 / 16));
  min-height: 0;
  overflow: hidden;
  background: #15151a;
}

.title-screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  align-content: center;
  justify-items: start;
  gap: clamp(10px, 2.1vh, 18px);
  padding: clamp(22px, 6vw, 72px);
  background:
    linear-gradient(90deg, rgba(255, 156, 198, 0.82), rgba(255, 214, 110, 0.48) 48%, rgba(114, 215, 231, 0.1)),
    url("assets/backgrounds/school_gate.png") center / cover;
  transition: opacity 300ms ease, visibility 300ms ease;
}

.title-screen::before {
  position: absolute;
  inset: 0;
  content: "";
  background:
    radial-gradient(circle at 12% 22%, rgba(255, 255, 255, 0.72) 0 6px, transparent 7px),
    radial-gradient(circle at 24% 18%, rgba(255, 255, 255, 0.52) 0 4px, transparent 5px),
    radial-gradient(circle at 38% 28%, rgba(255, 255, 255, 0.5) 0 5px, transparent 6px),
    linear-gradient(120deg, rgba(19, 18, 28, 0.22), rgba(19, 18, 28, 0.58));
  pointer-events: none;
}

.title-screen.is-closed {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.title-badge,
.logo-title,
.title-copy,
.title-actions,
.story-card {
  position: relative;
  z-index: 1;
}

.title-badge {
  padding: 9px 14px;
  border: 2px solid rgba(255, 255, 255, 0.82);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.24);
  color: #fff;
  font-weight: 700;
  text-shadow: 0 2px 10px rgba(113, 59, 87, 0.42);
  backdrop-filter: blur(10px);
}

.logo-title {
  display: grid;
  gap: 2px;
  margin: 0;
  color: #fff;
  font-weight: 900;
  line-height: 1.02;
  text-shadow:
    0 4px 0 rgba(255, 117, 172, 0.72),
    0 10px 22px rgba(96, 42, 76, 0.38);
}

.logo-title span {
  color: #fff9b8;
  font-size: clamp(30px, 5.5vw, 70px);
}

.logo-title strong {
  color: #fff;
  font-size: clamp(42px, 7.8vw, 96px);
}

.title-copy {
  max-width: 580px;
  margin: 0;
  color: #fff;
  font-size: clamp(17px, 2.4vw, 24px);
  font-weight: 700;
  line-height: 1.6;
  text-shadow: 0 2px 12px rgba(73, 43, 65, 0.5);
}

.title-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.title-actions button {
  min-width: 146px;
  padding: 14px 20px;
  border: 2px solid rgba(255, 255, 255, 0.88);
  border-radius: 999px;
  background: linear-gradient(180deg, #fff, #ffe1ee);
  color: #9c315e;
  font-weight: 900;
  box-shadow: 0 14px 28px rgba(94, 44, 72, 0.24);
  cursor: pointer;
}

.title-actions button:first-child {
  background: linear-gradient(180deg, #fff8aa, #ff9cc6);
  color: #fff;
  text-shadow: 0 2px 8px rgba(133, 45, 91, 0.35);
}

.story-card {
  display: none;
  max-width: 560px;
  padding: 14px 16px;
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  font-weight: 700;
  line-height: 1.7;
  text-shadow: 0 2px 10px rgba(91, 42, 69, 0.42);
  backdrop-filter: blur(12px);
}

.story-card.open {
  display: block;
}

.stage {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.backdrop {
  position: absolute;
  inset: 0;
  background-position: center;
  background-size: cover;
  transform: scale(1.02);
  transition: background-image 500ms ease, filter 500ms ease;
}

.backdrop::after {
  position: absolute;
  inset: 0;
  content: "";
  background:
    linear-gradient(to top, rgba(9, 9, 13, 0.78), rgba(9, 9, 13, 0.08) 58%, rgba(9, 9, 13, 0.24)),
    linear-gradient(90deg, rgba(9, 9, 13, 0.52), rgba(9, 9, 13, 0.06) 52%, rgba(9, 9, 13, 0.25));
}

.scene-label {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 2;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(12, 13, 18, 0.48);
  backdrop-filter: blur(12px);
  color: var(--muted);
  font-size: 12px;
}

.heroine-art {
  position: absolute;
  right: clamp(18px, 7vw, 120px);
  bottom: 29%;
  z-index: 1;
  width: min(33vw, 400px);
  max-height: 58%;
  object-fit: contain;
  filter: drop-shadow(0 24px 40px var(--shadow));
}

.heroine-art.is-hidden {
  opacity: 0;
}

.portrait-cutin {
  position: absolute;
  left: clamp(22px, 6vw, 92px);
  top: 9%;
  z-index: 2;
  width: clamp(150px, 18vw, 230px);
  height: clamp(150px, 18vw, 230px);
  margin: 0;
  overflow: hidden;
  border: 3px solid rgba(255, 255, 255, 0.86);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(255, 156, 198, 0.34), rgba(114, 215, 231, 0.22));
  background-image: url("assets/toka_portrait_grid_2x2.png");
  background-size: 200% 200%;
  background-position: 0 0;
  background-repeat: no-repeat;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
  opacity: 0;
  transform: translateY(8px) scale(0.97);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.portrait-cutin.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.portrait-cutin[data-expression="normal"] {
  background-position: 0 0;
}

.portrait-cutin[data-expression="smile"],
.portrait-cutin[data-expression="blush"] {
  background-position: 100% 0;
}

.portrait-cutin[data-expression="sad"] {
  background-position: 0 100%;
}

.portrait-cutin[data-expression="tear_smile"] {
  background-position: 100% 100%;
}

.dialogue-panel {
  position: absolute;
  left: 50%;
  bottom: 1.5%;
  transform: translateX(-50%);
  z-index: 3;
  width: min(880px, calc(100% - 28px));
  margin: 0;
  padding: clamp(8px, 1.1vh, 11px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(44, 42, 58, 0.32), rgba(18, 18, 26, 0.4));
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(4px);
}

.status-bar {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: clamp(5px, 0.8vh, 8px);
}

.chapter {
  margin: 0 0 4px;
  color: var(--accent-2);
  font-size: 10px;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: clamp(16px, 2vw, 22px);
  font-weight: 700;
  line-height: 1.25;
}

.meters {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 6px;
}

.meters span {
  min-width: 58px;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.text-box {
  min-height: clamp(56px, 10vh, 78px);
  padding: clamp(8px, 1.1vh, 11px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(13, 14, 19, 0.3), rgba(18, 18, 25, 0.38));
  text-shadow: 0 2px 9px rgba(0, 0, 0, 0.86);
}

.speaker {
  margin: 0 0 5px;
  color: var(--accent);
  font-weight: 700;
  font-size: 13px;
}

.line {
  margin: 0;
  font-size: clamp(13px, 1.55vw, 17px);
  line-height: 1.58;
}

.choices {
  display: grid;
  gap: clamp(5px, 0.8vh, 7px);
  margin-top: clamp(5px, 0.8vh, 8px);
}

.choices button,
.controls button,
.log-header button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--ink);
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

.choices button {
  width: 100%;
  padding: clamp(6px, 0.9vh, 8px) 10px;
  text-align: left;
  font-size: 13px;
  line-height: 1.5;
  background:
    linear-gradient(90deg, rgba(255, 156, 198, 0.1), rgba(114, 215, 231, 0.08));
  text-shadow: 0 2px 9px rgba(0, 0, 0, 0.82);
}

.choices button:hover,
.controls button:hover,
.log-header button:hover {
  transform: translateY(-1px);
  border-color: rgba(242, 163, 95, 0.78);
  background: rgba(242, 163, 95, 0.14);
}

.controls {
  display: flex;
  justify-content: end;
  gap: 7px;
  margin-top: clamp(5px, 0.8vh, 8px);
}

.controls button,
.log-header button {
  min-width: 72px;
  padding: 6px 10px;
  font-size: 13px;
}

.log-panel {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 5;
  display: none;
  width: min(420px, calc(100% - 36px));
  max-height: min(520px, calc(100vh - 36px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(10, 11, 15, 0.96);
  box-shadow: 0 24px 60px var(--shadow);
}

.log-panel.open {
  display: block;
}

.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.log-header h2 {
  margin: 0;
  font-size: 18px;
}

.log-content {
  max-height: 420px;
  overflow: auto;
  padding: 14px;
}

.log-entry {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.65;
}

.log-entry strong {
  color: var(--ink);
}

.ending-card {
  border-color: rgba(242, 163, 95, 0.44);
}

.backdrop-ui-polish {
  position: absolute;
  inset: auto 0 0;
  height: 28vh;
  pointer-events: none;
  background: linear-gradient(to top, rgba(7, 7, 10, 0.62), transparent);
}

@media (max-width: 740px) {
  .stage {
    height: 100%;
  }

  .title-screen {
    justify-items: stretch;
  }

  .title-actions button {
    flex: 1;
    min-width: 128px;
  }

  .heroine-art {
    right: -22px;
    width: 58vw;
    bottom: 39%;
    max-height: 45vh;
  }

  .portrait-cutin {
    left: 14px;
    top: 58px;
    width: 132px;
    height: 132px;
  }

  .dialogue-panel {
    width: calc(100% - 18px);
    bottom: 8px;
    padding: 9px;
  }

  .status-bar {
    display: block;
  }

  .meters {
    justify-content: start;
    margin-top: 10px;
  }

  .text-box {
    min-height: 72px;
  }

  .controls {
    justify-content: stretch;
  }

  .controls button {
    flex: 1;
    min-width: 0;
  }
}

@media (max-height: 760px) {
  .scene-label {
    top: 12px;
    left: 12px;
    padding: 6px 10px;
  }

  .heroine-art {
    bottom: 31vh;
    max-height: 56vh;
  }

  .portrait-cutin {
    top: 54px;
    width: 166px;
    height: 166px;
  }

  .dialogue-panel {
    width: min(860px, calc(100% - 24px));
  }

  .chapter {
    font-size: 11px;
  }

  .text-box {
    min-height: 60px;
  }

  .log-content {
    max-height: 330px;
  }
}
