:root {
  --bg: #0a0c10;
  --bg2: #10131a;
  --surface: #161a24;
  --surface2: #1d222e;
  --line: #262c3a;
  --text: #eef1f6;
  --muted: #8d96a9;
  --faint: #5b6478;
  --tech: #4cc9f0;
  --mgmt: #f4b942;
  --strat: #f472b6;
  --ok: #3ddc84;
  --ng: #ff5c6c;
  --accent: #7c8cff;
  --gold: #ffb84c;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --top-h: 52px;
  --nav-h: 58px;
  --fs: 17px;
  --radius: 20px;
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
:root[data-theme="light"] {
  --bg: #f4f5f8; --bg2: #ffffff; --surface: #ffffff; --surface2: #f0f2f6; --line: #e1e5ee;
  --text: #141821; --muted: #5a6478; --faint: #9aa3b5;
  --tech: #0b8fc2; --mgmt: #c77d00; --strat: #d1308a; --ok: #1fa85c; --ng: #e0364a; --accent: #4b5bd6; --gold: #c77d00;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  position: fixed; inset: 0; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: var(--fs); line-height: 1.6;
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
  touch-action: manipulation; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
b, strong { font-weight: 700; }
small { font-size: .75em; }
[hidden] { display: none !important; }

/* ---------- top HUD ---------- */
#top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 20;
  height: calc(var(--top-h) + var(--sat)); padding: var(--sat) 14px 0 16px;
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(to bottom, rgba(10,12,16,.92), rgba(10,12,16,.55) 70%, transparent);
  pointer-events: none;
}
:root[data-theme="light"] #top { background: linear-gradient(to bottom, rgba(244,245,248,.95), rgba(244,245,248,.6) 70%, transparent); }
#top > * { pointer-events: auto; }
.brand { font-family: var(--mono); font-weight: 800; letter-spacing: .02em; display: flex; align-items: baseline; gap: 4px; }
.brand-ap { font-size: 22px; background: linear-gradient(120deg, var(--tech), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand-sub { font-size: 11px; color: var(--muted); font-family: var(--font); font-weight: 600; }
.hud { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.hud-item b { color: var(--text); font-variant-numeric: tabular-nums; }
.hud-item small { margin-left: 2px; }
.hud-count { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.hud-gear { font-size: 20px; color: var(--muted); padding: 4px; }
.ring { position: relative; width: 30px; height: 30px; display: inline-block; }
.ring svg { width: 30px; height: 30px; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--line); stroke-width: 3.5; }
.ring-fg { fill: none; stroke: var(--ok); stroke-width: 3.5; stroke-linecap: round; stroke-dasharray: 97.4; stroke-dashoffset: 97.4; transition: stroke-dashoffset .5s ease; }
.ring-txt { position: absolute; inset: 0; display: grid; place-items: center; font-size: 10px; font-weight: 700; color: var(--text); font-family: var(--mono); }
.combo {
  position: absolute; left: 50%; top: calc(var(--sat) + var(--top-h) + 2px); transform: translateX(-50%);
  font-family: var(--mono); font-weight: 800; font-size: 13px; letter-spacing: .08em;
  color: var(--gold); background: rgba(255,184,76,.12); border: 1px solid rgba(255,184,76,.35);
  padding: 3px 12px; border-radius: 999px; animation: pop .35s cubic-bezier(.2,1.4,.4,1);
}

/* ---------- feed ---------- */
#feed {
  position: absolute; inset: 0; overflow-y: scroll; overflow-x: hidden;
  scroll-snap-type: y mandatory; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain; scrollbar-width: none;
}
#feed::-webkit-scrollbar { display: none; }
.card {
  position: relative; height: 100%; width: 100%; scroll-snap-align: start; scroll-snap-stop: always;
  padding: calc(var(--sat) + var(--top-h) + 6px) 18px calc(var(--nav-h) + var(--sab) + 10px);
  display: flex; flex-direction: column;
}
.card-inner {
  flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px 22px; position: relative; isolation: isolate;
  box-shadow: 0 20px 50px -20px rgba(0,0,0,.6);
  display: flex; flex-direction: column;
}
.card-inner::-webkit-scrollbar { display: none; }
.card-inner::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; border-radius: var(--radius) var(--radius) 0 0;
  background: var(--c, var(--accent)); opacity: .9;
}
.card-inner::after {
  content: ""; position: absolute; inset: 0; z-index: -1; border-radius: inherit; pointer-events: none;
  background: radial-gradient(120% 60% at 100% 0%, color-mix(in srgb, var(--c, var(--accent)) 14%, transparent), transparent 60%);
}
.card[data-major="tech"] { --c: var(--tech); }
.card[data-major="mgmt"] { --c: var(--mgmt); }
.card[data-major="strat"] { --c: var(--strat); }
.card[data-kind="system"] { --c: var(--accent); }

.meta { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-weight: 700; font-size: 11.5px; letter-spacing: .02em;
  background: color-mix(in srgb, var(--c, var(--accent)) 18%, transparent); color: var(--c, var(--accent)); }
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.kind { font-family: var(--mono); font-size: 11px; color: var(--faint); letter-spacing: .1em; text-transform: uppercase; margin-left: auto; }
.sub { color: var(--muted); }
.due-tag { color: var(--gold); font-weight: 700; }

h1.title { font-size: 24px; line-height: 1.3; margin: 0 0 12px; font-weight: 800; letter-spacing: -.01em; }
.body { font-size: var(--fs); color: var(--text); margin: 0 0 14px; white-space: pre-line; }
.points { margin: 0 0 14px; padding: 0; list-style: none; }
.points li { position: relative; padding-left: 20px; margin: 6px 0; font-size: calc(var(--fs) - 1px); }
.points li::before { content: "◆"; position: absolute; left: 0; font-size: 10px; color: var(--c, var(--accent)); top: .45em; }
.formula { font-family: var(--mono); font-size: 14px; background: var(--surface2); border: 1px dashed var(--line); border-radius: 12px; padding: 10px 12px; margin: 0 0 14px; white-space: pre-line; }
.tip { background: color-mix(in srgb, var(--gold) 12%, transparent); border: 1px solid color-mix(in srgb, var(--gold) 35%, transparent); border-radius: 14px; padding: 10px 12px; font-size: 14.5px; color: var(--text); margin-bottom: 14px; white-space: pre-line; }
.tip::before { content: "試験ではこう出る"; display: block; font-size: 11px; font-weight: 800; letter-spacing: .08em; color: var(--gold); margin-bottom: 3px; }

.q { font-size: calc(var(--fs) + 1px); font-weight: 600; line-height: 1.65; margin: 0 0 16px; white-space: pre-line; }
.choices { display: flex; flex-direction: column; gap: 9px; margin-bottom: 14px; }
.choice {
  display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start; text-align: left;
  padding: 11px 13px; border-radius: 14px; background: var(--surface2); border: 1.5px solid var(--line);
  font-size: calc(var(--fs) - 1px); line-height: 1.5; transition: transform .08s, border-color .15s, background .15s;
  white-space: pre-line;
}
.choice:active { transform: scale(.985); }
.choice .lbl { font-family: var(--mono); font-weight: 800; color: var(--muted); width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; background: var(--surface); font-size: 13px; }
.choice.picked { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--surface2)); }
.choice.correct { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, var(--surface2)); }
.choice.correct .lbl { background: var(--ok); color: #04210f; }
.choice.wrong { border-color: var(--ng); background: color-mix(in srgb, var(--ng) 12%, var(--surface2)); }
.choice.wrong .lbl { background: var(--ng); color: #fff; }
.choices.done .choice { pointer-events: none; }
.choices.done .choice:not(.correct):not(.wrong):not(.picked) { opacity: .5; }

.tf-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 10px 0 14px; }
.tf-btn { font-size: 40px; font-weight: 900; padding: 18px 0; border-radius: 18px; background: var(--surface2); border: 1.5px solid var(--line); font-family: var(--mono); }
.tf-btn.correct { border-color: var(--ok); color: var(--ok); }
.tf-btn.wrong { border-color: var(--ng); color: var(--ng); }
.tf-btns.done .tf-btn { pointer-events: none; }
.tf-btns.done .tf-btn:not(.correct):not(.wrong) { opacity: .4; }

.term-box { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 12px 0; }
.term { font-size: 30px; font-weight: 900; line-height: 1.3; letter-spacing: -.01em; }
.term-hint { color: var(--faint); font-size: 13px; margin-top: 16px; }
.term-def { margin-top: 16px; font-size: var(--fs); color: var(--text); white-space: pre-line; animation: fadeup .3s ease; }
.term-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }

