/* =========================================================
   IELTS 写作机考平台 · 样式
   ========================================================= */

:root {
  --navy: #0f2f4f;
  --navy-deep: #0a2136;
  --ink: #16273a;
  --ink-soft: #445a70;
  --muted: #7b8b9e;
  --line: #dfe5ec;
  --line-soft: #ebf0f5;
  --bg: #eef1f5;
  --card: #ffffff;
  --accent: #1c5d99;
  --accent-deep: #164a7a;
  --ok: #157347;
  --warn: #b45309;
  --danger: #b42318;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 47, 79, .06), 0 1px 3px rgba(15, 47, 79, .08);
  --shadow-md: 0 8px 28px rgba(15, 47, 79, .12);
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-exam: Arial, "Helvetica Neue", Helvetica, "PingFang SC", sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

button { font-family: inherit; }

/* ---------- 通用控件 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .06s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-deep); }

.btn-ghost { background: #fff; color: var(--ink-soft); border-color: var(--line); }
.btn-ghost:hover:not(:disabled) { border-color: #c3cedb; color: var(--ink); }

.btn-soft { background: #eef3f9; color: var(--accent-deep); border-color: #dbe6f2; }
.btn-soft:hover:not(:disabled) { background: #e3ecf6; }

.btn-danger { background: #fff; color: var(--danger); border-color: #f0cfcb; }
.btn-danger:hover:not(:disabled) { background: #fdf3f2; }

.btn-sm { height: 30px; padding: 0 12px; font-size: 13px; border-radius: 7px; }
.btn-block { width: 100%; height: 44px; font-size: 15px; }

input[type="text"], input[type="password"], input[type="number"], input[type="datetime-local"], textarea, select {
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  height: 40px;
  width: 100%;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { height: auto; padding: 10px 12px; line-height: 1.7; resize: vertical; }
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(28, 93, 153, .12);
}

.form-error {
  margin: 2px 0 0;
  padding: 9px 12px;
  border-radius: 8px;
  background: #fdf1f0;
  border: 1px solid #f4d6d3;
  color: var(--danger);
  font-size: 13px;
  line-height: 1.5;
}

.muted { color: var(--muted); }

/* =========================================================
   登录页
   ========================================================= */

.login-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 500px at 50% -10%, #dfe8f2 0%, rgba(223, 232, 242, 0) 65%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 396px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 34px 32px 26px;
  box-shadow: var(--shadow-md);
}

.login-brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 18px;
}
.brand-mark {
  font-family: var(--font-exam);
  font-weight: 700;
  letter-spacing: .16em;
  font-size: 15px;
  color: var(--navy);
}
.brand-sub {
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}

.login-title {
  margin: 0 0 6px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: .01em;
}
.login-desc {
  margin: 0 0 22px;
  font-size: 13.5px;
  color: var(--muted);
}

.field { display: block; margin-bottom: 14px; }
.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: .02em;
}

#loginForm .form-error { margin-bottom: 12px; }

.login-foot {
  margin: 18px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

/* =========================================================
   考试界面
   ========================================================= */

.exam {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

.exam-header {
  flex: 0 0 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  background: var(--navy);
  color: #fff;
}

.eh-left { display: flex; align-items: baseline; gap: 9px; min-width: 0; }
.eh-brand {
  font-family: var(--font-exam);
  font-weight: 700;
  letter-spacing: .18em;
  font-size: 14px;
}
.eh-brand-sub {
  font-size: 10.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, .62);
  white-space: nowrap;
}

.eh-center {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .04em;
  color: rgba(255, 255, 255, .92);
  padding: 5px 14px;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 999px;
  white-space: nowrap;
}

.eh-right { display: flex; align-items: center; gap: 14px; }

.timer {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px 5px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  font-variant-numeric: tabular-nums;
  transition: background .2s ease, color .2s ease;
}
#timerText {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .04em;
}
.timer.is-over { background: rgba(240, 180, 41, .2); color: #ffd166; }

/* 截止倒计时 */
.deadline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .12);
  color: rgba(255, 255, 255, .85);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.deadline.is-urgent { background: rgba(228, 84, 68, .25); color: #ffb3a7; }

.eh-candidate {
  font-size: 12.5px;
  color: rgba(255, 255, 255, .78);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.exam-body {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(300px, 40%) 1px minmax(0, 1fr);
  min-height: 0;
  background: var(--bg);
}

.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--card);
}

.pane-divider { background: var(--line); }

