/* 听图：暖纸色、墨色、深青。正在说的话永远是最大的字。 */

@font-face {
  font-family: "TingTu Serif";
  src: local("Songti SC"), local("Source Han Serif SC"), local("Noto Serif CJK SC"), local("Noto Serif SC");
  font-display: swap;
}

@font-face {
  font-family: "TingTu Sans";
  src: local("PingFang SC"), local("Hiragino Sans GB"), local("Source Han Sans SC"), local("Noto Sans CJK SC"), local("Microsoft YaHei");
  font-display: swap;
}

:root {
  --paper: #f3efe6;
  --card: #fffcf7;
  --ink: #1a1814;
  --muted: #6b6459;
  --hair: #ded5c4;
  --teal: #0e6b66;
  --clay: #b4623f;
  --serif: "TingTu Serif", "Songti SC", "Noto Serif SC", "Source Han Serif SC", serif;
  --sans: "TingTu Sans", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", system-ui, sans-serif;
  --margin: clamp(20px, 5vw, 64px);
}

* { box-sizing: border-box; }

/* 元素自带的 display 会盖掉 hidden 属性，统一兜住 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

body {
  background-image: radial-gradient(circle at 20% 10%, #fbf7ef 0%, transparent 55%),
                    radial-gradient(circle at 85% 0%, #f7f1e4 0%, transparent 45%);
  background-attachment: fixed;
  /* 底部常驻提示条，正文别被它压住 */
  padding-bottom: 58px;
}

.skip {
  position: absolute; left: -999px;
  background: var(--ink); color: var(--card); padding: 12px 18px; border-radius: 8px;
}
.skip:focus { left: 16px; top: 16px; z-index: 50; }

/* 顶栏 */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding: clamp(18px, 2.4vw, 28px) var(--margin) 0;
}

.brand { display: flex; align-items: baseline; gap: 12px; }
.brand-name {
  font-family: var(--serif);
  font-size: clamp(22px, 2vw, 26px);
  letter-spacing: 0.08em;
}
.brand-sub {
  font-size: 13px; letter-spacing: 0.22em; color: var(--muted);
}

.status {
  display: inline-flex; align-items: center; gap: 9px;
  font-size: 14px; color: var(--muted);
}
.status-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--hair);
  transition: background 200ms ease;
}
.status[data-state="listening"] { color: var(--teal); }
.status[data-state="listening"] .status-dot {
  background: var(--teal);
  animation: pulse 1.8s ease-in-out infinite;
}
.status[data-state="speaking"] { color: var(--teal); }
.status[data-state="speaking"] .status-dot { background: var(--teal); }
.status[data-state="error"] { color: var(--clay); }
.status[data-state="error"] .status-dot { background: var(--clay); }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.82); }
}

/* 场景 */
main { padding: 0 var(--margin) clamp(24px, 4vw, 56px); }

.scene { animation: rise 420ms ease both; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* 搜索场景：一张占六成视高的居中卡片 */
.scene-search {
  min-height: calc(100vh - 150px);
  display: grid; place-items: center;
}

.welcome {
  width: min(860px, 100%);
  min-height: min(64vh, 680px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(18px, 2.6vw, 30px);
  padding: clamp(28px, 5vw, 60px) clamp(22px, 4vw, 52px);
  background: var(--card);
  border: 1px solid var(--hair);
  border-radius: 26px;
  box-shadow: 0 1px 0 #fff inset, 0 24px 60px -46px rgba(26, 24, 20, 0.5);
  text-align: center;
}

/* 听写环 */
.ring {
  position: relative;
  width: clamp(120px, 15vh, 196px); height: clamp(120px, 15vh, 196px);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid rgba(14, 107, 102, 0.35);
}
.ring-halo {
  position: absolute; inset: -18px; border-radius: 50%;
  border: 1px solid rgba(14, 107, 102, 0.14);
}
.ring .bar {
  display: inline-block;
  width: 3px;
  border-radius: 2px;
  background: rgba(14, 107, 102, 0.55);
  transform-origin: center;
  margin: 0 3.5px;
}
.ring .bar.b1 { height: 16%; }
.ring .bar.b2 { height: 30%; }
.ring .bar.b3 { height: 42%; }
.ring .bar.b4 { height: 30%; }
.ring .bar.b5 { height: 16%; }

.ring.breathing { animation: breathe 5.2s ease-in-out infinite; }
@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(14, 107, 102, 0.10); }
  50% { box-shadow: 0 0 0 16px rgba(14, 107, 102, 0.05); }
}

