:root {
  --ink: #1b1320;
  --ink-soft: #2d1e28;
  --cream: #fff3e2;
  --paper: #f8ead6;
  --gold: #f3c987;
  --gold-deep: #d39a61;
  --rose: #d28f80;
  --wine: #9d5d5d;
  --night: #100c16;
  --font-serif: "Noto Serif CJK SC", "Songti SC", "STSong", "Yu Mincho", "Noto Serif SC", serif;
  --font-sans: "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", "Yu Gothic", sans-serif;
  --font-mono: "SFMono-Regular", "Cascadia Mono", "Roboto Mono", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #0c0911;
}

body {
  font-family: var(--font-sans);
  color: var(--cream);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse at 50% 16%, rgba(123, 83, 100, 0.28), transparent 48%),
    radial-gradient(ellipse at 50% 100%, rgba(38, 23, 33, 0.9), #09070d 72%);
}

button,
input,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 1px solid rgba(255, 210, 153, 0.8);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.app {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  isolation: isolate;
  background: #17101d;
  --keyboard-inset: 0px;
}

@media (min-width: 560px) {
  .app {
    width: min(430px, 92vw);
    height: min(900px, 94dvh);
    border-radius: 34px;
    box-shadow:
      0 50px 120px rgba(0, 0, 0, 0.65),
      0 0 0 1px rgba(255, 231, 203, 0.08),
      inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  }
}

.app::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 18;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 38%, transparent 38%, rgba(9, 6, 13, 0.14) 70%, rgba(7, 5, 10, 0.44) 100%),
    linear-gradient(180deg, rgba(13, 9, 18, 0.22) 0%, transparent 18%, transparent 62%, rgba(12, 8, 17, 0.28) 100%);
}

.app::after {
  content: "";
  position: absolute;
  inset: -20%;
  z-index: 33;
  pointer-events: none;
  opacity: 0.055;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.8'/%3E%3C/svg%3E");
  animation: grainShift 0.7s steps(2) infinite;
}

/* ---------- boot ---------- */

.boot {
  position: absolute;
  inset: 0;
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background:
    radial-gradient(ellipse at 42% 32%, rgba(239, 181, 135, 0.22), transparent 48%),
    linear-gradient(180deg, #211827 0%, #110c17 76%);
  transition: opacity 0.8s ease;
  pointer-events: none;
}

.boot::before {
  content: "";
  position: absolute;
  width: 68%;
  height: 44%;
  left: 5%;
  top: 13%;
  border: 1px solid rgba(255, 218, 178, 0.16);
  box-shadow:
    inset 0 0 90px rgba(255, 193, 132, 0.05),
    0 0 60px rgba(255, 193, 132, 0.03);
  transform: skewY(-4deg);
}

.boot.is-gone {
  opacity: 0;
}

.boot-star {
  color: #f2c987;
  font-size: 17px;
  text-shadow: 0 0 20px rgba(242, 201, 135, 0.55);
  animation: bootStar 2.4s ease-in-out infinite;
}

.boot-name {
  margin-top: 3px;
  color: #ffeedb;
  font-family: var(--font-serif);
  font-size: 28px;
  letter-spacing: 0.18em;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.45);
}

.boot-name span {
  color: #f6d29b;
}

.boot-sub {
  color: rgba(255, 227, 197, 0.42);
  font-family: var(--font-mono);
  font-size: 7px;
  letter-spacing: 0.28em;
}

.boot-progress {
  display: flex;
  gap: 5px;
  margin-top: 22px;
}

.boot-progress i {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #d8b184;
  opacity: 0.35;
  animation: bootDot 1.4s ease-in-out infinite;
}

.boot-progress i:nth-child(2) {
  animation-delay: 0.18s;
}

.boot-progress i:nth-child(3) {
  animation-delay: 0.36s;
}

@keyframes bootStar {
  0%, 100% { opacity: 0.5; transform: translateY(0) scale(0.92); }
  50% { opacity: 1; transform: translateY(-2px) scale(1.05); }
}

@keyframes bootDot {
  0%, 100% { opacity: 0.25; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-2px); }
}

/* ---------- scene ---------- */

.scene {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: #3b2b36;
}

.scene-svg {
  display: block;
  width: 100%;
  height: 100%;
  transform: scale(1.04);
  transform-origin: 53% 44%;
  filter: saturate(1.06) contrast(1.01) brightness(1.05);
}

.scene-fallback {
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 36% 30%, rgba(255, 213, 159, 0.64), transparent 38%),
    linear-gradient(180deg, #6e566d 0%, #c98f82 42%, #2a1c2b 78%, #120d18 100%);
}