.verdict { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; margin: 4px 0 8px; animation: fadeup .25s ease; }
.verdict.ok { color: var(--ok); } .verdict.ng { color: var(--ng); }
.verdict .xp { font-family: var(--mono); font-size: 12px; color: var(--gold); background: rgba(255,184,76,.12); padding: 2px 8px; border-radius: 999px; margin-left: auto; }
.explain { background: var(--surface2); border-radius: 14px; padding: 12px 14px; font-size: calc(var(--fs) - 2px); line-height: 1.7; white-space: pre-line; animation: fadeup .3s ease; margin-bottom: 12px; -webkit-user-select: text; user-select: text; }
.explain::before { content: "解説"; display: block; font-size: 11px; font-weight: 800; letter-spacing: .1em; color: var(--muted); margin-bottom: 4px; }

.actions { display: flex; gap: 8px; margin-top: auto; padding-top: 10px; flex-wrap: wrap; position: sticky; bottom: -22px; margin-bottom: -22px; padding-bottom: 22px; background: linear-gradient(to top, var(--surface) 62%, transparent); z-index: 2; padding-top: 18px; }
.sys .actions { position: static; margin-bottom: 0; padding-bottom: 0; background: none; }
.row .meta2 .w { color: var(--c, var(--accent)); font-weight: 700; }
.btn { flex: 1; padding: 12px 14px; border-radius: 14px; font-weight: 700; font-size: 15px; background: var(--surface2); border: 1px solid var(--line); text-align: center; min-width: 0; transition: transform .08s; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--c, var(--accent)); color: #0a0c10; border-color: transparent; }
.btn.ghost { flex: 0 0 auto; padding: 12px; }
.btn.on { color: var(--gold); border-color: rgba(255,184,76,.5); }
.btn.sm { padding: 8px 12px; font-size: 13px; flex: 0 0 auto; }
.link { color: var(--c, var(--accent)); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }

