/* ===== TOKENS (Notion/Linear) ===== */
:root {
  --bg: #ffffff;
  --sidebar: #f7f7f8;
  --soft: #f7f7f8;
  --hover: #efeff1;
  --active: #ebebed;
  --line: #ebebed;
  --line-strong: #e0e0e3;
  --text: #1a1a1a;
  --text-2: #3c3f44;
  --text-sub: #6b6f76;
  --muted: #8a8f98;
  --accent: #4f5bd5;
  --accent-soft: #eef0fc;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #18181b;
    --sidebar: #1f1f23;
    --soft: #222226;
    --hover: #2a2a2f;
    --active: #2f2f35;
    --line: #2c2c31;
    --line-strong: #38383e;
    --text: #ececef;
    --text-2: #c9cad0;
    --text-sub: #9a9ca5;
    --muted: #7c7f88;
    --accent: #8b94f0;
    --accent-soft: #262a45;
  }
}

/* Mọi theme màu cũ đều quy về một màu nhấn duy nhất */
.theme-blue, .theme-purple, .theme-green, .theme-amber, .theme-rose, .theme-teal,
.module, .test-card, .quick, .tip {
  --tx-c: var(--accent); --bd-c: var(--line); --bg-c: var(--soft);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  letter-spacing: -0.005em;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; color: inherit; }
p { margin: 0; }
svg.lucide { width: 16px; height: 16px; stroke-width: 1.8; }

/* ===== APP SHELL ===== */
.app { height: 100vh; display: flex; flex-direction: column; }

.topbar {
  height: 48px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; min-width: 0; }

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  display: grid; place-items: center;
  background: var(--text); color: var(--bg);
}
.brand-mark svg.lucide { width: 13px; height: 13px; }
.brand > div { display: flex; align-items: center; gap: 6px; min-width: 0; }
.brand-name { font-weight: 600; font-size: 14px; white-space: nowrap; }
.brand-sub {
  font-size: 13px; color: var(--text-sub);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 48vw;
}
.brand-sub::before { content: '/'; margin-right: 6px; color: var(--muted); }

.chip-badge { display: none; }

.voice-picker-wrap {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 0 8px;
  min-height: 30px;
  color: var(--text-sub);
  background: var(--bg);
}
.voice-picker-wrap .voice-icon { width: 14px; height: 14px; flex-shrink: 0; }
.voice-select {
  appearance: none; -webkit-appearance: none;
  background: transparent; border: none; outline: none;
  font-family: inherit; font-size: 13px; font-weight: 500;
  color: var(--text); cursor: pointer;
  padding-right: 16px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a8f98' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right center;
}
.voice-select option { background: var(--bg); color: var(--text); }

.icon-btn {
  width: 30px; height: 30px; border-radius: 6px;
  display: grid; place-items: center;
  border: 0; background: transparent; color: var(--text-sub);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 300px;
}
.app.nav-collapsed .layout { grid-template-columns: 0 minmax(0, 1fr) 300px; }
.app.aside-collapsed .layout { grid-template-columns: 250px minmax(0, 1fr) 0; }
.app.nav-collapsed.aside-collapsed .layout { grid-template-columns: 0 minmax(0, 1fr) 0; }
.app.nav-collapsed .nav, .app.aside-collapsed .aside { overflow: hidden; padding: 0; border: 0; }

/* ===== LỀ TRÁI ===== */
.nav {
  overflow-y: auto;
  padding: 12px 10px;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
  display: flex; flex-direction: column; gap: 1px;
}
.nav-label {
  padding: 14px 10px 4px;
  font-size: 12px; font-weight: 500; color: var(--text-sub);
}
.nav-label:first-child { padding-top: 4px; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  min-height: 32px;
  padding: 4px 10px;
  border: 0; border-radius: 6px;
  background: transparent; color: var(--text-2);
  text-align: left; font-weight: 400; font-size: 14px;
}
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--active); color: var(--text); font-weight: 500; }

.dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; background: var(--muted) !important; }
.nav-item.active .dot { background: var(--accent) !important; }

/* ===== GIỮA ===== */
.content {
  overflow-y: auto;
  padding: 56px 24px 96px;
  min-width: 0;
}
.content > * { max-width: 760px; margin-left: auto; margin-right: auto; }