.curtain-left {
  transform-origin: 10% 8%;
  animation: curtainSway 10.5s ease-in-out infinite alternate;
}

.curtain-right {
  transform-origin: 92% 7%;
  animation: curtainSway 12.5s ease-in-out -4s infinite alternate-reverse;
}

.window-glow {
  animation: windowBreathe 9s ease-in-out infinite;
}

.desk {
  transform-origin: center bottom;
  animation: deskBreathe 12s ease-in-out infinite;
}

.dust-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
  overflow: hidden;
  pointer-events: none;
}

.mote {
  position: absolute;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: #ffe5b7;
  box-shadow: 0 0 7px rgba(255, 219, 169, 0.8);
  opacity: 0;
  animation: moteFloat linear infinite;
}

.mote:nth-child(3n) {
  width: 3px;
  height: 3px;
  background: #ffd29a;
}

.mote:nth-child(4n) {
  opacity: 0.25;
}

/* ---------- top bar ---------- */

.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 40;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: calc(16px + env(safe-area-inset-top)) 18px 0;
  pointer-events: none;
}

.topbar::before {
  content: "";
  position: absolute;
  inset: 0 0 -48px;
  z-index: -1;
  background: linear-gradient(180deg, rgba(14, 10, 19, 0.54), transparent);
  pointer-events: none;
}

.identity {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.55);
}

.eyebrow {
  display: block;
  font-family: var(--font-mono);
  font-size: 7.5px;
  line-height: 1.4;
  letter-spacing: 0.28em;
  color: rgba(255, 222, 181, 0.64);
}

.identity h1 {
  margin: 4px 0 3px;
  font-family: var(--font-serif);
  font-size: clamp(20px, 5.5vw, 23px);
  font-weight: 500;
  letter-spacing: 0.12em;
  line-height: 1.1;
  color: #ffefdc;
}

.identity h1 span {
  display: inline-block;
  margin-left: 0.12em;
  color: #ffe0b4;
}

.status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 9.5px;
  letter-spacing: 0.15em;
  color: rgba(255, 236, 216, 0.67);
}

.status i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #cbe0aa;
  box-shadow: 0 0 8px rgba(203, 224, 170, 0.9);
  animation: statusPulse 3.2s ease-in-out infinite;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  pointer-events: auto;
}

.clock {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  color: rgba(255, 239, 221, 0.55);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 231, 206, 0.16);
  background: rgba(29, 20, 31, 0.28);
  color: rgba(255, 240, 222, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  cursor: pointer;
  transition: background 0.25s ease, transform 0.2s ease;
}

.icon-btn svg {
  width: 17px;
  height: 17px;
}

.icon-btn:active {
  transform: scale(0.9);
  background: rgba(255, 226, 193, 0.14);
}

.chapter {
  position: absolute;
  top: 33%;
  right: 9px;
  z-index: 12;
  writing-mode: vertical-rl;
  font-family: var(--font-serif);
  font-size: 8.5px;
  letter-spacing: 0.26em;
  color: rgba(255, 224, 184, 0.36);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

/* ---------- character ---------- */

.character-stage {
  position: absolute;
  top: 6.2%;
  left: 52%;
  z-index: 7;
  width: min(113vw, 488px);
  height: 70.5%;
  transform: translateX(-50%);
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.45s cubic-bezier(0.22, 0.8, 0.25, 1);
}

.character-glow {
  position: absolute;
  left: 50%;
  top: 27%;
  width: 82%;
  height: 58%;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(255, 210, 153, 0.28), rgba(255, 174, 128, 0.06) 48%, transparent 72%);
  filter: blur(24px);
  pointer-events: none;
}

.character {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 22px 32px rgba(12, 7, 14, 0.5));
  animation: characterEnter 1.35s cubic-bezier(0.16, 0.84, 0.23, 1) both;
}

.mio-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  transform-origin: 50% 88%;
}

/* Official art mode: one layered master image, subtle motion only. */
.official-art-wrap {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: auto;
  touch-action: manipulation;
  transform-origin: 50% 100%;
}

.official-art {
  position: absolute;
  inset: 0;
  display: block;
  width: auto;
  height: 100%;
  max-width: 100%;
  margin: 0 auto;
  object-fit: contain;
  object-position: center bottom;
  user-select: none;
  -webkit-user-drag: none;
  filter:
    drop-shadow(0 20px 30px rgba(12, 7, 14, 0.52))
    drop-shadow(0 0 18px rgba(255, 193, 144, 0.08));
  animation: officialBreathe 7.2s ease-in-out infinite;
  transform-origin: 50% 92%;
  transition: opacity 0.32s ease, filter 0.4s ease;
}

