:root {
  --bg: #f4f7f9;
  --card: #ffffff;
  --primary: #1c8c8c;
  --primary-dark: #156d6d;
  --accent: #f0a500;
  --text: #243240;
  --muted: #6b7c8c;
  --border: #dfe6ec;
  --correct: #1faa59;
  --wrong: #d64545;
  --pass-bg: #e7f7ef;
  --fail-bg: #fdecec;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", "Yu Gothic UI", "Hiragino Sans", "Meiryo", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
}

#app {
  max-width: 760px;
  margin: 0 auto;
  padding: 28px 18px 56px;
}

header.app-head { text-align: center; margin-bottom: 22px; }
header.app-head h1 { font-size: 20px; margin: 0 0 4px; color: var(--primary-dark); }
header.app-head p { margin: 0; font-size: 13px; color: var(--muted); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 26px;
  box-shadow: 0 4px 18px rgba(28, 140, 140, 0.06);
}

.hidden { display: none !important; }

/* Buttons */
button {
  font-family: inherit; cursor: pointer; border: none; border-radius: 9px;
  font-size: 15px; padding: 12px 22px;
  transition: background .15s, transform .05s, opacity .15s;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-ghost { background: #eef3f6; color: var(--text); }
.btn-ghost:hover { background: #e1e9ee; }
.btn-row { display: flex; gap: 12px; justify-content: space-between; margin-top: 24px; flex-wrap: wrap; }

/* Fields */
.field { margin: 18px 0; text-align: left; }
.field label { display: block; font-size: 14px; margin-bottom: 6px; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 14px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 9px; font-family: inherit; background: #fff;
}
.field textarea { min-height: 96px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.meta-note { font-size: 13px; color: var(--muted); background: #eef6f6; border-radius: 9px; padding: 12px 14px; margin-top: 8px; }

/* Progress + timer */
.progress-wrap { margin-bottom: 18px; }
.progress-text { font-size: 13px; color: var(--muted); margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 15px; color: var(--primary-dark); background: #e9f6f6; padding: 4px 12px; border-radius: 99px; }
.timer.warning { color: #fff; background: var(--accent); }
.timer.danger { color: #fff; background: var(--wrong); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }
.progress-bar { height: 8px; background: #e6edf1; border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--primary); transition: width .25s; }

.q-type-tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 99px; margin-bottom: 12px; }
.tag-choice { background: #e4f0fb; color: #1f6fb2; }
.tag-tf { background: #fdf0db; color: #b9820a; }
.q-text { font-size: 18px; line-height: 1.6; margin: 0 0 20px; font-weight: 600; }

.options { display: flex; flex-direction: column; gap: 12px; }
.option {
  border: 1.5px solid var(--border); border-radius: 11px; padding: 15px 16px; font-size: 16px;
  background: #fff; text-align: left; display: flex; align-items: center; gap: 12px; width: 100%;
}
.option:hover:not(.locked) { border-color: var(--primary); background: #f3fbfb; }
.option.selected { border-color: var(--primary); background: #e9f6f6; }
.option .mark { flex: 0 0 26px; height: 26px; width: 26px; border-radius: 50%; border: 2px solid var(--border); display: grid; place-items: center; font-size: 14px; font-weight: 700; color: var(--muted); }
.option.selected .mark { border-color: var(--primary); color: var(--primary); }
.option.correct { border-color: var(--correct); background: var(--pass-bg); }
.option.correct .mark { border-color: var(--correct); background: var(--correct); color: #fff; }
.option.wrong { border-color: var(--wrong); background: var(--fail-bg); }
.option.wrong .mark { border-color: var(--wrong); background: var(--wrong); color: #fff; }
.option.locked { cursor: default; }

.explanation { margin-top: 16px; font-size: 14px; line-height: 1.6; background: #f4f7f9; border-left: 4px solid var(--primary); padding: 12px 14px; border-radius: 0 8px 8px 0; }

/* Result */
.result-head { text-align: center; }
.result-badge { display: inline-block; font-size: 22px; font-weight: 800; padding: 10px 28px; border-radius: 99px; margin-bottom: 14px; }
.badge-pass { background: var(--pass-bg); color: var(--correct); }
.badge-fail { background: var(--fail-bg); color: var(--wrong); }
.score-big { font-size: 40px; font-weight: 800; margin: 6px 0; }
.score-sub { color: var(--muted); font-size: 15px; margin-bottom: 8px; line-height: 1.6; }
.save-state { font-size: 13px; margin-top: 6px; }
.save-ok { color: var(--correct); }
.save-ng { color: var(--wrong); }

.review-list { margin-top: 22px; display: flex; flex-direction: column; gap: 10px; }
.review-item { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; font-size: 14px; }
.review-item .r-q { font-weight: 600; margin-bottom: 4px; }
.review-item .r-line { color: var(--muted); }
.review-item.ok { border-left: 4px solid var(--correct); }
.review-item.ng { border-left: 4px solid var(--wrong); }
.r-ok { color: var(--correct); font-weight: 700; }
.r-ng { color: var(--wrong); font-weight: 700; }

/* Tables (admin) */
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
table.grid th, table.grid td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table.grid th { color: var(--muted); font-weight: 600; font-size: 13px; background: #f7fafb; position: sticky; top: 0; }
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 99px; }
.pill-done { background: var(--pass-bg); color: var(--correct); }
.pill-todo { background: #eef0f2; color: var(--muted); }
.pill-pass { background: var(--pass-bg); color: var(--correct); }
.pill-fail { background: var(--fail-bg); color: var(--wrong); }
.tbl-wrap { max-height: 460px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.row-x { color: var(--wrong); cursor: pointer; font-weight: 700; background: none; padding: 2px 8px; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.toolbar button { font-size: 13px; padding: 9px 16px; }
.toolbar .spacer { flex: 1; }

.stat-row { display: flex; gap: 12px; flex-wrap: wrap; margin: 4px 0 16px; }
.stat { background: #f7fafb; border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; flex: 1; min-width: 120px; text-align: center; }
.stat .num { font-size: 26px; font-weight: 800; color: var(--primary-dark); }
.stat .lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }

.section-title { font-size: 15px; font-weight: 700; margin: 26px 0 8px; color: var(--primary-dark); }
.muted-line { color: var(--muted); font-size: 13px; padding: 14px 0; text-align: center; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--text); color: #fff; padding: 12px 20px; border-radius: 10px; font-size: 14px; opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