/* 正在发声时，环内的短条跟着动 */
.is-live .ring .bar { animation: bars 1.05s ease-in-out infinite; }
.is-live .ring .bar.b1 { animation-delay: 0ms; }
.is-live .ring .bar.b2 { animation-delay: 110ms; }
.is-live .ring .bar.b3 { animation-delay: 220ms; }
.is-live .ring .bar.b4 { animation-delay: 330ms; }
.is-live .ring .bar.b5 { animation-delay: 440ms; }

@keyframes bars {
  0%, 100% { transform: scaleY(0.6); opacity: 0.6; }
  50% { transform: scaleY(1.15); opacity: 1; }
}

/* 大字 */
.big {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(30px, 3.6vw, 58px);
  line-height: 1.45;
  letter-spacing: 0.01em;
  max-width: 20em;
  text-wrap: balance;
}

/* 当前位置 */
.where {
  display: inline-flex; align-items: baseline; gap: 10px;
  font-size: 14px; color: var(--muted);
  padding: 7px 14px;
  border: 1px solid var(--hair);
  border-radius: 999px;
  background: #fbf7ef;
}
.where-value { color: var(--ink); letter-spacing: 0.04em; }
.where-label { letter-spacing: 0.14em; }

/* 可以这样说 */
.examples {
  display: flex; flex-wrap: wrap; gap: 10px 12px; justify-content: center;
  margin: 0; padding: 0; list-style: none;
}
.examples li {
  font-size: 15px; color: var(--muted);
  padding: 8px 15px;
  border: 1px dashed var(--hair);
  border-radius: 999px;
}

/* 检索结果 */
.results {
  width: min(560px, 100%);
  margin: 4px 0 0; padding: 0; list-style: none;
  text-align: left;
  display: grid; gap: 2px;
}
.results[hidden] { display: none; }
.results li {
  display: grid;
  grid-template-columns: 56px 1fr;
  align-items: baseline;
  gap: 4px 12px;
  padding: 14px 18px 14px 16px;
  border-left: 2px solid transparent;
  border-radius: 0 12px 12px 0;
  color: var(--ink);
  transition: border-color 180ms ease, background 180ms ease;
}
.results .no {
  font-family: var(--serif);
  font-size: 30px; color: var(--muted); line-height: 1;
}
.results .title { font-size: 19px; }
.results .meta { grid-column: 2; font-size: 13px; color: var(--muted); }
.results li.current {
  border-left-color: var(--teal);
  background: #faf5ea;
}
.results li.current .no { color: var(--teal); }
.results li.current::after {
  content: "正在说";
  grid-column: 2;
  font-size: 12px; letter-spacing: 0.12em; color: var(--teal);
}

/* 看图场景 */
.scene-page {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: clamp(24px, 3.4vw, 52px);
  align-items: start;
  padding-top: clamp(12px, 2vw, 24px);
  max-height: calc(100vh - 120px);
}
.scene-page[hidden] { display: none; }

.frame {
  margin: 0;
  background: var(--card);
  border: 1px solid var(--hair);
  border-radius: 20px;
  padding: clamp(18px, 2.2vw, 30px);
  box-shadow: 0 1px 0 #fff inset, 0 26px 70px -58px rgba(26, 24, 20, 0.55);
}
.frame-label {
  font-size: 12px; letter-spacing: 0.2em; color: var(--muted);
  margin-bottom: 14px;
}
.frame-image {
  background: #fff; border-radius: 10px; overflow: hidden;
  display: grid; place-items: center;
  min-height: 200px;
}
.frame-image img {
  display: block; width: 100%; height: auto;
  /* 给图片一个可见的底色，加载中被当成「有内容」，不会看着像空白卡住 */
  background: #fff;
}
.frame-image img[hidden] { display: none; }
.frame-fail {
  margin: 0; padding: 28px 20px;
  font-size: 15px; line-height: 1.7; color: var(--muted);
  text-align: center; max-width: 24em;
}
.frame-fail[hidden] { display: none; }

.narration {
  display: flex; flex-direction: column; gap: clamp(16px, 2vw, 24px);
  min-height: 62vh;
  justify-content: center;
}
.narration .line { text-align: left; max-width: 20em; }

.frame { position: sticky; top: 24px; align-self: start; }
.narration .dialogue { max-height: 26vh; margin-top: auto; }
.where-page { align-self: flex-start; }

/* 对话留痕 */
.dialogue {
  margin: 0; padding: 0; list-style: none;
  display: grid; gap: 12px;
  max-height: 30vh; overflow: auto;
  scrollbar-width: thin;
}
.dialogue li { font-size: 15px; line-height: 1.6; color: var(--muted); }
.dialogue li::before {
  content: attr(data-who);
  display: inline-block;
  margin-right: 8px; font-size: 12px; letter-spacing: 0.1em;
  color: var(--hair);
}
.dialogue li:first-child { color: var(--ink); font-size: 17px; }
.dialogue li:first-child::before { color: var(--teal); }