.official-art-base {
  opacity: 1;
}

.official-art-pose {
  opacity: 0;
}

.official-art-wrap.mood-pout .official-art-base {
  opacity: 0;
}

.official-art-wrap.mood-pout .official-art-pose {
  opacity: 1;
}

.official-blush {
  position: absolute;
  top: 24.5%;
  width: 9%;
  height: 5.6%;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  filter: blur(2px);
  background: radial-gradient(ellipse, rgba(209, 91, 103, 0.8), rgba(209, 91, 103, 0) 72%);
  mix-blend-mode: multiply;
  transition: opacity 0.35s ease;
}

.official-blush-left {
  left: 38%;
}

.official-blush-right {
  left: 55%;
}

.official-spark {
  position: absolute;
  top: 19%;
  right: 27%;
  color: #f0bea0;
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  text-shadow: 0 0 14px rgba(240, 190, 160, 0.7);
  transition: opacity 0.35s ease;
}

.official-art-wrap.mood-happy .official-art {
  filter:
    drop-shadow(0 20px 30px rgba(12, 7, 14, 0.52))
    drop-shadow(0 0 18px rgba(255, 193, 144, 0.14))
    brightness(1.04)
    saturate(1.05);
}

.official-art-wrap.mood-happy .official-blush {
  opacity: 0.36;
}

.official-art-wrap.mood-happy .official-spark {
  opacity: 0.9;
  animation: sparkle 2.4s ease-in-out infinite;
}

.official-art-wrap.mood-shy .official-blush {
  opacity: 0.68;
}

.official-art-wrap.mood-shy .official-art {
  filter:
    drop-shadow(0 20px 30px rgba(12, 7, 14, 0.52))
    drop-shadow(0 0 18px rgba(255, 172, 148, 0.14))
    brightness(1.03);
}

.official-art-wrap.mood-worried .official-art {
  filter:
    drop-shadow(0 20px 30px rgba(12, 7, 14, 0.52))
    saturate(0.88)
    brightness(0.96);
}

.official-art-wrap.mood-pout .official-art {
  filter:
    drop-shadow(0 20px 30px rgba(12, 7, 14, 0.52))
    saturate(0.94)
    brightness(0.99);
}

.official-art-wrap.action-tilt {
  animation: officialTilt 1.15s ease both;
}

.official-art-wrap.action-nod {
  animation: officialNod 0.8s ease both;
}

.official-art-wrap.action-shy {
  animation: officialShy 1.3s ease both;
}

.official-art-wrap.action-wave {
  animation: officialWave 1.2s ease both;
}

.official-art-wrap.action-lean {
  animation: officialLean 1.3s ease both;
}

.official-art-wrap.is-thinking {
  animation: officialThink 2.2s ease-in-out infinite;
}

@keyframes officialBreathe {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-2px) scale(1.004); }
}

@keyframes officialTilt {
  0% { transform: rotate(0); }
  35% { transform: rotate(-2.2deg) translateY(1px); }
  70% { transform: rotate(-1.1deg) translateY(1px); }
  100% { transform: rotate(0); }
}

@keyframes officialNod {
  0%, 100% { transform: translateY(0); }
  38% { transform: translateY(8px); }
  68% { transform: translateY(2px); }
}

@keyframes officialShy {
  0% { transform: rotate(0) translateY(0); }
  38% { transform: rotate(1.8deg) translateY(5px); }
  100% { transform: rotate(0) translateY(0); }
}

@keyframes officialWave {
  0%, 100% { transform: rotate(0); }
  30% { transform: rotate(-1.8deg); }
  55% { transform: rotate(1.2deg); }
  75% { transform: rotate(-0.8deg); }
}

@keyframes officialLean {
  0%, 100% { transform: translateY(0) scale(1); }
  38% { transform: translateY(9px) scale(1.008); }
}

@keyframes officialThink {
  0%, 100% { transform: rotate(0) translateY(0); }
  35% { transform: rotate(0.9deg) translateY(-2px); }
  70% { transform: rotate(-0.6deg) translateY(-1px); }
}

@keyframes sparkle {
  0%, 100% { opacity: 0.35; transform: scale(0.85) rotate(0); }
  50% { opacity: 1; transform: scale(1.1) rotate(12deg); }
}

