:root {
  --green: #1f7a4d;
  --green-dark: #16603b;
  --green-soft: #e7f4ec;
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #1c2420;
  --muted: #66736c;
  --line: #dfe5e1;
  --blue: #2563eb; --blue-soft: #e5edff;
  --amber: #a15c00; --amber-soft: #fff3dc;
  --red: #c02626; --red-soft: #fde8e8;
  --radius: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
a { color: var(--green); }
h1 { font-size: 1.6rem; margin: .2em 0 .3em; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 1.6em 0 .6em; }
h3 { font-size: 1rem; margin: 1.4em 0 .4em; }
.card h2:first-child { margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.loading { text-align: center; color: var(--muted); padding: 4rem 1rem; }
.error { color: var(--red); margin: .4rem 0 0; }
.warn-text { color: var(--amber); font-weight: 600; }
.hint { color: var(--muted); font-size: .85rem; display: block; margin: .3rem 0; }
[hidden] { display: none !important; }

/* brand */
.brand { display: inline-flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); }
.brand .muted { font-weight: 400; }
.logo {
  width: 30px; height: 30px; border-radius: 8px; background: var(--green); color: #fff;
  display: inline-grid; place-items: center; font-weight: 800;
}
.brand-link { text-decoration: none; }

/* layout */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: .7rem 1.25rem; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.container { max-width: 980px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head p { margin: 0; }
.head-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.topbar .user { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }
.back { text-decoration: none; font-size: .9rem; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem; margin-bottom: 1rem;
}
.card.flush { padding: 0; overflow-x: auto; }
.empty { color: var(--muted); text-align: center; padding: 1.5rem; margin: 0; }
.row { display: flex; gap: .5rem; margin-bottom: 1rem; }
.spacer { flex: 1; }
.savebar {
  position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: .5rem;
  padding: .8rem 0; background: linear-gradient(transparent, var(--bg) 35%);
}

/* forms */
input, select, textarea {
  font: inherit; color: inherit; background: #fff;
  border: 1px solid var(--line); border-radius: 8px; padding: .55rem .7rem; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green); outline-offset: -1px; border-color: var(--green); }
input[type=radio], input[type=checkbox] { width: auto; accent-color: var(--green); transform: scale(1.15); }
textarea { resize: vertical; }
.field { display: block; margin-bottom: 1rem; }
.field .label { display: block; font-weight: 600; margin-bottom: .3rem; }
.narrow { max-width: 140px; }
.inline-form { display: flex; gap: .5rem; flex-wrap: wrap; }
.inline-form input { flex: 1 1 200px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  font: inherit; font-weight: 600; text-decoration: none; white-space: nowrap;
  padding: .5rem .9rem; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--text);
}
.btn:hover { border-color: #b9c4bd; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-dark); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--red); }
.btn.small { padding: .25rem .6rem; font-size: .85rem; }
.btn.icon { padding: .25rem .55rem; }
.btn.big { padding: .8rem 1.6rem; font-size: 1.05rem; }
.btn.wide { width: 100%; margin-top: .5rem; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .7rem 1rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover, tbody tr:hover { background: #fafcfb; }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn { margin-left: .25rem; }

/* badges */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 99px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.badge.small { margin-left: .4rem; font-size: .72rem; }
.badge.grey { background: #eef1ef; color: var(--muted); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.red { background: var(--red-soft); color: var(--red); }

/* invite link box */
.linkbox { margin-top: 1rem; padding: 1rem; border-radius: 8px; background: var(--green-soft); border: 1px solid #c4e3d1; }
.linkrow { display: flex; gap: .5rem; margin-top: .5rem; flex-wrap: wrap; }
.linkrow input { flex: 1 1 260px; font-family: Consolas, monospace; font-size: .85rem; }

/* editor */
.qcard textarea { margin: .7rem 0; }
.qhead { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.qhead select { width: auto; }
.points { display: inline-flex; align-items: center; gap: .3rem; color: var(--muted); }
.points input { width: 75px; }
.options { display: grid; gap: .45rem; }
.option-row { display: flex; align-items: center; gap: .6rem; }
.option-row .grow { flex: 1; }
.options > .btn { justify-self: start; }

/* review */
.info { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1.5rem; margin: 0; }
.info dt { color: var(--muted); }
.info dd { margin: 0; }
.qtext { font-weight: 500; margin: .6rem 0; }
.answer { background: #f7f9f8; border: 1px solid var(--line); border-radius: 8px; padding: .8rem; }
.answer.empty { color: var(--muted); text-align: left; padding: .8rem; }
.grade { display: inline-flex; align-items: center; gap: .4rem; margin-top: .8rem; font-weight: 600; }
.grade input { width: 90px; }
.review-options { list-style: none; padding: 0; margin: 0; display: grid; gap: .35rem; }
.review-options li { display: flex; align-items: center; gap: .5rem; padding: .45rem .7rem; border: 1px solid var(--line); border-radius: 8px; flex-wrap: wrap; }
.review-options li.is-correct { border-color: #9fd3b5; background: var(--green-soft); }
.review-options li.picked:not(.is-correct) { border-color: #f1b4b4; background: var(--red-soft); }
.review-options .mark { width: 1.1em; font-weight: 700; }
.review-options .tag { margin-left: auto; font-size: .75rem; color: var(--green); font-weight: 600; }
.review-options .tag.pick { margin-left: .5rem; color: var(--muted); }
.review-options li .tag + .tag { margin-left: .5rem; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login .card { width: 100%; max-width: 380px; }
.login h1 { margin: 1rem 0; }

/* candidate */
.take { max-width: 760px; margin: 0 auto; padding: 1rem 1rem 4rem; }
.take > .card:first-child { margin-top: 1.5rem; }
.center { text-align: center; padding: 2.5rem 1.5rem; }
.facts { display: flex; gap: 1rem; margin: 1.2rem 0; }
.facts > div { flex: 1; background: var(--green-soft); border-radius: 8px; padding: .8rem 1rem; }
.facts strong { display: block; font-size: 1.4rem; color: var(--green); }
.facts span { color: var(--muted); font-size: .9rem; }
.rules { padding-left: 1.2rem; margin: 0 0 1.5rem; }
.rules li { margin: .25rem 0; }
.take-bar {
  position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  background: var(--card); border: 1px solid var(--line); border-top: 0; border-radius: 0 0 var(--radius) var(--radius);
  padding: .7rem 1rem; margin-bottom: 1rem; box-shadow: 0 4px 12px rgba(0,0,0,.05);
}
.take-title { min-width: 0; }
.take-title strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timer {
  font: 700 1.6rem/1 Consolas, "SF Mono", monospace; padding: .45rem .8rem; border-radius: 8px;
  background: var(--green-soft); color: var(--green); font-variant-numeric: tabular-nums;
}
.timer.warn { background: var(--amber-soft); color: var(--amber); }
.timer.danger { background: var(--red-soft); color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .6; } }
.saved { font-size: .85rem; color: var(--muted); }
.saved.ok { color: var(--green); }
.saved.bad { color: var(--red); font-weight: 600; }
.qnum { font-size: .85rem; color: var(--green); font-weight: 600; }
.choices { display: grid; gap: .5rem; }
.choice {
  display: flex; align-items: center; gap: .7rem; padding: .7rem .9rem; cursor: pointer;
  border: 1px solid var(--line); border-radius: 8px; transition: background .1s;
}
.choice:hover { background: #fafcfb; }
.choice:has(input:checked) { border-color: var(--green); background: var(--green-soft); }
.submit-card { text-align: center; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); z-index: 50;
  background: #1c2420; color: #fff; padding: .6rem 1.1rem; border-radius: 8px; font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: calc(100% - 2rem);
}
.toast.error { background: var(--red); }

@media (max-width: 600px) {
  h1 { font-size: 1.35rem; }
  th, td { padding: .6rem .6rem; }
  .facts { flex-direction: column; }
  .timer { font-size: 1.3rem; }
  .info { grid-template-columns: 1fr; gap: .1rem; }
  .info dd { margin-bottom: .5rem; }
}
