:root {
  --bg: #f6f4ee; --panel: #ffffff; --ink: #1d1f24; --muted: #6b6f7a; --line: #e5e1d8;
  --brand: #1f4e79; --brand-2: #2f6fa7; --accent: #c8792b; --good: #2e7d4f; --bad: #b4352f; --warn: #a36a00;
  --tint: #eef3f9; --tint-2: #fbf3ea; --tint-good: #edf7f0; --tint-bad: #fbeeed; --tint-key: #fff8e6;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 6px 18px rgba(31,78,121,.06);
  --sans: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--sans); color: var(--ink); background: var(--bg); line-height: 1.55; font-size: 16px; }
a { color: var(--brand-2); }
h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.9rem; font-weight: 800; letter-spacing: -.01em; }
h2 { font-size: 1.35rem; font-weight: 700; }
h3 { font-size: 1.1rem; font-weight: 700; margin-top: 1.4em; color: var(--brand); }
p { margin: 0 0 .9em; }
small, .muted { color: var(--muted); }
table { border-collapse: collapse; width: 100%; margin: .6em 0 1.2em; font-size: .95rem; }
th, td { border: 1px solid var(--line); padding: .55em .7em; text-align: left; vertical-align: top; }
th { background: var(--tint); font-weight: 600; }
ul, ol { padding-left: 1.3em; margin: 0 0 .9em; }
li { margin: .25em 0; }
code { background: var(--tint); padding: .1em .35em; border-radius: 4px; font-size: .9em; }
.hidden { display: none !important; }