.mio-svg .head {
  transform-box: view-box;
  transform-origin: 320px 450px;
  animation: headFloat 7s ease-in-out infinite;
}

.mio-svg .body {
  transform-box: view-box;
  transform-origin: 320px 740px;
  animation: bodyBreathe 6.2s ease-in-out infinite;
}

.mio-svg .back-hair {
  transform-box: view-box;
  transform-origin: 320px 260px;
  animation: hairSway 8.5s ease-in-out infinite alternate;
}

.mio-svg .front-hair {
  transform-box: view-box;
  transform-origin: 320px 200px;
  animation: fringeSway 7.8s ease-in-out -2s infinite alternate;
}

.mio-svg .arm-left {
  transform-box: view-box;
  transform-origin: 180px 560px;
  animation: armRest 6.2s ease-in-out infinite;
}

.mio-svg .arm-wave {
  transform-box: view-box;
  transform-origin: 460px 560px;
  animation: armRest 6.2s ease-in-out -1.5s infinite;
}

.mio-svg .mouth {
  opacity: 0;
  transition: opacity 0.2s ease;
}

.mio-svg .mouth-calm {
  opacity: 1;
}

.mio-svg .eyes-open {
  opacity: 1;
  transition: opacity 0.22s ease;
}

.mio-svg .eyes-happy,
.mio-svg .eyes-soft {
  opacity: 0;
  transition: opacity 0.22s ease;
}

.mio-svg .blush {
  opacity: 0.38;
  transition: opacity 0.4s ease;
}

.mio-svg .brow {
  transform-box: view-box;
  transition: transform 0.3s ease;
}

.mio-svg .brow-left {
  transform-origin: 278px 268px;
}

.mio-svg .brow-right {
  transform-origin: 365px 265px;
}

.mio-svg .blink-lids {
  opacity: 0;
  animation: blink 7.2s infinite;
}

.mio-svg.mood-happy .eyes-open {
  opacity: 0;
}

.mio-svg.mood-happy .eyes-happy {
  opacity: 1;
}

.mio-svg.mood-happy .mouth-calm,
.mio-svg.mood-shy .mouth-calm,
.mio-svg.mood-curious .mouth-calm {
  opacity: 0;
}

.mio-svg.mood-happy .mouth-smile {
  opacity: 1;
}

.mio-svg.mood-happy .blush,
.mio-svg.mood-shy .blush {
  opacity: 0.95;
}

.mio-svg.mood-shy .eyes-open {
  opacity: 0;
}

.mio-svg.mood-shy .eyes-soft {
  opacity: 1;
}

.mio-svg.mood-shy .mouth-pout {
  opacity: 0;
}

.mio-svg.mood-shy .mouth-smile {
  opacity: 1;
}

.mio-svg.mood-shy .brow-left {
  transform: translateY(-2px) rotate(-2deg);
}

.mio-svg.mood-shy .brow-right {
  transform: translateY(-2px) rotate(2deg);
}

.mio-svg.mood-curious .mouth-open {
  opacity: 1;
}

.mio-svg.mood-curious .brow-right {
  transform: translateY(-5px) rotate(-5deg);
}

.mio-svg.mood-worried .brow-left {
  transform: rotate(9deg) translateY(-1px);
}

.mio-svg.mood-worried .brow-right {
  transform: rotate(-9deg) translateY(-1px);
}

.mio-svg.mood-worried .mouth-frown {
  opacity: 1;
}

.mio-svg.mood-worried .mouth-calm {
  opacity: 0;
}

.mio-svg.mood-pout .mouth-pout {
  opacity: 1;
}

.mio-svg.mood-pout .mouth-calm {
  opacity: 0;
}

.mio-svg.mood-pout .brow-left {
  transform: rotate(-5deg) translateY(2px);
}

.mio-svg.mood-pout .brow-right {
  transform: rotate(5deg) translateY(2px);
}

.mio-svg.mood-pout .blush {
  opacity: 0.5;
}

.mio-svg.action-tilt .head {
  animation: headTilt 1.15s ease both;
}

.mio-svg.action-nod .head {
  animation: headNod 0.8s ease both;
}

.mio-svg.action-shy .head {
  animation: headShy 1.3s ease both;
}

.mio-svg.action-wave .arm-wave {
  animation: waveHand 1.45s cubic-bezier(0.2, 0.8, 0.3, 1) both;
}

.mio-svg.action-lean .mio-root {
  transform-box: view-box;
  transform-origin: 50% 100%;
  animation: leanIn 1.3s ease both;
}

