:root {
  --bg: #f7f7f5;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --line: #d8d8d4;
  --accent: #1f5fb4;
  --good: #1a7a3a;
  --bad: #b3261e;
  --card: #ffffff;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
}

#login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
#login-overlay .card { width: 100%; max-width: 360px; }
#login-overlay input[type="password"] {
  display: block;
  width: 100%;
  margin: 0.6rem 0;
  padding: 0.6rem 0.7rem;
  font-size: 1rem;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
}
#login-overlay button { width: 100%; }
#login-overlay .error {
  margin-top: 0.6rem;
  color: var(--bad);
  font-size: 0.9rem;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 5;
}
#header-right { display: flex; gap: 0.5rem; align-items: center; }

h1 { font-size: 1.1rem; margin: 0; }
h2 { margin-top: 0; }

#timer {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  border-radius: 0.4rem;
  background: #eef2f8;
  color: var(--accent);
}
#timer.warn { background: #fdecea; color: var(--bad); }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.25rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}
.card h3 { margin-top: 0; }
.card p { color: var(--muted); margin: 0.25rem 0 0.75rem; }

select, button {
  font: inherit;
  padding: 0.5rem 0.9rem;
  border-radius: 0.4rem;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
}
select { margin-left: 0.4rem; }
button { background: var(--accent); color: #fff; border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--muted); border-color: var(--line); }

.muted { color: var(--muted); font-size: 0.9rem; }
.err { color: var(--bad); }

#progress {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

#question-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.q-text { font-weight: 600; font-size: 1.05rem; margin-bottom: 0.25rem; }
.q-hint { color: var(--muted); font-size: 0.85rem; margin-bottom: 0.85rem; }

.options { list-style: none; padding: 0; margin: 0; }
.options li {
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  margin-bottom: 0.5rem;
  background: #fff;
}
.options label {
  display: flex;
  gap: 0.6rem;
  padding: 0.7rem 0.9rem;
  cursor: pointer;
  align-items: flex-start;
}
.options input { margin-top: 0.2rem; }
.options li.good { border-color: var(--good); background: #eaf6ee; }
.options li.bad  { border-color: var(--bad);  background: #fdecea; }
.options li.disabled label { cursor: default; }

.explanation {
  margin-top: 0.9rem;
  padding: 0.75rem 0.9rem;
  background: #f1f1ee;
  border-left: 3px solid var(--accent);
  border-radius: 0.3rem;
  font-size: 0.95rem;
}
.explanation .verdict { font-weight: 700; margin-right: 0.4rem; }
.explanation .verdict.good { color: var(--good); }
.explanation .verdict.bad  { color: var(--bad); }

#nav-buttons { display: flex; gap: 0.5rem; flex-wrap: wrap; }
#nav-buttons #btn-prev { margin-right: auto; background: #fff; color: var(--fg); border-color: var(--line); }

#score-summary {
  font-size: 1.1rem;
  padding: 1rem 1.25rem;
  border-radius: 0.5rem;
  background: #fff;
  border: 1px solid var(--line);
  margin-bottom: 0.5rem;
}
#score-summary .pass { color: var(--good); font-weight: 700; }
#score-summary .fail { color: var(--bad);  font-weight: 700; }

#save-status { margin-bottom: 1rem; }

#results-list .result-item {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.85rem 1rem;
  margin-bottom: 0.6rem;
}
#results-list .result-item .q { font-weight: 600; margin-bottom: 0.3rem; }
#results-list .result-item .a { font-size: 0.9rem; color: var(--muted); }
#results-list .result-item.bad { border-left: 3px solid var(--bad); }
#results-list .result-item.good { border-left: 3px solid var(--good); }
#results-list .result-item .origin {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.05rem 0.4rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  background: #eef0ee;
  border-radius: 0.3rem;
  vertical-align: middle;
}

#history-list { margin-bottom: 1rem; }
.history-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1.2fr 0.6fr;
  gap: 0.6rem;
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  padding: 0.6rem 0.8rem;
  margin-bottom: 0.45rem;
  font-size: 0.92rem;
}
.history-row.good { border-left: 3px solid var(--good); }
.history-row.bad  { border-left: 3px solid var(--bad); }
.history-row .pass { color: var(--good); font-weight: 700; margin-left: 0.4rem; }
.history-row .fail { color: var(--bad);  font-weight: 700; margin-left: 0.4rem; }
.hr-time { font-variant-numeric: tabular-nums; color: var(--muted); text-align: right; }
@media (max-width: 520px) {
  .history-row { grid-template-columns: 1fr 1fr; }
  .hr-date { grid-column: 1 / span 2; font-weight: 600; }
}

#stats-body h3 { margin-top: 1.5rem; margin-bottom: 0.5rem; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}
@media (max-width: 520px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
.stat-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.8rem 0.9rem;
  text-align: center;
}
.stat-num {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
}
.stat-lbl {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.mode-table {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  overflow: hidden;
}
.mode-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr 1fr;
  gap: 0.5rem;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}
.mode-row:last-child { border-bottom: none; }
.mode-row .m-name { font-weight: 600; }

.exam-table-wrap { overflow-x: auto; }
.exam-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  overflow: hidden;
  font-size: 0.92rem;
}
.exam-table th, .exam-table td {
  padding: 0.5rem 0.7rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.exam-table th {
  background: #f0f0ec;
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.exam-table tr:last-child td { border-bottom: none; }
.exam-table tr.good td:first-child { border-left: 3px solid var(--good); }
.exam-table tr.bad  td:first-child { border-left: 3px solid var(--bad); }

.missed-list { display: flex; flex-direction: column; gap: 0.45rem; }
.missed-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  background: #fff;
  border: 1px solid var(--line);
  border-left: 3px solid var(--bad);
  border-radius: 0.4rem;
  padding: 0.7rem 0.9rem;
  font-size: 0.92rem;
}
.missed-q { flex: 1; }
.missed-q .origin {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.05rem 0.4rem;
  font-size: 0.72rem;
  color: var(--muted);
  background: #eef0ee;
  border-radius: 0.3rem;
  vertical-align: middle;
}
.missed-stat { white-space: nowrap; font-weight: 600; }

#home-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.2rem;
  margin-bottom: 1rem;
  font-size: 0.92rem;
  color: var(--muted);
}
#home-summary b { color: var(--fg); font-weight: 700; }
#home-summary:empty { display: none; }

#prefs {
  margin-bottom: 1rem;
  font-size: 0.92rem;
  color: var(--muted);
}
#prefs label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  user-select: none;
}
#prefs input { cursor: pointer; }

#exam-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.5rem;
}
.exam-btn {
  background: #fff;
  color: var(--fg);
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 0.45rem;
  padding: 0.7rem 0.6rem;
  text-align: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font: inherit;
  transition: border-color 0.1s ease, transform 0.05s ease;
}
.exam-btn:hover { border-color: var(--accent); }
.exam-btn:active { transform: translateY(1px); }
.exam-btn.untried { border-left-color: var(--line); }
.exam-btn.good    { border-left-color: var(--good); }
.exam-btn.ok      { border-left-color: #c9a300; }
.exam-btn.bad     { border-left-color: var(--bad); }
.eb-num {
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--accent);
}
.eb-stats { font-size: 0.74rem; color: var(--muted); }
.eb-stats b { color: var(--fg); }
