/* ==========================================================================
   He thong giao dien
   --------------------------------------------------------------------------
   Nguyen tac:
   - Mau nen trung tinh hoi am, KHONG dung gradient trang tri.
   - Mot mau nhan duy nhat cho hanh dong. Mau con lai danh het cho ket qua
     cham bai, vi do moi la thong tin quan trong nhat tren man hinh.
   - Ket qua luon co CA mau LAN chu viet tat, khong bao gio chi dua vao mau.
   - Chu so, thoi gian, ket qua dung font mono de cot thang hang khi doc luot.
   ========================================================================== */

:root {
  /* Nen va chu */
  --bg:         #faf9f7;
  --surface:    #ffffff;
  --surface-2:  #f4f2ef;
  --border:     #e4e0da;
  --border-str: #d2ccc3;
  --ink:        #1a1816;
  --ink-2:      #4a4540;
  --muted:      #7d766d;

  /* Mau nhan */
  --accent:     #1b4dd8;
  --accent-ink: #ffffff;
  --accent-bg:  #e9eefc;
  --accent-br:  #c3d0f7;

  /* Ket qua cham */
  --ac:    #0a7f57;  --ac-bg:   #e3f5ed;  --ac-br:   #b6e3d1;
  --wa:    #c62828;  --wa-bg:   #fdeaea;  --wa-br:   #f5c2c2;
  --tle:   #a35a00;  --tle-bg:  #fdf0dd;  --tle-br:  #f2d5a8;
  --rte:   #6d28d9;  --rte-bg:  #f1ebfd;  --rte-br:  #ddcdf8;
  --ce:    #5c6470;  --ce-bg:   #eef0f3;  --ce-br:   #d6dae0;
  --ie:    #a1145c;  --ie-bg:   #fdeaf3;  --ie-br:   #f6c4dd;

  /* Hinh khoi */
  --r-sm: 5px;
  --r:    9px;
  --r-lg: 14px;
  --shadow:    0 1px 2px rgba(26,24,22,.05), 0 1px 3px rgba(26,24,22,.04);
  --shadow-lg: 0 4px 6px -2px rgba(26,24,22,.06), 0 12px 28px -8px rgba(26,24,22,.14);

  --sans: "Segoe UI", Inter, -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", "JetBrains Mono", "SF Mono", Consolas, "Liberation Mono", monospace;
}

:root[data-theme="dark"] {
  --bg:         #121214;
  --surface:    #1a1a1d;
  --surface-2:  #212126;
  --border:     #2c2c33;
  --border-str: #3d3d46;
  --ink:        #eceaea;
  --ink-2:      #bdb9b6;
  --muted:      #8b8781;

  --accent:     #7ba2ff;
  --accent-ink: #0e1424;
  --accent-bg:  #1a2440;
  --accent-br:  #2f4478;

  --ac:    #3ecf9a;  --ac-bg:   #10281f;  --ac-br:   #1d5040;
  --wa:    #f87171;  --wa-bg:   #2c1616;  --wa-br:   #5c2727;
  --tle:   #f0b429;  --tle-bg:  #2c2210;  --tle-br:  #59431a;
  --rte:   #b492f8;  --rte-bg:  #241c38;  --rte-br:  #443466;
  --ce:    #9aa3af;  --ce-bg:   #1e2126;  --ce-br:   #363b44;
  --ie:    #f472b6;  --ie-bg:   #2e1524;  --ie-br:   #5c2946;

  --shadow:    0 1px 2px rgba(0,0,0,.4);
  --shadow-lg: 0 8px 30px -8px rgba(0,0,0,.7);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; font-weight: 650; line-height: 1.25; letter-spacing: -0.012em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }

code, kbd, pre, .mono { font-family: var(--mono); font-variant-ligatures: none; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* ---------- Bo cuc ---------- */

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }
.wrap-narrow { max-width: 760px; margin: 0 auto; padding: 0 20px; }

.site-head {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0; z-index: 40;
}
.site-head .wrap { display: flex; align-items: center; gap: 26px; height: 56px; }