.mio-svg.is-thinking .head {
  animation: thinkTilt 2.2s ease-in-out infinite;
}

/* speech bubble */

.speech-bubble {
  position: absolute;
  z-index: 9;
  right: 11%;
  top: 45%;
  max-width: 48%;
  padding: 10px 13px;
  border-radius: 16px 16px 16px 5px;
  background: rgba(250, 238, 222, 0.97);
  color: #35222a;
  font-family: var(--font-serif);
  font-size: 12.5px;
  line-height: 1.65;
  letter-spacing: 0.02em;
  box-shadow:
    0 14px 32px rgba(13, 8, 15, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
  transform-origin: left bottom;
  animation: bubbleIn 0.38s cubic-bezier(0.18, 0.9, 0.26, 1.18) both;
}

.speech-bubble::after {
  content: "";
  position: absolute;
  left: -7px;
  bottom: 5px;
  width: 13px;
  height: 13px;
  background: rgba(250, 238, 222, 0.97);
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
  transform: rotate(12deg);
}

.speech-bubble.is-leaving {
  animation: bubbleOut 0.28s ease both;
}

/* ---------- chat ---------- */

.chat-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--keyboard-inset);
  z-index: 20;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  height: 49%;
  padding: 0 15px calc(10px + env(safe-area-inset-bottom));
  background:
    linear-gradient(180deg, rgba(15, 11, 20, 0) 0%, rgba(15, 11, 20, 0.45) 11%, rgba(15, 11, 20, 0.88) 25%, rgba(15, 11, 20, 0.97) 44%, #0f0b15 72%);
  transition: height 0.25s ease;
}

.chat-fade {
  position: absolute;
  left: 0;
  right: 0;
  top: -1px;
  height: 60px;
  background: linear-gradient(180deg, transparent, rgba(15, 11, 20, 0.48));
  pointer-events: none;
}

.chat-log {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 11px;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 27px 2px 4px;
  scrollbar-width: none;
  overscroll-behavior: contain;
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 22px, #000 100%);
  mask-image: linear-gradient(180deg, transparent 0, #000 22px, #000 100%);
  scroll-behavior: smooth;
}

.chat-log::-webkit-scrollbar {
  display: none;
}

.chat-spacer {
  flex: 1 0 2px;
}

.day-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  margin-bottom: 1px;
  font-family: var(--font-serif);
  font-size: 8.5px;
  letter-spacing: 0.18em;
  color: rgba(255, 226, 194, 0.38);
}

.day-divider::before,
.day-divider::after {
  content: "";
  height: 1px;
  flex: 1;
  background: linear-gradient(90deg, transparent, rgba(255, 220, 184, 0.18));
}

.day-divider::after {
  background: linear-gradient(90deg, rgba(255, 220, 184, 0.18), transparent);
}

.msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex: 0 0 auto;
  max-width: 100%;
  animation: messageRise 0.42s cubic-bezier(0.2, 0.8, 0.24, 1) both;
}

.msg-mio {
  padding-right: 11%;
}

.msg-user {
  justify-content: flex-end;
  padding-left: 14%;
}

.msg-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  margin-bottom: 2px;
  border-radius: 50%;
  color: #f8d59a;
  background: rgba(38, 25, 38, 0.82);
  border: 1px solid rgba(255, 212, 164, 0.23);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22);
  font-size: 10px;
}

.msg-bubble {
  position: relative;
  min-width: 0;
  word-break: break-word;
  white-space: pre-wrap;
}

.msg-mio .msg-bubble {
  padding: 10px 13px 9px;
  border-radius: 4px 16px 16px 16px;
  background:
    linear-gradient(180deg, rgba(250, 239, 224, 0.98), rgba(239, 222, 204, 0.97));
  color: #32212a;
  box-shadow:
    0 10px 24px rgba(0, 0, 0, 0.19),
    inset 0 1px 0 rgba(255, 255, 255, 0.72);
  font-family: var(--font-serif);
  font-size: 13.5px;
  line-height: 1.72;
  letter-spacing: 0.015em;
}

.msg-mio .msg-bubble::before {
  content: "";
  position: absolute;
  left: -6px;
  bottom: 4px;
  width: 12px;
  height: 13px;
  background: #f3e3cf;
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
  transform: rotate(10deg);
}

.msg-user .msg-bubble {
  padding: 9px 13px;
  border-radius: 15px 4px 15px 15px;
  background: rgba(83, 54, 63, 0.78);
  border: 1px solid rgba(255, 214, 174, 0.17);
  color: #fff0e3;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-size: 13px;
  line-height: 1.6;
}

