/* 立體書播放器：羊毛氈童書風。字用霞鶩文楷（接近課本的楷書），注音直排在字的右邊。 */
:root {
  --cream: #fff8ea;
  --paper: #fffcf4;
  --ink: #4b3a33;
  --ink-soft: #7d665b;
  --coral: #c87f68;       /* 磚紅 */
  --coral-deep: #a8654f;
  --sun: #d8b56c;         /* 芥末黃 */
  --sun-deep: #b7944f;
  --teal: #aac7ce;        /* 霧藍 */
  --teal-deep: #7fa3ab;
  --sage: #a9be9b;        /* 鼠尾草綠 */
  --rose: #d7a3a3;        /* 乾燥玫瑰 */
  --line: #eadcc6;        /* 燕麥米 */
  --wood: #9c7254;
  --stitch: rgba(125, 102, 91, 0.35);
  --story: "LXGW WenKai TC", "Kaiti TC", "BiauKai", "DFKai-SB", serif;
}

.cb-player {
  position: relative;
  width: 100%;
  height: min(calc(100svh - 84px), 760px);
  min-height: 460px;
  overflow: hidden;
  background: #f6e6cc;
  border-radius: 28px;
  box-shadow: 0 0 0 8px var(--paper), 0 0 0 10px var(--line), 0 18px 40px rgba(90, 60, 30, 0.22);
  font-family: var(--story);
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.cb-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.cb-trail { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.cb-ui { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.cb-ui button { pointer-events: auto; font: inherit; color: inherit; }
.cb-ui [hidden] { display: none !important; }

/* 注音：字的右邊一欄直排符號；聲調黏在最後一個符號右上方、輕聲點在最上面（台灣課本排法）。聲調用畫的，才夠清楚 */
.zy { display: inline-flex; align-items: center; vertical-align: middle; margin: 0 0.06em 0 0; line-height: 1; }
.zy-c { line-height: 1; }
.zy-r {
  display: inline-flex; align-items: center; height: 1.12em; margin-left: 0.04em;
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif; font-weight: 600; color: var(--ink-soft);
}
.zy-s { display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 0.4em; line-height: 1.02; padding-right: 0.62em; }
.zy-r.n3 .zy-s { font-size: 0.35em; }
.zy-s i { position: relative; font-style: normal; display: block; }
.zy-t { position: absolute; left: 100%; top: -0.12em; width: 0.58em; height: 0.58em; margin-left: 0.04em; background: currentColor; -webkit-mask: var(--tone) center / contain no-repeat; mask: var(--tone) center / contain no-repeat; }
.zy-t.t2 { --tone: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M2.5 8.5 L7.5 1.5' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
.zy-t.t3 { --tone: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M1.8 2 L5 8.3 L8.2 2' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
.zy-t.t4 { --tone: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M2.5 1.5 L7.5 8.5' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
.zy-l { display: block; width: 0.28em; height: 0.28em; border-radius: 50%; background: currentColor; margin-bottom: 0.12em; }
.zy-x { display: inline-block; line-height: 1; vertical-align: middle; }

.no-zy .zy-r { display: none; }

/* ---------- 上方工具列 ---------- */
.cb-top { position: absolute; top: 14px; left: 14px; right: 14px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.cb-title {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  background: var(--paper); padding: 5px 16px 5px 5px; border-radius: 999px;
  box-shadow: 0 3px 0 var(--line), 0 6px 14px rgba(90, 60, 30, 0.12);
}
.cb-tag { background: var(--coral); color: #fff; font-size: 14px; padding: 4px 12px; border-radius: 999px; white-space: nowrap; }
.cb-page-title { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cb-tools { display: flex; gap: 8px; }
.cb-icon {
  width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer; font-size: 19px;
  background: var(--paper); box-shadow: 0 3px 0 var(--line), 0 6px 14px rgba(90, 60, 30, 0.12);
}
.cb-zy-btn { font-family: "PingFang TC", sans-serif; font-weight: 800; font-size: 20px; color: var(--teal-deep); }
.cb-icon.off { opacity: 0.45; }
.cb-icon.off::after { content: ""; position: absolute; }

/* ---------- 提示 ---------- */
.cb-hint {
  position: absolute; top: 72px; left: 50%; transform: translateX(-50%);
  background: var(--sun); padding: 8px 18px; border-radius: 999px; font-size: 18px;
  box-shadow: 0 3px 0 var(--sun-deep), 0 8px 16px rgba(90, 60, 30, 0.18);
  animation: cb-bob 1.6s ease-in-out infinite; white-space: nowrap; max-width: calc(100% - 24px); overflow: hidden;
}
@keyframes cb-bob { 50% { transform: translate(-50%, -4px); } }

/* ---------- 對話卡：像童書的一頁紙，縫線邊框 ---------- */
.cb-card {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  width: min(720px, calc(100% - 28px));
  background: var(--paper); border-radius: 22px; padding: 18px 22px 14px;
  box-shadow: 0 4px 0 var(--line), 0 14px 30px rgba(90, 60, 30, 0.2);
  outline: 2px dashed var(--stitch); outline-offset: -8px;
  pointer-events: auto;
}
.cb-card.choosing { max-height: calc(100% - 76px); overflow-y: auto; }
.cb-who {
  position: absolute; top: -14px; left: 22px;
  font-size: 15px; color: #fff; background: var(--ink-soft); padding: 3px 14px; border-radius: 999px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12);
}
.cb-card[data-who="polly"] .cb-who { background: #6f93b8; }
.cb-card[data-who="anan"] .cb-who { background: #c9a04f; }
.cb-card[data-who="mom"] .cb-who { background: #85a177; }
.cb-card[data-who="mimi"] .cb-who { background: #c08a5e; }
.cb-text { font-size: clamp(24px, 3vw, 30px); line-height: 1.6; min-height: 1.7em; letter-spacing: 0.02em; }
.cb-text.in { animation: cb-in 0.35s ease-out; }
@keyframes cb-in { from { opacity: 0; transform: translateY(6px); } }
.cb-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; margin-top: 10px; }
.cb-actions:empty { display: none; }
.cb-card.choosing .cb-actions { flex-direction: column; align-items: stretch; }

/* ---------- 按鈕：胖胖的毛氈按鈕 ---------- */
.cb-btn {
  border: 0; border-radius: 16px; padding: 10px 20px; font-size: 19px; cursor: pointer; white-space: nowrap;
  background: #fff; box-shadow: 0 4px 0 var(--line); border: 2px solid var(--line);
  transition: transform 0.1s, box-shadow 0.1s;
}
.cb-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.cb-btn.primary { background: var(--coral); color: #fff; border-color: var(--coral-deep); box-shadow: 0 4px 0 var(--coral-deep); }
.cb-btn.primary:active { box-shadow: 0 1px 0 var(--coral-deep); }
.cb-btn.primary .zy-r { color: rgba(255, 255, 255, 0.92); }
.cb-overlay.cover .cb-btn.primary .zy-r { color: var(--ink-soft); }
.cb-btn.big { font-size: 24px; padding: 14px 34px; border-radius: 20px; }
.cb-btn.choice {
  text-align: left; font-size: 24px; padding: 8px 14px; white-space: normal; display: flex; align-items: center; gap: 12px;
  outline: 2px dashed transparent; outline-offset: -6px;
}
.cb-btn.choice:hover { border-color: var(--coral); outline-color: rgba(240, 113, 103, 0.35); }
.cb-choice-key {
  flex: none; width: 34px; height: 34px; border-radius: 50%; background: var(--sun); display: grid; place-items: center;
  font-family: "PingFang TC", sans-serif; font-weight: 800; font-size: 16px; box-shadow: 0 2px 0 var(--sun-deep);
}

/* ---------- 翻頁紙張 ---------- */
.cb-flip {
  position: absolute; inset: 0; background: linear-gradient(90deg, #fffaf0, #f3e3c7);
  transform-origin: left center; transform: perspective(1400px) rotateY(-90deg); opacity: 0;
}
.cb-flip.go { animation: cb-flip 0.9s ease-in-out; }
@keyframes cb-flip {
  0% { transform: perspective(1400px) rotateY(-90deg); opacity: 1; transform-origin: right center; }
  45% { transform: perspective(1400px) rotateY(0deg); opacity: 1; transform-origin: right center; }
  55% { transform: perspective(1400px) rotateY(0deg); opacity: 1; transform-origin: left center; }
  100% { transform: perspective(1400px) rotateY(90deg); opacity: 1; transform-origin: left center; }
}

/* ---------- 疊在畫面上的卡片（封面、結局、想想、完成） ---------- */
.cb-overlay {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 18px;
  background: rgba(74, 53, 49, 0.28); opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
.cb-overlay.show { opacity: 1; pointer-events: auto; }
.cb-panel {
  position: relative; width: min(480px, 100%); max-height: 100%; overflow: auto;
  background: var(--paper); border-radius: 26px; padding: 30px 26px 22px; text-align: center;
  box-shadow: 0 6px 0 var(--line), 0 20px 44px rgba(60, 35, 20, 0.3);
  outline: 2px dashed var(--stitch); outline-offset: -10px;
  transform-origin: left center; transition: transform 0.7s ease-in, opacity 0.7s;
}
.cb-panel h2 { margin: 8px 0 12px; font-size: clamp(30px, 5vw, 40px); font-weight: 700; line-height: 1.35; }
.cb-panel h3 { margin: 16px 0 10px; font-size: 21px; font-weight: 700; }
.cb-panel p { color: var(--ink-soft); line-height: 1.8; margin: 0 0 6px; font-size: 17px; }
.cb-panel-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }

/* 封面：像一本書的封面，左邊有書背，場景和角色露在旁邊 */
.cb-overlay.cover { background: linear-gradient(90deg, rgba(74, 53, 49, 0.18), rgba(74, 53, 49, 0) 60%); place-items: center start; padding: 28px; }
.cb-overlay.cover .cb-panel {
  width: min(470px, 100%); text-align: left; padding: 34px 30px 26px 46px; border-radius: 10px 28px 28px 10px;
  background: linear-gradient(135deg, #bcd4d9, var(--teal)); color: var(--ink); outline-color: rgba(255, 255, 255, 0.75);
  box-shadow: 0 8px 0 var(--teal-deep), 0 24px 48px rgba(40, 70, 80, 0.35);
}
.cb-overlay.cover .cb-panel::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 20px; background: rgba(0, 0, 0, 0.14); border-radius: 10px 0 0 10px; }
.cb-overlay.cover h2 { font-size: clamp(34px, 4.4vw, 46px); white-space: nowrap; text-shadow: 0 2px 0 rgba(255, 255, 255, 0.5); }
.cb-overlay.cover .zy-r { color: var(--ink-soft); }
.cb-overlay.cover p { color: var(--ink); font-size: 17px; }
.cb-overlay.cover .cb-panel-actions { justify-content: flex-start; }
.cb-overlay.cover .cb-btn.primary { background: var(--sun); color: var(--ink); border-color: var(--sun-deep); box-shadow: 0 5px 0 var(--sun-deep); }
.cb-overlay.opening .cb-panel { transform: perspective(1200px) rotateY(-100deg); opacity: 0; }
.cb-cover-tags { display: flex; gap: 8px; }
.cb-cover-tags span { background: rgba(255, 255, 255, 0.9); color: var(--teal-deep); padding: 3px 12px; border-radius: 999px; font-size: 15px; }

/* 結局、完成 */
.cb-ribbon {
  display: inline-block; background: var(--sun); padding: 5px 18px; border-radius: 999px; font-size: 18px;
  box-shadow: 0 3px 0 var(--sun-deep);
}
.cb-count { font-size: 20px; margin-bottom: 10px; }
.cb-count > b { color: var(--coral); font-size: 28px; font-family: "PingFang TC", sans-serif; }
.cb-stars { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 8px; }
.cb-stars li { background: #fff; border: 2px dashed var(--line); border-radius: 14px; padding: 8px; color: #bca78f; font-size: 19px; }
.cb-stars li.got { border-style: solid; border-color: var(--sun); color: var(--ink); background: #fffaeb; }
.cb-note { font-size: 17px; }
.cb-badge {
  width: 104px; height: 104px; margin: 6px auto 4px; border-radius: 50%; display: grid; place-items: center; font-size: 50px;
  background: #eee3d3; filter: grayscale(1); opacity: 0.5;
}
.cb-badge.got {
  background: radial-gradient(circle, #fff4c2, var(--sun)); filter: none; opacity: 1; animation: cb-spin 1s ease-out;
  box-shadow: 0 0 0 6px #fff, 0 0 0 8px var(--sun), 0 0 0 11px #fff; outline: 2px dashed var(--sun-deep); outline-offset: -8px;
}
@keyframes cb-spin { from { transform: scale(0.3) rotate(-30deg); } }

/* 換你想想：心情貼紙＋錄音 */
.cb-think-q { display: flex; gap: 10px; align-items: flex-start; text-align: left; font-size: 22px; line-height: 1.7; background: #edf3f4; border-radius: 16px; padding: 12px 14px; }
.cb-polly-dot { flex: none; font-size: 28px; }
.cb-feelings { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.cb-feeling {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 4px 8px; cursor: pointer;
  background: #fff; border: 2px solid var(--line); border-radius: 18px; box-shadow: 0 3px 0 var(--line); transition: transform 0.15s;
}
.cb-feeling .e { font-size: 38px; line-height: 1.1; }
.cb-feeling .l { font-size: 19px; }
.cb-feeling.on { border-color: var(--coral); background: #fbefea; box-shadow: 0 3px 0 var(--coral-deep); transform: scale(1.06) rotate(-2deg); }
.cb-rec { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.cb-rec-btn {
  border: 0; cursor: pointer; font-size: 20px; padding: 12px 22px; border-radius: 999px;
  background: var(--teal); color: #fff; box-shadow: 0 4px 0 var(--teal-deep);
}
.cb-rec-btn.recording { background: var(--coral); box-shadow: 0 4px 0 var(--coral-deep); animation: cb-pulse 1s ease-in-out infinite; }
@keyframes cb-pulse { 50% { transform: scale(1.06); } }
.cb-privacy { font-size: 13px !important; margin-top: 8px !important; font-family: "PingFang TC", sans-serif; }

/* 想想本 */
.cb-notebook { margin-top: 14px; text-align: left; background: #fffaeb; border-radius: 16px; padding: 6px 14px 10px; border: 2px dashed var(--line); }
.cb-notebook h3 { margin: 8px 0; font-size: 19px; }
.cb-notebook ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.cb-notebook li { display: flex; align-items: center; gap: 10px; font-size: 18px; }
.cb-notebook .d { color: var(--ink-soft); font-family: "PingFang TC", sans-serif; font-size: 14px; min-width: 3.2em; }
.cb-notebook .f { flex: 1; font-size: 22px; }
.cb-mini { border: 0; cursor: pointer; width: 34px; height: 34px; border-radius: 50%; background: var(--teal); color: #fff; font-size: 14px; }

.player-fallback { position: absolute; left: 16px; right: 16px; bottom: 16px; background: #fff; padding: 12px 16px; border-radius: 12px; }

@media (max-width: 640px) {
  .cb-player { height: calc(100svh - 70px); border-radius: 20px; box-shadow: 0 0 0 5px var(--paper), 0 0 0 7px var(--line), 0 10px 24px rgba(90, 60, 30, 0.2); }
  .cb-top { top: 10px; left: 10px; right: 10px; }
  .cb-icon { width: 40px; height: 40px; font-size: 17px; }
  .cb-page-title { font-size: 15px; }
  .cb-card { bottom: 10px; padding: 16px 16px 12px; }
  .cb-text { font-size: 25px; line-height: 1.75; }
  .cb-btn.choice { font-size: 19px; padding: 6px 10px; gap: 8px; }
  .cb-choice-key { width: 28px; height: 28px; font-size: 14px; }
  .cb-card.choosing .cb-text { font-size: 20px; }
  .cb-card.choosing .cb-actions { gap: 7px; margin-top: 6px; }
  .cb-hint { font-size: 16px; top: 62px; }
  .cb-overlay.cover { place-items: end center; padding: 14px; background: linear-gradient(0deg, rgba(74, 53, 49, 0.2), rgba(74, 53, 49, 0) 60%); }
  .cb-overlay.cover .cb-panel { padding: 24px 20px 20px 36px; }
  .cb-overlay.cover p { font-size: 15px; }
  .cb-feeling .e { font-size: 32px; }
}
@media (prefers-reduced-motion: reduce) {
  .cb-hint, .cb-rec-btn.recording { animation: none; }
  .cb-flip.go { animation-duration: 0.01s; }
}