.brand {
  font-weight: 680; font-size: .96rem; color: var(--ink);
  letter-spacing: -.01em; white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand span { color: var(--muted); font-weight: 500; }

.nav { display: flex; gap: 2px; margin-left: auto; align-items: center; }
.nav a {
  color: var(--ink-2); padding: 6px 11px; border-radius: var(--r-sm);
  font-size: .89rem; font-weight: 520;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--accent-bg); color: var(--accent); }

.whoami {
  font-size: .82rem; color: var(--muted); padding-left: 14px;
  margin-left: 6px; border-left: 1px solid var(--border);
  display: flex; align-items: center; gap: 9px;
}
.whoami b { color: var(--ink-2); font-weight: 600; }

.icon-btn {
  background: none; border: 1px solid transparent; cursor: pointer;
  color: var(--muted); border-radius: var(--r-sm); padding: 5px 7px;
  font-size: .95rem; line-height: 1; display: inline-flex; align-items: center;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

main { padding: 30px 0 70px; }

.page-head { margin-bottom: 22px; }
.page-head p { margin: 5px 0 0; color: var(--muted); font-size: .92rem; }

/* ---------- Thanh phan chung ---------- */

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--shadow);
}
.card-pad { padding: 18px 20px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  background: var(--accent); color: var(--accent-ink);
  border: 1px solid transparent; border-radius: var(--r-sm);
  padding: 8px 16px; font: inherit; font-size: .9rem; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  transition: filter .12s ease, opacity .12s ease;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn:active { filter: brightness(.94); }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: none; }
.btn-ghost {
  background: var(--surface); color: var(--ink-2); border-color: var(--border-str);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); filter: none; }
.btn-sm { padding: 5px 11px; font-size: .83rem; }

input[type=text], input[type=password], select, textarea {
  width: 100%; padding: 9px 12px; font: inherit; font-size: .93rem;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--border-str); border-radius: var(--r-sm);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: .84rem; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }

.hint { font-size: .83rem; color: var(--muted); }

.msg { padding: 10px 13px; border-radius: var(--r-sm); font-size: .88rem; margin-bottom: 14px; }
.msg-err  { background: var(--wa-bg); color: var(--wa); border: 1px solid var(--wa-br); }
.msg-warn { background: var(--tle-bg); color: var(--tle); border: 1px solid var(--tle-br); }
.msg-ok   { background: var(--ac-bg); color: var(--ac); border: 1px solid var(--ac-br); }

/* ---------- Nhan ket qua ---------- */

.verdict {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--mono); font-size: .78rem; font-weight: 700;
  padding: 2px 8px; border-radius: 4px; border: 1px solid; letter-spacing: .02em;
  white-space: nowrap;
}
.v-AC  { color: var(--ac);  background: var(--ac-bg);  border-color: var(--ac-br); }
.v-WA  { color: var(--wa);  background: var(--wa-bg);  border-color: var(--wa-br); }
.v-TLE { color: var(--tle); background: var(--tle-bg); border-color: var(--tle-br); }
.v-RTE { color: var(--rte); background: var(--rte-bg); border-color: var(--rte-br); }
.v-CE  { color: var(--ce);  background: var(--ce-bg);  border-color: var(--ce-br); }
.v-IE  { color: var(--ie);  background: var(--ie-bg);  border-color: var(--ie-br); }
.v-pending, .v-judging {
  color: var(--muted); background: var(--surface-2); border-color: var(--border);
}
.v-judging::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: .25; } 50% { opacity: 1; } }