.msg-proactive .msg-bubble {
  border: 1px solid rgba(218, 166, 109, 0.28);
  background:
    linear-gradient(180deg, rgba(252, 241, 224, 0.98), rgba(235, 215, 193, 0.98));
}

.msg-speaker {
  display: block;
  margin-bottom: 2px;
  font-family: var(--font-mono);
  font-size: 7px;
  line-height: 1.2;
  letter-spacing: 0.22em;
  color: rgba(121, 78, 64, 0.56);
}

.msg-proactive .msg-speaker::after {
  content: " · 主动来找你";
  letter-spacing: 0.08em;
  opacity: 0.68;
}

.typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 19px;
  padding: 0 2px;
}

.typing-bubble i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #9e7164;
  animation: typingDot 1.15s ease-in-out infinite;
}

.typing-bubble i:nth-child(2) {
  animation-delay: 0.16s;
}

.typing-bubble i:nth-child(3) {
  animation-delay: 0.32s;
}

/* ---------- composer ---------- */

.composer {
  position: relative;
  z-index: 3;
  flex: 0 0 auto;
  padding-top: 5px;
}

.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  min-height: 53px;
  padding: 6px 6px 6px 16px;
  border-radius: 27px;
  background:
    linear-gradient(180deg, rgba(255, 246, 234, 0.105), rgba(255, 246, 234, 0.065));
  border: 1px solid rgba(255, 226, 193, 0.2);
  box-shadow:
    0 15px 38px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.09);
  backdrop-filter: blur(24px) saturate(125%);
  -webkit-backdrop-filter: blur(24px) saturate(125%);
  transition: border-color 0.25s ease, background 0.25s ease;
}

.composer:focus-within .composer-inner {
  border-color: rgba(255, 216, 169, 0.42);
  background:
    linear-gradient(180deg, rgba(255, 246, 234, 0.135), rgba(255, 246, 234, 0.08));
}

#input {
  flex: 1;
  min-width: 0;
  max-height: 94px;
  margin: 0;
  padding: 9px 0 7px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: #fff2e4;
  font-family: var(--font-sans);
  font-size: 14.5px;
  line-height: 1.55;
  letter-spacing: 0.01em;
  scrollbar-width: none;
}

#input::-webkit-scrollbar {
  display: none;
}

#input::placeholder {
  color: rgba(255, 238, 220, 0.38);
  letter-spacing: 0.03em;
}

.send-btn {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 41px;
  height: 41px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(145deg, #f8d89c, #d99677);
  color: #3d252a;
  box-shadow:
    0 6px 18px rgba(194, 121, 93, 0.36),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
  cursor: pointer;
  transition: transform 0.18s ease, opacity 0.2s ease, filter 0.2s ease;
}

.send-btn svg {
  width: 19px;
  height: 19px;
  margin: 1px 0 0 1px;
}

.send-btn:active {
  transform: scale(0.9);
  filter: brightness(0.94);
}

.send-btn:disabled {
  opacity: 0.42;
  cursor: default;
}

.composer-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 8px 0;
  font-family: var(--font-mono);
  font-size: 7.5px;
  letter-spacing: 0.16em;
  color: rgba(255, 231, 207, 0.34);
}

#modeLabel {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.mode-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #d8b58a;
  box-shadow: 0 0 6px rgba(216, 181, 138, 0.75);
}

.enter-hint {
  opacity: 0.7;
}