.hero { margin-bottom: 8px; padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.hero h1 {
  margin: 10px 0 8px;
  font-size: 32px; font-weight: 700; line-height: 1.2; letter-spacing: -0.025em;
}
.hero p { color: var(--text-sub); font-size: 15px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 500; color: var(--text-sub);
}
.pill svg.lucide { width: 13px; height: 13px; }

.muted { color: var(--muted); font-size: 13px; }

/* ===== MODULE ===== */
.module {
  padding: 36px 0 32px;
  border-bottom: 1px solid var(--line);
}
.module:last-of-type { border-bottom: 0; }

.module-head { margin-bottom: 16px; }
.module-num {
  display: inline-block;
  padding: 1px 6px; border-radius: 4px;
  border: 1px solid var(--line-strong);
  font-size: 11.5px; font-weight: 500; color: var(--text-sub);
}
.module h3 {
  margin: 8px 0 2px;
  font-size: 20px; font-weight: 600; letter-spacing: -0.015em; line-height: 1.35;
}
.module-meaning { color: var(--text-sub); }

.formula-card {
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex; flex-direction: column; gap: 10px;
  align-items: flex-start;
}
.formula-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 500; color: var(--text-sub);
}
.formula-label svg.lucide { width: 13px; height: 13px; }
.formula-text { font-size: 16px; font-weight: 500; line-height: 1.5; }

.rhythm {
  display: flex; gap: 10px; align-items: flex-start;
  margin: 10px 0 0;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text-sub);
}
.rhythm svg.lucide { flex-shrink: 0; margin-top: 2px; }
.rhythm strong { color: var(--text); font-size: 13px; font-weight: 600; }
.rhythm p { color: var(--text-sub); font-size: 13px; }

.sub-title {
  display: flex; align-items: center; gap: 6px;
  margin: 28px 0 8px;
  font-size: 13px; font-weight: 600; color: var(--text);
}
.sub-title svg.lucide { width: 14px; height: 14px; color: var(--text-sub); }