.tag {
  display: inline-block; font-size: .75rem; padding: 1px 8px; border-radius: 20px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.diff { font-size: .74rem; font-weight: 700; padding: 1px 8px; border-radius: 20px; border: 1px solid; }
.diff-easy   { color: var(--ac);  background: var(--ac-bg);  border-color: var(--ac-br); }
.diff-medium { color: var(--tle); background: var(--tle-bg); border-color: var(--tle-br); }
.diff-hard   { color: var(--wa);  background: var(--wa-bg);  border-color: var(--wa-br); }

/* ---------- Bang ---------- */

.table-wrap { overflow-x: auto; border-radius: var(--r); border: 1px solid var(--border); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
thead th {
  text-align: left; padding: 9px 14px; font-size: .74rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  background: var(--surface-2); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td { padding: 9px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
td.mono { font-family: var(--mono); font-size: .84rem; }

.empty { padding: 44px 20px; text-align: center; color: var(--muted); font-size: .92rem; }

/* ---------- Danh sach bai ---------- */

.problem-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); }
.problem-card {
  display: block; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: 16px 18px; color: inherit;
  transition: border-color .13s ease, transform .13s ease, box-shadow .13s ease;
}
.problem-card:hover {
  text-decoration: none; border-color: var(--border-str);
  transform: translateY(-1px); box-shadow: var(--shadow-lg);
}
.problem-card .row1 { display: flex; align-items: center; gap: 9px; margin-bottom: 3px; }
.problem-card .name { font-weight: 680; font-size: 1.02rem; font-family: var(--mono); letter-spacing: -.01em; }
.problem-card .sub { color: var(--muted); font-size: .83rem; }
.problem-card .meta {
  margin-top: 12px; padding-top: 11px; border-top: 1px solid var(--border);
  display: flex; gap: 14px; font-size: .78rem; color: var(--muted);
  font-family: var(--mono);
}
.problem-card .best { margin-left: auto; font-weight: 700; }

/* ---------- Trang bai tap ---------- */

.split { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 18px; align-items: start; }
@media (max-width: 1000px) { .split { grid-template-columns: minmax(0,1fr); } }

.statement { padding: 22px 24px; }
.statement h2 { margin: 24px 0 9px; font-size: 1.05rem; }
.statement h2:first-child { margin-top: 0; }
.statement p { margin: 0 0 12px; }
.statement ul, .statement ol { margin: 0 0 12px; padding-left: 22px; }
.statement li { margin-bottom: 5px; }
.statement code { background: var(--surface-2); padding: 1px 5px; border-radius: 3px; font-size: .87em; }

.limits {
  display: flex; flex-wrap: wrap; gap: 8px 20px; padding: 11px 16px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-sm); margin-bottom: 18px; font-size: .83rem;
}
.limits div { display: flex; gap: 6px; align-items: baseline; }
.limits dt { color: var(--muted); }
.limits dd { margin: 0; font-family: var(--mono); font-weight: 600; }

.sample { margin-bottom: 14px; }
.sample-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 560px) { .sample-grid { grid-template-columns: 1fr; } }
.io-box { border: 1px solid var(--border); border-radius: var(--r-sm); overflow: hidden; }
.io-box header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 10px; background: var(--surface-2); border-bottom: 1px solid var(--border);
  font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted);
}
.io-box pre {
  margin: 0; padding: 10px 12px; font-family: var(--mono); font-size: .84rem;
  line-height: 1.5; white-space: pre-wrap; word-break: break-word; max-height: 260px; overflow: auto;
}
.copy-btn {
  background: none; border: none; cursor: pointer; color: var(--muted);
  font: inherit; font-size: .7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; padding: 0;
}
.copy-btn:hover { color: var(--accent); }

.explain {
  margin-top: 9px; padding: 9px 12px; font-size: .85rem; color: var(--ink-2);
  background: var(--accent-bg); border-left: 3px solid var(--accent-br); border-radius: 0 var(--r-sm) var(--r-sm) 0;
}

/* ---------- Khu soan code ---------- */

.editor-panel { position: sticky; top: 76px; }
@media (max-width: 1000px) { .editor-panel { position: static; } }

.editor-head {
  display: flex; align-items: center; gap: 10px; padding: 9px 14px;
  border-bottom: 1px solid var(--border); background: var(--surface-2);
  border-radius: var(--r) var(--r) 0 0;
}
.editor-head .title { font-size: .82rem; font-weight: 700; color: var(--ink-2); }
.editor-head .spacer { margin-left: auto; }

.CodeMirror {
  height: 460px; font-family: var(--mono) !important; font-size: 13.5px; line-height: 1.55;
  border: none; background: var(--surface); color: var(--ink);
}
@media (max-width: 1000px) { .CodeMirror { height: 380px; } }

