/* 基础样式：配色变量、顶栏、首页、场景页、复盘；学习相关页面（计划、复习、表达库、学习记录）在 study.css */
:root {
  --bg: #f4f5f7; --panel: #ffffff; --ink: #1b1d21; --muted: #6b7079; --line: #e2e4e9;
  --accent: #b3372b; --accent-soft: #f6e3df; --good: #2f7d4f; --good-soft: #e2f1e7;
  --warn: #a8660b; --warn-soft: #f8ecd6; --bad: #b3372b; --bad-soft: #f6e3df; --info: #3a5ba8; --info-soft: #e3e9f7;
  --me: #1b1d21; --me-ink: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121316; --panel: #1b1d21; --ink: #eceef2; --muted: #969ba5; --line: #2d3037;
    --accent: #e0685a; --accent-soft: #3a211d; --good: #6cc38f; --good-soft: #1c3025;
    --warn: #e0a64a; --warn-soft: #362a17; --bad: #e0685a; --bad-soft: #3a211d; --info: #86a4e8; --info-soft: #1e2638;
    --me: #eceef2; --me-ink: #121316;
  }
}
* { box-sizing: border-box; }
.ic { width: 1.05em; height: 1.05em; vertical-align: -.17em; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.55 Inter, -apple-system, "PingFang SC", sans-serif; }
h1, h2, h3, .serif { font-family: Fraunces, Georgia, "Songti SC", serif; font-weight: 700; }
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }

