/*! styles.css —— AIGC 题库刷题 · 移动端优先
 * 配色用 CSS 变量，深浅色由 html[data-theme] 切换（auto 模式由 JS 解析成 light/dark）。
 */

:root {
  --bg: #f4f5f7;
  --bg-soft: #eceef1;
  --card: #ffffff;
  --card-2: #fafbfc;
  --text: #16181d;
  --text-2: #5b6270;
  --muted: #8b929e;
  --line: #e3e6ea;
  --brand: #2f6bff;
  --brand-soft: #e8efff;
  --ok: #12a150;
  --ok-soft: #e6f7ed;
  --bad: #e5484d;
  --bad-soft: #fdecec;
  --warn: #d98a00;
  --warn-soft: #fdf3e0;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 6px 16px rgba(16, 24, 40, .06);
  --radius: 14px;
  --radius-sm: 10px;
  --fs: 16px;
  --tab-h: 56px;
}

html[data-theme="dark"] {
  --bg: #0e1116;
  --bg-soft: #151a21;
  --card: #171c23;
  --card-2: #1c222b;
  --text: #e8eaee;
  --text-2: #a8b0bd;
  --muted: #7d8695;
  --line: #262d37;
  --brand: #6b93ff;
  --brand-soft: #1b2740;
  --ok: #3ecf7a;
  --ok-soft: #14291e;
  --bad: #ff6b6f;
  --bad-soft: #2e1a1c;
  --warn: #f0b429;
  --warn-soft: #2c2317;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 16px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* 关键：作者样式里的 display 会盖掉 UA 的 [hidden]{display:none}，
   抽屉/返回键/提示条都靠 hidden 属性开关，必须显式兜住 */
[hidden] { display: none !important; }

html { font-size: var(--fs); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 1rem/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  overscroll-behavior-y: none;
}

button { font: inherit; color: inherit; }

/* ------------------------------------------------------------------ 布局 */

.app { display: flex; flex-direction: column; min-height: 100dvh; }

.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .5rem;
  padding: .55rem .75rem;
  padding-top: calc(.55rem + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.bar-title { flex: 1; font-size: 1rem; font-weight: 600; letter-spacing: .2px; }
.bar-title small { display: block; font-weight: 400; font-size: .72rem; color: var(--muted); }

.ibtn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 2.2rem; height: 2.2rem; padding: 0 .5rem;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  color: var(--text-2); cursor: pointer; font-size: .95rem;
}
.ibtn:active { transform: scale(.96); }

.main { flex: 1; padding: .75rem .75rem calc(var(--tab-h) + 1.5rem); }
.main.no-tabs { padding-bottom: 6rem; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--card) 94%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabs button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: none; border: 0; cursor: pointer; color: var(--muted); font-size: .7rem;
}
.tabs button span { font-size: 1.05rem; line-height: 1; }
.tabs button.on { color: var(--brand); font-weight: 600; }

/* ------------------------------------------------------------------ 通用 */

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: .9rem; margin-bottom: .75rem;
}
.card.tight { padding: .7rem .8rem; }
.card h3 { margin: 0 0 .55rem; font-size: .95rem; }
.card h3 .sub { font-weight: 400; color: var(--muted); font-size: .78rem; margin-left: .4rem; }

