/* ==========================================================
   拍照识词 —— 沿用主项目「语音室」视觉方案
   - 冷调石板灰纸面，电光蓝只用在「声音」相关元素上
   - 音标用 Gentium Plus（SIL 语言学字体，IPA 覆盖完整）
   - 英文词头用 Newsreader，中文走系统字体栈
   ========================================================== */

:root {
  --ink:        #0E121A;
  --ink-soft:   #39424F;
  --dim:        #6A7585;
  --line:       #D7DDE5;
  --line-soft:  #E7EBF0;
  --paper:      #EDF0F4;
  --card:       #FFFFFF;
  --signal:     #0B4FE0;   /* 声音 = 信号，只用于音频元素 */
  --signal-ink: #083AA8;
  --signal-wash:#E4EBFD;
  --sea:        #0C6E6B;   /* 音标 */
  --amber:      #8A5A00;
  --warn-bg:    #FDF3E3;
  --warn-line:  #E8CE9A;
  --bad:        #A32020;
  --bad-bg:     #FCEDED;

  --font-head: "Newsreader", Georgia, "Times New Roman", serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
             "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  --font-ipa: "Gentium Plus", "Charis SIL", "Doulos SIL", "DejaVu Sans",
              "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", Consolas, monospace;

  --r: 10px;
  --shadow: 0 1px 2px rgba(14, 18, 26, .05), 0 8px 24px -14px rgba(14, 18, 26, .18);
}

* { box-sizing: border-box; }

/* 纸面是一整片平色，顶部没有任何提亮 —— 这是刻意的，别往上加渐变或柔光。
   原因：iOS 26 的 Safari 不再读 <meta theme-color>（只有装成 PWA 才用），顶栏
   颜色改成从页面背景推导。所以「顶栏色」不是能单独填的一个值，它就是下面这个
   background。页面顶部只要比它亮一点，顶栏看上去就比页面深一截，而且改
   theme-color 完全无效 —— 那个标签根本没被读。
   贴在顶部的 fixed 元素还会自己掺和进取色，更没法预测。
   平色是唯一在「iOS 26 从背景取色」和「iOS 15–18 读 theme-color」下都成立的解。 */
html {
  -webkit-text-size-adjust: 100%;
  color-scheme: light dark;
  /* 铺在 html 上而不只是 body：iOS 橡皮筋回弹时露出的是 html 的画布，
     只给 body 上色的话，往下拉过头会闪出一条系统灰白。 */
  background: var(--paper);
}

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.65;
}

a { color: var(--signal-ink); }

.wrap {
  max-width: 940px;
  margin: 0 auto;
  /* 左右吃进安全区，横屏和刘海机型上文字不会贴到圆角里 */
  padding: 0 max(20px, env(safe-area-inset-left)) calc(72px + env(safe-area-inset-bottom));
}

.hidden { display: none !important; }

/* ---------- 首屏 ---------- */
.hero { padding: 40px 0 26px; }
.hero-ipa {
  font-family: var(--font-ipa);
  font-size: clamp(34px, 7.5vw, 62px);
  line-height: 1.1;
  color: var(--ink);
  letter-spacing: -.01em;
}
.hero-ipa .slash { color: var(--signal); font-weight: 400; }
.hero-title {
  font-family: var(--font-head);
  font-size: clamp(22px, 3.4vw, 30px);
  font-weight: 500;
  margin: 16px 0 0;
  letter-spacing: .01em;
}
.hero-sub {
  color: var(--ink-soft);
  margin: 10px 0 0;
  max-width: 54ch;
}

/* ---------- 通用区块 ---------- */
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
}
.eyebrow {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--dim);
  margin: 36px 0 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.eyebrow::after { content: ""; flex: 1; height: 1px; background: var(--line); }
/* order 让计数排到那条分隔线之后，靠右收尾 */
/* 同步状态。文案可能比这行放得下的长，所以截断 + 用 title 兜住全文；
   完整的说明在词表为空时由空状态那行来说（见 app.js 的 setSyncNote）。 */
.eyebrow-sync {
  order: 4;
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  font-size: 12px;
  color: #A8B2C0;
}
/* 空的 span 也会吃掉一份 flex gap，没内容时直接不占位 */
.eyebrow-sync:empty { display: none; }