/* system cards */
.sys { text-align: center; display: flex; flex-direction: column; align-items: center; justify-content: center; flex: 1; gap: 10px; }
.sys .big { font-size: 56px; line-height: 1; }
.sys h1 { font-size: 26px; margin: 6px 0 2px; font-weight: 900; }
.sys p { margin: 0; color: var(--muted); font-size: 15px; white-space: pre-line; }
.sys .numbers { display: flex; gap: 18px; margin: 10px 0; }
.sys .numbers div { text-align: center; }
.sys .numbers b { display: block; font-size: 30px; font-family: var(--mono); line-height: 1.1; }
.sys .numbers span { font-size: 12px; color: var(--muted); }
.sys .actions { width: 100%; margin-top: 10px; }
.sys .actions .btn { flex: 1; }
.hint { margin-top: 10px; font-size: 13px; color: var(--muted); background: var(--surface2); border-radius: 12px; padding: 10px 12px; text-align: left; width: 100%; }
.swipe-hint { position: absolute; bottom: calc(var(--nav-h) + var(--sab) + 14px); left: 0; right: 0; text-align: center; font-size: 12px; color: var(--faint); pointer-events: none; animation: bob 1.6s ease-in-out infinite; }

/* ---------- nav ---------- */
#tabs {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--nav-h) + var(--sab)); padding: 0 8px var(--sab);
  display: flex; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 10.5px; font-weight: 600; color: var(--faint); }
.tab-ico { font-size: 19px; line-height: 1; }
.tab.active { color: var(--text); }
.tab.active .tab-ico { color: var(--accent); }