.ring-small {
  width: 44px; height: 44px; border-color: rgba(14, 107, 102, 0.3);
  margin-top: auto;
}
.ring-small .ring-halo { inset: -7px; }
.ring-small .bar { width: 2px; margin: 0 1.5px; }
.ring-small .bar.b1 { height: 22%; }
.ring-small .bar.b2 { height: 34%; }
.ring-small .bar.b3 { height: 44%; }
.ring-small .bar.b4 { height: 34%; }
.ring-small .bar.b5 { height: 22%; }

/* 开始前的遮罩 */
.gate {
  position: fixed; inset: 0; z-index: 30;
  display: grid; place-items: center;
  padding: 24px;
  background: rgba(243, 239, 230, 0.86);
  backdrop-filter: blur(6px);
}
.gate[hidden] { display: none; }
.gate-card {
  width: min(460px, 100%);
  text-align: center;
  background: var(--card);
  border: 1px solid var(--hair);
  border-radius: 22px;
  padding: 34px 30px;
  box-shadow: 0 30px 80px -60px rgba(26, 24, 20, 0.6);
  display: grid; gap: 12px;
}
.gate-title {
  margin: 0; font-family: var(--serif); font-size: clamp(26px, 3vw, 34px);
}
.gate-hint { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.6; }

/* 登录表单 */
.gate-field {
  display: grid; gap: 6px; text-align: left;
  margin-top: 4px;
}
.gate-label { font-size: 13px; letter-spacing: 0.12em; color: var(--hair); }
.gate-input {
  font: inherit; font-size: 16px;
  padding: 12px 14px;
  border: 1px solid var(--hair); border-radius: 12px;
  background: #fffdf9; color: var(--ink);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
.gate-input:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(14, 107, 102, 0.16);
}
.gate-input:disabled { opacity: 0.6; }
.gate-button {
  margin: 10px auto 0;
  font: inherit; font-size: 17px;
  padding: 13px 30px; border-radius: 999px;
  border: 1px solid var(--teal); background: var(--teal); color: #fff;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease;
}
.gate-button:hover { background: #0b5a56; }
.gate-button:active { transform: scale(0.98); }
.gate-button:focus-visible { outline: 3px solid rgba(14, 107, 102, 0.35); outline-offset: 3px; }
.gate-note { margin: 4px 0 0; font-size: 13px; color: var(--muted); min-height: 1.2em; }

/* 出错提示 */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  z-index: 40;
  max-width: min(560px, calc(100% - 32px));
  padding: 14px 20px;
  background: var(--ink); color: var(--card);
  border-radius: 12px; font-size: 15px; line-height: 1.5;
  box-shadow: 0 18px 40px -30px rgba(0, 0, 0, 0.6);
}
.toast[hidden] { display: none; }

/* 演示提示条：常驻底部，随当前页面换台词 */
.coach {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; align-items: baseline; flex-wrap: wrap;
  gap: 8px 14px;
  padding: 10px var(--margin);
  background: rgba(255, 252, 247, 0.94);
  border-top: 1px solid var(--hair);
  backdrop-filter: blur(8px);
  font-size: 14px;
  color: var(--muted);
}
.coach-label {
  flex: none;
  font-size: 12px; letter-spacing: 0.18em; color: var(--hair);
}
.coach-list {
  display: flex; flex-wrap: wrap; gap: 6px 10px;
  margin: 0; padding: 0; list-style: none;
}
.coach-list li {
  padding: 4px 11px;
  border: 1px solid var(--hair);
  border-radius: 999px;
  color: var(--ink);
  white-space: nowrap;
}
.toast { bottom: 78px; }

/* 窄屏：先字幕，再图 */
@media (max-width: 860px) {
  .scene-page { grid-template-columns: 1fr; max-height: none; }
  .frame { position: static; }
  .scene-search { min-height: auto; padding-top: 3vh; }
  .welcome { min-height: auto; padding: 28px 22px 30px; }
  .narration { order: 1; min-height: auto; gap: 14px; }
  .frame { order: 2; }
  .ring-small { display: none; }
  .dialogue { max-height: 22vh; }
  .results li { grid-template-columns: 40px 1fr; padding: 12px; }
  .results .no { font-size: 24px; }
}

/* 手机：先听清楚，再往下看图 */
@media (max-width: 560px) {
  .big { font-size: 22px; line-height: 1.5; }
  .where { font-size: 12px; padding: 6px 12px; }
  .examples { gap: 8px; }
  .examples li { font-size: 13px; padding: 7px 12px; }
  .narration .line { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .scene { animation: none; }
}