.eyebrow-note {
  order: 3;
  flex: none;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

/* ---------- 采集区 ---------- */
.capture {
  padding: 24px;
  transition: border-color .15s, background .15s;
}
.capture.is-over { border-color: var(--signal); background: var(--signal-wash); }
.capture-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.capture-hint { color: var(--dim); font-size: 13px; margin: 14px 0 0; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  padding: 9px 16px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background .14s, border-color .14s, transform .14s;
}
.btn:hover { background: #F5F7FA; border-color: #C3CBD6; }
.btn:active { transform: translateY(1px); }
/* 手机上这是主操作，指头要够得舒服 —— 44px 是 iOS 的最小可点尺寸 */
.btn-lg { padding: 12px 22px; font-size: 15.5px; min-height: 46px; }
.btn-primary {
  background: var(--signal);
  border-color: var(--signal);
  color: #fff;
  font-weight: 500;
}
.btn-primary:hover { background: var(--signal-ink); border-color: var(--signal-ink); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--dim); }
.btn-quiet:hover { background: #EEF1F5; color: var(--ink); }
.btn-danger:hover { background: var(--bad-bg); border-color: #E2B4B4; color: var(--bad); }
.btn-sm { padding: 6px 12px; font-size: 13px; }

:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- 提示条 ---------- */
.note {
  padding: 13px 16px;
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 13.5px;
  margin: 14px 0;
}
.note-bad  { background: var(--bad-bg); border-color: #E2B4B4; color: #7A1A1A; }
.error-hint { margin: 6px 0 0; opacity: .85; }

.empty {
  padding: 40px 24px;
  text-align: center;
  color: var(--dim);
  border: 1px dashed var(--line);
  border-radius: var(--r);
  background: rgba(255, 255, 255, .5);
  margin-top: 20px;
}

.foot {
  margin-top: 44px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--dim);
  font-size: 12.5px;
}

/* ---------- 处理进度 ---------- */
.progress-card { padding: 30px 26px; text-align: center; margin-top: 20px; }
.progress-stage { font-family: var(--font-head); font-size: 20px; margin: 0 0 6px; }
.progress-hint { color: var(--dim); font-size: 13.5px; margin: 0 0 20px; }
.bar { height: 6px; background: var(--line-soft); border-radius: 999px; overflow: hidden; }
.bar-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--signal), #4B85FF);
  border-radius: 999px;
  transition: width .4s ease;
}

/* 等待动画：一组起伏的声波柱 */
.waiting {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
  height: 34px;
  margin-bottom: 18px;
}
.waiting i {
  width: 4px;
  height: 30%;
  background: var(--signal);
  border-radius: 2px;
  opacity: .8;
  animation: wave 1.1s ease-in-out infinite;
}
.waiting i:nth-child(2) { animation-delay: .12s; }
.waiting i:nth-child(3) { animation-delay: .24s; }
.waiting i:nth-child(4) { animation-delay: .36s; }
.waiting i:nth-child(5) { animation-delay: .48s; }
.waiting i:nth-child(6) { animation-delay: .60s; }
@keyframes wave {
  0%, 100% { height: 22%; opacity: .5; }
  50%      { height: 100%; opacity: 1; }
}

/* ---------- 工具条 ---------- */
.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.search {
  flex: 1;
  min-width: 180px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: inherit;
  /* 不小于 16px：iOS Safari 会给更小字号的输入框自动放大页面，
     一聚焦整个版面就跳一下，很难受 */
  font-size: 16px;
  background: var(--card);
  color: var(--ink);
}
.search::placeholder { color: #A8B2C0; }
.search:focus { outline: 2px solid var(--signal); outline-offset: 1px; border-color: var(--signal); }

/* ---------- 词条 ---------- */
.entries { display: grid; gap: 8px; }
.entry {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  /* 右边留 20px 就够：那儿原来有个删除按钮，词表改成共享后去掉了 */
  padding: 18px 20px 18px 60px;
  transition: border-color .16s, box-shadow .16s;
}
.entry::before {
  /* 左侧信号线：播放时点亮 */
  content: "";
  position: absolute;
  left: 0;
  top: 14px;
  bottom: 14px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--line-soft);
  transition: background .2s;
}
.entry:hover { border-color: #C6D0DD; }
.entry.is-playing { border-color: var(--signal); box-shadow: 0 0 0 3px var(--signal-wash); }
.entry.is-playing::before { background: var(--signal); }

.entry-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.entry-word {
  font-family: var(--font-head);
  font-size: 27px;
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: -.005em;
}
.entry-ipa {
  font-family: var(--font-ipa);
  font-size: 16px;
  color: var(--sea);
  white-space: nowrap;
}
.entry-zh { color: var(--ink-soft); font-size: 15px; margin-top: 4px; }

.example {
  margin-top: 14px;
  padding: 13px 15px 13px 46px;
  background: #F7F9FB;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  position: relative;
}
.example-en {
  font-family: var(--font-head);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
}
.example-zh { color: var(--dim); font-size: 13.5px; margin-top: 5px; }

/* ---------- 均衡器播放按钮（本设计的标志元素） ---------- */
.play {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 2.5px;
  position: absolute;
  transition: border-color .14s, background .14s, box-shadow .14s;
}
.play:hover:not([disabled]) { border-color: var(--signal); background: var(--signal-wash); }
/* 与词头视觉居中对齐：词条上内边距 18 + 词头行高 31 的一半 - 按钮 32 的一半 */
.play-word    { left: 16px; top: 18px; }
.play-example { left: 11px; top: 50%; transform: translateY(-50%); }

.play i {
  display: block;
  width: 3px;
  border-radius: 2px;
  background: var(--signal);
  transition: height .18s ease, background .18s;
}
/* 静止态：一个凝固的波形剪影 */
.play i:nth-child(1) { height: 6px; }
.play i:nth-child(2) { height: 13px; }
.play i:nth-child(3) { height: 9px; }
.play i:nth-child(4) { height: 16px; }

.play[disabled] { cursor: not-allowed; opacity: .45; }
.play[disabled] i { background: var(--dim); }

/* 播放中：波形活起来 */
.play.is-playing {
  border-color: var(--signal);
  background: var(--signal-wash);
  box-shadow: 0 0 0 3px rgba(11, 79, 224, .12);
}
.play.is-playing i { animation: bar .85s ease-in-out infinite; }
.play.is-playing i:nth-child(1) { animation-delay: 0s; }
.play.is-playing i:nth-child(2) { animation-delay: .1s; }
.play.is-playing i:nth-child(3) { animation-delay: .2s; }
.play.is-playing i:nth-child(4) { animation-delay: .3s; }
@keyframes bar {
  0%, 100% { height: 5px; }
  50%      { height: 17px; }
}

/* 加载中 */
.play.is-loading i { background: #A8B2C0; animation: bar 1.4s ease-in-out infinite; }

/* ---------- 响应式 ---------- */
@media (max-width: 620px) {
  .hero { padding: 34px 0 20px; }
  .entry { padding: 15px 16px 15px 54px; }
  .entry::before { display: none; }
  .entry-word { font-size: 22px; }
  .entry-head { align-items: center; gap: 9px; }
  .play-word { left: 14px; top: 15px; width: 30px; height: 30px; }
  .example { padding: 12px 13px 12px 44px; }
  .play-example { left: 9px; width: 30px; height: 30px; }
  .capture-actions .btn { flex: 1; justify-content: center; }
}

/* ---------- 深色模式 ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --ink:        #E8ECF2;
    --ink-soft:   #B4BECC;
    --dim:        #8794A5;
    --line:       #2A323E;
    --line-soft:  #222933;
    --paper:      #0C1016;
    --card:       #141A22;
    --signal:     #5B92FF;
    --signal-ink: #8FB4FF;
    --signal-wash:#17233B;
    --sea:        #4FBDB8;
    --amber:      #E0B054;
    --warn-bg:    #2A2113;
    --warn-line:  #4A3A1C;
    --bad:        #F09393;
    --bad-bg:     #2B1717;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -14px rgba(0, 0, 0, .7);
  }
  /* 深色下同样不加柔光，理由见文件上方 html 规则前的注释 */
  .btn:hover { background: #1D242E; border-color: #3A4553; }
  .btn-primary { color: #08122A; }
  .example { background: #101620; }
  .empty { background: rgba(20, 26, 34, .5); }
}

/* ---------- 无障碍：尊重减少动效 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  .play.is-playing i:nth-child(even) { height: 16px; }
  .play.is-playing i:nth-child(odd)  { height: 8px; }
}
