:root {
  --bg: #f6f3ee;
  --panel: #fffdf9;
  --ink: #202722;
  --muted: #747970;
  --line: #ded8ce;
  --accent: #c66a4b;
  --green: #557d68;
  --soft: #f1ece4;
}

* { box-sizing: border-box; }
html, body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--panel);
}
body {
  min-height: 100svh;
  background: var(--panel);
  color: var(--ink);
  font-family: Pretendard, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: manipulation;
}
button, input, select, textarea { font: inherit; }
button { color: inherit; cursor: pointer; }

.phone-app {
  width: 100vw;
  max-width: none;
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  min-height: -webkit-fill-available;
  margin: 0;
  background: var(--panel);
  display: grid;
  grid-template-rows: calc(58px + env(safe-area-inset-top, 0px)) minmax(0, 1fr);
  overflow: hidden;
  border: 0;
}
.phone-app.with-bottom-nav {
  grid-template-rows:
    calc(58px + env(safe-area-inset-top, 0px))
    minmax(0, 1fr)
    calc(68px + env(safe-area-inset-bottom, 0px));
}
.phone-app.story-mode {
  grid-template-rows: minmax(0, 1fr);
}

.app-header {
  display: grid;
  grid-template-columns: 26px 1fr 40px;
  align-items: center;
  padding: env(safe-area-inset-top, 0px) 18px 0;
  column-gap: 0;
  border-bottom: 0;
  background: rgba(255, 253, 249, 0.94);
}
.app-header.has-back {
  grid-template-columns: 34px 1fr 40px;
  column-gap: 8px;
}
.app-header[data-screen="landing"] .brand-logo {
  visibility: hidden;
}
.app-header[data-screen="story"] {
  display: none;
}
.app-header h1 {
  margin: 0;
  text-align: left;
  font-family: Pretendard, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}
.brand-logo {
  color: #527b42;
  font-size: 27px;
  font-weight: 950;
  line-height: 1;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.65);
}
.app-header.has-back .brand-logo {
  font-size: 24px;
}
.brand-logo span {
  position: relative;
  display: inline-block;
}
.brand-logo span:before,
.brand-logo span:after {
  content: "";
  position: absolute;
  display: block;
  background: #5f8a49;
  border-radius: 100% 0 100% 0;
  transform-origin: 0 100%;
}
.brand-logo span:before {
  width: 11px;
  height: 7px;
  right: -9px;
  top: -8px;
  transform: rotate(-22deg);
}
.brand-logo span:after {
  width: 9px;
  height: 6px;
  right: -2px;
  top: -13px;
  background: #7fa85e;
  transform: rotate(40deg);
}
.icon-button {
  border: 0;
  background: transparent;
}
.icon-button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 27px;
  line-height: 1;
  color: #6f756c;
}
.home-button {
  visibility: hidden;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: white;
  color: var(--green);
}
.home-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.screen {
  display: none;
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 22px 18px calc(88px + env(safe-area-inset-bottom, 0px));
  position: relative;
}
.screen.active {
  display: block;
  animation: fade 0.2s ease;
}
@keyframes fade {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}
.screen-title p,
.step-label,
.story-top p {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}
.screen-title h2,
.story-top h2 {
  margin: 0 0 22px;
  font-family: "Gowun Batang", serif;
  font-size: 26px;
  line-height: 1.35;
}

.landing-hero {
  padding: 12px 2px 24px;
}
.landing-hero p {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 900;
}
.landing-hero h2 {
  margin: 0 0 10px;
  font-family: "Gowun Batang", serif;
  font-size: 42px;
  line-height: 1.12;
}
.landing-hero span {
  display: block;
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.55;
}

.tabs {
  height: 44px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--soft);
  border-radius: 10px;
  margin-bottom: 14px;
}
.tabs button {
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 13px;
  font-weight: 800;
}
.tabs button.active { background: white; color: var(--accent); }
.auth-panel {
  display: grid;
  gap: 12px;
  margin-top: 18px;
  padding: 22px 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 12px 36px rgba(61, 45, 28, 0.07);
  text-align: center;
}
.auth-seed-mark {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  justify-self: center;
  border-radius: 18px;
  background: #eef5e9;
  color: var(--green);
  font-size: 22px;
  font-weight: 900;
}
.auth-panel strong {
  color: var(--ink);
  font-size: 18px;
}
.auth-panel p {
  margin: -4px 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.55;
}
.social-login {
  display: grid;
  gap: 9px;
  margin-bottom: 0;
}
.social-login button {
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  color: #2f332f;
  font-weight: 900;
}
.auth-divider {
  position: relative;
  display: grid;
  place-items: center;
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.auth-divider:before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  border-top: 1px solid var(--line);
}
.auth-divider span {
  position: relative;
  padding: 0 10px;
  background: var(--panel);
}