header { display: flex; align-items: center; gap: 16px; padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
header h1 { font-size: 20px; margin: 0; display: flex; align-items: baseline; gap: .28em; white-space: nowrap; }
header h1 > a { color: inherit; text-decoration: none; }
/* 红色语言名：本身是个下拉（切换语言），样式跟标题一致 */
#hLang { color: var(--accent); position: relative; }
.tick-ruler { position: absolute; visibility: hidden; pointer-events: none; left: 0; top: 0; }
.tick-ruler > span { position: absolute; white-space: nowrap; }
.dd.brand .dd-btn { font: inherit; color: inherit; border: none; background: none; padding: 0; gap: 3px; }
.dd.brand .dd-btn > .ic { display: none; }   /* 不要下拉箭头，语言名本身就是按钮 */
.dd.brand .dd-v { font-weight: inherit; }
.dd.brand .dd-menu { font: 400 14px/1.55 Inter, -apple-system, "PingFang SC", sans-serif; }
/* 语言选择页：各语言名叠在同一格里轮流翻牌登台，格子宽度跟着当前的名字伸缩（brand() 里量） */
.tick { display: inline-grid; perspective: 300px; transition: width .45s cubic-bezier(.34, 1.3, .64, 1); }
.tick > span { grid-area: 1 / 1; justify-self: start; white-space: nowrap; opacity: 0; transform-origin: 50% 0; }
.tick > .on { opacity: 1; animation: flap-in .55s cubic-bezier(.34, 1.56, .64, 1); }
.tick > .off { animation: flap-out .35s ease-in; }
@keyframes flap-in { from { opacity: 0; transform: rotateX(-95deg); } 40% { opacity: 1; } }
@keyframes flap-out { from { opacity: 1; } to { opacity: 0; transform: translateY(.35em) rotateX(70deg); } }
/* 选定语言：从上面掉下来，落地压扁再弹起 */
.drop { display: inline-block; }
.drop.in { animation: drop-in .7s cubic-bezier(.2, .9, .3, 1.2); transform-origin: 50% 100%; }
@keyframes drop-in { 0% { opacity: 0; transform: translateY(-.9em) rotate(-6deg); } 55% { opacity: 1; transform: translateY(0) scale(1.08, .88); }
  75% { transform: translateY(-.12em) scale(.97, 1.04); } 100% { transform: none; } }
@media (prefers-reduced-motion: reduce) { .tick > span, .drop.in { animation: none !important; } }
.timer { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.bar { width: 120px; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .5s; }
/* 超过目标：目标以内实色，超出部分斜纹流动，交界处留一道细缝当刻度 */
.bar i.over, .pbar i.over { background: linear-gradient(90deg, var(--good) calc(var(--g) - 1.5px), var(--panel) calc(var(--g) - 1.5px) var(--g), transparent var(--g)),
  repeating-linear-gradient(-45deg, var(--good) 0 4px, color-mix(in srgb, var(--good) 45%, var(--panel)) 4px 8px);
  background-size: 100% 100%, 11.3px 100%; animation: overflow-run 1s linear infinite; }
@keyframes overflow-run { to { background-position: 0 0, 11.3px 0; } }
.timer .extra { color: var(--good); font-weight: 600; }
@media (prefers-reduced-motion: reduce) { .bar i.over, .pbar i.over { animation: none; } }

.btn { border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 8px 14px; border-radius: 8px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: default; }

main { max-width: 1100px; margin: 0 auto; padding: 24px 20px 40px; }

/* home */
.stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 24px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px; flex: 1; min-width: 140px; }
.stat b { display: block; font-size: 24px; font-family: Fraunces, serif; }
.stat small { color: var(--muted); }
.stat.review { cursor: pointer; border-color: var(--accent); background: var(--accent-soft); }
.section-h { display: flex; align-items: baseline; justify-content: space-between; margin: 8px 0 12px; }
.section-h h2 { margin: 0; font-size: 22px; }
.cards3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); gap: 14px; }
.opt { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; cursor: pointer; display: flex; flex-direction: column; gap: 8px; transition: transform .15s, border-color .15s; }
.opt:hover { transform: translateY(-2px); border-color: var(--accent); }
/* 卡片底图：淡、偏灰，从右上角往左下渐隐，只给个氛围，不抢文字 */
.opt { position: relative; overflow: hidden; }
.opt > :not(.ph) { position: relative; }
.opt .ph { position: absolute; inset: 0; background: center / cover no-repeat; opacity: .16; filter: grayscale(.4);
  -webkit-mask-image: linear-gradient(215deg, #000 10%, transparent 70%); mask-image: linear-gradient(215deg, #000 10%, transparent 70%);
  transition: opacity .25s; pointer-events: none; }
.opt:hover .ph { opacity: .26; }
/* 已演过的卡：变淡，右上角标记，点开回到那场戏 */
.opt.played > :not(.ph):not(.played-mark) { opacity: .5; }
.opt .played-mark { position: absolute; top: 18px; right: 18px; font-size: 12px; color: var(--good); display: flex; align-items: center; gap: 3px; }
@media (prefers-color-scheme: dark) { .opt .ph { opacity: .22; } .opt:hover .ph { opacity: .32; } }
.tag { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--muted); width: fit-content; }
.tag.news { background: var(--info-soft); color: var(--info); }
.opt h3 { margin: 0; font-size: 19px; }
.opt .en { color: var(--muted); font-size: 13px; font-style: italic; }
.opt p { margin: 0; }
a.opt { color: inherit; text-decoration: none; }
.opt .meta { color: var(--muted); font-size: 13px; }
.opt h3 .hl { color: var(--accent); }
/* 日语注音 */
ruby rt { font-size: .55em; color: var(--muted); font-weight: 400; }
.noruby rt { display: none; }
.lang-ja .msg, .lang-ja .cn .better { line-height: 2; }
.custom { display: flex; gap: 8px; margin-top: 14px; }
.custom input { flex: 1; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); font: inherit; }
.history { margin-top: 32px; }
.hist { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(340px, 100%), 1fr)); gap: 8px; }
.hrow { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  color: var(--ink); text-decoration: none; transition: border-color .15s, transform .15s; }
.hrow:hover { border-color: var(--muted); transform: translateY(-1px); }
.hrow .hi { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none; background: var(--accent-soft); color: var(--accent); font-size: 17px; }
.hrow .hi.done { background: var(--good-soft); color: var(--good); }
.hrow .ht { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.hrow .ht b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hrow .ht small { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.pill { font-size: 12px; padding: 1px 9px; border-radius: 99px; white-space: nowrap; }
.pill.done { color: var(--good); background: var(--good-soft); }
.pill.live { color: var(--accent); background: var(--accent-soft); }
.hrow > .ic { color: var(--muted); }

/* 下拉框（core.js 的 dd()） */
.dd { position: relative; display: inline-block; }
.dd-btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 8px; padding: 5px 8px 5px 10px; font-size: 13px; white-space: nowrap; }
.dd-btn:hover, .dd.open .dd-btn { border-color: var(--muted); }
.dd-btn > .ic { color: var(--muted); transition: transform .15s; }
.dd.open .dd-btn > .ic { transform: rotate(180deg); }
.dd-lb { color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.dd-v { font-weight: 600; }
.dd-menu { display: none; position: absolute; top: calc(100% + 6px); left: 0; z-index: 20; min-width: 100%; padding: 4px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgb(0 0 0 / .12); }
.dd.right .dd-menu { left: auto; right: 0; }
.dd.open .dd-menu { display: block; animation: dd-in .12s ease-out; }
@keyframes dd-in { from { opacity: 0; transform: translateY(-4px); } }
.dd-menu button { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 14px; border: none; background: none; color: var(--ink);
  padding: 7px 10px; border-radius: 7px; font-size: 14px; text-align: left; white-space: nowrap; }
.dd-menu button:hover, .dd-menu button:focus-visible { background: var(--bg); outline: none; }
.dd-menu button small { color: var(--muted); font-size: 12px; margin-left: 8px; }
.dd-menu button .ic { visibility: hidden; color: var(--accent); }
.dd-menu button.on { font-weight: 600; }
.dd-menu button.on .ic { visibility: visible; }
/* 首页“我的水平”：大字，不要框 */
.dd.big .dd-btn { border-color: transparent; padding: 0 6px 0 0; margin-left: -1px; font: 700 24px/1.2 Fraunces, serif; }
.dd.big .dd-btn:hover, .dd.big.open .dd-btn { border-color: transparent; color: var(--accent); }
.dd.big .dd-btn > .ic { width: 18px; height: 18px; }
.dd.big .dd-menu { min-width: 170px; }

/* scene：整页撑满，聊天区尽量大 */
#scene { max-width: 1440px; padding: 10px 20px 14px; }
#scene:not(.hidden) { display: flex; flex-direction: column; gap: 10px; height: calc(100dvh - var(--hh, 53px)); }
.brief { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 14px; flex: none; }
.brief-top { display: flex; gap: 10px; align-items: center; min-width: 0; }
.brief h2 { margin: 0; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40%; }
.brief .goal { flex: 1; min-width: 0; font-size: 14px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.brief .goal b { color: var(--accent); }
.brief .more-btn { border: none; background: none; color: var(--muted); font-size: 13px; padding: 4px 6px; white-space: nowrap; }
.brief .more-btn:hover { color: var(--ink); }
#dbgBtn:empty { display: none; }
.brief-more { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 14px; color: var(--muted); }
.brief-more .fullgoal { color: var(--ink); margin-bottom: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { font-size: 12.5px; padding: 2px 9px; border-radius: 99px; border: 1px dashed var(--muted); color: var(--muted); }
.chip.now { border: 1px solid var(--accent); color: var(--accent); background: var(--accent-soft); }
.chip.used { border: 1px solid var(--good); background: var(--good-soft); color: var(--good); }
.stage { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 12px; flex: 1; min-height: 0; }
.chatbox, .coachbox { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; display: flex; flex-direction: column; min-height: 0; }
.msgs { flex: 1; overflow-y: auto; padding: 18px 22px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 78%; font-size: 16px; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; }
.msg.ai { background: var(--bg); border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.me { background: var(--me); color: var(--me-ink); align-self: flex-end; border-bottom-right-radius: 4px; }
.msg .who { font-size: 12px; color: var(--accent); font-weight: 600; margin-bottom: 2px; }
.msg em { color: var(--muted); }
.msg .search { font-size: 12px; color: var(--info); margin-top: 6px; }
.say { border: none; background: none; color: inherit; padding: 0 0 0 6px; font-size: 14px; opacity: .55; vertical-align: middle; line-height: 1; }
.say:hover { opacity: 1; }
.say.playing { opacity: 1; animation: pulse 1s ease-in-out infinite; }
.say.loading { opacity: 1; animation: spin 1s linear infinite; display: inline-block; }
@keyframes pulse { 50% { transform: scale(1.25); } }
.audio-ctl { display: flex; gap: 6px; align-items: center; font-size: 13px; }
.audio-ctl > button { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 6px; padding: 3px 8px; font-size: 13px; }
.audio-ctl button.off { color: var(--muted); text-decoration: line-through; }
mark.idiom { background: none; color: inherit; text-decoration: underline 2px var(--warn); text-underline-offset: 3px; cursor: help; }
.msg .acts { display: flex; gap: 2px; margin: 4px 0 -4px -6px; }
.msg .acts .say { padding: 2px 6px; }
.say.tr.on { opacity: 1; color: var(--info); }
.msg .zh { margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--line); font-size: 14px; color: var(--muted); white-space: normal; }
.gloss { margin-top: 8px; padding-top: 6px; border-top: 1px dashed var(--line); font-size: 13px; white-space: normal; display: flex; flex-direction: column; gap: 3px; }
.gloss b { color: var(--warn); font-weight: 600; }
.gloss small { color: var(--muted); }
.gloss .keep, .cn .tip .keep { border: 1px solid var(--line); background: var(--panel); color: var(--muted); border-radius: 99px; font-size: 12px; padding: 0 8px; margin-left: 6px; }
.gloss .keep:hover, .cn .tip .keep:hover { color: var(--ink); border-color: var(--muted); }
.gloss .keep.kept, .cn .tip .keep.kept { color: var(--good); border-color: var(--good); cursor: default; }
.curtain { align-self: center; text-align: center; background: var(--accent-soft); color: var(--accent); border-radius: 12px; padding: 10px 18px; font-size: 14px; }
.curtain .btn { margin-left: 10px; padding: 4px 12px; }
.typing { color: var(--muted); font-style: italic; font-size: 14px; }
.composer { border-top: 1px solid var(--line); padding: 10px; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font: inherit; background: var(--bg); color: var(--ink); max-height: 140px; }
.composer textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.coachbox h3 { margin: 0; padding: 10px 14px 8px; font-size: 15px; }
.coachbox .targets { padding: 0 14px 10px; border-bottom: 1px solid var(--line); }
.coachbox .targets:empty, .coachbox .vocab:empty { display: none; }
.coachbox .vocab { padding: 0 14px 8px; }
.coachbox .lbl { width: 100%; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.coachbox .lbl small { opacity: .7; margin-left: 4px; }
.chip.word { border-style: solid; border-color: var(--line); color: var(--ink); background: var(--bg); cursor: pointer; font: inherit; font-size: 12.5px; }
.chip.word:hover { border-color: var(--muted); }
.chip.word.kept { color: var(--good); border-color: var(--good); cursor: default; }
.coachlist { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.cn { border-radius: 10px; padding: 8px 12px; font-size: 14px; border-left: 4px solid var(--line); background: var(--bg); cursor: pointer; }
.cn.good { border-color: var(--good); } .cn.improve { border-color: var(--warn); } .cn.error { border-color: var(--bad); } .cn.chinese { border-color: var(--info); }
.cn .head { display: flex; gap: 8px; align-items: baseline; }
.cn .v { font-weight: 600; font-size: 12.5px; white-space: nowrap; }
.cn .orig { color: var(--muted); font-size: 12.5px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cn.good .v { color: var(--good); } .cn.improve .v { color: var(--warn); } .cn.error .v { color: var(--bad); } .cn.chinese .v { color: var(--info); }
.cn .better { margin-top: 4px; font-weight: 500; font-size: 15px; }
.cn .more { margin-top: 4px; }
.cn .iss { margin: 2px 0 0; padding-left: 16px; font-size: 13.5px; }
.cn .iss s { color: var(--bad); }
.cn .iss b { color: var(--good); font-weight: 600; }
.cn .iss small { color: var(--muted); }
.cn .tip { margin-top: 4px; color: var(--info); font-size: 13px; }
.cn.fold { opacity: .75; }
.cn.fold .more { display: none; }
.cn.fold .better { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { color: var(--muted); font-size: 14px; padding: 8px; }

/* 提示词调试面板 */
.dbg { position: fixed; inset: 0; background: color-mix(in srgb, var(--bg) 70%, transparent); z-index: 15; display: flex; justify-content: flex-end; }
.dbg-panel { width: min(860px, 100%); height: 100%; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.dbg-top { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.dbg-top small { color: var(--muted); flex: 1; }
.dbg-body { flex: 1; overflow-y: auto; padding: 12px 16px 40px; }
.dbg-body details { border: 1px solid var(--line); border-radius: 10px; margin: 8px 0; }
.dbg-body summary { cursor: pointer; padding: 8px 12px; font-weight: 500; }
.dbg-body summary small { color: var(--muted); font-weight: 400; }
.dbg-body details > div { padding: 0 12px 10px; }
.dbg-body h4 { margin: 10px 0 4px; font-size: 13px; color: var(--accent); }
.dbg-body pre { margin: 0; white-space: pre-wrap; word-break: break-word; font: 12.5px/1.5 ui-monospace, Menlo, monospace; background: var(--bg); border-radius: 8px; padding: 10px; max-height: 480px; overflow: auto; }

/* debrief + review */
.paper { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 24px; max-width: 760px; margin: 0 auto; }
.paper h2 { margin-top: 0; }
.issue { border-left: 4px solid var(--warn); padding: 6px 12px; margin: 10px 0; background: var(--bg); border-radius: 6px; }
.card { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin: 8px 0; }
.card b { font-size: 16px; }
.card .ex { color: var(--muted); font-style: italic; }
.rv-situation { font-size: 18px; margin: 16px 0; font-family: Fraunces, "Songti SC", serif; }
.rv-meaning { color: var(--muted); }
.rv-input { width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit; min-height: 70px; margin: 10px 0; }
.result { border-radius: 10px; padding: 12px; margin-top: 12px; }
.result.pass { background: var(--good-soft); } .result.fail { background: var(--bad-soft); }
.progress { color: var(--muted); font-size: 13px; }

.overlay { position: fixed; inset: 0; background: color-mix(in srgb, var(--bg) 85%, transparent); display: flex; align-items: center; justify-content: center; z-index: 20; flex-direction: column; gap: 12px; }
.overlay .serif { font-size: 22px; }
.spinner { width: 36px; height: 36px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
/* 推荐构思中：骨架卡片 + 小转圈 */
.thinking { grid-column: 1 / -1; color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 8px; padding: 4px 2px; }
.mini-spin { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: -2px; margin-right: 6px; flex: none; }
.thinking .mini-spin { margin-right: 0; }
.btn:disabled { opacity: .6; cursor: default; }
.opt.sk { cursor: default; pointer-events: none; display: flex; flex-direction: column; gap: 10px; }
.opt.sk i { display: block; height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--line) 25%, var(--bg) 50%, var(--line) 75%); background-size: 200% 100%; animation: shimmer 1.4s ease-in-out infinite; }
.opt.sk i:nth-child(1) { width: 35%; } .opt.sk i:nth-child(2) { width: 80%; height: 18px; } .opt.sk i:nth-child(3) { width: 60%; } .opt.sk i:nth-child(4) { width: 95%; height: 34px; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

