:root {
  --bg: #f4f4f9;
  --panel: #ffffff;
  --panel-2: #f0f0f7;
  --line: #e2e2ec;
  --text: #1d1b2c;
  --muted: #6b6880;
  --accent: #4f46e5;
  --accent-2: #db2777;
  --grad: linear-gradient(135deg, #4f46e5, #9333ea 55%, #db2777);
  --ok: #059669;
  --ok-bg: #e7f8f1;
  --ng: #dc2626;
  --ng-bg: #fdecec;
  --seen: #64748b;
  --seen-bg: #eef1f5;
  --shadow: 0 1px 2px rgba(20, 16, 60, .06), 0 6px 20px rgba(20, 16, 60, .06);
  --r: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12111a;
    --panel: #1c1b27;
    --panel-2: #262433;
    --line: #322f42;
    --text: #ecebf5;
    --muted: #9a97ad;
    --accent: #8b85ff;
    --ok: #34d399;
    --ok-bg: #0f2e25;
    --ng: #f87171;
    --ng-bg: #3a1717;
    --seen: #94a3b8;
    --seen-bg: #243041;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
button, a { touch-action: manipulation; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* ヘッダー */
.bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 8px) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: .02em; }
.brand img { border-radius: 7px; }
.brand span { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; font-size: 18px; }
.crumb { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: flex-end; gap: 8px; color: var(--muted); font-size: 14px; }
.crumb b { color: var(--text); font-weight: 700; }

main { max-width: 900px; margin: 0 auto; padding: 16px max(16px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }

/* ホーム */
.summary {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px;
}
.stat { background: var(--panel); border-radius: var(--r); padding: 12px 14px; box-shadow: var(--shadow); }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
h2 { font-size: 15px; color: var(--muted); font-weight: 700; margin: 22px 4px 10px; }
.years { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.year { display: flex; flex-direction: column; background: var(--panel); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.ymain { display: block; padding: 14px 16px 12px; transition: background .1s; }
.ymain:active { background: var(--panel-2); }
.ymiss {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 10px 16px; border-top: 1px solid var(--line); font-size: 14px; font-weight: 700; color: var(--ng);
}
.ymiss b { font-variant-numeric: tabular-nums; }
.ymiss:active { background: var(--ng-bg); }
.ymiss.off { color: var(--muted); font-weight: 400; font-size: 13px; }
.missall {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 14px 18px; border-radius: var(--r); color: #fff; background: linear-gradient(135deg, #e11d48, #db2777 50%, #9333ea);
  box-shadow: 0 6px 18px rgba(225, 29, 72, .25);
}
.missall:active { transform: scale(.99); }
.missall b { display: block; font-size: 17px; }
.missall small { display: block; font-size: 13px; opacity: .9; }
.missall .cnt { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.missall .cnt small { display: inline; font-size: 14px; margin-left: 2px; }
.missall.off { background: var(--panel); color: var(--muted); box-shadow: var(--shadow); pointer-events: none; }
.tag { background: var(--ng-bg); color: var(--ng); font-weight: 700; font-size: 12px; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.crumb b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qhead .no .sub { font-size: 14px; color: var(--muted); font-weight: 700; margin-left: 4px; }
.gy { font-size: 13px; color: var(--muted); font-weight: 700; margin: 12px 2px 6px; }
.gy:first-child { margin-top: 0; }
.pbody { max-height: calc(100vh - 180px); overflow: auto; }
.year .t { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.year .t b { font-size: 17px; }
.year .t small { color: var(--muted); font-variant-numeric: tabular-nums; }
.year .meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; margin-top: 8px; font-variant-numeric: tabular-nums; }
.dots { display: grid; grid-template-columns: repeat(25, 1fr); gap: 2px; margin-top: 10px; }
.dots i { height: 6px; border-radius: 2px; background: var(--panel-2); }
.dots i.c { background: var(--ok); }
.dots i.w { background: var(--ng); }
.dots i.v { background: var(--seen); opacity: .55; }
.foot { margin-top: 28px; color: var(--muted); font-size: 12px; text-align: center; }
.tools { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 22px; }
.btn-s { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px 14px; font-size: 14px; }

/* 問題画面 */
.qhead { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.qhead .no { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.qhead .no small { color: var(--muted); font-weight: 600; font-size: 14px; }
.qhead .hist { margin-left: auto; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.nav { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 20px; line-height: 1; }
.nav:disabled { opacity: .35; }
.sheet {
  background: #fff; border-radius: var(--r); box-shadow: var(--shadow); padding: 12px;
  overflow: hidden;
}
.sheet img { display: block; height: auto; max-width: 100%; margin: 0; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
@media (prefers-color-scheme: dark) { .sheet img { filter: brightness(.94); } }

.dock {
  position: sticky; bottom: 0; z-index: 5;
  margin: 12px -4px 0; padding: 10px 4px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg) 14px);
}
.choices { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.choice {
  height: 64px; border-radius: 14px; border: 2px solid var(--line); background: var(--panel);
  font-size: 26px; font-weight: 700; box-shadow: var(--shadow);
  transition: transform .06s ease, background .15s, border-color .15s;
}
.choice:active { transform: scale(.96); }
.choice.right { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.choice.wrong { background: var(--ng-bg); border-color: var(--ng); color: var(--ng); }
.choice.dim { opacity: .45; }
.row2 { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-top: 10px; align-items: stretch; }
.result {
  display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 0 14px; border-radius: 12px;
  background: var(--panel-2); color: var(--muted); font-weight: 700; font-size: 17px;
}
.result.ok { background: var(--ok-bg); color: var(--ok); }
.result.ng { background: var(--ng-bg); color: var(--ng); }
.result.seen { background: var(--seen-bg); color: var(--seen); }
.result .big { font-size: 22px; }
.primary {
  min-width: 168px; min-height: 52px; border: 0; border-radius: 12px; padding: 0 18px;
  background: var(--grad); color: #fff; font-weight: 800; font-size: 17px;
  box-shadow: 0 6px 18px rgba(124, 58, 237, .28);
}
.primary:active { transform: scale(.98); }

/* 問題一覧 */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 8px; }
.cell {
  height: 52px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-variant-numeric: tabular-nums;
}
.cell.c { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.cell.w { background: var(--ng-bg); border-color: var(--ng); color: var(--ng); }
.cell.v { background: var(--seen-bg); border-color: var(--seen); color: var(--seen); }
.cell.cur { outline: 3px solid var(--accent); outline-offset: 1px; }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 12px; margin: 10px 2px 0; flex-wrap: wrap; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; background: var(--panel-2); border: 1px solid var(--line); }
.legend .c::before { background: var(--ok); border-color: var(--ok); }
.legend .w::before { background: var(--ng); border-color: var(--ng); }
.legend .v::before { background: var(--seen); border-color: var(--seen); }

.overlay {
  position: fixed; inset: 0; z-index: 20; background: rgba(10, 8, 30, .4);
  display: flex; align-items: flex-start; justify-content: center; padding: calc(env(safe-area-inset-top) + 60px) 16px 16px;
}
.pop { background: var(--bg); border-radius: 18px; padding: 16px; width: min(560px, 100%); box-shadow: var(--shadow); }
.pop .ph { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-weight: 800; }

.endcard { background: var(--panel); border-radius: var(--r); box-shadow: var(--shadow); padding: 18px; }
.endcard .score { font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; }
.endcard .acts { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.endcard .acts .primary, .endcard .acts .btn-s { min-height: 48px; display: flex; align-items: center; justify-content: center; }
.endcard .done { display: flex; align-items: center; min-height: 48px; padding: 0 14px; border-radius: 12px; background: var(--ok-bg); color: var(--ok); font-weight: 700; }

@media (max-width: 520px) {
  .summary .stat .v { font-size: 19px; }
  .choice { height: 58px; font-size: 24px; }
  .primary { min-width: 132px; font-size: 16px; }
  .result { font-size: 15px; }
}
