* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; }
:root {
  --bg: #f2f4f7; --card: #ffffff; --text: #1f2937; --muted: #6b7280; --gray-text: #374151;
  --line: #e5e7eb; --input-bg: #ffffff; --input-line: #d1d5db;
  --gray-bg: #e5e7eb; --blue-bg: #eff6ff; --blue-text: #1d4ed8; --blue-line: #93c5fd;
  --red-bg: #fef2f2; --red-text: #b91c1c; --red-line: #fecaca;
  --green-bg: #f0fdf4; --green-text: #15803d; --green-line: #bbf7d0;
  --amber-bg: #fef3c7; --amber-text: #92400e;
  --primary: #2563eb; --shadow: 0 1px 3px rgba(0,0,0,.06);
}
:root[data-theme="dark"] {
  --bg: #0f172a; --card: #1e293b; --text: #e5e7eb; --muted: #94a3b8; --gray-text: #d1d5db;
  --line: #334155; --input-bg: #0f172a; --input-line: #475569;
  --gray-bg: #334155; --blue-bg: #172554; --blue-text: #93c5fd; --blue-line: #3b82f6;
  --red-bg: #450a0a; --red-text: #fca5a5; --red-line: #7f1d1d;
  --green-bg: #052e16; --green-text: #86efac; --green-line: #14532d;
  --amber-bg: #451a03; --amber-text: #fcd34d;
  --primary: #3b82f6; --shadow: 0 1px 3px rgba(0,0,0,.4);
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.6;
}
#app { max-width: 640px; margin: 0 auto; min-height: 100vh; padding: 16px 14px calc(96px + env(safe-area-inset-bottom)); }
button { font: inherit; border: none; background: none; cursor: pointer; color: inherit; }
input { font: inherit; color: inherit; }

.topbar { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.topbar h1 { font-size: 1.15rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .sub { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.iconbtn { padding: 6px 10px; border-radius: 8px; background: var(--gray-bg); font-size: .85rem; color: var(--gray-text); white-space: nowrap; }

.card { background: var(--card); border-radius: 14px; padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card h2 { font-size: 1.05rem; margin-bottom: 6px; }
.meta { font-size: .8rem; color: var(--muted); margin-bottom: 10px; }
.statline { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .82rem; color: var(--gray-text); margin-bottom: 12px; }
.statline b { color: var(--primary); }
.statline .warn b { color: var(--red-text); }

.modegrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modebtn {
  min-height: 52px; border-radius: 10px; background: var(--blue-bg); color: var(--blue-text);
  font-size: .95rem; font-weight: 600; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.modebtn small { font-size: .72rem; font-weight: 400; color: var(--muted); }
.modebtn.wrong { background: var(--red-bg); color: var(--red-text); }
.modebtn.review { background: var(--green-bg); color: var(--green-text); }
.modebtn:disabled { opacity: .45; }
.modebtn:active { filter: brightness(.95); }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: .85rem; color: var(--gray-text); margin-bottom: 4px; }
.field input {
  width: 100%; padding: 12px; border: 1px solid var(--input-line); border-radius: 10px; font-size: 1rem; background: var(--input-bg);
}
.field input:focus { outline: 2px solid var(--blue-line); border-color: var(--primary); }
.primary {
  width: 100%; min-height: 48px; border-radius: 10px; background: var(--primary); color: #fff; font-size: 1rem; font-weight: 600;
}
.primary:active { filter: brightness(.92); }
.hint { font-size: .78rem; color: var(--muted); margin-top: 10px; text-align: center; }

.qhead { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.tag { font-size: .72rem; padding: 2px 8px; border-radius: 999px; background: var(--gray-bg); color: var(--gray-text); }
.tag.judge { background: var(--amber-bg); color: var(--amber-text); }
.tag.single { background: var(--blue-bg); color: var(--blue-text); }
.tag.fill { background: var(--green-bg); color: var(--green-text); }
.tag.lastok { background: var(--green-bg); color: var(--green-text); }
.tag.lastno { background: var(--red-bg); color: var(--red-text); }
.tag.wrongtag { background: var(--red-bg); color: var(--red-text); }
.qtext { font-size: 1.02rem; line-height: 2.1; word-break: break-word; }
.qtext img { max-width: 100%; border-radius: 8px; display: block; margin: 8px 0; }
.fill-input {
  width: 7.5em; max-width: 45vw; padding: 4px 8px; margin: 0 2px; border: none; border-bottom: 2px solid var(--blue-line);
  background: var(--blue-bg); border-radius: 6px 6px 0 0; font-size: 1rem; text-align: center;
}
.fill-input:focus { outline: none; border-bottom-color: var(--primary); }
.fill-input:disabled { background: var(--gray-bg); border-bottom-color: var(--input-line); color: var(--muted); }

.opts { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.opt {
  display: flex; gap: 10px; align-items: flex-start; text-align: left;
  padding: 12px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--card); font-size: .95rem; min-height: 46px;
}
.opt .letter { font-weight: 700; color: var(--muted); }
.opt.sel { border-color: var(--primary); background: var(--blue-bg); }
.opt.sel .letter { color: var(--blue-text); }
.opt:disabled { opacity: .7; }
.judgebtns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.judgebtn { min-height: 56px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); font-size: 1.05rem; font-weight: 600; }
.judgebtn.sel { border-color: var(--primary); background: var(--blue-bg); color: var(--blue-text); }

.feedback { margin-top: 14px; border-radius: 10px; padding: 12px; font-size: .92rem; }
.feedback.bad { background: var(--red-bg); border: 1px solid var(--red-line); color: var(--red-text); }
.feedback.good { background: var(--green-bg); border: 1px solid var(--green-line); color: var(--green-text); }
.feedback .ans { font-weight: 700; margin: 4px 0; }
.feedback .exp { color: var(--muted); font-size: .85rem; margin-top: 6px; }
.feedback .blankline { margin-top: 4px; }

.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--line);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
}
.actionbar .inner { max-width: 640px; margin: 0 auto; display: flex; gap: 10px; }
.actionbar .primary { flex: 1; }
.actionbar .secondary { flex: 1; min-height: 48px; border-radius: 10px; background: var(--gray-bg); color: var(--gray-text); font-weight: 600; }
.autotoggle { flex: 0 0 auto; min-height: 48px; padding: 0 14px; border-radius: 10px; background: var(--gray-bg); color: var(--muted); font-size: .85rem; font-weight: 600; }
.autotoggle.on { background: var(--blue-bg); color: var(--blue-text); }

.summary { text-align: center; padding: 28px 16px; }
.summary .big { font-size: 2.2rem; font-weight: 700; color: var(--primary); margin: 8px 0; }
.summary .row { color: var(--gray-text); font-size: .95rem; margin-bottom: 4px; }
.summary .btns { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.summary .btns .secondary { min-height: 48px; border-radius: 10px; background: var(--gray-bg); color: var(--gray-text); font-weight: 600; }
.summary .btns .secondary.wrongbtn { background: var(--red-bg); color: var(--red-text); }

#toast {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 99;
  background: #16a34a; color: #fff; padding: 10px 22px; border-radius: 999px; font-size: .95rem;
  box-shadow: 0 4px 12px rgba(0,0,0,.18); max-width: 86vw; text-align: center;
}
#toast.bad { background: #dc2626; }
#toast.info { background: #374151; }
