:root {
  --purple: #673ab7;
  --purple-dark: #5e35b1;
  --purple-tint: #ede7f6;
  --bg: #f0ebf8;
  --card: #fff;
  --border: #dadce0;
  --text: #202124;
  --muted: #5f6368;
  --error: #d93025;
  --success: #188038;
  --font: Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.5 var(--font);
  min-height: 100vh;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--purple); }
:focus-visible { outline: 2px solid var(--purple); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  height: 64px; padding: 0 16px;
  background: #fff; border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--muted); font-size: 22px; }
.topbar-actions { display: flex; gap: 8px; }

main { outline: none; }
.container { width: min(770px, calc(100% - 24px)); margin: 12px auto 48px; }

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  margin-bottom: 12px;
}
.card.header { border-top: 10px solid var(--purple); padding-top: 22px; }
.card.header h1 { font-size: 32px; font-weight: 400; line-height: 1.25; margin: 0 0 8px; }
.card.header .desc { white-space: pre-wrap; margin: 0; }
.card.header .required-note { border-top: 1px solid var(--border); margin: 16px -24px 0; padding: 12px 24px 0; color: var(--error); font-size: 14px; }
.card.notice { border-left: 6px solid var(--purple); }
.card.notice h2 { margin: 0 0 4px; font-size: 18px; font-weight: 500; }
.card.notice p { margin: 0; color: var(--muted); }
.card.has-error { border-color: var(--error); }

/* ---------- question (taking) ---------- */
.q-head { display: flex; align-items: flex-start; gap: 12px; }
.q-title { flex: 1; font-size: 16px; line-height: 1.5; margin: 0; letter-spacing: .1px; white-space: pre-wrap; }
.req { color: var(--error); margin-left: 4px; }
.q-hint { color: var(--muted); margin: 4px 0 0; font-size: 14px; white-space: pre-wrap; }
.q-body { margin-top: 16px; }
.q-error { display: flex; align-items: center; gap: 8px; color: var(--error); font-size: 12px; margin-top: 12px; }

.speak {
  flex: none; width: 36px; height: 36px; border-radius: 50%;
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  display: grid; place-items: center;
}
.speak:hover { background: #f1f3f4; }
.speak.on { color: var(--purple); background: var(--purple-tint); }

.option { display: flex; align-items: center; gap: 12px; padding: 8px 0; cursor: pointer; min-height: 40px; }
.option span { line-height: 1.4; }
input[type=radio] {
  appearance: none; -webkit-appearance: none; flex: none; margin: 0;
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--muted); display: grid; place-items: center; cursor: pointer;
}
input[type=radio]::after {
  content: ""; width: 10px; height: 10px; border-radius: 50%;
  background: var(--purple); transform: scale(0); transition: transform .12s;
}
input[type=radio]:checked { border-color: var(--purple); }
input[type=radio]:checked::after { transform: scale(1); }

.line-input, .line-textarea {
  display: block; width: 100%; max-width: 100%;
  border: none; border-bottom: 1px solid var(--border);
  padding: 6px 0; background: transparent; outline: none; border-radius: 0;
}
.line-input { max-width: 50%; }
.line-input:focus, .line-textarea:focus { border-bottom: 2px solid var(--purple); padding-bottom: 5px; }
.line-textarea { resize: none; overflow: hidden; min-height: 32px; }
@media (max-width: 600px) { .line-input { max-width: 100%; } }

.form-footer { display: flex; align-items: center; justify-content: space-between; margin: 8px 0 24px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 24px; border-radius: 4px; border: none;
  font-weight: 500; letter-spacing: .25px; cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--purple); color: #fff; }