/* ---------- sheet (overlay panels) ---------- */
.sheet { position: absolute; inset: 0; z-index: 30; background: var(--bg); display: flex; flex-direction: column; animation: slideup .25s ease; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: calc(var(--sat) + 12px) 18px 10px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; font-size: 20px; font-weight: 900; }
.sheet-close { font-size: 18px; color: var(--muted); padding: 6px 8px; }
.sheet-body { flex: 1; overflow-y: auto; padding: 14px 18px calc(var(--nav-h) + var(--sab) + 20px); -webkit-overflow-scrolling: touch; }
.sheet-body h3 { font-size: 12px; letter-spacing: .1em; color: var(--muted); margin: 18px 0 8px; font-weight: 800; text-transform: uppercase; }
.sheet-body h3:first-child { margin-top: 2px; }
.sheet-body p { color: var(--muted); font-size: 14px; margin: 6px 0; }
.sheet-body .btn { width: 100%; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.row .grow { flex: 1; min-width: 0; }
.row .name { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.row .name small { color: var(--faint); font-weight: 600; font-family: var(--mono); }
.row .meta2 { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; gap: 10px; flex-wrap: wrap; }
.row .meta2 span { white-space: nowrap; }
.bar { height: 5px; border-radius: 99px; background: var(--line); margin-top: 7px; overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; background: var(--c, var(--accent)); }
.bar i.acc { background: var(--ok); opacity: .9; }
.row[data-major="tech"] { --c: var(--tech); } .row[data-major="mgmt"] { --c: var(--mgmt); } .row[data-major="strat"] { --c: var(--strat); }
.toggle { width: 44px; height: 26px; border-radius: 99px; background: var(--line); position: relative; flex: 0 0 auto; transition: background .15s; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: left .15s; }
.toggle.on { background: var(--ok); } .toggle.on::after { left: 21px; }
.pill { padding: 6px 12px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--surface2); border: 1px solid var(--line); color: var(--muted); flex: 0 0 auto; }
.pill.on { color: var(--text); border-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; }
.stat b { display: block; font-size: 26px; font-family: var(--mono); line-height: 1.1; }
.stat span { font-size: 12px; color: var(--muted); }
.days { display: flex; gap: 6px; align-items: flex-end; height: 70px; margin: 8px 0 4px; }
.days div { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; font-size: 10px; color: var(--faint); font-family: var(--mono); }
.days i { display: block; width: 100%; border-radius: 6px 6px 3px 3px; background: var(--accent); min-height: 3px; }
.days .today i { background: var(--ok); }
.seg { display: flex; gap: 6px; }
.seg .pill { flex: 1; text-align: center; }
.field { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 15px; gap: 10px; }
.field .seg { width: 58%; }
.list-item { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; display: block; width: 100%; text-align: left; }
.list-item .t { font-weight: 700; }
.list-item .s { color: var(--muted); font-size: 12px; }
.danger { color: var(--ng); }
.major-head { display: flex; align-items: center; justify-content: space-between; margin: 18px 0 4px; }
.major-head h3 { margin: 0; }

/* exam */
.exam-timer { font-family: var(--mono); font-weight: 800; color: var(--gold); }
.exam-progress { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.result-cats { width: 100%; text-align: left; font-size: 13px; }
.result-cats .row { padding: 8px 0; }
.score { font-size: 64px; font-family: var(--mono); font-weight: 900; line-height: 1; }
.score small { font-size: 20px; color: var(--muted); }

/* ---------- toast / fx ---------- */
.toast { position: absolute; left: 50%; bottom: calc(var(--nav-h) + var(--sab) + 16px); transform: translateX(-50%); z-index: 40;
  background: var(--surface2); border: 1px solid var(--line); color: var(--text); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); animation: pop .3s cubic-bezier(.2,1.4,.4,1); max-width: 90%; text-align: center; }
.fx { position: absolute; inset: 0; pointer-events: none; z-index: 50; overflow: hidden; }
.fx .p { position: absolute; width: 8px; height: 8px; border-radius: 2px; animation: confetti 1.1s ease-out forwards; }
.xp-float { position: absolute; font-family: var(--mono); font-weight: 900; color: var(--gold); font-size: 18px; animation: floatup .9s ease-out forwards; pointer-events: none; z-index: 45; text-shadow: 0 2px 10px rgba(0,0,0,.5); }

@keyframes pop { from { transform: translateX(-50%) scale(.6); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }
@keyframes fadeup { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes slideup { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes confetti { 0% { transform: translate(0,0) rotate(0); opacity: 1; } 100% { transform: translate(var(--dx), var(--dy)) rotate(540deg); opacity: 0; } }
@keyframes floatup { 0% { transform: translateY(0); opacity: 0; } 15% { opacity: 1; } 100% { transform: translateY(-70px); opacity: 0; } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.shake { animation: shake .3s ease; }

@media (min-width: 640px) {
  #feed, #top, #tabs, .sheet { left: 50%; right: auto; width: 440px; transform: translateX(-50%); }
  .toast { left: 50%; }
  body { background: #05060a; }
  :root[data-theme="light"] body { background: #dfe3ea; }
}
