:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #142033;
  --muted: #5b6b82;
  --line: #e2e7f0;
  --brand: #1f4fd1;
  --brand-dark: #173ba0;
  --brand-soft: #e8eefc;
  --accent: #ff8a1f;
  --good: #14915a;
  --good-soft: #e3f6ec;
  --bad: #d23a3a;
  --bad-soft: #fde8e8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 32, 51, .05), 0 6px 20px rgba(20, 32, 51, .06);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { font-family: "Inter", system-ui, sans-serif; background: var(--bg); color: var(--ink); line-height: 1.55; min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.9rem; line-height: 1.2; margin: .2em 0 .4em; letter-spacing: -.02em; }
h2 { font-size: 1.25rem; margin: 1.6em 0 .6em; }
h3 { margin: 0 0 .3em; font-size: 1.05rem; }
main { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: 28px 20px 60px; }
input, select { font: inherit; width: 100%; padding: 11px 13px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); margin-top: 6px; }
input:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 14px; }
select { width: auto; min-width: 220px; margin: 0; }

.muted { color: var(--muted); }
.small { font-size: .86rem; }
.center { text-align: center; justify-content: center; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.narrow { max-width: 680px; margin: 0 auto; }
.loading { padding: 80px; text-align: center; color: var(--muted); }

.topbar { position: sticky; top: 0; z-index: 20; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 16px; padding: 10px 20px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; color: var(--ink); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(135deg, var(--brand), #5b84ff); color: #fff; display: grid; place-items: center; font-weight: 800; }
nav { display: flex; align-items: center; gap: 4px; margin-left: auto; flex-wrap: wrap; }
nav a, .link-btn { padding: 8px 12px; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: .93rem; display: inline-flex; align-items: center; gap: 6px; }
nav a:hover, .link-btn:hover { background: var(--bg); color: var(--ink); text-decoration: none; }
nav a.active { color: var(--brand); background: var(--brand-soft); }
.link-btn { background: none; border: 0; cursor: pointer; font: inherit; font-weight: 600; font-size: .93rem; }
.menu-btn { display: none; margin-left: auto; background: none; border: 1px solid var(--line); border-radius: 8px; font-size: 1.2rem; padding: 4px 10px; cursor: pointer; }

.footer { text-align: center; padding: 20px; color: var(--muted); font-size: .82rem; border-top: 1px solid var(--line); background: #fff; }
.credit { font-size: .9rem; color: var(--ink); margin-bottom: 6px; }
.credit-tag { display: inline-block; margin-left: 6px; padding: 2px 9px; border-radius: 99px; background: #fff4e5; color: #b35c00; font-size: .75rem; font-weight: 700; border: 1px solid #ffd8a8; }

.badge { background: var(--accent); color: #fff; font-size: .72rem; font-weight: 700; padding: 1px 7px; border-radius: 99px; min-width: 20px; text-align: center; }
.pill { background: var(--brand-soft); color: var(--brand-dark); font-size: .75rem; font-weight: 700; padding: 3px 9px; border-radius: 99px; white-space: nowrap; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 700; border-radius: 10px; padding: 11px 18px; border: 1.5px solid transparent; cursor: pointer; transition: .15s; }
.btn:hover { text-decoration: none; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { border-color: var(--brand); color: var(--brand); }
.btn.sm { padding: 7px 12px; font-size: .86rem; }
.btn:disabled { opacity: .6; cursor: default; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; }
.grid.tiles { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); margin: 18px 0; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.trades { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.grid.list { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); margin-top: 14px; }

.tile { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; color: var(--ink); box-shadow: var(--shadow); transition: .15s; }
.tile:hover { transform: translateY(-2px); border-color: var(--brand); text-decoration: none; }
.tile p { color: var(--muted); margin: 0; font-size: .9rem; }
.tile-icon { font-size: 1.8rem; display: block; margin-bottom: 8px; }

.item { display: flex; justify-content: space-between; align-items: center; gap: 12px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; color: var(--ink); font-weight: 600; }
.item:hover { border-color: var(--brand); text-decoration: none; }

.tabs { display: inline-flex; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 8px; }
.tabs a { padding: 8px 20px; border-radius: 9px; font-weight: 700; color: var(--muted); }
.tabs a.active { background: var(--brand); color: #fff; }
.tabs a:hover { text-decoration: none; }
.mixed { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-top: 10px; }
.mixed p { margin: 0; }

.hero { display: grid; grid-template-columns: 1.2fr 1fr; gap: 40px; align-items: center; padding-top: 30px; }
.hero h1 { font-size: 2.6rem; }
.hl { color: var(--brand); }
.hero-list { list-style: none; padding: 0; display: grid; gap: 8px; font-weight: 600; }
.signin h2 { margin-top: 0; }
.signin .btn { width: 100%; }
.dev-note { background: #fff6e8; border: 1px dashed var(--accent); padding: 8px 12px; border-radius: 8px; font-size: .85rem; margin-top: 14px; }

.quiz-split { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.passage { max-height: calc(100vh - 140px); overflow: auto; position: sticky; top: 80px; }
.passage h2 { margin-top: 0; }
.mini-passage { background: var(--bg); border-radius: 10px; padding: 4px 14px; max-height: 260px; overflow: auto; font-size: .92rem; margin-bottom: 10px; }
.quiz-head { display: flex; justify-content: space-between; }
.progress { height: 6px; background: var(--line); border-radius: 99px; margin: 10px 0 18px; overflow: hidden; }
.progress div { height: 100%; background: var(--brand); transition: width .3s; }
.q { font-size: 1.25rem; margin: 0 0 16px; }
.choices { display: grid; gap: 10px; }
.choice { display: flex; align-items: center; gap: 12px; text-align: left; font: inherit; background: #fff; border: 1.5px solid var(--line); border-radius: 12px; padding: 13px 14px; cursor: pointer; transition: .12s; color: var(--ink); }
.choice:hover:not(:disabled) { border-color: var(--brand); background: var(--brand-soft); }
.choice:disabled { cursor: default; }
.letter { width: 28px; height: 28px; flex: none; border-radius: 8px; background: var(--bg); display: grid; place-items: center; font-weight: 800; font-size: .85rem; color: var(--muted); }
.choice.right { border-color: var(--good); background: var(--good-soft); }
.choice.right .letter { background: var(--good); color: #fff; }
.choice.wrong { border-color: var(--bad); background: var(--bad-soft); }
.choice.wrong .letter { background: var(--bad); color: #fff; }
.explain { border-radius: 10px; padding: 12px 14px; margin: 16px 0 12px; }
.explain.ok { background: var(--good-soft); }
.explain.no { background: var(--bad-soft); }
.score-ring { --p: 0; width: 130px; height: 130px; border-radius: 50%; margin: 10px auto; display: grid; place-items: center; background: conic-gradient(var(--brand) calc(var(--p) * 1%), var(--line) 0); }
.score-ring span { width: 104px; height: 104px; border-radius: 50%; background: #fff; display: grid; place-items: center; font-size: 1.7rem; font-weight: 800; }

.stat-card { display: flex; align-items: center; gap: 36px; flex-wrap: wrap; }
.stat-card .btn { margin-left: auto; }
.big { font-size: 1.8rem; font-weight: 800; }
.tips ul { margin: 0; padding-left: 20px; }
.tips { margin-top: 20px; }

.trade { display: flex; gap: 14px; }
.trade-icon { font-size: 1.9rem; }
.trade p { margin: 8px 0 0; color: var(--muted); font-size: .93rem; }

.people { display: grid; gap: 8px; margin-top: 8px; }
.person { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: #fff; border: 1px solid var(--line); border-radius: 12px; }
.card .person { border: 0; padding: 8px 0; }
.person.big .avatar { width: 52px; height: 52px; font-size: 1.1rem; }
.pinfo { display: flex; flex-direction: column; flex: 1; min-width: 0; color: var(--ink); }
.pinfo span { overflow: hidden; text-overflow: ellipsis; }
.pinfo:hover { text-decoration: none; }
.avatar { --h: 220; width: 38px; height: 38px; flex: none; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: .85rem; color: #fff; background: hsl(var(--h) 60% 50%); }
.more { position: relative; }
.more summary { list-style: none; cursor: pointer; padding: 4px 10px; border-radius: 8px; font-weight: 800; color: var(--muted); }
.more summary::-webkit-details-marker { display: none; }
.more[open] > div { position: absolute; right: 0; top: 32px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); display: grid; min-width: 150px; z-index: 5; overflow: hidden; }
.more button { background: none; border: 0; font: inherit; text-align: left; padding: 10px 14px; cursor: pointer; }
.more button:hover { background: var(--bg); }
.more .danger { color: var(--bad); }
.blocked { margin-top: 24px; }
.blocked summary { cursor: pointer; color: var(--muted); font-weight: 600; }

.chat { display: flex; flex-direction: column; height: calc(100vh - 190px); min-height: 420px; padding: 0; overflow: hidden; max-width: 760px; margin: 0 auto; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.back { font-size: 1.3rem; font-weight: 800; padding: 0 6px; }
.back:hover { text-decoration: none; }
.msgs { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; background: #fafbfe; }
.msg { display: flex; flex-direction: column; max-width: 75%; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.theirs { align-self: flex-start; }
.bubble { padding: 9px 14px; border-radius: 16px; white-space: pre-wrap; word-break: break-word; }
.mine .bubble { background: var(--brand); color: #fff; border-bottom-right-radius: 5px; }
.theirs .bubble, .theirs-bubble { background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.meta { font-size: .74rem; color: var(--muted); margin-top: 3px; display: flex; align-items: center; gap: 4px; }
.report { background: none; border: 0; cursor: pointer; color: var(--muted); font-size: .8rem; padding: 0 2px; }
.report:hover { color: var(--bad); }
.composer { display: flex; gap: 10px; padding: 12px; border-top: 1px solid var(--line); }
.composer input { margin: 0; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.table tr:last-child td { border-bottom: 0; }
.score { font-weight: 800; }
.score.good { color: var(--good); }
.score.ok { color: #b9770e; }
.score.low { color: var(--bad); }
.report-card { margin-bottom: 12px; }
.report-card .bubble { display: inline-block; margin-bottom: 6px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 12px; font-weight: 600; box-shadow: var(--shadow); z-index: 50; max-width: 90vw; }
.toast.bad { background: var(--bad); }

@media (max-width: 860px) {
  .menu-btn { display: block; }
  nav { display: none; position: absolute; top: 100%; left: 0; right: 0; background: #fff; border-bottom: 1px solid var(--line); flex-direction: column; align-items: stretch; padding: 8px; }
  nav.open { display: flex; }
  .hero, .quiz-split { grid-template-columns: 1fr; }
  .hero h1 { font-size: 2rem; }
  .passage { position: static; max-height: none; }
  .msg { max-width: 88%; }
  h1 { font-size: 1.6rem; }
}