/* ---------- settings sheet ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 4, 9, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fadeIn 0.25s ease both;
}

.sheet-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 520px;
  max-height: min(88dvh, 820px);
  padding: 0 20px calc(20px + env(safe-area-inset-bottom));
  border-radius: 28px 28px 0 0;
  background:
    radial-gradient(ellipse at 80% 0%, rgba(143, 92, 84, 0.24), transparent 38%),
    linear-gradient(180deg, #211724, #130e19 58%);
  border: 1px solid rgba(255, 226, 199, 0.12);
  border-bottom: 0;
  box-shadow: 0 -30px 80px rgba(0, 0, 0, 0.6);
  animation: sheetUp 0.42s cubic-bezier(0.18, 0.85, 0.22, 1) both;
  overflow: hidden;
}

@media (min-width: 560px) {
  .sheet {
    align-items: center;
    padding: 20px;
  }

  .sheet-card {
    border-radius: 28px;
    border-bottom: 1px solid rgba(255, 226, 199, 0.12);
    animation-name: sheetIn;
  }
}

.sheet-grab {
  width: 34px;
  height: 3px;
  margin: 9px auto 4px;
  border-radius: 4px;
  background: rgba(255, 235, 214, 0.2);
}

.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 12px 0 17px;
  border-bottom: 1px solid rgba(255, 230, 205, 0.09);
}

.sheet-head h2 {
  margin: 4px 0 0;
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: #fff0df;
}

.sheet-close {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid rgba(255, 232, 208, 0.13);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 239, 220, 0.7);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.settings-scroll {
  max-height: calc(min(88dvh, 820px) - 92px);
  overflow-y: auto;
  padding: 17px 1px 2px;
  scrollbar-width: none;
}

.settings-scroll::-webkit-scrollbar {
  display: none;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 14px;
}

.field > span {
  font-size: 10px;
  letter-spacing: 0.12em;
  color: rgba(255, 229, 204, 0.62);
}

.field input {
  width: 100%;
  height: 42px;
  padding: 0 13px;
  border-radius: 12px;
  border: 1px solid rgba(255, 226, 199, 0.13);
  background: rgba(255, 247, 235, 0.055);
  color: #fff0e2;
  font-size: 13px;
  letter-spacing: 0.02em;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.field input::placeholder {
  color: rgba(255, 232, 210, 0.28);
  font-size: 11.5px;
}

.field input:focus {
  border-color: rgba(255, 206, 154, 0.45);
  background: rgba(255, 247, 235, 0.075);
  outline: 0;
}

.field-group {
  margin: 7px 0 18px;
  padding: 15px 14px 4px;
  border-radius: 16px;
  border: 1px solid rgba(255, 229, 202, 0.1);
  background: rgba(255, 247, 235, 0.025);
}

.group-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}

.group-title > span {
  font-family: var(--font-serif);
  font-size: 13px;
  letter-spacing: 0.08em;
  color: #ffe7cf;
}

.group-title em {
  font-style: normal;
  font-family: var(--font-mono);
  font-size: 7.5px;
  letter-spacing: 0.06em;
  color: rgba(255, 219, 177, 0.5);
}

.field-note {
  margin: 0 0 11px;
  font-size: 10px;
  line-height: 1.7;
  color: rgba(255, 229, 205, 0.38);
}

.settings-actions {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-top: 2px;
}

.primary-btn,
.ghost-btn {
  width: 100%;
  height: 44px;
  border-radius: 13px;
  font-size: 12px;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.primary-btn {
  border: 0;
  background: linear-gradient(135deg, #f5d49e, #d99b79);
  color: #3a2428;
  box-shadow: 0 8px 24px rgba(180, 112, 86, 0.26);
}

.ghost-btn {
  border: 1px solid rgba(255, 227, 199, 0.13);
  background: transparent;
  color: rgba(255, 229, 204, 0.6);
}

.privacy-note {
  margin: 17px 0 0;
  font-size: 9.5px;
  line-height: 1.75;
  color: rgba(255, 228, 203, 0.3);
}

.version-line {
  margin-top: 16px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 7px;
  letter-spacing: 0.16em;
  color: rgba(255, 229, 205, 0.2);
}

/* ---------- toast ---------- */

.toast {
  position: absolute;
  left: 50%;
  bottom: 96px;
  z-index: 120;
  max-width: 82%;
  padding: 8px 13px;
  border: 1px solid rgba(255, 228, 197, 0.16);
  border-radius: 10px;
  background: rgba(25, 16, 26, 0.9);
  color: rgba(255, 238, 218, 0.82);
  font-size: 10.5px;
  line-height: 1.5;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(12px);
  transform: translateX(-50%);
  animation: toastIn 0.3s ease both;
}

/* ---------- keyboard / short screens ---------- */

body.keyboard-open .character-stage {
  opacity: 0.38;
  transform: translateX(-50%) translateY(-18px) scale(0.94);
}

body.keyboard-open .chapter {
  opacity: 0;
}

@media (max-height: 720px) {
  .character-stage {
    top: 3.5%;
    height: 70%;
    width: min(112vw, 470px);
  }

  .chat-panel {
    height: 54%;
    padding-left: 13px;
    padding-right: 13px;
  }

  .topbar {
    padding-top: calc(11px + env(safe-area-inset-top));
  }

  .identity h1 {
    font-size: 19px;
  }

  .chat-log {
    gap: 9px;
    padding-top: 23px;
  }

  .msg-mio {
    padding-right: 7%;
  }

  .msg-mio .msg-bubble {
    font-size: 12.8px;
    line-height: 1.66;
  }

  .composer-inner {
    min-height: 48px;
  }

  .send-btn {
    width: 38px;
    height: 38px;
  }

  .speech-bubble {
    top: 43%;
    font-size: 11.5px;
  }
}