/* Nút */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 30px;
  padding: 0 12px; border-radius: 6px;
  font-size: 13px; font-weight: 500;
  border: 1px solid var(--line-strong);
  transition: background .12s;
}
.btn svg.lucide { width: 14px; height: 14px; }
.btn-solid { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn-solid:hover { opacity: .88; }
.btn-ghost { background: var(--bg); color: var(--text); }
.btn-ghost:hover { background: var(--hover); }

/* Cụm từ: dạng bảng */
.chips {
  display: flex; flex-direction: column;
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.chip {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 4px 16px;
  min-height: 42px; padding: 9px 14px;
  background: var(--bg); border: 0; border-bottom: 1px solid var(--line);
  text-align: left;
}
.chip:last-child { border-bottom: 0; }
.chip:hover { background: var(--soft); }
.chip-en { font-weight: 500; color: var(--text); font-size: 14px; }
.chip-vi { font-size: 13px; color: var(--text-sub); }

/* Q&A */
.qa-list { display: flex; flex-direction: column; gap: 10px; }
.qa {
  border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px;
}
.qa-q, .qa-a { display: flex; gap: 10px; align-items: flex-start; }
.qa-q { margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.qa-q p { font-weight: 600; }
.qa-q small, .qa-a-body small { display: block; color: var(--text-sub); font-size: 13px; margin-top: 2px; }
.qa-a-body { flex: 1; }
.qa-a-body em { font-style: normal; font-weight: 500; color: var(--accent); }
.qa-a .btn { flex-shrink: 0; }

.qa-tag {
  flex-shrink: 0;
  width: 20px; height: 20px; border-radius: 4px; margin-top: 1px;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 600;
  background: var(--soft); color: var(--text-sub); border: 1px solid var(--line);
}
.qa-tag-a { color: var(--accent); }

/* Ghi chép */
.notes { margin-top: 20px; }
.notes summary {
  cursor: pointer; list-style: none;
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 500; color: var(--text-sub);
}
.notes summary:hover { color: var(--text); }
.notes summary::-webkit-details-marker { display: none; }
.notes textarea {
  display: block; width: 100%; min-height: 84px; margin-top: 8px;
  padding: 10px 12px; border-radius: var(--radius);
  border: 1px solid var(--line-strong); background: var(--bg);
  font: inherit; font-size: 14px; color: var(--text); resize: vertical;
}
.notes textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* Đang phát audio */
.playing { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Chiến thuật */
.steps { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.step {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  display: grid; grid-template-columns: 170px 1fr; gap: 16px; align-items: baseline;
}
.step:last-child { border-bottom: 0; }
.step-label { font-weight: 500; color: var(--text-sub); font-size: 13px; }

/* Đề thi */
.test-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 24px;
}
.test-card {
  display: flex; gap: 12px; align-items: center;
  padding: 12px 14px; border-radius: var(--radius);
  border: 1px solid var(--line);
}
.test-card:hover { background: var(--soft); }
.test-num {
  width: 32px; height: 32px; border-radius: 6px; flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--soft); border: 1px solid var(--line);
  font-size: 12px; font-weight: 600; color: var(--text-sub);
  font-variant-numeric: tabular-nums;
}
.test-card strong { display: block; font-size: 14px; font-weight: 500; }
.test-card small { display: block; color: var(--text-sub); font-size: 12px; }
.test-card code {
  display: block; margin-top: 2px; font-size: 11.5px;
  color: var(--muted); word-break: break-all;
  font-family: ui-monospace, Menlo, monospace;
}

/* Pager */
.pager {
  display: flex; justify-content: space-between; gap: 12px;
  margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--line);
}

/* ===== LỀ PHẢI ===== */
.aside {
  overflow-y: auto;
  padding: 16px 14px;
  border-left: 1px solid var(--line);
  background: var(--bg);
  display: flex; flex-direction: column; gap: 12px;
}
.aside-head {
  display: flex; align-items: center; gap: 6px;
  font-weight: 600; font-size: 13px;
}
.aside-head svg.lucide { width: 14px; height: 14px; color: var(--text-sub); }

.quick-list { display: flex; flex-direction: column; gap: 6px; }
.quick {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
  width: 100%; padding: 10px 12px; border-radius: var(--radius);
  background: var(--bg); border: 1px solid var(--line);
  text-align: left;
}
.quick:hover { background: var(--soft); }
.quick-num { font-size: 11px; font-weight: 500; color: var(--text-sub); }
.quick strong { font-size: 13px; font-weight: 500; }
.quick em { color: var(--text-sub); font-size: 12.5px; font-style: normal; }
.quick-play {
  margin-top: 2px; display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 500; color: var(--accent);
}
.quick-play svg.lucide { width: 12px; height: 12px; }

.tip {
  background: var(--soft); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px;
}
.tip-title {
  display: flex; align-items: center; gap: 6px;
  font-weight: 600; font-size: 13px; margin-bottom: 4px;
}
.tip-title svg.lucide { width: 14px; height: 14px; color: var(--text-sub); }
.tip p { color: var(--text-sub); font-size: 13px; }
.formula {
  margin-top: 10px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
  font-size: 12px; color: var(--muted);
}
.formula span {
  padding: 1px 6px; border-radius: 4px; background: var(--bg); border: 1px solid var(--line-strong);
  color: var(--text); font-weight: 500;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 230px minmax(0, 1fr); }
  .aside { display: none; }
  .app.aside-collapsed .layout { grid-template-columns: 230px minmax(0, 1fr); }
}

@media (max-width: 760px) {
  .app { height: auto; min-height: 100vh; }
  .topbar { position: sticky; top: 0; z-index: 10; }
  .layout { grid-template-columns: 1fr; }
  .app.nav-collapsed .layout { grid-template-columns: 1fr; }
  .nav { border-right: 0; border-bottom: 1px solid var(--line); max-height: 40vh; }
  .app.nav-collapsed .nav { display: none; }
  .content { overflow: visible; padding: 28px 16px 48px; }
  .hero h1 { font-size: 26px; }
  .step { grid-template-columns: 1fr; gap: 2px; }
  .qa-a { flex-wrap: wrap; }
  .brand-name { display: none; }
  .brand-sub::before { display: none; }
  .voice-select { max-width: 110px; text-overflow: ellipsis; }
}

/* ===== BÀI TẬP LUYỆN VIẾT ===== */
.exercise-stat { margin-left: auto; font-size: 12px; font-weight: 400; color: var(--text-sub); }
.exercise-list { display: flex; flex-direction: column; gap: 10px; }
.exercise {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.exercise-q { display: flex; gap: 10px; align-items: flex-start; }
.exercise-q p { font-weight: 600; }
.exercise-q small { display: block; color: var(--text-sub); font-size: 13px; margin-top: 2px; }
.exercise textarea {
  width: 100%; min-height: 76px; padding: 10px 12px; border-radius: var(--radius);
  border: 1px solid var(--line-strong); background: var(--bg);
  font: inherit; font-size: 14px; color: var(--text); resize: vertical;
}
.exercise textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.exercise-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.exercise-actions .btn[disabled] { opacity: .5; cursor: wait; }
.exercise-result {
  padding: 10px 14px; border-radius: var(--radius);
  background: var(--soft); border: 1px solid var(--line); font-size: 13px;
}
.exercise-result ul { margin: 6px 0 0; padding-left: 18px; color: var(--text-2); }
.result-score { font-size: 13px; color: var(--text-sub); }
.result-score strong { font-size: 22px; font-weight: 700; color: var(--text); letter-spacing: -0.02em; }
.result-parts { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--text-sub); margin-top: 2px; }
.level-good { border-color: #b7e4cd; }
.level-good .result-score strong { color: #0f7b6c; }
.level-ok .result-score strong { color: #b26b00; }
.level-low .result-score strong { color: #c4314b; }
@media (prefers-color-scheme: dark) {
  .level-good .result-score strong { color: #4cc9a6; }
  .level-ok .result-score strong { color: #e8a948; }
  .level-low .result-score strong { color: #f07489; }
}
.exercise-q > div { flex: 1; }
.btn-translate { flex-shrink: 0; min-height: 26px; padding: 0 8px; font-size: 12px; color: var(--text-sub); }
.exercise-q small[hidden], [hidden] { display: none !important; }
.real-tag { margin-left: 6px; padding: 1px 6px; border-radius: 4px; font-size: 11px; font-weight: 500; vertical-align: 2px; color: var(--accent); background: var(--accent-soft); }
.btn-mic.recording { background: #c4314b; border-color: #c4314b; color: #fff; animation: rec 1.2s ease-in-out infinite; }
@keyframes rec { 50% { box-shadow: 0 0 0 4px rgba(196, 49, 75, .25); } }

/* ===== GEMINI ===== */
.ai-settings-btn { min-height: 30px; }
.ai-dialog {
  width: min(440px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line);
  border-radius: 12px; background: var(--bg); color: var(--text);
}
.ai-dialog::backdrop { background: rgba(0, 0, 0, .35); }
.ai-settings-form { display: flex; flex-direction: column; gap: 6px; padding: 20px; }
.ai-settings-form h2 { margin: 0 0 4px; font-size: 16px; }
.ai-settings-form p { margin-bottom: 8px; }
.ai-settings-form a { color: var(--accent); }
.ai-settings-form label { font-size: 13px; font-weight: 500; margin-top: 6px; }
.ai-settings-form input {
  font: inherit; padding: 8px 10px; border-radius: 6px; min-height: 36px;
  border: 1px solid var(--line-strong); background: var(--bg); color: var(--text);
}
.ai-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

.ai-review { padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--soft); font-size: 13.5px; display: flex; flex-direction: column; gap: 8px; }
.ai-scores { display: flex; gap: 16px; color: var(--text-sub); }
.ai-scores strong { font-size: 18px; color: var(--text); }
.ai-errors { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }
.ai-errors s { color: #c4314b; }
.ai-corrected { border-top: 1px solid var(--line); padding-top: 8px; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.ai-corrected p { font-weight: 500; }
.ai-error { color: #c4314b; }

.ai-fab {
  position: fixed; right: 20px; bottom: 20px; z-index: 30;
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 999px; border: 0;
  background: var(--text); color: var(--bg); font-weight: 500;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
}
.ai-chat {
  position: fixed; right: 20px; bottom: 76px; z-index: 30;
  width: min(380px, calc(100vw - 32px)); height: min(520px, calc(100vh - 120px));
  display: flex; flex-direction: column;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .18);
}
.ai-chat header { display: flex; justify-content: space-between; align-items: center; padding: 8px 8px 8px 14px; border-bottom: 1px solid var(--line); }
.ai-chat-log { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; font-size: 13.5px; }
.ai-msg { padding: 8px 12px; border-radius: 10px; max-width: 90%; }
.ai-msg-user { align-self: flex-end; background: var(--accent); color: #fff; }
.ai-msg-ai { align-self: flex-start; background: var(--soft); border: 1px solid var(--line); }
.ai-chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.ai-chat-form textarea {
  flex: 1; resize: none; font: inherit; font-size: 14px; padding: 8px 10px;
  border-radius: 8px; border: 1px solid var(--line-strong); background: var(--bg); color: var(--text);
}
.ai-chat-form .btn { align-self: flex-end; min-height: 36px; }
@media (max-width: 760px) {
  .ai-settings-btn span, .ai-fab span { display: none; }
  .ai-fab { right: 16px; bottom: 16px; padding: 0 14px; }
  .ai-chat { right: 16px; bottom: 70px; }
}
.ai-review-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 12px; }
.ai-review-head .muted { font-size: 12px; }
.ai-speak {
  border: 0; background: none; padding: 4px 6px; margin: 0 -6px; border-radius: 6px;
  text-align: left; font-weight: 500; font-size: 14px; color: var(--text); cursor: pointer;
}
.ai-speak:hover { background: var(--hover); }
.ai-speak.speaking { background: var(--accent-soft); color: var(--accent); }
.ai-check { display: flex; gap: 8px; align-items: flex-start; margin-top: 12px; font-weight: 400 !important; font-size: 13px; color: var(--text-2); }
.ai-check input { margin-top: 3px; min-height: 0 !important; }
.btn-mic[disabled] { opacity: .7; cursor: progress; }
