:root {
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", sans-serif;
  background: #181723;
  color: #fff7eb;
  --rose: #f0b8a8;
  --ink: #1e1b2a;
  --serif: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif CJK JP", serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, input { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:focus-visible, input:focus-visible { outline: 2px solid #ffd3a8; outline-offset: 3px; }

.game {
  position: relative;
  isolation: isolate;
  max-width: 49rem;
  margin: auto;
  background: #262131;
}

.scenery {
  position: absolute;
  z-index: -2;
  inset: 0;
  overflow: hidden;
  background:
    linear-gradient(0deg, #171623 2%, transparent 72%),
    var(--image, none) center / cover,
    linear-gradient(150deg, #222334 16%, #694656 63%, #b47770 100%);
}

.scenery:not(.has-image)::before {
  content: "";
  position: absolute;
  inset: 5% -2% 24% 19%;
  border: .55rem solid #1c1928;
  opacity: .9;
  background:
    repeating-linear-gradient(90deg, transparent 0 26%, #211c2b 26% 27.7%),
    linear-gradient(0deg, transparent 0 38%, #231e2f 38% 40%, transparent 40%),
    linear-gradient(175deg, #25263a 20%, #845968 64%, #dd9d83);
  box-shadow: -2rem 2.3rem 0 #211d2a, 0 0 5rem #1b182b90;
  transform: skewY(-8deg);
}

.scenery:not(.has-image)::after {
  content: "";
  position: absolute;
  inset: 44% 0 22% 0;
  background: repeating-linear-gradient(90deg, #332b40 0 10%, #292639 10% 17%, #4a3548 17% 24%);
  clip-path: polygon(0 50%, 9% 50%, 9% 27%, 18% 27%, 18% 50%, 27% 50%, 27% 36%, 38% 36%, 38% 57%, 49% 57%, 49% 14%, 57% 14%, 57% 49%, 69% 49%, 69% 33%, 77% 33%, 77% 55%, 86% 55%, 86% 21%, 96% 21%, 96% 43%, 100% 43%, 100% 100%, 0 100%);
  opacity: .75;
}

[data-scene="lobby"] .scenery:not(.has-image)::before,
[data-scene="rainOffice"] .scenery:not(.has-image)::before,
[data-scene="rainStreet"] .scenery:not(.has-image)::before,
[data-scene="rainStation"] .scenery:not(.has-image)::before {
  background:
    repeating-linear-gradient(107deg, transparent 0 24px, #ddd5ed35 25px 26px, transparent 27px 32px),
    linear-gradient(145deg, #172433, #55506b 74%, #8e707f);
}

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  padding: max(1rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right))
    max(1.25rem, env(safe-area-inset-bottom)) max(1.25rem, env(safe-area-inset-left));
}

.title-screen {
  display: flex;
  align-items: flex-end;
  background: linear-gradient(0deg, #171522 19%, #21192d2b 75%);
}

.title-content { width: min(100%, 27rem); margin: 16vh auto clamp(1.4rem, 8vh, 5rem); }
h1, h2, p { margin: 0; }
h1, h2 { font-family: var(--serif); font-weight: 600; }
h1 { font-size: clamp(2.05rem, 9.2vw, 4.2rem); line-height: 1.22; letter-spacing: .035em; }
h1 em { color: var(--rose); font-style: normal; }
.title-content p { margin: 1.25rem 0 1.75rem; color: #e5d5d1; font-size: .95rem; }

.primary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .75rem;
  width: 100%;
  min-height: 3.35rem;
  padding: .8rem 1.15rem;
  border: 0;
  border-radius: .3rem;
  background: #edb6a6;
  color: #281e2c;
  font-weight: 700;
}

.centered { display: grid; place-items: center; background: #1a16259c; }
.card, .dialogue { border: 1px solid #b68c934f; background: #221c2cf5; }
.card { width: min(100%, 26rem); border-radius: .5rem; padding: clamp(1rem, 5vw, 2rem); }
.card h2 { font-size: clamp(1.5rem, 7vw, 2.2rem); }
.card p { margin: .8rem 0 1.25rem; line-height: 1.7; }
.card label { display: block; color: #ead8d4; font-size: .9rem; }
input {
  display: block;
  width: 100%;
  padding: .8rem;
  margin: .45rem 0 1rem;
  border: 1px solid #a17e91;
  border-radius: .25rem;
  background: #171522;
  color: inherit;
  font-size: 1rem;
}

.card .error { color: #ffd1bd; margin: -.3rem 0 .8rem; }
.text-button { min-height: 44px; padding: .4rem .65rem; border: 0; background: transparent; color: inherit; }
.card .text-button { display: block; margin: .55rem auto 0; }

.story-screen {
  display: flex;
  flex-direction: column;
  gap: .65rem;
  min-height: 100svh;
  z-index: 1;
}
.story-header { display: flex; align-items: center; z-index: 1; }
.story-header .text-button, .location {
  background: #21192bee;
  border: 1px solid #b68c934f;
  border-radius: .3rem;
}
.speaker, .ending-kind { color: var(--rose); }

/* Keep this layer outside the story screen so dialogue never sizes it. */
.character {
  --portrait-viewport: 100vh;
  --portrait-width: min(105vw, 58vh, 29rem);
  --portrait-height: calc(var(--portrait-width) * 1.5);
  --portrait-inset: calc(max(1.25rem, env(safe-area-inset-bottom)) + .5rem);
  pointer-events: none;
  position: fixed;
  z-index: 0;
  inset: 0 0 auto;
  height: var(--portrait-viewport);
  overflow: hidden;
}

@supports (height: 100svh) {
  .character {
    --portrait-viewport: 100svh;
    --portrait-width: min(105vw, 58svh, 29rem);
  }
}

.game:not([data-screen="story-panel"]) .character { display: none; }

.character.has-image::before {
  content: "";
  position: absolute;
  top: calc(var(--portrait-viewport) - var(--portrait-height) - var(--portrait-inset));
  left: 50%;
  width: var(--portrait-width);
  height: var(--portrait-height);
  background: var(--image, none) center bottom / contain no-repeat;
  transform: translate(calc(-50% + var(--portrait-x, 0%)), var(--portrait-y, 0%));
}

/* Align the eyes of Misaki's expressions against the normal portrait. */
.character[data-character="misaki"][data-expression="angry"] { --portrait-x: -2%; --portrait-y: -3.3%; }
.character[data-character="misaki"][data-expression="blush"] { --portrait-y: -3.3%; }
.character[data-character="misaki"][data-expression="love"] { --portrait-y: -4%; }
.character[data-character="misaki"][data-expression="shy"] { --portrait-y: -2.6%; }
.character[data-character="misaki"][data-expression="smile"] { --portrait-x: -1%; --portrait-y: -.7%; }
.character[data-character="misaki"][data-expression="troubled"] { --portrait-x: -1%; --portrait-y: -.4%; }
:is(.character, .ending-portrait)[data-character="misaki"][data-expression="jito"] { --portrait-y: -2.5%; }
:is(.character, .ending-portrait)[data-character="misaki"][data-expression="pout"] { --portrait-x: -1%; --portrait-y: -1.6%; }
:is(.character, .ending-portrait)[data-character="misaki"][data-expression="laugh"] { --portrait-x: -1.6%; --portrait-y: -1%; }
:is(.character, .ending-portrait)[data-character="misaki"][data-expression="sad"] { --portrait-x: -1.6%; --portrait-y: -3.7%; }
:is(.character, .ending-portrait)[data-character="misaki"][data-expression="surprised"] { --portrait-x: -1.6%; }
:is(.character, .ending-portrait)[data-character="misaki"][data-expression="cold"] { --portrait-x: -2.3%; --portrait-y: -1.6%; }

.portrait {
  position: absolute;
  bottom: 8%;
  left: 50%;
  width: min(82%, 19rem);
  height: min(90%, 25rem);
  transform: translateX(-50%);
  background: linear-gradient(135deg, #625064, #312a3d 65%);
  border-radius: 48% 48% 12% 12% / 65% 65% 7% 7%;
  clip-path: polygon(0 65%, 23% 47%, 39% 40%, 40% 7%, 61% 7%, 63% 40%, 79% 48%, 100% 65%, 100% 100%, 0 100%);
}

.portrait::before {
  content: "";
  position: absolute;
  inset: 0 29% 47%;
  background: linear-gradient(108deg, #312637 17%, #5a414e 59%, #281f31 90%);
  border-radius: 46% 50% 30% 35%;
}

.portrait::after {
  content: "";
  position: absolute;
  inset: 12% 35% 53% 37%;
  border-radius: 45% 40% 48% 46%;
  background: linear-gradient(120deg, #bd8981, #e3ac94 57%, #9f6f77);
  clip-path: polygon(2% 36%, 44% 24%, 62% 0, 77% 20%, 100% 34%, 96% 100%, 0 100%);
}

.character.has-image .portrait { display: none; }
.story-bottom { position: relative; z-index: 1; width: min(100%, 35rem); margin: auto auto 0; }
.location { display: inline-block; margin-bottom: .55rem; padding: .45rem .65rem; font-size: .8rem; }
.dialogue { position: relative; padding: 1rem; border-radius: .4rem; background: #221c2c; box-shadow: 0 .5rem 2rem #100c1999; }
.speaker { min-height: 1.4rem; font-size: .9rem; font-weight: 700; }
.speaker:empty { display: none; }
.line { min-height: 4.2rem; line-height: 1.65; overflow-wrap: anywhere; }
.continue {
  display: flex;
  justify-content: flex-end;
  align-items: flex-end;
  position: absolute;
  inset: 0;
  width: 100%;
  padding: .65rem 1rem;
  border: 0;
  border-radius: inherit;
  background: transparent;
  color: var(--rose);
  font-size: .78rem;
}
.dialogue.can-advance { padding-bottom: 2.35rem; }
.choices { display: grid; gap: .45rem; margin-top: .65rem; }
.choices button {
  min-height: 44px;
  padding: .55rem .65rem;
  text-align: left;
  border: 1px solid #9d7989;
  border-radius: .25rem;
  color: #fff7eb;
  background: #3c2c41;
  font-size: .9rem;
  line-height: 1.4;
}
.ending-kind { font-size: .82rem; font-weight: 700; letter-spacing: .18em; }

.ending-screen {
  --ending-viewport: 100vh;
  --ending-portrait-width: min(105vw, 55vh, 29rem);
  --ending-portrait-height: calc(var(--ending-portrait-width) * 1.5);
  display: grid;
  justify-items: center;
  align-content: end;
  min-height: var(--ending-viewport);
  padding-top: max(env(safe-area-inset-top), clamp(10rem, 38vh, 22rem));
  isolation: isolate;
  overflow: hidden;
}

@supports (height: 100svh) {
  .ending-screen {
    --ending-viewport: 100svh;
    --ending-portrait-width: min(105vw, 55svh, 29rem);
    padding-top: max(env(safe-area-inset-top), clamp(10rem, 38svh, 22rem));
  }
}

.ending-portrait {
  position: absolute;
  top: max(1rem, env(safe-area-inset-top), calc(var(--ending-viewport) - var(--ending-portrait-height) - 5rem));
  left: 50%;
  width: var(--ending-portrait-width);
  height: var(--ending-portrait-height);
  transform: translate(calc(-50% + var(--portrait-x, 0%)), var(--portrait-y, 0%));
  background: var(--image, none) center bottom / contain no-repeat;
  pointer-events: none;
}

.ending-card {
  position: relative;
  z-index: 1;
  display: grid;
  gap: .45rem;
  padding: .75rem 1rem;
  overflow-wrap: anywhere;
  background: #221c2c;
}

.ending-card p {
  margin: 0;
  line-height: 1.55;
}

.ending-card .primary {
  min-height: 44px;
  padding: .5rem .8rem;
  font-size: .95rem;
}

/* Temporary scenery for the first two chapters. */
[data-scene="dayOffice"] .scenery:not(.has-image)::before,
[data-scene="afternoonOffice"] .scenery:not(.has-image)::before,
[data-scene="morningOffice"] .scenery:not(.has-image)::before {
  background:
    repeating-linear-gradient(90deg, transparent 0 26%, #3e4356 26% 27.7%),
    linear-gradient(0deg, transparent 0 38%, #3e4356 38% 40%, transparent 40%),
    linear-gradient(175deg, #607b96 20%, #b1c1d1 64%, #ead5b5);
}

[data-scene="restaurant"] .scenery:not(.has-image)::before {
  border-color: #392428;
  background:
    radial-gradient(ellipse at 25% 22%, #f6c48b 0 2%, transparent 12%),
    radial-gradient(ellipse at 75% 22%, #f6c48b 0 2%, transparent 12%),
    repeating-linear-gradient(90deg, #773f38 0 13%, #452e37 13% 25%);
}

[data-scene="restaurant"] .scenery:not(.has-image)::after {
  background: linear-gradient(#a16a54, #3b2832);
  clip-path: polygon(0 70%, 19% 70%, 19% 57%, 48% 57%, 48% 80%, 68% 80%, 68% 62%, 100% 62%, 100% 100%, 0 100%);
}

.game[data-tone="flashback"] .scenery {
  filter: saturate(.65) brightness(1.16);
}

.scene-transition {
  position: fixed;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(1.25rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right))
    max(1.25rem, env(safe-area-inset-bottom)) max(1.25rem, env(safe-area-inset-left));
  background: #0e0c12;
  color: #fff;
  text-align: center;
  touch-action: manipulation;
}

.game[data-transition="chapter"] .character,
.game[data-transition="chapter"] .story-screen {
  visibility: hidden;
}

.chapter-continue {
  position: absolute;
  inset: 0;
  width: 100%;
  padding: inherit;
  display: grid;
  place-content: center;
  gap: .9rem;
  border: 0;
  background: transparent;
  color: inherit;
}

.chapter-continue:focus-visible {
  outline-offset: -.5rem;
}

.chapter-number {
  font-size: .78rem;
  letter-spacing: .24em;
}

.chapter-title {
  font: 600 clamp(1.5rem, 6.5vw, 2.5rem)/1.4 var(--serif);
}

.chapter-location, .chapter-hint {
  font-size: .85rem;
  color: #ddd3df;
}

.chapter-hint {
  margin-top: 1.55rem;
}

.transition-label {
  font: 500 clamp(1rem, 5vw, 1.4rem)/1.5 var(--serif);
}

.scene-transition[data-type="flashback"] .transition-label {
  color: #f4ded2;
  letter-spacing: .12em;
}

.game[data-cg]:not([data-cg=""]) :is(.scenery, .character) {
  visibility: hidden;
}

.event-cg {
  position: fixed;
  z-index: 0;
  inset: 0 0 auto;
  width: min(100%, 49rem);
  height: 100vh;
  height: 100svh;
  margin-inline: auto;
  overflow: hidden;
  background: #181522;
  pointer-events: none;
}

.event-cg::before,
.event-cg::after {
  content: "";
  position: absolute;
  inset: 0;
}

.event-cg::before {
  background: linear-gradient(#17152299, #171522b3), var(--image, none) center / cover no-repeat;
  filter: blur(1rem);
  transform: scale(1.06);
}

/* Align the full image to the top so faces remain above the dialogue. */
.event-cg::after {
  background: var(--image, none) center top / contain no-repeat;
}

.memories-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 44px;
  margin-top: .65rem;
  padding: .65rem 1rem;
  border: 1px solid #c39caa91;
  border-radius: .45rem;
  color: #ffe0d8;
  background: #241c2ce8;
  font: 500 .85rem var(--serif);
  letter-spacing: .12em;
}

.memories-screen {
  background: linear-gradient(165deg, #221a2bec, #15121cf7);
}

.memories-back {
  margin-left: -.65rem;
}

.memories-header {
  max-width: 30rem;
  margin: .3rem auto .8rem;
  text-align: center;
}

.memories-header h2 {
  margin: 0;
  font: 600 clamp(1.55rem, 7vw, 2rem)/1.25 var(--serif);
  letter-spacing: .08em;
}

.memories-header h2 span {
  display: block;
  margin-top: .28rem;
  color: #e0bec5;
  font-size: .85rem;
  letter-spacing: .04em;
}

#memories-count {
  margin: .7rem 0 .28rem;
  color: #f0bdb0;
  font-size: .7rem;
  letter-spacing: .16em;
}

#memories-progress {
  display: block;
  width: min(100%, 12rem);
  height: .3rem;
  margin: auto;
  appearance: none;
  border: 0;
  border-radius: 1rem;
  overflow: hidden;
  background: #493647;
  color: var(--rose);
}

#memories-progress::-webkit-progress-bar { background: #493647; }
#memories-progress::-webkit-progress-value { background: var(--rose); }
#memories-progress::-moz-progress-bar { background: var(--rose); }

#memory-collections {
  max-width: 30rem;
  margin: 0 auto;
}

.memory-character {
  margin: .8rem 0 .55rem;
  color: #f1d8dc;
  font: 500 .95rem var(--serif);
}

.memory-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .55rem;
}

.memory-card {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  min-height: 44px;
  padding: 0;
  overflow: hidden;
  border: 1px solid #b68c9360;
  border-radius: .45rem;
  background: #2b2233;
  color: inherit;
  text-align: center;
}

.memory-thumb {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1.75;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 15%, #3b2b40, #201927);
  font-size: 1rem;
}

.memory-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 24%;
}

.memory-caption {
  display: grid;
  place-items: center;
  padding: .42rem .25rem;
  font: 500 clamp(.7rem, 3.2vw, .85rem)/1.35 var(--serif);
}

.memory-locked .memory-caption { color: #cbb6ca; }

.memory-viewer {
  position: fixed;
  z-index: 8;
  inset: 0;
  display: grid;
  grid-template-rows: 1fr;
  min-height: 0;
  padding: 0;
  background: #0e0c12;
}

.memory-viewer img {
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
}

.memory-close {
  position: absolute;
  top: max(.65rem, env(safe-area-inset-top));
  right: max(.65rem, env(safe-area-inset-right));
  border: 1px solid #c39caaa0;
  border-radius: .45rem;
  background: #181522ef;
}

.title-save-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .55rem;
}

.title-save-actions button:disabled {
  opacity: .48;
}

.play-menu-button { margin-left: auto; }

.save-dialog {
  width: min(calc(100% - 1.5rem), 30rem);
  max-height: calc(100% - 2rem);
  padding: .9rem;
  border: 1px solid #b68c9380;
  border-radius: .62rem;
  color: #fff4f0;
  background: linear-gradient(160deg, #2b2033, #171321);
  box-shadow: 0 1rem 3rem #09070dd9;
}

.save-dialog::backdrop { background: #110d16b8; }

.save-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .5rem;
}

.save-dialog-header h2 {
  color: var(--rose);
  font: 600 1.16rem var(--serif);
  letter-spacing: .12em;
}

.save-slots, .save-menu-actions { display: grid; gap: .46rem; }

.save-menu-actions .memories-button { margin: 0; }

.save-slot {
  display: flex;
  align-items: center;
  gap: .65rem;
  min-height: 48px;
  padding: .46rem .55rem;
  border: 1px solid #b68c9360;
  border-radius: .42rem;
  background: #2b2233;
  color: inherit;
  text-align: left;
}

.save-slot:disabled { opacity: .58; }

.save-slot-thumb {
  width: 3.75rem;
  aspect-ratio: 4 / 3;
  flex: none;
  overflow: hidden;
  border-radius: .25rem;
  background: #171321;
}

.save-slot-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 24%;
}

.save-slot-details { display: grid; gap: .14rem; font-size: .76rem; overflow-wrap: anywhere; }
.save-slot-number { color: var(--rose); font-size: .7rem; letter-spacing: .12em; }
.save-slot-chapter { font-weight: 600; }
.save-slot-empty, .save-slot-details time { color: #d2becd; }
#save-dialog-status { margin: .6rem 0 0; font-size: .83rem; }
.save-confirm { max-width: 24rem; }
.save-confirm p { margin: .2rem .1rem .8rem; line-height: 1.5; }
.save-confirm-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; }
.save-confirm-actions .primary { width: auto; min-height: 44px; }
