/* 豆豆的书房 —— 配色取自童真水彩绘本视觉系统 */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --paper: #fcfbf7;
  --room: #f6efe2;
  --ink: #3a3f44;
  --ink-soft: #718a99;
  --muted: #9a9187;
  --yellow: #f1c232;
  --orange: #f47b35;
  --red: #d94335;
  --blue: #2e6ead;
  --green: #5ca348;
  --wood: #86583b;
  --wood-light: #b8835a;
  --blush: #e9a49b;
  --radius: 22px;
  --font: "LXGW WenKai Screen", "Kaiti SC", "STKaiti", "KaiTi", "PingFang SC", "Microsoft YaHei", serif;
  /* 细纸纹 */
  --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='g'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.45 0 0 0 0 0.4 0 0 0 0 0.35 0 0 0 0.06 0'/></filter><rect width='100%' height='100%' filter='url(%23g)'/></svg>");
}

html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--room) var(--grain);
  color: var(--ink);
  min-height: 100vh;
  overflow-x: hidden;
}
/* 墙上几团很淡的水彩晕 */
body::before {
  content: "";
  position: fixed; inset: -10%;
  background:
    radial-gradient(38% 30% at 12% 18%, rgba(241, 194, 50, 0.16), transparent 70%),
    radial-gradient(30% 26% at 88% 12%, rgba(46, 110, 173, 0.10), transparent 70%),
    radial-gradient(34% 30% at 80% 85%, rgba(233, 164, 155, 0.14), transparent 70%);
  pointer-events: none;
  z-index: -1;
}

/* #app 盖在 3D 画布上面：自身不接收点击，让手指能点到书；普通页面和浮层上的按钮再各自接收 */
#app { position: relative; z-index: 1; width: 100%; min-height: 100vh; pointer-events: none; }
.screen:not(.overlay) { pointer-events: auto; }
/* 3D 世界铺在最底下；书房首页和阅读器是透明的浮层，只有按钮能点，其余点击穿透到 3D */
.world { position: fixed; inset: 0; z-index: 0; }
.world canvas { display: block; width: 100%; height: 100%; }
.screen.overlay { position: fixed; inset: 0; min-height: 0; padding: 0; background: none; pointer-events: none; animation: none; }
.screen.overlay > * { pointer-events: auto; }
.home-actions {
  position: absolute; left: 0; right: 0; bottom: max(18px, env(safe-area-inset-bottom));
  display: flex; align-items: center; justify-content: center; gap: 18px; pointer-events: none;
}
.home-actions > * { pointer-events: auto; }
.shelf-hint {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); max-width: 80vw;
  background: rgba(252, 251, 247, 0.92); border-radius: 18px; padding: 14px 22px;
  color: var(--ink-soft); font-size: 1.15rem; text-align: center; box-shadow: 0 4px 12px rgba(80, 50, 30, 0.18);
}
.sheet {
  position: absolute; inset: 0; background: rgba(58, 63, 68, 0.35);
  display: flex; align-items: flex-end; justify-content: center; padding: 20px;
}
.sheet-card {
  width: min(760px, 100%); max-height: 70vh; overflow: auto;
  background: var(--paper) var(--grain); border-radius: 24px; padding: 22px 24px 12px;
  display: flex; flex-direction: column; gap: 10px; box-shadow: 0 -6px 30px rgba(80, 50, 30, 0.25);
}
.screen {
  min-height: 100vh;
  padding: max(28px, env(safe-area-inset-top)) 32px 48px;
  display: flex; flex-direction: column; align-items: center; gap: 22px;
  animation: fadein 0.35s ease;
}
.screen-center { justify-content: center; }
.screen-narrow > * { width: 100%; max-width: 640px; }
.screen-narrow > .btn, .screen-narrow > .btn-row { width: auto; }
.hidden { display: none !important; }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.page-title { font-size: 2rem; font-weight: 700; text-align: center; letter-spacing: 0.04em; }
.hint { color: var(--muted); text-align: center; font-size: 1.1rem; }
.section-label { font-size: 1.15rem; color: var(--ink-soft); font-weight: 600; margin-bottom: 10px; }