.auth-card,
.summary-card,
.book-page {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
}
.auth-card {
  display: grid;
  gap: 13px;
  padding: 16px;
  margin-bottom: 24px;
}
.hidden { display: none !important; }
label {
  display: grid;
  gap: 7px;
  color: #3f453f;
  font-size: 13px;
  font-weight: 800;
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  outline: none;
}
input, select {
  height: 46px;
  padding: 0 12px;
}
textarea {
  height: 52dvh;
  resize: none;
  padding: 16px;
  line-height: 1.7;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(198, 106, 75, 0.11);
}
.two-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.divider {
  height: 1px;
  background: var(--line);
}
.photo-upload {
  min-height: 142px;
  place-items: center;
  overflow: hidden;
  border: 1.5px dashed #cfc7bb;
  border-radius: 12px;
  background: #f8f5ef;
  position: relative;
}
.photo-upload input {
  position: absolute;
  opacity: 0;
  inset: 0;
}
.photo-upload img {
  display: none;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.photo-upload.has-image img { display: block; }
.photo-upload span {
  z-index: 1;
  color: var(--muted);
  font-weight: 800;
}

.primary-button, .ghost-button {
  height: 48px;
  border-radius: 10px;
  padding: 0 16px;
  font-size: 14px;
  font-weight: 800;
}
.primary-button {
  border: 0;
  background: var(--ink);
  color: white;
}
.ghost-button {
  border: 1px solid var(--line);
  background: white;
}
.bottom-button {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 18px;
  width: calc(100% - 36px);
}
.screen[data-screen="situation"] .bottom-button {
  position: static;
  width: 100%;
  margin-top: 16px;
}

.home-intro {
  margin-bottom: 24px;
}
.screen[data-screen="home"] .home-intro {
  display: none;
}
.home-intro p {
  margin: 0 0 7px;
  color: #76685b;
  font-size: 17px;
  font-weight: 800;
}
.home-intro h2 {
  margin: 0;
  color: #2d241d;
  font-size: 29px;
  line-height: 1.22;
  letter-spacing: 0;
}
.create-story-card {
  width: 100%;
  min-height: 352px;
  border: 0;
  border-radius: 30px;
  margin: 0 0 26px;
  padding: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(180deg, #ffe3a4 0%, #ffd06e 100%);
  box-shadow: 0 18px 44px rgba(195, 137, 55, 0.22);
  text-align: center;
}
.create-story-card:before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 38%;
  background: linear-gradient(180deg, rgba(255, 215, 123, 0.2), #ffc45b 42%, #ffc056);
  z-index: 0;
}
.create-story-visual {
  position: relative;
  width: 100%;
  height: 222px;
  flex: 0 0 222px;
  object-fit: cover;
  object-position: center 50%;
  z-index: 1;
}
.plus-badge {
  position: absolute;
  bottom: 24px;
  left: 50%;
  width: 64px;
  height: 64px;
  transform: translateX(-50%);
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.96);
  color: #ff9a2f;
  font-size: 43px;
  font-weight: 600;
  box-shadow: 0 10px 28px rgba(167, 103, 24, 0.16);
  z-index: 3;
}
.create-story-copy {
  position: relative;
  display: block;
  padding: 24px 18px 88px;
  z-index: 2;
}
.create-story-card strong {
  display: block;
  margin-top: 0;
  color: #34261a;
  font-size: 28px;
  line-height: 1.2;
  position: relative;
}
.create-story-card small {
  display: none;
  margin-top: 9px;
  color: rgba(52, 38, 26, 0.64);
  font-size: 17px;
  font-weight: 800;
  position: relative;
}
.bottom-nav {
  height: calc(68px + env(safe-area-inset-bottom, 0px));
  display: none;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 7px 16px calc(8px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  background: rgba(255, 253, 249, 0.96);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 30px rgba(55, 43, 28, 0.07);
}
.bottom-nav button {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 3px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}
.bottom-nav button.active {
  background: transparent;
  color: #557d3f;
}
.bottom-nav svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.15;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.bottom-nav button.active svg {
  fill: rgba(85, 125, 63, 0.14);
}
.child-manage-list {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}
.coupon-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff8e8;
  padding: 14px;
  margin-bottom: 14px;
}
.coupon-card p {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}
.coupon-card strong {
  color: #573d24;
  font-size: 22px;
}
.coupon-card .primary-button {
  width: auto;
  min-width: 104px;
  padding: 0 14px;
}
.child-manage-card {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
  padding: 12px;
}
.child-manage-card img {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--soft);
}
.child-manage-card h3 {
  margin: 0 0 4px;
  font-size: 15px;
}
.child-manage-card p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
}
.child-actions {
  display: flex;
  gap: 7px;
}
.child-actions button {
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.logout-wide {
  width: 100%;
  margin-top: auto;
  min-height: 44px;
  flex-shrink: 0;
}
#addChildButton {
  margin-bottom: 16px;
}
.screen[data-screen="mypage"].active {
  display: flex;
  flex-direction: column;
}
.screen[data-screen="mypage"].active > * {
  flex-shrink: 0;
}
.section-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.section-row h2 {
  margin: 0;
  font-size: 16px;
}
.section-row .ghost-button {
  height: 34px;
  padding: 0 11px;
  font-size: 12px;
}