@media (max-height: 620px) {
  .character-stage {
    top: 1.5%;
    height: 66%;
  }

  .chat-panel {
    height: 59%;
  }

  .identity h1 {
    font-size: 17px;
  }

  .status {
    font-size: 8px;
  }

  .chapter {
    display: none;
  }

  .composer-meta {
    display: none;
  }

  .chat-panel {
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 360px) {
  .topbar {
    padding-left: 14px;
    padding-right: 14px;
  }

  .chat-panel {
    padding-left: 12px;
    padding-right: 12px;
  }

  .msg-mio {
    padding-right: 3%;
  }

  .msg-user {
    padding-left: 8%;
  }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }

  .mio-svg .blink-lids {
    opacity: 0;
  }
}

/* ---------- keyframes ---------- */

@keyframes characterEnter {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes headFloat {
  0%, 100% { transform: translateY(0) rotate(-0.3deg); }
  50% { transform: translateY(-4px) rotate(0.6deg); }
}

@keyframes bodyBreathe {
  0%, 100% { transform: scaleY(1) translateY(0); }
  50% { transform: scaleY(1.008) translateY(-1px); }
}

@keyframes hairSway {
  from { transform: rotate(-0.8deg); }
  to { transform: rotate(0.9deg); }
}

@keyframes fringeSway {
  from { transform: rotate(-0.55deg) translateX(-1px); }
  to { transform: rotate(0.65deg) translateX(1px); }
}

@keyframes armRest {
  0%, 100% { transform: rotate(0); }
  50% { transform: rotate(-0.7deg); }
}

@keyframes blink {
  0%, 90.5%, 94.2%, 100% { opacity: 0; }
  91.8%, 93% { opacity: 1; }
}

@keyframes statusPulse {
  0%, 100% { opacity: 0.55; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1.1); }
}

@keyframes curtainSway {
  from { transform: skewX(-0.4deg) scaleX(1); }
  to { transform: skewX(1.2deg) scaleX(1.012); }
}

@keyframes windowBreathe {
  0%, 100% { opacity: 0.92; }
  50% { opacity: 1; }
}

@keyframes deskBreathe {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(1px); }
}

@keyframes moteFloat {
  0% {
    opacity: 0;
    transform: translate3d(0, 16px, 0) scale(0.6);
  }
  18% { opacity: var(--mote-opacity, 0.35); }
  80% { opacity: var(--mote-opacity, 0.35); }
  100% {
    opacity: 0;
    transform: translate3d(var(--mote-drift, 22px), -92px, 0) scale(1.05);
  }
}

@keyframes grainShift {
  0% { transform: translate(0, 0); }
  25% { transform: translate(-1.5%, 1%); }
  50% { transform: translate(1%, -1.5%); }
  75% { transform: translate(1.5%, 1.5%); }
  100% { transform: translate(0, 0); }
}

@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(8px) scale(0.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes bubbleOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(-4px) scale(0.97); }
}

@keyframes messageRise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30% { transform: translateY(-3px); opacity: 1; }
}

@keyframes sheetUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@keyframes sheetIn {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes headTilt {
  0% { transform: rotate(0); }
  32% { transform: rotate(-4deg) translateY(1px); }
  70% { transform: rotate(-2.4deg) translateY(1px); }
  100% { transform: rotate(0); }
}

@keyframes headNod {
  0%, 100% { transform: translateY(0); }
  35% { transform: translateY(7px) rotate(1deg); }
  65% { transform: translateY(2px); }
}

@keyframes headShy {
  0% { transform: rotate(0); }
  38% { transform: rotate(3.5deg) translateY(5px); }
  100% { transform: rotate(0); }
}

@keyframes waveHand {
  0% { transform: rotate(0); }
  22% { transform: rotate(-36deg); }
  40% { transform: rotate(-29deg); }
  58% { transform: rotate(-38deg); }
  75% { transform: rotate(-28deg); }
  100% { transform: rotate(0); }
}

@keyframes leanIn {
  0% { transform: translateY(0) scale(1); }
  40% { transform: translateY(8px) scale(1.018); }
  100% { transform: translateY(0) scale(1); }
}

@keyframes thinkTilt {
  0%, 100% { transform: rotate(0) translateY(0); }
  30% { transform: rotate(1.6deg) translateY(-2px); }
  65% { transform: rotate(-1deg) translateY(-1px); }
}
