:root {
  --bg: #f6f5f1; --panel: #ffffff; --soft: #f1efe8; --line: #dedcd3; --line2: #c9c6bb;
  --text: #22221f; --muted: #6b6a64; --accent: #185fa5; --accent-bg: #e6f1fb;
  --ok: #3b6d11; --ok-bg: #eaf3de; --bad: #a32d2d; --bad-bg: #fcebeb; --warn: #854f0b; --warn-bg: #faeeda;
  --mono: ui-monospace, "Cascadia Code", Consolas, "Courier New", monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; }
button { font: inherit; padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line2); background: var(--panel); color: var(--text); cursor: pointer; }
button:hover { background: var(--soft); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #0c447c; }
button.danger { color: var(--bad); }
button:disabled { opacity: .55; cursor: default; }
input, textarea, select { font: inherit; padding: 7px 10px; border: 1px solid var(--line2); border-radius: 8px; background: var(--panel); color: var(--text); }
textarea { resize: vertical; }
code, pre, .mono { font-family: var(--mono); font-size: 13px; }
h1, h2, h3 { font-weight: 600; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* Thanh trên cùng */
.topbar { height: 52px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 17px; }
.topbar .right { display: flex; gap: 12px; align-items: center; }
.pill { font-size: 13px; padding: 3px 10px; border-radius: 99px; background: var(--soft); color: var(--muted); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }

/* Bố cục học sinh */
.layout { display: grid; grid-template-columns: 230px minmax(0, 1fr) 360px; height: calc(100vh - 52px); }
.sidebar { border-right: 1px solid var(--line); background: var(--panel); overflow: auto; padding: 10px; }
.sidebar .ex { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; line-height: 1.4; }
.sidebar .ex:hover { background: var(--soft); }
.sidebar .ex.active { background: var(--accent-bg); color: var(--accent); }
.sidebar .ex .mark { width: 18px; flex: none; color: var(--ok); font-weight: 700; }
.main { overflow: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.desc { white-space: pre-wrap; line-height: 1.55; margin: 6px 0 0; }
.example { display: flex; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
.example > div { flex: 1; min-width: 140px; }
.example pre { background: var(--soft); border-radius: 8px; padding: 8px 10px; margin: 4px 0 0; white-space: pre-wrap; }
.label { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.editor-wrap { border: 1px solid var(--line2); border-radius: 10px; overflow: hidden; background: #fff; }
.CodeMirror { height: 300px; font-family: var(--mono); font-size: 14px; }
.cm-error-line { background: var(--bad-bg) !important; }
#codeFallback { width: 100%; height: 300px; border: 0; font-family: var(--mono); font-size: 14px; padding: 8px; tab-size: 4; }
.io { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 12px; }
.io textarea { width: 100%; height: 130px; font-family: var(--mono); font-size: 13px; }
.output { height: 130px; overflow: auto; background: #1f1f1d; color: #e9e8e2; border-radius: 8px; padding: 8px 10px; margin: 0; white-space: pre-wrap; font-family: var(--mono); font-size: 13px; }
.output .err { color: #f7a3a3; }
.output .info { color: #9fc7ef; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.status { font-size: 13px; color: var(--muted); }
.explain { margin-top: 8px; font-size: 13px; background: var(--warn-bg); color: var(--warn); padding: 6px 10px; border-radius: 8px; }
.tests { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; font-size: 14px; }
.tests .t { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.tests .detail { width: 100%; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tests .detail pre { background: var(--soft); padding: 6px 8px; border-radius: 6px; margin: 2px 0 0; white-space: pre-wrap; }

/* Trợ giảng */
.tutor { border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.tutor .head { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.chat { flex: 1; overflow: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { padding: 9px 12px; border-radius: 10px; font-size: 14px; line-height: 1.55; max-width: 95%; word-wrap: break-word; }
.msg.me { align-self: flex-end; background: var(--accent-bg); color: #0c447c; }
.msg.ai { background: var(--soft); }
.msg.sys { align-self: center; font-size: 13px; color: var(--muted); background: none; }
.msg pre { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; overflow: auto; }
.msg code { background: rgba(0,0,0,.06); padding: 0 4px; border-radius: 4px; }
.msg pre code { background: none; padding: 0; }

/* Tra cứu lỗi */
.output .lookup-btn { margin-top: 8px; font-family: inherit; font-size: 13px; padding: 3px 10px; background: #3a2a1a; color: #f5c98a; border-color: #8a5a22; }
.output .lookup-btn:hover { background: #4a3520; }
.msg.guide { background: var(--warn-bg); border-left: 3px solid var(--warn); max-width: 100%; scroll-margin-top: 8px; }
.msg.guide ul, .msg.guide ol { margin: 2px 0; padding-left: 20px; }
.msg.guide li { margin: 2px 0; }
.g-title { font-weight: 600; color: var(--warn); margin-bottom: 4px; }
.g-line { font-size: 13px; margin-bottom: 6px; }
.g-orig { font-size: 13px; margin-bottom: 2px; }
.g-orig code { background: var(--panel); color: var(--bad); }
.g-note { font-size: 13px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 5px 9px; margin: 6px 0; color: var(--muted); }
.g-more { margin-top: 8px; font-size: 13px; }
.g-more summary { cursor: pointer; color: var(--muted); }
.g-more > div { margin-top: 4px; }
.g-sec { font-weight: 600; font-size: 13px; margin-top: 8px; }
.g-ex { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px; }
.g-ex pre { margin: 2px 0 0; font-size: 12px; }
.g-bad { font-size: 12px; color: var(--bad); font-weight: 600; }
.g-good { font-size: 12px; color: var(--ok); font-weight: 600; }
.g-foot { font-size: 12px; color: var(--muted); margin-top: 8px; }
.ask { padding: 10px 14px 14px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.ask textarea { width: 100%; height: 70px; }
.rule { font-size: 12px; color: var(--muted); }

/* Đăng nhập */
.overlay { position: fixed; inset: 0; background: rgba(30, 30, 28, .45); display: flex; align-items: center; justify-content: center; z-index: 10; }
.login { width: 360px; background: var(--panel); border-radius: 14px; padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.login input { width: 100%; font-size: 17px; text-transform: uppercase; }
.error-text { color: var(--bad); font-size: 13px; min-height: 18px; }

/* Giáo viên */
.tpage { max-width: 1150px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 12px; }
.tabs button.active { border-bottom-color: var(--accent); color: var(--accent); }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.metric { background: var(--soft); border-radius: 10px; padding: 12px 14px; }
.metric .v { font-size: 26px; font-weight: 600; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
.bar { height: 8px; background: var(--soft); border-radius: 99px; overflow: hidden; min-width: 80px; }
.bar > span { display: block; height: 100%; background: var(--ok); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; }
.qa { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.qa pre { background: var(--soft); padding: 6px 8px; border-radius: 6px; margin: 0; white-space: pre-wrap; max-height: 220px; overflow: auto; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.form { display: flex; flex-direction: column; gap: 10px; }
.form textarea, .form input[type=text] { width: 100%; }
.testrow { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 8px; }
.testrow textarea { height: 60px; font-family: var(--mono); font-size: 13px; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 200px minmax(0, 1fr); height: auto; }
  .tutor { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); min-height: 420px; }
}
@media (max-width: 700px) {
  .layout { grid-template-columns: 1fr; }
  .io { grid-template-columns: 1fr; }
}