/* layout */
.app { display: grid; grid-template-columns: 260px 1fr; grid-template-rows: auto 1fr; min-height: 100vh; }
.sidebar { grid-row: 1 / span 2; background: var(--panel); border-right: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; gap: 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 6px 10px; border-bottom: 1px solid var(--line); }
.brand .logo { font-size: 1.6rem; }
.brand b { display: block; font-size: 1rem; }
.brand small { display: block; font-size: .78rem; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { text-decoration: none; color: var(--ink); padding: 9px 10px; border-radius: 8px; font-weight: 500; font-size: .95rem; }
nav a.sub { font-size: .85rem; padding-left: 26px; color: var(--muted); }
nav a:hover { background: var(--tint); }
nav a.active { background: var(--brand); color: #fff; }
nav a.sub.active { background: var(--tint); color: var(--brand); font-weight: 600; }
.countdown { margin-top: auto; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border-radius: var(--radius); padding: 14px; }
.countdown b { font-size: 2rem; display: block; line-height: 1; }
.countdown small { color: rgba(255,255,255,.85); }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 22px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar-title { font-weight: 700; flex: 1; }
#menuBtn { display: none; }
.main { padding: 26px 30px 80px; max-width: 1080px; width: 100%; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -280px; width: 270px; z-index: 20; transition: left .2s; box-shadow: none; }
  .sidebar.open { left: 0; box-shadow: 0 0 0 100vw rgba(0,0,0,.35); }
  #menuBtn { display: inline-flex; }
  .main { padding: 18px 16px 90px; }
}

/* components */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 9px 14px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--brand-2); color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); color: #fff; }
.btn.small { padding: 6px 10px; font-size: .85rem; }
.btn.ghost { background: transparent; }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }
.iconbtn { border: 0; background: transparent; font-size: 1.15rem; cursor: pointer; padding: 6px 8px; border-radius: 8px; color: var(--ink); }
.iconbtn:hover { background: var(--tint); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card.tight { padding: 14px 16px; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.pill { display: inline-block; background: var(--tint); color: var(--brand); border-radius: 999px; padding: 2px 10px; font-size: .78rem; font-weight: 600; }
.pill.warn { background: var(--tint-2); color: var(--accent); }
.pill.good { background: var(--tint-good); color: var(--good); }
.pill.bad { background: var(--tint-bad); color: var(--bad); }
.pill.grey { background: #eee; color: var(--muted); }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .72rem; font-weight: 700; color: var(--accent); margin-bottom: .4em; }
.hero { background: linear-gradient(135deg, #1f4e79 0%, #2f6fa7 70%, #3b83c0 100%); color: #fff; border-radius: 16px; padding: 26px 28px; margin-bottom: 20px; box-shadow: var(--shadow); }
.hero h1 { color: #fff; margin-bottom: .2em; }
.hero p { color: rgba(255,255,255,.9); max-width: 60ch; }
.hero .pill { background: rgba(255,255,255,.18); color: #fff; }
.stat { display: flex; flex-direction: column; }
.stat b { font-size: 1.7rem; line-height: 1.1; }
.stat small { color: var(--muted); }
.progressbar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progressbar > div { height: 100%; background: var(--good); border-radius: 99px; transition: width .3s; }
.err { color: var(--bad); font-size: .9rem; min-height: 1.2em; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
input[type=text], input[type=password], input[type=date], select, textarea { font: inherit; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--ink); width: 100%; }
textarea { resize: vertical; }

/* day blocks */
.day-blocks { display: grid; gap: 8px; margin: 10px 0; }
.block { display: grid; grid-template-columns: 70px 1fr; gap: 12px; padding: 10px 12px; background: var(--tint); border-radius: 9px; }
.block .t { font-weight: 700; color: var(--brand); font-size: .85rem; white-space: nowrap; }
.block .h { font-weight: 700; display: block; }
.block .d { color: var(--ink); font-size: .93rem; }
.phase-1 .block { background: var(--tint); } .phase-2 .block { background: var(--tint-2); } .phase-3 .block { background: var(--tint-good); }
.day-list { display: grid; gap: 6px; }
.day-row { display: grid; grid-template-columns: 110px 1fr auto; gap: 12px; align-items: center; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; }
.day-row.today { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(31,78,121,.12); }
.day-row.done { opacity: .65; }
.day-row .d { font-weight: 600; font-size: .9rem; }
.day-row .d small { display: block; font-weight: 400; }
.day-row .f { font-size: .9rem; color: var(--muted); }
.day-row.review { background: #fbfaf5; } .day-row.practice { background: #fdf8f2; } .day-row.mock { background: #f1f8f3; } .day-row.exam { background: #fff3f2; border-color: var(--bad); }
.week-head { margin: 18px 0 8px; font-weight: 700; color: var(--brand); display: flex; gap: 10px; align-items: center; }
.checkbox { width: 22px; height: 22px; accent-color: var(--good); cursor: pointer; }

/* chapter reading */
.reader { font-family: var(--serif); font-size: 1.06rem; line-height: 1.65; }
.reader h3 { font-family: var(--sans); font-size: 1.05rem; }
.reader table { font-family: var(--sans); font-size: .92rem; }
.reader .callout { font-family: var(--sans); font-size: .96rem; }
.callout { border-left: 4px solid var(--brand-2); background: var(--tint); padding: 12px 16px; border-radius: 8px; margin: 1em 0; }
.callout.key { border-color: var(--warn); background: var(--tint-key); }
.callout.good { border-color: var(--good); background: var(--tint-good); }
.callout.tip { border-color: var(--accent); background: var(--tint-2); }
.callout.maria { border-color: #7b4fa1; background: #f5f0fa; }
.callout ol, .callout ul { margin-bottom: 0; }
.mnemonic { background: #fff; border: 1px dashed var(--accent); padding: 8px 12px; border-radius: 8px; display: inline-block; font-family: var(--sans); font-size: .93rem; }
.steps { display: grid; gap: 6px; margin: .8em 0 1.2em; font-family: var(--sans); font-size: .95rem; }
.steps > div { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; }
.steps b { color: var(--accent); margin-right: 6px; }
.grid4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin: .6em 0 1.2em; font-family: var(--sans); }
.grid4 > div { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: .92rem; }
.grid4 > div b { display: block; color: var(--brand); margin-bottom: 3px; }
.grid4.compact > div { display: flex; gap: 8px; align-items: baseline; } .grid4.compact b { margin: 0; }
.twocol { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.orgchart { display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 1em 0 1.4em; font-family: var(--sans); }
.orgchart .node { background: #fff; border: 1px solid var(--brand-2); border-radius: 10px; padding: 10px 14px; text-align: center; font-weight: 700; color: var(--brand); max-width: 420px; }
.orgchart .node.top { background: var(--brand); color: #fff; border-color: var(--brand); }
.orgchart .node.top span { color: rgba(255,255,255,.9); }
.orgchart .node span { display: block; font-weight: 400; color: var(--ink); font-size: .85rem; margin-top: 4px; }
.orgchart .node.sub { border-style: dashed; }
.orgchart .arrow { color: var(--muted); font-size: .85rem; }
.orgchart .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; max-width: 760px; }
.linkage { display: flex; flex-direction: column; align-items: center; gap: 4px; margin: 1em 0 1.4em; font-family: var(--sans); }
.linkage > div { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; text-align: center; font-size: .92rem; width: 100%; max-width: 460px; }
.linkage > div span { display: block; color: var(--muted); font-size: .85rem; }
.linkage .op { border: 0; background: none; font-weight: 800; font-size: 1.2rem; color: var(--accent); padding: 0; }
.parts-nav { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.parts-nav a { font-size: .82rem; text-decoration: none; background: var(--panel); border: 1px solid var(--line); padding: 5px 10px; border-radius: 999px; color: var(--ink); }
.parts-nav a:hover { border-color: var(--brand-2); color: var(--brand); }
.part { scroll-margin-top: 80px; }
.part-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.part-head h2 { margin: 0; }

/* quiz */
.quiz-item { border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; margin-bottom: 12px; background: #fff; }
.quiz-item .q { font-weight: 600; margin-bottom: 10px; }
.opts { display: grid; gap: 6px; }
.opt { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.opt:hover { border-color: var(--brand-2); }
.opt.sel { border-color: var(--brand); background: var(--tint); }
.opt.correct { border-color: var(--good); background: var(--tint-good); }
.opt.wrong { border-color: var(--bad); background: var(--tint-bad); }
.explain { margin-top: 10px; padding: 10px 12px; border-radius: 8px; background: var(--tint-key); font-size: .93rem; }
.explain.ok { background: var(--tint-good); } .explain.no { background: var(--tint-bad); }
.points { display: grid; gap: 6px; margin: 8px 0; }
.points label { display: flex; gap: 8px; align-items: flex-start; font-size: .93rem; }
.model { background: var(--tint); padding: 10px 12px; border-radius: 8px; font-size: .93rem; margin-top: 8px; }
.score { font-size: 1.4rem; font-weight: 800; }

/* flashcards */
.flash { perspective: 1000px; cursor: pointer; min-height: 200px; }
.flash .inner { position: relative; width: 100%; min-height: 200px; transition: transform .5s; transform-style: preserve-3d; }
.flash.flipped .inner { transform: rotateY(180deg); }
.flash .face { position: absolute; inset: 0; backface-visibility: hidden; display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px; border-radius: 14px; background: #fff; border: 1px solid var(--line); box-shadow: var(--shadow); font-size: 1.1rem; }
.flash .face.back { transform: rotateY(180deg); background: var(--tint-key); font-family: var(--serif); }

/* tutor */
.tutor { position: fixed; right: 18px; bottom: 18px; width: min(460px, calc(100vw - 24px)); height: min(680px, calc(100vh - 40px)); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 16px 50px rgba(0,0,0,.18); display: flex; flex-direction: column; z-index: 30; overflow: hidden; }
.tutor.page { position: static; width: 100%; height: calc(100vh - 140px); box-shadow: var(--shadow); }
.tutor-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--tint); }
.tutor-head small { display: block; font-size: .78rem; }
.tutor-actions { display: flex; align-items: center; gap: 4px; }
.switch { display: inline-flex; align-items: center; gap: 4px; font-size: .78rem; cursor: pointer; }
.tutor-quick { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.tutor-quick button { font-size: .78rem; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 10px; cursor: pointer; }
.tutor-quick button:hover { border-color: var(--brand-2); color: var(--brand); }
.tutor-log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 92%; padding: 10px 13px; border-radius: 12px; font-size: .94rem; line-height: 1.5; }
.msg.user { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.ai { align-self: flex-start; background: var(--tint); border-bottom-left-radius: 4px; }
.msg.ai h1, .msg.ai h2, .msg.ai h3 { font-size: 1rem; margin: .6em 0 .3em; }
.msg.ai p { margin: 0 0 .6em; } .msg.ai p:last-child { margin: 0; }
.msg.ai table { font-size: .85rem; margin: .4em 0; }
.msg.ai ul, .msg.ai ol { margin: .2em 0 .5em; }
.msg.ai code { font-size: .85em; }
.msg.err { background: var(--tint-bad); color: var(--bad); align-self: stretch; }
.tutor-input { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.tutor-input textarea { flex: 1; }
.cursor::after { content: '▍'; animation: blink 1s infinite; color: var(--brand-2); }
@keyframes blink { 50% { opacity: 0; } }

/* login */
.login { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 100; }
.login-card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 30px; width: min(380px, 92vw); text-align: center; box-shadow: var(--shadow); display: grid; gap: 12px; }
.login-card .logo { font-size: 2.6rem; }
.login-card h1 { font-size: 1.4rem; }
.login-card input { text-align: center; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: .9rem; z-index: 50; box-shadow: var(--shadow); }
@media print { .sidebar, .topbar, .tutor, .btn { display: none !important; } .app { display: block; } .main { max-width: none; padding: 0; } }
