:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #eef0f5;
  --text: #1a1f2b;
  --muted: #5f6878;
  --border: #d9dde6;
  --accent: #3b5bdb;
  --accent-soft: #e6ebff;
  --on-accent: #ffffff;
  --rec: #1f8a4c;
  --rec-soft: #e3f5ea;
  --easy: #1f8a4c;
  --medium: #b7791f;
  --hard: #c0392b;
  --decided: #3b5bdb;
  --info: #8e44ad;
  --applied: #5f6878;
  --warn-bg: #fff4d6;
  --warn-text: #7a5300;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1420;
    --surface: #171e2d;
    --surface-2: #1f2839;
    --text: #e6e9f0;
    --muted: #96a0b3;
    --border: #2c3648;
    --accent: #7b93ff;
    --accent-soft: #232d4d;
    --on-accent: #0f1420;
    --rec: #4cc985;
    --rec-soft: #183326;
    --easy: #4cc985;
    --medium: #e6b04f;
    --hard: #ff7a6b;
    --decided: #7b93ff;
    --info: #c89cf0;
    --applied: #96a0b3;
    --warn-bg: #3a2f12;
    --warn-text: #f3d48a;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1420; --surface: #171e2d; --surface-2: #1f2839; --text: #e6e9f0; --muted: #96a0b3;
  --border: #2c3648; --accent: #7b93ff; --accent-soft: #232d4d; --on-accent: #0f1420; --rec: #4cc985; --rec-soft: #183326;
  --easy: #4cc985; --medium: #e6b04f; --hard: #ff7a6b; --decided: #7b93ff; --info: #c89cf0;
  --applied: #96a0b3; --warn-bg: #3a2f12; --warn-text: #f3d48a; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow-x: hidden;
}
a { color: var(--accent); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .86em;
  background: var(--surface-2); padding: .08em .3em; border-radius: 4px; overflow-wrap: anywhere; }
pre { background: var(--surface-2); padding: 10px 12px; border-radius: 8px; overflow-x: auto; font-size: .85em; }
pre code { background: none; padding: 0; }
.muted { color: var(--muted); }
.pad { padding: 16px; }
button { font: inherit; cursor: pointer; }
button.link { background: none; border: none; color: var(--muted); padding: 4px; }
button.primary { background: var(--accent); color: var(--on-accent); border: none; border-radius: 10px;
  padding: 12px 18px; font-weight: 600; }
button.primary:disabled { opacity: .5; cursor: default; }
button.ghost { background: none; border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 10px 14px; }
textarea, input[type=search], input[type=password], select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; width: 100%; }
textarea { min-height: 96px; resize: vertical; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center;
  justify-content: space-between; gap: 8px; padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar .brand { font-weight: 700; color: var(--text); text-decoration: none; }
.topbar form { margin: 0; }

main { max-width: 760px; margin: 0 auto; padding: 12px 16px 96px; }

/* ---------- list ---------- */
.stats { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .9em; color: var(--muted); margin: 4px 0 12px; }
.stats b { color: var(--text); }
.controls { display: grid; gap: 10px; margin-bottom: 14px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 6px 12px; font-size: .9em; white-space: nowrap; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chip .n { opacity: .7; margin-left: 4px; }
.row2 { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.row2 select { width: auto; }

.card { display: block; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 10px; box-shadow: var(--shadow);
  color: inherit; text-decoration: none; }
.card:active { background: var(--surface-2); }
.card h2 { font-size: 1.02em; margin: 6px 0 4px; line-height: 1.35; }
.card .summary { color: var(--muted); font-size: .92em; }
.card .summary p { margin: 0; }
.card .answer { margin-top: 8px; font-size: .9em; border-left: 3px solid var(--decided);
  padding-left: 8px; }
.card .answer.info { border-color: var(--info); }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: .78em; }
.qid { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); overflow-wrap: anywhere; }
.badge { display: inline-block; border-radius: 999px; padding: 1px 8px; font-weight: 600;
  font-size: .78rem; border: 1px solid currentColor; white-space: nowrap; }
.badge.easy { color: var(--easy); }
.badge.medium { color: var(--medium); }
.badge.hard { color: var(--hard); }
.badge.undecided { color: var(--muted); }
.badge.decided { color: var(--decided); }
.badge.info_requested { color: var(--info); }
.badge.applied, .badge.withdrawn { color: var(--applied); }
.badge.rec { color: var(--rec); background: var(--rec-soft); border-color: transparent; }
.badge.note { color: var(--info); border-style: dashed; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* ---------- detail ---------- */
.nav { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.nav a, .nav span { font-size: .92em; text-decoration: none; }
.nav .pn { display: flex; gap: 6px; }
.nav .pn a, .nav .pn span { border: 1px solid var(--border); border-radius: 8px; padding: 4px 10px;
  background: var(--surface); }
.nav .pn span { color: var(--muted); opacity: .5; }
.detail h1 { font-size: 1.3em; line-height: 1.3; margin: 8px 0 10px; }
.section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow); }
.section > h3 { margin: 0 0 8px; font-size: .8em; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.section .body > :first-child { margin-top: 0; }
.section .body > :last-child { margin-bottom: 0; }
.body { overflow-wrap: anywhere; }
.body table { border-collapse: collapse; display: block; overflow-x: auto; font-size: .9em; }
.body th, .body td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; }
details.section > summary { cursor: pointer; font-weight: 600; list-style: none; display: flex;
  justify-content: space-between; align-items: center; gap: 8px; }
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::after { content: ""; flex: none; width: 8px; height: 8px; margin: 0 4px 4px 0;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg);
  transition: transform .15s; }