.row { display: flex; align-items: center; gap: .5rem; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.tiny { font-size: .72rem; }
.center { text-align: center; }
.mt { margin-top: .6rem; }
.mb { margin-bottom: .6rem; }
.hidden { display: none !important; }

code {
  background: var(--bg-soft); padding: .1rem .35rem; border-radius: 5px;
  font-size: .86em; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
}

.pill {
  display: inline-block; padding: .12rem .5rem; border-radius: 999px;
  background: var(--bg-soft); color: var(--text-2); font-size: .72rem; white-space: nowrap;
}
.pill.brand { background: var(--brand-soft); color: var(--brand); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .62rem .9rem; border-radius: var(--radius-sm);
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  cursor: pointer; font-size: .92rem; font-weight: 500;
}
.btn:active { transform: scale(.985); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.block { width: 100%; }
.btn.sm { padding: .42rem .65rem; font-size: .82rem; }
.btn-row { display: flex; gap: .5rem; }
.btn-row .btn { flex: 1; }

.bar-track { height: 6px; border-radius: 999px; background: var(--bg-soft); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--brand); transition: width .25s; }
.bar-fill.ok { background: var(--ok); }
.bar-fill.bad { background: var(--bad); }
.bar-fill.warn { background: var(--warn); }

/* ------------------------------------------------------------------ 首页 */

.hero { display: flex; align-items: center; gap: .9rem; }
.ring { position: relative; width: 74px; height: 74px; flex: none; }
.ring svg { transform: rotate(-90deg); }
.ring .val {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-size: .95rem; font-weight: 700;
}
.ring .val small { font-size: .6rem; font-weight: 400; color: var(--muted); }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.stat { background: var(--card-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .55rem; text-align: center; }
.stat b { display: block; font-size: 1.15rem; line-height: 1.3; }
.stat span { font-size: .7rem; color: var(--muted); }

.entry {
  display: flex; align-items: center; gap: .7rem; width: 100%;
  padding: .7rem .8rem; margin-bottom: .5rem; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); cursor: pointer;
}
.entry:active { transform: scale(.99); }
.entry .ico {
  display: flex; align-items: center; justify-content: center;
  width: 2.1rem; height: 2.1rem; flex: none; border-radius: 10px;
  background: var(--brand-soft); color: var(--brand); font-size: 1.05rem;
}
.entry .txt { flex: 1; min-width: 0; }
.entry .txt b { display: block; font-size: .93rem; }
.entry .txt span { display: block; font-size: .74rem; color: var(--muted); }
.entry .go { color: var(--muted); font-size: .9rem; }

/* ------------------------------------------------------------------ 练习 */

.p-head { margin-bottom: .6rem; }
.p-head .meta { display: flex; align-items: center; gap: .4rem; margin-bottom: .45rem; font-size: .74rem; color: var(--muted); }
.p-head .meta .grow { text-align: right; }

.stem { font-size: 1.06rem; line-height: 1.6; font-weight: 500; }
.stem .idx { color: var(--muted); font-weight: 400; margin-right: .3rem; }

.opts { display: flex; flex-direction: column; gap: .5rem; margin-top: .85rem; }
.opt {
  display: flex; align-items: flex-start; gap: .6rem; width: 100%;
  padding: .68rem .75rem; text-align: left;
  background: var(--card-2); border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  cursor: pointer; transition: border-color .15s, background .15s;
}
.opt:active { transform: scale(.995); }
.opt .key {
  display: flex; align-items: center; justify-content: center; flex: none;
  width: 1.5rem; height: 1.5rem; border-radius: 50%;
  background: var(--card); border: 1px solid var(--line);
  font-size: .78rem; font-weight: 700; color: var(--text-2);
}
.opt .val { flex: 1; font-size: .95rem; line-height: 1.5; }
.opt .mark { flex: none; font-size: .9rem; color: var(--muted); }
.opt.picked { border-color: var(--brand); background: var(--brand-soft); }
.opt.picked .key { background: var(--brand); border-color: var(--brand); color: #fff; }
.opt.correct { border-color: var(--ok); background: var(--ok-soft); }
.opt.correct .key { background: var(--ok); border-color: var(--ok); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .key { background: var(--bad); border-color: var(--bad); color: #fff; }
.opt.missed { border-style: dashed; border-color: var(--ok); }
.opt.locked { cursor: default; }
.opt.locked:active { transform: none; }

.fb { border-radius: var(--radius); padding: .8rem .85rem; margin-top: .8rem; border: 1px solid var(--line); background: var(--card); }
.fb.ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, var(--line)); }
.fb.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 35%, var(--line)); }
.fb .head { display: flex; align-items: center; gap: .45rem; font-weight: 600; margin-bottom: .45rem; }
.fb .body { font-size: .9rem; line-height: 1.6; }
.fb .body p { margin: .35rem 0 0; }
.fb .kv b { color: var(--text-2); font-weight: 500; }
.ansline { font-size: .95rem; }
.ansline b { color: var(--ok); }

.ref {
  margin-top: .5rem; padding: .6rem .7rem; border-radius: var(--radius-sm);
  background: var(--card-2); border: 1px dashed var(--line);
  font-size: .9rem; line-height: 1.65; white-space: pre-wrap;
}

.p-foot {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: flex; align-items: center; gap: .45rem;
  padding: .5rem .75rem calc(.5rem + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--card) 95%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.p-foot .btn { flex: none; }
.p-foot .btn.main-act { flex: 1; }

.swipe-hint { text-align: center; color: var(--muted); font-size: .7rem; margin-top: .9rem; }

.summary-hero { text-align: center; padding: 1rem 0 .4rem; }
.summary-hero .big { font-size: 2.4rem; font-weight: 700; line-height: 1.1; }
.summary-hero .big.ok { color: var(--ok); }
.summary-hero .big.bad { color: var(--bad); }

/* ------------------------------------------------------------------ 列表 */

.item {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--card); box-shadow: var(--shadow);
  padding: .7rem .75rem; margin-bottom: .5rem;
}
.item .top { display: flex; align-items: center; gap: .4rem; margin-bottom: .3rem; font-size: .72rem; color: var(--muted); }
.item .q { font-size: .92rem; line-height: 1.5; }
.item .actions { display: flex; gap: .4rem; margin-top: .5rem; }