.editor-foot {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px;
  border-top: 1px solid var(--border); background: var(--surface-2);
  border-radius: 0 0 var(--r) var(--r);
}
.editor-foot .spacer { margin-left: auto; }
kbd {
  font-size: .74rem; padding: 1px 5px; border-radius: 3px;
  background: var(--surface); border: 1px solid var(--border-str);
  box-shadow: 0 1px 0 var(--border-str); color: var(--muted);
}

/* ---------- Ket qua cham ---------- */

.result { margin-top: 16px; }
.result-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.result-score { font-family: var(--mono); font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; }
.result-note { color: var(--muted); font-size: .87rem; }

.test-grid { display: flex; flex-wrap: wrap; gap: 5px; padding: 14px 18px; }
.test-chip {
  font-family: var(--mono); font-size: .74rem; font-weight: 700;
  padding: 3px 8px; border-radius: 4px; border: 1px solid; cursor: pointer;
  display: inline-flex; gap: 5px; align-items: baseline;
}
.test-chip small { font-weight: 500; opacity: .75; }

.test-detail { padding: 0 18px 16px; }
.test-detail pre {
  margin: 4px 0 0; padding: 9px 12px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  font-family: var(--mono); font-size: .82rem; white-space: pre-wrap;
  max-height: 180px; overflow: auto;
}
.compile-log {
  margin: 0; padding: 13px 16px; background: var(--surface-2);
  font-family: var(--mono); font-size: .8rem; line-height: 1.5;
  white-space: pre-wrap; max-height: 340px; overflow: auto;
  border-top: 1px solid var(--border); color: var(--ink-2);
}

/* ---------- Cong mat khau ---------- */

.gate {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center;
  padding: 24px; background: var(--bg);
}
.gate-box { width: 100%; max-width: 340px; }
.gate-mark {
  width: 34px; height: 34px; border-radius: 8px; margin-bottom: 22px;
  border: 1px solid var(--border-str); background: var(--surface);
  display: grid; place-items: center; font-family: var(--mono);
  font-size: .9rem; color: var(--muted);
}
.gate h1 { font-size: 1.05rem; font-weight: 620; margin-bottom: 4px; }
.gate .hint { margin-bottom: 20px; }
.gate form { display: flex; flex-direction: column; gap: 10px; }
.gate footer { margin-top: 34px; font-size: .76rem; color: var(--muted); }

/* ---------- Bang xep hang ---------- */

.rank-pos { font-family: var(--mono); font-weight: 700; color: var(--muted); width: 46px; }
.rank-1 .rank-pos { color: #b8860b; }
.rank-2 .rank-pos { color: #8a8a8a; }
.rank-3 .rank-pos { color: #a0682d; }
.score-cell { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; }
.score-full { color: var(--ac); font-weight: 700; }
.score-part { color: var(--tle); }
.score-zero { color: var(--muted); }
.score-none { color: var(--border-str); }

/* ---------- Vun vat ---------- */

.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { margin-left: auto; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.katex { font-size: 1.02em; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Subtask ---------- */

.subtask-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }
.subtask-row {
  display: flex; align-items: center; gap: 11px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface);
  font-size: .86rem;
}
.subtask-row .st-name { font-weight: 650; white-space: nowrap; }
.subtask-row .st-con { color: var(--ink-2); flex: 1; min-width: 0; }
.subtask-row .st-pts {
  font-family: var(--mono); font-weight: 700; white-space: nowrap; color: var(--muted);
}
.subtask-row.st-ok   { border-color: var(--ac-br); background: var(--ac-bg); }
.subtask-row.st-ok   .st-pts { color: var(--ac); }
.subtask-row.st-fail { border-color: var(--wa-br); background: var(--wa-bg); }
.subtask-row.st-fail .st-pts { color: var(--wa); }
.subtask-row .st-tests { font-family: var(--mono); font-size: .78rem; color: var(--muted); }

.io-mode {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: .78rem; font-weight: 700;
  padding: 2px 8px; border-radius: 4px;
  color: var(--rte); background: var(--rte-bg); border: 1px solid var(--rte-br);
}