.pane-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 22px;
  height: 42px;
  border-bottom: 1px solid var(--line-soft);
  background: #fbfcfe;
}
.pane-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}
.pane-note {
  font-size: 12px;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pane-note.muted { color: #9aa8b8; }

.prompt-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 22px 24px 48px;
}

.prompt-instr {
  font-family: var(--font-exam);
  font-size: 13.5px;
  line-height: 1.75;
  color: var(--ink-soft);
  padding: 12px 14px;
  margin-bottom: 18px;
  background: #f5f8fb;
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  white-space: pre-line;
}
.prompt-instr strong { color: var(--ink); font-weight: 700; }

.prompt-text {
  font-family: var(--font-exam);
  font-size: 16.5px;
  line-height: 1.85;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
  letter-spacing: .002em;
}

.prompt-figure { margin: 20px 0 0; }
.prompt-figure img {
  max-width: 100%;
  height: auto;
  display: block;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

/* 作答区用 grid 保证输入框撑满剩余高度 */
.pane-answer {
  display: grid;
  grid-template-rows: 42px minmax(0, 1fr);
  min-height: 0;
}

#answer {
  height: 100%;
  width: 100%;
  min-height: 0;
  border: none;
  border-radius: 0;
  padding: 22px 26px 40px;
  font-family: var(--font-exam);
  font-size: 17px;
  line-height: 1.95;
  color: #10233a;
  background: #fff;
  resize: none;
  box-shadow: none;
  outline: none;
  caret-color: var(--accent);
}
#answer:focus { box-shadow: none; border: none; }
#answer::placeholder { color: #b6c1cd; }

.exam-footer {
  flex: 0 0 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  background: #fff;
  border-top: 1px solid var(--line);
}

.wf { display: flex; align-items: baseline; gap: 8px; }
.wf-label {
  font-family: var(--font-exam);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--muted);
}
.wf-num {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 21px;
  font-weight: 700;
  color: var(--navy);
  min-width: 34px;
  font-variant-numeric: tabular-nums;
}
.wf-min { font-size: 12px; color: var(--muted); }
.wf.is-short .wf-num { color: var(--warn); }

.footer-right { display: flex; align-items: center; gap: 14px; }

.save-state {
  font-size: 12px;
  color: var(--muted);
  transition: color .2s ease;
}
.save-state.is-saved { color: var(--ok); }

/* =========================================================
   交卷完成页
   ========================================================= */

.done-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1000px 420px at 50% 0%, #e3ebf4 0%, rgba(227, 235, 244, 0) 70%),
    var(--bg);
}
.done-card {
  width: 100%;
  max-width: 430px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 36px 34px 28px;
  text-align: center;
  box-shadow: var(--shadow-md);
}
.done-icon {
  width: 62px;
  height: 62px;
  margin: 0 auto 16px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #e8f4ee;
  color: var(--ok);
}
.done-card h2 { margin: 0 0 8px; font-size: 21px; font-weight: 700; }
.done-desc { margin: 0 0 22px; font-size: 13.5px; color: var(--muted); line-height: 1.6; }

.done-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  margin: 0 0 24px;
  background: var(--line-soft);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  overflow: hidden;
}
.done-stats > div { background: #fbfcfe; padding: 14px 8px; }
.done-stats dt { font-size: 11.5px; color: var(--muted); margin-bottom: 6px; }
.done-stats dd {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
}

/* 交卷页 · 老师评分 */
.done-score {
  margin: 0 0 24px;
  padding: 18px 16px 16px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: #fbfcfe;
  text-align: left;
}
.ds-title {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.ds-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1px;
  background: var(--line-soft);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  overflow: hidden;
}
.ds-grid > div { background: #fff; padding: 10px 4px; text-align: center; }
.ds-grid dt { font-size: 10.5px; color: var(--muted); margin-bottom: 4px; }
.ds-grid dd { margin: 0; font-size: 16px; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.ds-grid .ds-overall { background: #f2f7fc; }
.ds-grid .ds-overall dd { color: var(--accent-deep); }
.ds-comment {
  margin: 12px 0 0;
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink-soft);
  white-space: pre-wrap;
}

/* =========================================================
   老师后台
   ========================================================= */

.admin-login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 520px at 50% -10%, #dbe5f0 0%, rgba(219, 229, 240, 0) 65%),
    var(--bg);
}

.admin-shell {
  display: grid;
  grid-template-columns: 226px minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  background: var(--navy-deep);
  color: #cfdaea;
  display: flex;
  flex-direction: column;
  padding: 22px 14px 16px;
}
.sb-brand { padding: 0 10px 20px; }
.sb-brand strong {
  display: block;
  font-family: var(--font-exam);
  font-size: 14px;
  letter-spacing: .18em;
  color: #fff;
}
.sb-brand span {
  display: block;
  margin-top: 5px;
  font-size: 11px;
  letter-spacing: .08em;
  color: rgba(207, 218, 234, .6);
}

.sb-nav { display: flex; flex-direction: column; gap: 3px; }
.sb-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 38px;
  padding: 0 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: rgba(207, 218, 234, .82);
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.sb-item:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.sb-item.is-active { background: rgba(255, 255, 255, .13); color: #fff; font-weight: 600; }
.sb-count {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .16);
  color: #fff;
}

.sb-foot { margin-top: auto; padding: 0 4px; }
.sb-addr {
  font-size: 11px;
  line-height: 1.6;
  color: rgba(207, 218, 234, .55);
  word-break: break-all;
  padding: 0 8px 10px;
}

.admin-main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }

.admin-top {
  flex: 0 0 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 26px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.admin-top h1 { margin: 0; font-size: 16px; font-weight: 700; }
.admin-top .sub { font-size: 12.5px; color: var(--muted); }

.admin-body { flex: 1 1 auto; overflow-y: auto; padding: 24px 26px 48px; }

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-soft);
}
.card-head h2 { margin: 0; font-size: 14px; font-weight: 700; }
.card-head .hint { font-size: 12px; color: var(--muted); }
.card-body { padding: 16px 18px; }
.card-body.tight { padding: 0; }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toolbar select { width: auto; min-width: 190px; }