.empty { text-align: center; color: var(--muted); padding: 2.2rem 1rem; font-size: .88rem; }
.empty .big { font-size: 1.8rem; display: block; margin-bottom: .4rem; }

/* ------------------------------------------------------------------ 答题卡 */

.cells { display: grid; grid-template-columns: repeat(auto-fill, minmax(2.4rem, 1fr)); gap: .35rem; }
.cell {
  aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center;
  border-radius: 8px; border: 1px solid var(--line); background: var(--card-2);
  font-size: .78rem; color: var(--text-2); cursor: pointer;
}
.cell.done { background: var(--brand-soft); border-color: color-mix(in srgb, var(--brand) 30%, var(--line)); color: var(--brand); }
.cell.ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 30%, var(--line)); color: var(--ok); }
.cell.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 30%, var(--line)); color: var(--bad); }
.cell.fav { box-shadow: inset 0 -3px 0 var(--warn); }
.cell.cur { outline: 2px solid var(--brand); outline-offset: 1px; }

.legend { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .6rem; font-size: .72rem; color: var(--muted); }
.legend i { display: inline-block; width: .7rem; height: .7rem; border-radius: 3px; margin-right: .2rem; vertical-align: -1px; }

/* ------------------------------------------------------------------ 学情 */

.topic-row { margin-bottom: .7rem; }
.topic-row .line { display: flex; align-items: baseline; gap: .4rem; font-size: .84rem; margin-bottom: .25rem; }
.topic-row .line .nm { flex: 1; }
.topic-row .line .pc { font-variant-numeric: tabular-nums; color: var(--text-2); }

.bars { display: flex; align-items: flex-end; gap: 3px; height: 88px; margin-top: .3rem; }
.bars .b { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.bars .b i { display: block; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.bars .b.s0 i { background: var(--bg-soft); }
.labels { display: flex; gap: 3px; margin-top: .25rem; font-size: .6rem; color: var(--muted); }
.labels span { flex: 1; text-align: center; overflow: hidden; }

.tips { margin: 0; padding-left: 1.1rem; font-size: .88rem; line-height: 1.7; }
.tips li { margin-bottom: .2rem; }

/* ------------------------------------------------------------------ 设置 */

.set-row { display: flex; align-items: center; gap: .6rem; padding: .65rem 0; border-bottom: 1px solid var(--line); }
.set-row:last-child { border-bottom: 0; }
.set-row .txt { flex: 1; }
.set-row .txt b { display: block; font-size: .9rem; font-weight: 500; }
.set-row .txt span { display: block; font-size: .72rem; color: var(--muted); margin-top: .1rem; }

.switch { position: relative; width: 46px; height: 27px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch i {
  position: absolute; inset: 0; border-radius: 999px; background: var(--bg-soft);
  border: 1px solid var(--line); transition: background .18s;
  pointer-events: none; /* 让点击落在下层的 input 上 */
}
.switch i::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 21px; height: 21px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); transition: transform .18s;
}
.switch input:checked + i { background: var(--brand); border-color: var(--brand); }
.switch input:checked + i::after { transform: translateX(19px); }

.seg { display: flex; gap: .3rem; background: var(--bg-soft); padding: .2rem; border-radius: 10px; }
.seg button {
  flex: 1; padding: .32rem .5rem; border: 0; border-radius: 8px; background: transparent;
  color: var(--text-2); font-size: .82rem; cursor: pointer;
}
.seg button.on { background: var(--card); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

/* ------------------------------------------------------------------ 抽屉 */

.sheet-mask { position: fixed; inset: 0; z-index: 30; background: rgba(8, 12, 20, .45); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  max-height: 82dvh; display: flex; flex-direction: column;
  background: var(--card); border-radius: 18px 18px 0 0;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .25);
  animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-head { display: flex; align-items: center; gap: .5rem; padding: .7rem .9rem; border-bottom: 1px solid var(--line); }
.sheet-head b { flex: 1; font-size: .95rem; }
.sheet-body { padding: .9rem; overflow: auto; padding-bottom: calc(.9rem + env(safe-area-inset-bottom)); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + 2rem); z-index: 40;
  transform: translateX(-50%);
  padding: .5rem .9rem; border-radius: 999px;
  background: rgba(20, 24, 32, .92); color: #fff; font-size: .82rem;
  max-width: 82vw; text-align: center;
  animation: fade .2s ease-out;
}
@keyframes fade { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* 平板/桌面：收窄成手机宽度，阅读更舒服 */
@media (min-width: 720px) {
  .app { max-width: 720px; margin: 0 auto; }
  .tabs, .p-foot, .sheet {
    right: auto; width: 100%; max-width: 720px;
    left: 50%; transform: translateX(-50%);
  }
  .sheet { animation: none; }
  .stem { font-size: 1.12rem; }
}