.story-list,
.profile-list,
.theme-list {
  display: grid;
  gap: 10px;
  max-height: calc(100dvh - 230px);
  overflow: auto;
  padding-bottom: 12px;
}
.filter-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 0 12px;
}
.filter-chips button {
  flex: 0 0 auto;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  padding: 0 13px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}
.filter-chips button.active {
  border-color: #efc46c;
  background: #fff2d5;
  color: #8f5a1d;
}
.story-item,
.profile-card,
.theme-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: white;
  padding: 13px;
}
.story-item {
  display: grid;
  grid-template-columns: 74px 1fr auto;
  gap: 12px;
  align-items: center;
  text-align: left;
  box-shadow: 0 8px 24px rgba(61, 45, 28, 0.06);
}
.story-item img {
  width: 74px;
  height: 74px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--soft);
}
.story-item h3,
.profile-card h3,
.theme-card h3 {
  margin: 0 0 5px;
  font-size: 15px;
}
.story-item p,
.profile-card p,
.theme-card p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}
.story-item .delete-story-button {
  width: 42px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: #a35b46;
  font-size: 12px;
  font-weight: 900;
}

.companion-card {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
}
.companion-list {
  display: grid;
  gap: 8px;
}
.companion-row {
  display: grid;
  grid-template-columns: 92px 1fr 34px;
  gap: 8px;
  align-items: center;
}
.companion-row select,
.companion-row input {
  height: 40px;
  font-size: 12px;
}
.companion-row button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: white;
  color: #a35b46;
  font-weight: 900;
}
.empty-state {
  padding: 28px 16px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
  text-align: center;
}
.profile-card {
  display: grid;
  grid-template-columns: 62px 1fr;
  gap: 12px;
  align-items: center;
}
.profile-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(198, 106, 75, 0.1);
}
.profile-card img {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--soft);
}

.story-field { position: relative; }
.story-field span {
  position: absolute;
  right: 13px;
  bottom: 12px;
  color: var(--muted);
  font-size: 11px;
}
.theme-card.selected {
  border-color: var(--green);
  background: #f4faf6;
}
.summary-card {
  padding: 16px;
  margin-top: 12px;
}
.summary-card span {
  display: block;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 7px;
}
.summary-card p {
  margin: 0;
  color: #404840;
  font-size: 14px;
  line-height: 1.65;
}

