:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --ok: #22c55e;
  --ng: #f87171;
  --due: #fbbf24;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN",
    "Yu Gothic", Meiryo, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.title { font-weight: 700; font-size: 17px; }
.icon-btn {
  background: none; border: none; color: var(--text);
  font-size: 20px; cursor: pointer; padding: 4px 8px;
}

.view { padding: 20px 16px 40px; max-width: 640px; margin: 0 auto; }
.hidden { display: none !important; }

h2 { font-size: 20px; margin: 8px 0 12px; }
.hint { color: var(--muted); font-size: 14px; margin-top: 0; }

label {
  display: block;
  margin: 16px 0 4px;
  font-size: 14px;
  color: var(--muted);
}
label.row { display: flex; align-items: center; gap: 8px; color: var(--text); }
input[type="url"], input[type="password"], input[type="text"], input[type="number"] {
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  font-size: 16px;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: 10px;
  color: var(--text);
}
input[type="checkbox"] { width: 20px; height: 20px; }

button {
  font-size: 16px;
  border-radius: 12px;
  border: none;
  padding: 14px 18px;
  cursor: pointer;
  color: var(--text);
  background: var(--surface2);
}
button.primary { background: var(--accent); color: #06223a; font-weight: 700; }
button.big { font-size: 18px; padding: 16px; width: 100%; }
button:active { transform: scale(0.98); }

.msg { margin-top: 14px; font-size: 14px; color: var(--muted); min-height: 20px; }
.msg.error { color: var(--ng); }
.msg.success { color: var(--ok); }

/* 出題 */
.progress {
  height: 6px; background: var(--surface2);
  border-radius: 99px; overflow: hidden;
}
.progress-bar {
  height: 100%; width: 0%;
  background: var(--accent);
  transition: width 0.25s ease;
}
.counter {
  display: flex; justify-content: space-between;
  margin: 10px 2px 16px; font-size: 14px; color: var(--muted);
}
.tally { font-variant-numeric: tabular-nums; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px 20px;
  min-height: 180px;
}
.meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip {
  font-size: 12px; padding: 4px 10px; border-radius: 99px;
  background: var(--surface2); color: var(--text);
}
.chip.ghost { background: transparent; border: 1px solid var(--surface2); color: var(--muted); }
.chip.due { background: transparent; border: 1px solid var(--due); color: var(--due); }

.question { font-size: 21px; line-height: 1.6; font-weight: 600; }
.answer-block hr { border: none; border-top: 1px solid var(--surface2); margin: 20px 0; }
.answer { font-size: 17px; line-height: 1.75; color: var(--text); white-space: pre-wrap; }

.actions { margin-top: 20px; }
.grade-btns { display: flex; gap: 12px; }
button.ok { background: var(--ok); color: #052e10; font-weight: 700; }
button.ng { background: var(--ng); color: #3a0606; font-weight: 700; }

.ghost-btn {
  display: block;
  width: 100%;
  margin-top: 14px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  padding: 10px;
}
.ghost-btn:active { color: var(--text); }

/* 過去問モードの選択肢 */
.kk-choices { list-style: none; padding: 0; margin: 16px 0 0; }
.kk-choices li {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; margin: 8px 0;
  background: var(--surface2); border-radius: 10px; cursor: pointer;
  line-height: 1.6;
}
.kk-choices li.sel { outline: 2px solid var(--accent); }
.kk-choices li.correct { background: #14361f; }
.kk-choices li.wrong { background: #3f1518; }
.kk-choices .lab { font-weight: 700; min-width: 1.5em; }
.expl { white-space: pre-wrap; color: var(--muted); font-size: 15px; margin-top: 12px; line-height: 1.75; }
select {
  width: 100%; margin-top: 6px; padding: 12px 14px; font-size: 16px;
  background: var(--surface); border: 1px solid var(--surface2); border-radius: 10px; color: var(--text);
}
.maybe { background: var(--due); color: #3a2c06; font-weight: 700; }

.summary { font-size: 17px; line-height: 1.8; }
.done-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }

/* スピナー */
.spinner {
  width: 38px; height: 38px; margin: 40px auto 16px;
  border: 4px solid var(--surface2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loadingView { text-align: center; color: var(--muted); }
#doneView { text-align: center; }