table.grid { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.grid th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  background: #fbfcfe;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.grid td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
table.grid tbody tr:hover { background: #f8fafc; }
table.grid tbody tr:last-child td { border-bottom: none; }
table.grid .num { font-variant-numeric: tabular-nums; }
table.grid .row-link { cursor: pointer; }
table.grid .name { font-weight: 600; }
table.grid .preview {
  color: var(--muted);
  max-width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
table.grid .actions { display: flex; gap: 6px; justify-content: flex-end; }
table.grid .actions .btn { flex: 0 0 auto; min-width: 56px; white-space: nowrap; }
table.grid th:last-child, table.grid td:last-child { white-space: nowrap; }

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: #eef3f9;
  color: var(--accent-deep);
}
.tag.ok { background: #e8f4ee; color: var(--ok); }
.tag.warn { background: #fdf3e6; color: var(--warn); }
.tag.muted { background: #f1f4f8; color: var(--muted); }

.empty {
  padding: 44px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.8;
}

.form-grid { display: grid; gap: 14px; }
.form-grid.cols-2 { grid-template-columns: 1fr 1fr; }
.form-grid.cols-3 { grid-template-columns: 2fr 1fr 1fr; }
.field-hint { font-size: 11.5px; color: var(--muted); margin-top: 5px; line-height: 1.5; }

.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 4px; }
.form-actions.spaced { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line-soft); }

/* 弹窗 */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(10, 33, 54, .42);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 50;
  backdrop-filter: blur(2px);
}
.modal {
  width: 100%;
  max-width: 780px;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(10, 33, 54, .28);
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line-soft);
}
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--line-soft);
  background: #fbfcfe;
}
.icon-btn {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}
.icon-btn:hover { color: var(--ink); border-color: #c3cedb; }

.essay-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-bottom: 16px;
  font-size: 12.5px;
  color: var(--muted);
}
.essay-meta b { color: var(--ink); font-weight: 600; }

.essay-text {
  font-family: var(--font-exam);
  font-size: 15.5px;
  line-height: 1.9;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 18px 20px;
  background: #fbfcfe;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  margin-bottom: 18px;
  max-height: 42dvh;
  overflow-y: auto;
}

.grade-row { display: grid; grid-template-columns: 120px 1fr; gap: 12px; align-items: start; }

/* 四维评分 */
.criteria-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.overall-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: 8px;
  background: #f2f7fc;
  border: 1px solid #dbe6f2;
  font-size: 13px;
  color: var(--ink-soft);
}
.overall-line b {
  font-size: 22px;
  font-weight: 700;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
}
.win-tag { white-space: nowrap; }

/* 提示条 */
.notice {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.6;
  margin-bottom: 16px;
  border: 1px solid #dbe6f2;
  background: #f2f7fc;
  color: var(--ink-soft);
}
.notice.warn { border-color: #f5e0c3; background: #fdf7ee; color: #8a5a12; }
.notice b { color: inherit; }

/* Toast */
#toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translate(-50%, 12px);
  background: var(--navy-deep);
  color: #fff;
  font-size: 13.5px;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 80;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 小屏 ---------- */
@media (max-width: 860px) {
  .exam-body {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(140px, 34vh) 1px minmax(0, 1fr);
  }
  .eh-brand-sub, .eh-candidate { display: none; }
  .pane-note { display: none; }
  .deadline { display: none; }
  .ds-grid { grid-template-columns: repeat(5, 1fr); }
  .admin-shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { flex-direction: row; align-items: center; gap: 8px; padding: 10px 12px; overflow-x: auto; }
  .sb-brand, .sb-foot { display: none; }
  .sb-nav { flex-direction: row; }
  .form-grid.cols-2, .form-grid.cols-3 { grid-template-columns: 1fr; }
  .grade-row, .criteria-grid { grid-template-columns: 1fr 1fr; }
  .admin-body { padding: 16px; }
}