.screen[data-screen="story"] {
  padding: 0 0 calc(116px + env(safe-area-inset-bottom, 0px));
  background: #fffdf9;
}
.story-top {
  position: absolute;
  left: 18px;
  right: 18px;
  top: calc(16px + env(safe-area-inset-top, 0px));
  z-index: 3;
  display: flex;
  justify-content: center;
  gap: 12px;
  pointer-events: none;
}
.story-top > div {
  display: none;
}
.story-top h2 {
  display: none;
}
.story-top > span {
  flex: 0 0 auto;
  min-width: 76px;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid rgba(116, 121, 112, 0.16);
  background: rgba(255, 253, 249, 0.82);
  box-shadow: 0 8px 20px rgba(58, 44, 29, 0.08);
  color: rgba(60, 50, 39, 0.58);
  font-size: 18px;
  font-weight: 800;
  text-align: center;
  backdrop-filter: blur(10px);
}
.story-home-button {
  position: absolute;
  right: 18px;
  top: calc(14px + env(safe-area-inset-top, 0px));
  z-index: 5;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(116, 121, 112, 0.18);
  border-radius: 50%;
  background: rgba(255, 253, 249, 0.86);
  color: var(--green);
  box-shadow: 0 10px 24px rgba(58, 44, 29, 0.1);
  backdrop-filter: blur(10px);
}
.story-home-button svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.story-reader-page {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding-top: calc(72px + env(safe-area-inset-top, 0px));
  background: var(--soft);
  opacity: 1;
  transform: translateX(0);
  transition: opacity 180ms ease, transform 180ms ease;
}
.story-image {
  width: 100%;
  height: auto;
  min-height: 0;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  border-radius: 0;
  background: var(--soft);
  display: block;
}
.book-page {
  min-height: 34vh;
  margin-top: 0;
  padding: 26px 28px 128px;
  overflow: auto;
  background: #fffdf9;
}
.story-reader-page.page-changing,
.dialogue-page.page-changing {
  opacity: 0;
  transform: translateX(10px);
}
.book-page h3 {
  margin: 0 0 8px;
  font-family: "Gowun Batang", serif;
  font-size: 20px;
}
.book-page p {
  margin: 0;
  font-family: "Gowun Batang", serif;
  font-size: 23px;
  line-height: 1.85;
  font-weight: 700;
  color: rgba(42, 35, 28, 0.72);
  word-break: keep-all;
}
.lesson-box {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.55;
}
.lesson-box strong,
.lesson-box span {
  display: block;
}
.lesson-box strong {
  margin-bottom: 6px;
}
.lesson-box span + span {
  margin-top: 4px;
}
.audio-row {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: calc(74px + env(safe-area-inset-bottom, 0px));
  z-index: 4;
  display: grid;
  grid-template-columns: 1fr 1.25fr 76px;
  gap: 8px;
  margin-top: 0;
}
.audio-row button,
.audio-row select {
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: white;
  font-size: 12px;
  font-weight: 800;
}
.page-nav {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  z-index: 4;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.dialogue-page {
  min-height: 100%;
  display: grid;
  align-content: center;
  gap: 22px;
  padding: calc(72px + env(safe-area-inset-top, 0px)) 24px calc(142px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, #fbf2ff 0%, #f4edff 100%);
  opacity: 1;
  transform: translateX(0);
  transition: opacity 180ms ease, transform 180ms ease;
}
.dialogue-page.hidden,
.story-reader-page.hidden {
  display: none;
}
.dialogue-heading {
  text-align: center;
  color: #7d58bd;
}
.dialogue-heading span {
  display: block;
  margin-bottom: 6px;
  font-size: 30px;
}
.dialogue-heading h3 {
  margin: 0 0 8px;
  font-size: 28px;
  line-height: 1.25;
}
.dialogue-heading p {
  margin: 0;
  color: rgba(91, 71, 128, 0.72);
  font-size: 15px;
  font-weight: 900;
}
.dialogue-card {
  padding: 24px 20px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 14px 36px rgba(95, 67, 139, 0.08);
}
.dialogue-card strong {
  display: block;
  margin-bottom: 16px;
  color: #7050aa;
  font-size: 17px;
}
.dialogue-prompts {
  display: grid;
  gap: 16px;
}
.dialogue-prompts p {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 12px;
  align-items: start;
  margin: 0;
  color: rgba(45, 38, 31, 0.78);
  font-size: 16px;
  font-weight: 900;
  line-height: 1.55;
  word-break: keep-all;
}
.dialogue-prompts span {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 12px;
  background: #fff2d0;
}
.dialogue-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.dialogue-actions button {
  min-height: 52px;
  border-radius: 16px;
  font-weight: 900;
}
.dialogue-actions .primary-button {
  grid-column: 1 / -1;
  background: #8c5ccc;
}

.loading {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  place-items: center;
  padding: 18px;
  background:
    linear-gradient(90deg, rgba(255, 243, 220, 0.72), rgba(255, 253, 249, 0.88), rgba(255, 243, 220, 0.72));
}
.loading.visible { display: grid; }
.loading-card {
  position: relative;
  width: min(390px, 100%);
  min-height: min(760px, calc(100dvh - 36px));
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 18px;
  padding: 42px 28px;
  border-radius: 30px;
  background: linear-gradient(180deg, #fff0d9 0%, #ffe9c8 100%);
  box-shadow: 0 24px 80px rgba(108, 76, 39, 0.14);
  overflow: hidden;
}
.loading-close {
  position: absolute;
  left: 22px;
  top: 22px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: rgba(94, 86, 76, 0.28);
  font-size: 36px;
  line-height: 1;
}
.loading-sparkle {
  position: absolute;
  color: rgba(255, 255, 255, 0.95);
  font-size: 32px;
}
.sparkle-a { top: 92px; left: 50%; }
.sparkle-b { top: 250px; left: 74px; color: #ffc86f; }
.sparkle-c { right: 74px; bottom: 250px; color: #ffc86f; }
.loading-book {
  position: relative;
  width: min(260px, 78vw);
  aspect-ratio: 1.3;
  margin: 44px 0 18px;
  display: grid;
  place-items: end center;
}
.loading-book div {
  width: 100%;
  height: 72%;
  border-radius: 22px 22px 18px 18px;
  background:
    radial-gradient(circle at 36% 42%, #ffffff 0 21%, transparent 22%),
    linear-gradient(90deg, #f9d15d 0 8%, #fff 8% 50%, #e9f8ff 50% 92%, #f9d15d 92% 100%);
  box-shadow: 0 16px 24px rgba(181, 122, 31, 0.2);
  transform: perspective(300px) rotateX(7deg);
}
.loading-book span {
  position: absolute;
  right: 8%;
  bottom: 12%;
  width: 66px;
  height: 66px;
  border-radius: 50%;
  background: #f6b25f;
  box-shadow: -46px 4px 0 #f7c48a;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading h2 {
  max-width: 290px;
  margin: 0;
  color: #2f281f;
  font-size: 27px;
  line-height: 1.45;
  text-align: center;
  word-break: keep-all;
}
.loading p {
  margin: 0;
  color: rgba(52, 43, 33, 0.62);
  font-size: 17px;
  font-weight: 900;
}
.loading-progress {
  width: min(320px, 100%);
  height: 14px;
  margin-top: 36px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  overflow: hidden;
}
.loading-progress span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ff6e3d, #ffb13f);
  transition: width 320ms ease;
}
.loading strong {
  color: #db7c30;
  font-size: 18px;
  font-weight: 950;
}
.loading:not(.has-progress) .loading-progress,
.loading:not(.has-progress) #loadingPercent {
  display: none;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  z-index: 60;
  width: min(390px, calc(100vw - 32px));
  transform: translate(-50%, 14px);
  padding: 12px 14px;
  border-radius: 10px;
  background: #202722;
  color: white;
  font-size: 12px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: 0.22s;
}
.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.message-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 70;
  place-items: center;
  padding: 24px;
  background: rgba(37, 31, 24, 0.32);
}
.message-modal.visible {
  display: grid;
}
.message-card {
  width: min(340px, 100%);
  padding: 24px 20px 18px;
  border: 1px solid rgba(114, 86, 54, 0.18);
  border-radius: 18px;
  background: #fffdf9;
  box-shadow: 0 22px 70px rgba(52, 38, 24, 0.22);
  text-align: center;
}
.message-card strong {
  display: block;
  color: var(--ink);
  font-size: 19px;
  line-height: 1.35;
}
.message-card p {
  margin: 12px 0 18px;
  color: #5f5245;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.55;
  white-space: pre-line;
}
.message-card button {
  width: 100%;
}

@media (min-width: 520px) {
  body {
    background: var(--bg);
  }

  .phone-app {
    width: min(100vw, 430px);
    margin: 0 auto;
    border-left: 1px solid rgba(0, 0, 0, 0.05);
    border-right: 1px solid rgba(0, 0, 0, 0.05);
  }
}

@media (max-height: 720px) {
  .screen { padding-top: 16px; }
  .screen-title h2 { font-size: 23px; margin-bottom: 16px; }
  .home-intro { margin-bottom: 16px; }
  .home-intro h2 { font-size: 25px; }
  .create-story-card {
    min-height: 300px;
    border-radius: 24px;
    margin-bottom: 18px;
  }
  .plus-badge {
    bottom: 17px;
    width: 58px;
    height: 58px;
    font-size: 40px;
  }
  .create-story-visual {
    height: 184px;
    flex-basis: 184px;
  }
  .create-story-copy {
    padding: 18px 14px 78px;
  }
  .create-story-card strong {
    margin-top: 0;
    font-size: 23px;
  }
  .create-story-card small { font-size: 14px; }
  .screen[data-screen="story"] { padding-top: 0; }
  .story-reader-page { grid-template-rows: auto minmax(0, 1fr); }
  .story-image { min-height: 0; }
  .book-page { min-height: 31vh; padding: 22px 24px 112px; }
  .book-page p { font-size: 20px; line-height: 1.75; }
  .dialogue-page { padding-top: calc(50px + env(safe-area-inset-top, 0px)); gap: 16px; }
  .dialogue-heading h3 { font-size: 24px; }
  .loading-card { min-height: min(680px, calc(100dvh - 28px)); }
  .loading-book { width: min(220px, 72vw); margin-top: 24px; }
}