.btn.primary:hover { background: var(--purple-dark); box-shadow: 0 1px 2px rgba(60,64,67,.3), 0 1px 3px 1px rgba(60,64,67,.15); }
.btn.primary:disabled { opacity: .6; cursor: default; }
.btn.text { background: transparent; color: var(--purple); padding: 0 12px; }
.btn.text:hover { background: var(--purple-tint); }
.btn.outline { background: #fff; color: var(--purple); border: 1px solid var(--border); padding: 0 16px; }
.btn.outline:hover { background: var(--purple-tint); }
.btn.danger { color: var(--error); }
.btn.danger:hover { background: #fce8e6; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: none; background: transparent;
  color: var(--muted); cursor: pointer; display: grid; place-items: center;
}
.icon-btn:hover { background: #f1f3f4; }
.icon-btn:disabled { opacity: .35; cursor: default; background: transparent; }

/* ---------- test list ---------- */
.list-head { display: flex; align-items: center; gap: 12px; margin: 20px 0 16px; flex-wrap: wrap; }
.list-head h1 { font-size: 22px; font-weight: 400; margin: 0; flex: 1; }
.search {
  width: 100%; height: 48px; padding: 0 16px; margin-bottom: 16px;
  border: 1px solid var(--border); border-radius: 8px; background: #fff; outline: none;
  font-size: 16px;
}
.search:focus { border-color: var(--purple); box-shadow: 0 0 0 1px var(--purple); }
.test-row { display: flex; gap: 16px; align-items: center; padding: 16px 20px; }
.test-row .info { flex: 1; min-width: 0; }
.test-row h2 { font-size: 18px; font-weight: 400; margin: 0 0 2px; }
.test-row h2 a { color: var(--text); text-decoration: none; }
.test-row h2 a:hover { color: var(--purple); }
.test-row .meta { color: var(--muted); font-size: 13px; margin: 0; }
.test-row .actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 640px) {
  .test-row { flex-direction: column; align-items: stretch; }
  .test-row .actions { justify-content: flex-start; }
}
.empty { text-align: center; color: var(--muted); padding: 40px 24px; }
.empty p { margin: 0 0 16px; font-size: 16px; }

/* ---------- results ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin: 16px 0 4px; }
.stat { border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; }
.stat b { display: block; font-size: 26px; font-weight: 400; color: var(--purple); }
.stat span { color: var(--muted); font-size: 13px; }
.missed-list { margin: 8px 0 0; padding: 0; list-style: none; }
.missed-list li { display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.missed-list .count { flex: none; min-width: 64px; color: var(--error); font-weight: 500; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 20px; }

/* ---------- history ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 13px; white-space: nowrap; }
td.num, th.num { text-align: right; }
tr.detail td { background: #fafafa; }
.linkish { background: none; border: none; color: var(--purple); cursor: pointer; padding: 0; }

/* ---------- editor ---------- */
.ed-card { position: relative; }
.ed-card:focus-within::before {
  content: ""; position: absolute; left: -1px; top: -1px; bottom: -1px; width: 6px;
  background: #4285f4; border-radius: 8px 0 0 8px;
}
.card.header.ed-card:focus-within::before { top: -10px; }
.field {
  width: 100%; border: none; border-bottom: 1px solid var(--border);
  background: transparent; padding: 8px 0; outline: none; border-radius: 0;
}
.field:focus { border-bottom: 2px solid var(--purple); padding-bottom: 7px; }
.field.title { font-size: 32px; line-height: 1.25; }
.field.qtext { background: #f8f9fa; padding: 12px; font-size: 16px; border-radius: 4px 4px 0 0; }
.field.qtext:focus { padding-bottom: 11px; }
textarea.field { resize: vertical; min-height: 40px; }
.ed-top { display: flex; gap: 16px; align-items: flex-start; }
.ed-top .field.qtext { flex: 1; }
.ed-top select {
  flex: none; width: 190px; height: 48px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 4px; background: #fff;
}
@media (max-width: 600px) { .ed-top { flex-direction: column; align-items: stretch; } .ed-top select { width: 100%; } }
.ed-label { color: var(--muted); font-size: 12px; margin: 16px 0 4px; display: block; }
.ed-option { display: flex; align-items: center; gap: 12px; }
.ed-option .field { flex: 1; }
.ed-option .icon-btn { width: 32px; height: 32px; }
.ed-foot {
  display: flex; justify-content: flex-end; align-items: center; gap: 4px;
  border-top: 1px solid var(--border); margin: 20px -24px -8px; padding: 8px 16px 0;
}
.ed-foot .num { margin-right: auto; color: var(--muted); font-size: 13px; padding-left: 8px; }
.ed-bar {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap;
  background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px;
}
.ed-bar .left { margin-right: auto; }
.error-banner { background: #fce8e6; color: #a50e0e; border-radius: 8px; padding: 12px 16px; margin-bottom: 12px; }

.select { height: 40px; padding: 0 12px; border: 1px solid var(--border); border-radius: 4px; background: #fff; max-width: 100%; }
textarea.field.answers { background: #f8f9fa; padding: 8px 12px; border-radius: 4px 4px 0 0; }

/* ---------- login ---------- */
.login { max-width: 420px; margin: 10vh auto 0; }
.login .field { margin: 16px 0 24px; font-size: 16px; }

/* ---------- finish-now dialog ---------- */
.pw-dialog { border: none; border-radius: 8px; padding: 24px; width: min(380px, 90vw); box-shadow: 0 4px 24px rgba(0,0,0,.25); }
.pw-dialog::backdrop { background: rgba(32,33,36,.5); }
.pw-dialog h2 { margin: 0 0 4px; font-size: 20px; font-weight: 400; }
.pw-dialog p { margin: 0 0 8px; color: var(--muted); }
.pw-dialog .field { font-size: 16px; margin-bottom: 4px; }
.missed-list .count { min-width: 96px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: #323232; color: #fff; padding: 12px 20px; border-radius: 4px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.loading { text-align: center; color: var(--muted); padding: 48px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
