/* Family English — "study notebook" theme
   Palette: ink #17253B · paper #F7F8F4 · highlighter #F5C400 · teal #0E6B5C · line #DDE1D9 */

:root {
  --ink: #17253b;
  --ink-soft: #4a5568;
  --paper: #f7f8f4;
  --card: #ffffff;
  --line: #dde1d9;
  --hl: #f5c400;
  --hl-soft: #fdf3c4;
  --teal: #0e6b5c;
  --teal-soft: #e2f0ed;
  --red: #c0392b;
  --radius: 12px;
  --font-body: "Inter", system-ui, sans-serif;
  --font-display: "Fraunces", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 20px;
  border-bottom: 2px solid var(--ink);
  background: var(--card);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  font-family: var(--font-display); font-weight: 700; font-size: 20px;
  background: var(--hl); padding: 6px 10px; border-radius: 8px;
  box-shadow: 2px 2px 0 var(--ink);
}
.brand h1 { font-family: var(--font-display); font-size: 20px; margin: 0; line-height: 1.1; }
.brand .sub { margin: 0; font-size: 12px; color: var(--ink-soft); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.badge {
  font-size: 12px; font-weight: 600; padding: 4px 10px;
  background: var(--teal-soft); color: var(--teal);
  border: 1px solid var(--teal); border-radius: 999px; white-space: nowrap;
}

/* ---------- tabs ---------- */
.tabs {
  display: flex; gap: 6px; padding: 10px 20px 0;
  background: var(--card); border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.tab {
  font: inherit; font-weight: 600; color: var(--ink-soft);
  background: transparent; border: none; cursor: pointer;
  padding: 10px 14px; border-radius: 10px 10px 0 0; white-space: nowrap;
  border-bottom: 3px solid transparent;
}
.tab.active { color: var(--ink); border-bottom-color: var(--hl); background: var(--hl-soft); }

/* ---------- layout ---------- */
main { max-width: 860px; margin: 0 auto; padding: 20px; }
.panel { display: none; }
.panel.active { display: block; }
.panel-title { font-family: var(--font-display); font-size: 18px; margin: 20px 0 10px; }
.panel-title:first-child { margin-top: 0; }

/* ---------- controls ---------- */
select, input[type="text"], input[type="password"], textarea {
  font: inherit; color: var(--ink);
  background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; width: 100%;
}
select:focus, input:focus, textarea:focus, .btn:focus-visible {
  outline: 2px solid var(--teal); outline-offset: 1px;
}
textarea { resize: vertical; }
label { font-weight: 500; }
.field { display: block; margin-bottom: 12px; }
.field small { font-weight: 400; }
.option-row { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 14px; }
.option-row label { flex: 1 1 220px; }
.option-row select { margin-top: 4px; }
.mode-row { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.mode-pill {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 999px; cursor: pointer; font-weight: 600;
}
.mode-pill:has(input:checked) { background: var(--hl-soft); border-color: var(--hl); }

.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  background: var(--card); color: var(--ink);
  border: 1.5px solid var(--ink); border-radius: 10px;
  padding: 9px 16px;
}
.btn:hover { background: var(--hl-soft); }
.btn.primary { background: var(--ink); color: #fff; }
.btn.primary:hover { background: #22345a; }
.btn.ghost { border-color: var(--line); color: var(--ink-soft); }
.btn.mic { font-size: 18px; padding: 9px 14px; }
.btn.mic.recording { background: var(--red); border-color: var(--red); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { transform: scale(1.07); } }
@media (prefers-reduced-motion: reduce) { .btn.mic.recording { animation: none; } }

.composer { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.composer input[type="text"] { flex: 1 1 200px; width: auto; }
.hint { font-size: 12.5px; color: var(--ink-soft); }

/* ---------- chat ---------- */
.chat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  min-height: 320px; max-height: 55vh; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.empty-hint { margin: auto; text-align: center; color: var(--ink-soft); }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--teal-soft); border: 1px solid var(--teal); }
.msg.ai { align-self: flex-start; background: var(--paper); border: 1px solid var(--line); }
.msg.ai .correction { display: block; margin-top: 6px; font-size: 13px; color: var(--teal); }
.msg.system {
  align-self: center; background: var(--hl-soft); border: 1px dashed var(--hl);
  font-size: 13.5px; max-width: 100%;
}
.msg.thinking { color: var(--ink-soft); font-style: italic; }

/* ---------- kết quả chấm ---------- */
.grade-result {
  margin-top: 16px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; white-space: pre-wrap;
}
.grade-result .band-stamp {
  display: inline-block; font-family: var(--font-display); font-size: 26px; font-weight: 700;
  background: var(--hl); padding: 4px 14px; border-radius: 8px;
  box-shadow: 2px 2px 0 var(--ink); margin-bottom: 12px;
}

/* ---------- lịch sử ---------- */
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 16px;
}
.history-item .meta { font-size: 12.5px; color: var(--ink-soft); margin-bottom: 4px; }
.history-item .band { font-weight: 700; background: var(--hl-soft); padding: 1px 8px; border-radius: 6px; }
.history-item details summary { cursor: pointer; font-weight: 600; font-size: 13.5px; margin-top: 6px; }
.history-item pre { white-space: pre-wrap; font-family: inherit; font-size: 13.5px; margin: 6px 0 0; }

/* ---------- settings ---------- */
.settings-grid { max-width: 520px; }
code { background: var(--hl-soft); padding: 1px 5px; border-radius: 4px; }

@media (max-width: 620px) {
  .topbar { flex-wrap: wrap; }
  main { padding: 14px; }
  .msg { max-width: 95%; }
}

/* ---------- màn hình đăng nhập ---------- */
.login-screen[hidden] { display: none; }
.login-screen {
  position: fixed; inset: 0; z-index: 100;
  background: var(--paper);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
body.login-open > :not(.login-screen) { filter: blur(3px); pointer-events: none; }
.login-card {
  background: var(--card); border: 2px solid var(--ink); border-radius: var(--radius);
  box-shadow: 4px 4px 0 var(--ink);
  padding: 32px 28px; width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.login-card h2 { font-family: var(--font-display); margin: 4px 0 0; }
.login-card .brand-mark { align-self: center; font-size: 24px; }
.login-card input { text-align: center; }
#hcaptchaBox { display: flex; justify-content: center; min-height: 0; }
#hcaptchaBox iframe { max-width: 100%; }
.login-error { color: var(--red); font-size: 13.5px; min-height: 1.2em; margin: 0; }


/* ---------- quản lý thành viên & topbar user ---------- */
.btn-logout { padding: 6px 10px; font-size: 13px; }
.user-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.user-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.user-actions .btn { padding: 5px 10px; font-size: 13px; }