details.section[open] > summary::after { transform: rotate(-135deg); margin-bottom: -4px; }
details.section[open] > summary { margin-bottom: 10px; }
details.section > summary small { font-weight: 400; color: var(--muted); margin-left: auto; font-size: .8em; text-align: right; }

.notice { background: var(--warn-bg); color: var(--warn-text); border-radius: 10px; padding: 10px 12px;
  font-size: .92em; margin-bottom: 12px; }

.choice { display: block; position: relative; border: 1.5px solid var(--border); border-radius: 10px;
  padding: 12px 12px 12px 42px; margin-bottom: 8px; cursor: pointer; background: var(--surface); }
.choice input[type=radio] { position: absolute; left: 14px; top: 15px; width: 18px; height: 18px; margin: 0;
  accent-color: var(--accent); }
.choice.rec { border-color: var(--rec); background: var(--rec-soft); }
.choice.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.choice .label { font-weight: 600; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.choice .key { font-family: ui-monospace, monospace; color: var(--muted); font-weight: 700; }
.choice .desc { font-size: .93em; margin-top: 4px; }
.choice .desc > :first-child { margin-top: 0; }
.choice .desc > :last-child { margin-bottom: 0; }
.choice.alt { border-style: dashed; }
.extra { margin: -2px 0 10px; }
.extra label { display: block; font-size: .85em; color: var(--muted); margin-bottom: 4px; }
.savebar { position: sticky; bottom: 0; padding: 10px 0 max(10px, env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg) 30%); display: flex; gap: 8px;
  align-items: center; }
.savebar .primary { flex: 1; }
.savebar .status { font-size: .88em; color: var(--muted); }
.error { color: var(--hard); font-size: .9em; margin: 6px 0; }

.current { border-left: 4px solid var(--decided); }
.current.info_requested { border-left-color: var(--info); }
.history { list-style: none; padding: 0; margin: 0; font-size: .9em; }
.history li { padding: 8px 0; border-top: 1px solid var(--border); }
.history li:first-child { border-top: none; }
.history .when { color: var(--muted); font-size: .85em; }
.history .reply { margin-top: 4px; padding: 6px 10px; background: var(--surface-2); border-radius: 8px; }
.ptext { white-space: pre-wrap; overflow-wrap: anywhere; }

.apply-opt { border-top: 1px solid var(--border); padding-top: 8px; margin-top: 8px; }
.apply-opt h4 { margin: 0 0 4px; font-size: .95em; }

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px 22px; display: grid; gap: 12px; text-align: center; box-shadow: var(--shadow); }
.login-card h1 { margin: 0; font-size: 1.3em; }
.login-card p { margin: 0 0 6px; }
.login-mark { font-size: 2em; color: var(--accent); }
.alert { background: var(--warn-bg); color: var(--warn-text); border-radius: 8px; padding: 8px; font-size: .9em; }