/* ---------- 按钮 ---------- */
.btn {
  position: relative;
  border: none; border-radius: 999px;
  padding: 14px 28px;
  font: 600 1.2rem var(--font);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.12s, filter 0.2s;
}
.btn:active { transform: scale(0.96) rotate(-0.5deg); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--yellow); box-shadow: 0 3px 0 #d3a61f; }
.btn-blue { background: var(--blue); color: #fff; box-shadow: 0 3px 0 #1f5288; }
.btn-ghost { background: var(--paper); box-shadow: inset 0 0 0 2px #e4dccd; }
.btn-link { background: none; color: var(--muted); text-decoration: underline; text-underline-offset: 4px; font-size: 1.05rem; }
.btn-row { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }

/* 水彩色团（用 wobble 滤镜让边缘不规则） */
.blob { position: absolute; inset: 0; border-radius: 48% 52% 46% 54% / 55% 45% 55% 45%; filter: url(#wobble); }
.blob::after {
  content: ""; position: absolute; inset: 14% 18% 40% 22%;
  border-radius: 50%; background: rgba(255, 255, 255, 0.28); filter: blur(6px);
}
.blob-yellow { background: radial-gradient(circle at 40% 35%, #f8d867, var(--yellow) 60%, #e3ad1c); }
.blob-orange { background: radial-gradient(circle at 40% 35%, #f9a46c, var(--orange) 60%, #e0662a); }

/* ---------- 书房（3D，见 reader/room.js；这里只有浮层按钮） ---------- */
/* 讲新故事大按钮 */
.mic-cta {
  position: relative; border: none; background: none; cursor: pointer;
  width: 300px; height: 112px;
  display: flex; align-items: center; justify-content: center; gap: 14px;
  font: 700 1.6rem var(--font); color: var(--ink);
  transition: transform 0.15s;
}
.mic-cta:active { transform: scale(0.96); }
.mic-cta > :not(.blob) { position: relative; }
.mic-cta-icon { font-size: 2.2rem; }

.drafts { list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.drafts li {
  background: var(--paper); border-radius: 16px; padding: 14px 18px; cursor: pointer;
  box-shadow: inset 0 0 0 2px #ebe3d4; display: flex; flex-direction: column; gap: 4px;
}
.drafts li:active { transform: scale(0.98); }
.drafts .d-name { font-size: 1.15rem; font-weight: 700; }
.drafts .d-status { font-size: 0.95rem; color: var(--muted); }

/* ---------- 起名 / 录音 ---------- */
.title-input {
  width: min(520px, 100%); padding: 16px 22px; font: 1.3rem var(--font);
  border: none; border-radius: 999px; background: var(--paper); color: var(--ink);
  box-shadow: inset 0 0 0 2px #e4dccd; outline: none; text-align: center;
}
.title-input:focus { box-shadow: inset 0 0 0 3px var(--yellow); }

.mic {
  position: relative; width: 190px; height: 190px; border: none; background: none; cursor: pointer;
  transition: transform 0.15s;
}
.mic:active { transform: scale(0.95); }
.mic-icon { position: relative; font-size: 4.6rem; }
.mic.recording .blob { animation: breathe 1.6s ease-in-out infinite; background: radial-gradient(circle at 40% 35%, #ee7a6c, var(--red) 60%, #b8332a); }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08) rotate(3deg); } }
.timer { font-size: 2rem; font-variant-numeric: tabular-nums; color: var(--ink-soft); }

/* 处理中：三滴颜料轮流晕开 */
.brush { position: relative; width: 150px; height: 90px; }
.drop {
  position: absolute; top: 20px; width: 50px; height: 50px; border-radius: 50%;
  filter: url(#wobble); opacity: 0.85; animation: drip 1.8s ease-in-out infinite;
}
.d1 { left: 0; background: var(--yellow); }
.d2 { left: 50px; background: var(--blue); animation-delay: 0.3s; }
.d3 { left: 100px; background: var(--orange); animation-delay: 0.6s; }
@keyframes drip { 0%, 100% { transform: translateY(0) scale(0.85); } 40% { transform: translateY(-16px) scale(1.05); } }

/* ---------- 文字卡片 ---------- */
.paper-card {
  background: var(--paper) var(--grain);
  border-radius: var(--radius); padding: 26px 30px;
  box-shadow: 0 2px 0 #ece4d5, 0 12px 26px -16px rgba(80, 50, 30, 0.3);
}
.big-text { font-size: 1.35rem; line-height: 1.9; }
.story-text { font-size: 1.3rem; line-height: 2.05; white-space: pre-wrap; }
.questions ul { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.questions li {
  background: rgba(241, 194, 50, 0.22); border-radius: 16px; padding: 14px 18px; font-size: 1.25rem;
}
.segments { display: flex; flex-direction: column; gap: 12px; }
.segment-card { background: var(--paper); border-radius: 16px; padding: 14px 16px; box-shadow: inset 0 0 0 2px #ebe3d4; }
.segment-card p { margin-top: 8px; color: var(--ink-soft); font-size: 1.05rem; line-height: 1.7; }
.segment-card audio { width: 100%; }

/* ---------- 绘本工坊 ---------- */
.studio-head {
  width: 100%; max-width: 1100px;
  display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap;
}
.studio-head .page-title { text-align: left; }
.studio-head .hint { text-align: left; }
.cast { width: 100%; max-width: 1100px; display: flex; gap: 10px; flex-wrap: wrap; }
.cast span { background: var(--paper); border-radius: 999px; padding: 6px 14px; font-size: 0.98rem; color: var(--ink-soft); box-shadow: inset 0 0 0 2px #ebe3d4; }
.cast b { color: var(--ink); }
.studio-grid {
  width: 100%; max-width: 1100px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 20px;
}
.studio-page {
  background: var(--paper); border-radius: 16px; overflow: hidden;
  box-shadow: 0 2px 0 #ece4d5, 0 10px 20px -14px rgba(80, 50, 30, 0.35);
  display: flex; flex-direction: column;
}
.studio-page.wide { grid-column: span 2; }
.studio-page.wide .studio-art { aspect-ratio: 2; }
.studio-art { position: relative; aspect-ratio: 1; background: var(--paper) var(--grain); display: flex; align-items: center; justify-content: center; }
.studio-art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.studio-art .waiting { color: var(--muted); font-size: 1rem; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.studio-art .waiting.drawing::before {
  content: ""; width: 44px; height: 44px; border-radius: 50%; background: var(--yellow);
  filter: url(#wobble); animation: drip 1.4s ease-in-out infinite;
}
.studio-art .tag {
  position: absolute; left: 10px; top: 10px; background: rgba(252, 251, 247, 0.92);
  border-radius: 999px; padding: 2px 10px; font-size: 0.9rem; color: var(--ink-soft);
}
.studio-text {
  border: none; resize: none; background: transparent; outline: none;
  font: 1.02rem/1.65 var(--font); color: var(--ink); padding: 12px 14px 4px; min-height: 84px;
}
.studio-text:focus { background: rgba(241, 194, 50, 0.12); }
.studio-actions { display: flex; justify-content: space-between; padding: 4px 8px 10px; }
.studio-actions button {
  border: none; background: none; font: 0.98rem var(--font); color: var(--ink-soft);
  padding: 6px 8px; cursor: pointer; border-radius: 8px;
}
.studio-actions button:active { background: #f1eadc; }
.studio-actions button:disabled { opacity: 0.4; }

/* ---------- 阅读器（3D 书本在 #world 里，控件浮在上面） ---------- */
.reader-bar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2;
  padding: max(14px, env(safe-area-inset-top)) 16px 0;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  pointer-events: none;
}
.reader-bar > * { pointer-events: auto; }
.icon-btn {
  width: 48px; height: 48px; border-radius: 50%; border: none; background: rgba(252, 251, 247, 0.92);
  font-size: 1.3rem; color: var(--ink-soft); cursor: pointer; box-shadow: 0 4px 12px rgba(80, 50, 30, 0.18);
}
.reader-modes { display: flex; background: rgba(252, 251, 247, 0.92); border-radius: 999px; padding: 4px; box-shadow: 0 4px 12px rgba(80, 50, 30, 0.18); }
.mode { border: none; background: none; border-radius: 999px; padding: 9px 20px; font: 600 1.1rem var(--font); color: var(--muted); cursor: pointer; }
.mode.on { background: var(--yellow); color: var(--ink); }
.pageno {
  min-width: 48px; text-align: center; color: var(--ink); font-size: 1rem; white-space: nowrap;
  background: rgba(252, 251, 247, 0.85); border-radius: 999px; padding: 6px 12px;
}
.pageno:empty { visibility: hidden; }
.pill-btn {
  border: none; border-radius: 999px; padding: 10px 18px; cursor: pointer;
  font: 600 1.05rem var(--font); color: var(--ink);
  background: rgba(252, 251, 247, 0.92); box-shadow: 0 4px 12px rgba(80, 50, 30, 0.18);
}
.pill-btn:active { transform: scale(0.95); }
.popup-btn { position: absolute; z-index: 2; left: 0; top: 0; }

.turn {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  width: 56px; height: 56px; border-radius: 50%; border: none; background: rgba(252, 251, 247, 0.9);
  font-size: 2.2rem; line-height: 1; color: var(--ink-soft); cursor: pointer;
  box-shadow: 0 4px 12px rgba(80, 50, 30, 0.2);
}
.turn:active { transform: translateY(-50%) scale(0.92); }
.turn:disabled { visibility: hidden; }
.turn-prev { left: max(12px, env(safe-area-inset-left)); }
.turn-next { right: max(12px, env(safe-area-inset-right)); }

/* 结尾的按钮浮在右页上 */
.reader-end {
  position: absolute; left: 50%; right: 0; top: 50%; z-index: 2;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
@media (max-aspect-ratio: 1/1) {
  .turn { top: auto; bottom: max(24px, env(safe-area-inset-bottom)); transform: none; }
  .turn:active { transform: scale(0.92); }
}

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: rgba(58, 63, 68, 0.94); color: #fff; padding: 12px 24px; border-radius: 999px;
  font-size: 1.05rem; z-index: 20; max-width: 90vw; text-align: center;
}

@media (max-width: 600px) {
  .screen { padding-left: 16px; padding-right: 16px; }
  .page-title { font-size: 1.6rem; }
}
