/* ===== Culori (luminos / întunecat) ===== */
:root {
  --bg: #f6f5f1; --surface: #ffffff; --surface-2: #f0eee8;
  --text: #1c2128; --muted: #5f6772; --border: #e2dfd6;
  --mate: #2456c4; --ro: #b0362c; --accent: #3d4a5c; --accent-2: #d9822b;
  --def-bg: #eef3fd; --def-bd: #2456c4;
  --ret-bg: #fff6e3; --ret-bd: #c08514;
  --ex-bg: #ecf7f0; --ex-bd: #2e8a55;
  --at-bg: #fdeeec; --at-bd: #c4473b;
  --mark: #ffe58a;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 18px rgba(0,0,0,.06);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-math: "Cambria Math", Cambria, "STIX Two Math", "Times New Roman", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121519; --surface: #1a1e24; --surface-2: #232830;
    --text: #e4e7eb; --muted: #9aa3ad; --border: #2e343c;
    --mate: #86abff; --ro: #ff8f82; --accent-2: #f0a050;
    --def-bg: rgba(134,171,255,.10); --def-bd: #86abff;
    --ret-bg: rgba(240,180,60,.10); --ret-bd: #e3b04a;
    --ex-bg: rgba(80,190,120,.10); --ex-bd: #5cc287;
    --at-bg: rgba(255,120,105,.10); --at-bd: #ff8f82;
    --mark: #6b5a12;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121519; --surface: #1a1e24; --surface-2: #232830;
  --text: #e4e7eb; --muted: #9aa3ad; --border: #2e343c;
  --mate: #86abff; --ro: #ff8f82; --accent-2: #f0a050;
  --def-bg: rgba(134,171,255,.10); --def-bd: #86abff;
  --ret-bg: rgba(240,180,60,.10); --ret-bd: #e3b04a;
  --ex-bg: rgba(80,190,120,.10); --ex-bd: #5cc287;
  --at-bg: rgba(255,120,105,.10); --at-bd: #ff8f82;
  --mark: #6b5a12;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.3);
  color-scheme: dark;
}

/* ===== Bază ===== */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-padding-top: 76px; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.65 var(--font); -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }
kbd { font: 12px var(--font); padding: 1px 6px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; background: var(--surface); }
.materie-matematica, .nav-matematica { --accent: var(--mate); --c: var(--mate); }
.materie-romana, .nav-romana { --accent: var(--ro); --c: var(--ro); }

/* ===== Bara de sus ===== */
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px; height: 60px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); flex-shrink: 0; }
.logo-badge { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; background: linear-gradient(135deg, var(--mate), var(--ro)); color: #fff; font-weight: 700; font-size: 15px; }
.logo-text { font-weight: 650; line-height: 1.15; font-size: 15px; }
.logo-text small { display: block; font-weight: 400; color: var(--muted); font-size: 12.5px; }
.btn-icon { width: 40px; height: 40px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); font-size: 18px; cursor: pointer; flex-shrink: 0; }
.btn-icon:hover { background: var(--surface-2); }
#btn-meniu { display: none; }

/* ===== Căutare ===== */
.cautare { position: relative; flex: 1; max-width: 520px; margin-left: auto; }
.cautare input { width: 100%; height: 40px; padding: 0 14px 0 38px; font: 15px var(--font); color: var(--text); border: 1px solid var(--border); border-radius: 10px; outline: none;
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%238a929c' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='M11 11l3.5 3.5'/%3E%3C/svg%3E") no-repeat 12px center; }
.cautare input:focus { border-color: var(--mate); background-color: var(--surface); }
.rezultate { position: absolute; top: calc(100% + 6px); left: 0; right: 0; min-width: min(440px, calc(100vw - 32px)); max-height: 70vh; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; z-index: 40; }
.rez-item { display: block; padding: 9px 12px; border-radius: 8px; text-decoration: none; color: var(--text); border-left: 3px solid transparent; }
.rez-item.activ, .rez-item:hover { background: var(--surface-2); border-left-color: var(--c); }
.rez-loc { display: block; font-size: 12px; color: var(--muted); }
.rez-titlu { display: block; font-weight: 600; line-height: 1.35; }
.rez-text { display: block; font-size: 13.5px; color: var(--muted); line-height: 1.45; margin-top: 2px; }
.rez-gol { padding: 14px; color: var(--muted); font-size: 14.5px; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }

/* ===== Structură ===== */
.layout { display: flex; align-items: flex-start; }
.sidebar { position: sticky; top: 60px; width: 290px; flex-shrink: 0; height: calc(100vh - 60px); overflow-y: auto; padding: 18px 12px 40px; border-right: 1px solid var(--border); background: var(--surface); }
.continut { flex: 1; min-width: 0; }
.pagina { max-width: 820px; margin: 0 auto; padding: 32px 40px 80px; }

/* ===== Meniul lateral ===== */
.nav-materie { margin-bottom: 18px; }
.nav-materie-titlu { display: flex; align-items: center; gap: 8px; font-weight: 700; text-decoration: none; color: var(--text); padding: 6px 10px; font-size: 15px; }
.nav-materie-titlu::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.nav-capitol summary { cursor: pointer; padding: 6px 10px; font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); list-style: none; border-radius: 6px; user-select: none; }
.nav-capitol summary::-webkit-details-marker { display: none; }
.nav-capitol summary::before { content: "▸"; display: inline-block; width: 14px; transition: transform .15s; }
.nav-capitol[open] > summary::before { transform: rotate(90deg); }
.nav-capitol summary:hover { color: var(--text); }
.nav-capitol ul { list-style: none; margin: 2px 0 8px; padding: 0 0 0 14px; }
.nav-capitol a { display: block; padding: 5px 10px; border-radius: 7px; text-decoration: none; color: var(--text); font-size: 14.5px; line-height: 1.35; border-left: 3px solid transparent; }
.nav-capitol a:hover { background: var(--surface-2); }
.nav-capitol a.activ { background: var(--surface-2); border-left-color: var(--c); font-weight: 600; }
.nav-capitol a.in-curand { color: var(--muted); }

/* ===== Pagina de start și pagina materiei ===== */
.hero h1 { font-size: clamp(28px, 4.5vw, 38px); line-height: 1.2; margin: 8px 0 10px; letter-spacing: -.4px; }
.hero p { color: var(--muted); font-size: 17px; max-width: 640px; margin: 0; }
.carduri-materii { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; margin-top: 28px; }
.card-materie { background: var(--surface); border: 1px solid var(--border); border-top: 5px solid var(--c); border-radius: 16px; padding: 20px 22px; box-shadow: var(--shadow); }
.card-materie h2 { margin: 0; font-size: 21px; line-height: 1.3; }
.card-materie h2 a { color: var(--text); text-decoration: none; }
.progres { font-size: 13px; color: var(--muted); }
.card-materie ul { list-style: none; padding: 0; margin: 12px 0 0; }
.card-materie li { display: flex; justify-content: space-between; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--border); }
.card-materie li:last-child { border-bottom: 0; }
.card-materie li a { color: var(--text); text-decoration: none; }
.card-materie li a:hover { color: var(--c); }
.card-materie li small { color: var(--muted); }
.capitol-bloc h2 { font-size: 20px; margin: 32px 0 12px; }
.grila-teme { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.tema-card { display: block; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); text-decoration: none; color: var(--text); font-weight: 550; line-height: 1.35; }
.tema-card:hover { border-color: var(--accent); }
.tema-card.in-curand { color: var(--muted); background: transparent; border-style: dashed; }
.tema-card small { display: block; font-weight: 400; font-size: 12.5px; margin-top: 3px; }

/* ===== Pagina unei teme ===== */
.breadcrumb { font-size: 13.5px; color: var(--muted); }
.breadcrumb a { color: var(--muted); }
.pagina h1 { font-size: clamp(26px, 4vw, 34px); line-height: 1.2; margin: 6px 0 10px; letter-spacing: -.3px; }
.intro { font-size: 17.5px; color: var(--muted); }
.cuprins { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 18px; margin: 20px 0 28px; }
.cuprins-titlu { font-size: 12.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 700; margin-bottom: 6px; }
.cuprins ol { margin: 0; padding-left: 22px; columns: 2; column-gap: 32px; }
.cuprins li { break-inside: avoid; }
.cuprins a { text-decoration: none; color: var(--text); }
.cuprins a:hover { color: var(--accent); text-decoration: underline; }
.sectiune { margin-top: 44px; }
.sectiune h2 { font-size: 23px; line-height: 1.3; margin: 0 0 12px; padding-bottom: 8px; border-bottom: 2px solid var(--border); }
.sectiune h3 { font-size: 18px; margin: 26px 0 8px; }
.sectiune ul, .sectiune ol { padding-left: 24px; }
.sectiune li { margin: 4px 0; }

/* Casete: definiție / reține / exemplu / atenție */
.box { margin: 18px 0; padding: 14px 18px; border-radius: 12px; background: var(--b-bg); border-left: 4px solid var(--b-bd); }
.box-titlu { font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--b-bd); margin-bottom: 4px; }
.box > :last-child { margin-bottom: 0; }
.box > p:first-of-type { margin-top: 0; }
.def { --b-bg: var(--def-bg); --b-bd: var(--def-bd); }
.retine { --b-bg: var(--ret-bg); --b-bd: var(--ret-bd); }
.exemplu { --b-bg: var(--ex-bg); --b-bd: var(--ex-bd); }
.atentie { --b-bg: var(--at-bg); --b-bd: var(--at-bd); }
.rezolvare { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--b-bd); }
.rezolvare::before { content: "Rezolvare"; display: block; font-weight: 700; font-size: 14px; color: var(--b-bd); margin-bottom: 2px; }

/* Matematică */
.formula { margin: 14px 0; padding: 12px 16px; text-align: center; font-family: var(--font-math); font-size: 1.2em; line-height: 1.8; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow-x: auto; }
.m { font-family: var(--font-math); font-size: 1.07em; white-space: nowrap; }
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; font-size: .9em; line-height: 1.2; margin: 0 2px; }
.frac > span { padding: 0 3px; }
.frac > span + span { border-top: 1.5px solid currentColor; }
.rad { border-top: 1.5px solid currentColor; padding: 0 2px; margin-left: 1px; }
.acolada { display: inline-flex; align-items: center; vertical-align: middle; text-align: left; }
.acolada-semn { font-size: 2.6em; line-height: 1; font-weight: 200; margin-right: 4px; }
.acolada-cazuri { display: inline-flex; flex-direction: column; line-height: 1.5; }

/* Tabele */
.tabel-wrap { overflow-x: auto; margin: 16px 0; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 15px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-2); font-weight: 650; font-size: 13.5px; }
tr:last-child td { border-bottom: 0; }
td.da, td.nu, th.c, td.c { text-align: center; }
td.da { color: var(--ex-bd); font-weight: 700; }
td.nu { color: var(--muted); }

/* Grilă mică (ex.: pătrate perfecte) */
.grila { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; margin: 12px 0; }
.grila span { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 4px 8px; text-align: center; font-family: var(--font-math); }

/* Diagrama mulțimilor de numere */
.diagrama-multimi { margin: 18px 0; font-size: 15px; }
.dm { position: relative; border: 2px solid var(--dm-c); border-radius: 14px; padding: 32px 12px 10px; background: var(--dm-bg); }
.dm + .dm-ex, .dm-ex { display: block; margin-top: 8px; color: var(--muted); font-family: var(--font-math); }
.dm-et { position: absolute; top: 5px; left: 12px; font-family: var(--font-math); font-weight: 700; font-size: 18px; color: var(--dm-c); }
.dm-rand { display: flex; gap: 12px; flex-wrap: wrap; }
.dm-R { --dm-c: #7a828c; --dm-bg: rgba(122,130,140,.05); }
.dm-Q { --dm-c: #8a4fc7; --dm-bg: rgba(138,79,199,.06); flex: 3 1 260px; }
.dm-Z { --dm-c: #2c6fd1; --dm-bg: rgba(44,111,209,.06); }
.dm-N { --dm-c: #2e9a5a; --dm-bg: rgba(46,154,90,.08); }
.dm-I { --dm-c: #d9822b; --dm-bg: rgba(217,130,43,.07); flex: 1 1 150px; }

/* Axa numerelor */
.axa { display: block; width: 100%; max-width: 600px; height: auto; margin: 14px auto; }
.axa-linie, .axa-gradatie { stroke: var(--text); stroke-width: 1.5; }
.axa-varf { fill: var(--text); }
.axa text { fill: var(--text); font: 15px var(--font-math); text-anchor: middle; }
.axa .axa-eticheta { fill: var(--accent); font-weight: 700; }
.axa-punct { fill: var(--accent); }
.axa-interval { stroke: var(--accent); stroke-width: 4; stroke-linecap: round; }
.axa-interval.b { stroke: var(--accent-2); }
.capat { stroke-width: 2.5; }
.capat.plin { fill: var(--accent); }
.capat.plin.b { fill: var(--accent-2); }
.capat.gol { fill: var(--surface); }
.legenda { text-align: center; font-size: 14px; color: var(--muted); margin-top: -6px; }
.legenda b { color: var(--accent); }
.legenda b.b { color: var(--accent-2); }

/* Citate literare */
.citat { margin: 14px 0; padding: 12px 18px; border-left: 3px solid var(--accent); background: var(--surface); border-radius: 0 10px 10px 0; font-family: Georgia, "Times New Roman", serif; font-size: 1.05em; line-height: 1.6; }
.citat p { margin: 0 0 6px; }
.citat.vers p { margin: 0; }
.citat.vers p:empty { height: .8em; }
.citat .sursa { display: block; margin-top: 8px; font-family: var(--font); font-size: 13.5px; color: var(--muted); font-style: normal; }

/* Diagrame Venn */
.venn { display: block; width: 100%; max-width: 340px; height: auto; margin: 12px auto; }
.venn-zona { fill: var(--accent); opacity: .28; }
.venn-contur { fill: none; stroke: var(--text); stroke-width: 2; }
.venn text { fill: var(--text); font: 16px var(--font-math); text-anchor: middle; }
.venn .venn-et { font-weight: 700; font-size: 20px; fill: var(--accent); }
.grila-venn { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin: 16px 0; }
.venn-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px 12px 12px; text-align: center; }
.venn-card .venn { margin: 4px auto; }
.venn-card b { display: block; }
.venn-card small { color: var(--muted); font-size: 13.5px; }

/* Figuri geometrice */
.geo { display: block; width: 100%; height: auto; margin: 14px auto; }
.geo-fig { fill: var(--accent); fill-opacity: .07; stroke: var(--text); stroke-width: 2; stroke-linejoin: round; }
.geo-seg { stroke: var(--text); stroke-width: 1.6; }
.geo-seg.punctat { stroke-dasharray: 5 4; stroke: var(--muted); }
.geo-seg.accent { stroke: var(--accent); stroke-width: 2.2; }
.geo-seg.b { stroke: var(--accent-2); stroke-width: 2.2; }
.geo-marcaj { stroke: var(--accent); stroke-width: 1.6; fill: none; }
.geo-punct { fill: var(--text); }
.geo-elipsa { fill: var(--accent); fill-opacity: .07; stroke: none; }
.geo-seg.geo-contur { stroke-width: 2; }
.geo text { fill: var(--text); font: italic 17px var(--font-math); text-anchor: middle; dominant-baseline: middle; }
.geo .geo-text { font: 14px var(--font-math); fill: var(--accent); }
.grila-fig { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin: 16px 0; }
.grila-fig > div { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px 12px 12px; text-align: center; }
.grila-fig .geo { margin: 4px auto; }
.grila-fig b { display: block; }
.grila-fig small { color: var(--muted); font-size: 13.5px; }

/* Navigare între teme */
.prev-next { display: flex; justify-content: space-between; gap: 12px; margin-top: 56px; padding-top: 20px; border-top: 1px solid var(--border); }
.prev-next a { flex: 1; max-width: 48%; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; text-decoration: none; color: var(--text); background: var(--surface); line-height: 1.35; }
.prev-next a:hover { border-color: var(--accent); }
.prev-next small { display: block; color: var(--muted); font-size: 12.5px; margin-bottom: 2px; }
.prev-next .urm { text-align: right; margin-left: auto; }
.in-lucru { margin-top: 24px; padding: 32px; border: 2px dashed var(--border); border-radius: 16px; text-align: center; color: var(--muted); }

/* ===== Mobil ===== */
.fundal { position: fixed; inset: 60px 0 0 0; background: rgba(0,0,0,.35); z-index: 20; }
@media (max-width: 960px) {
  #btn-meniu { display: block; }
  .sidebar { position: fixed; top: 60px; left: 0; bottom: 0; height: auto; width: min(310px, 86vw); z-index: 25; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  body.meniu-deschis .sidebar { transform: none; }
}
@media (max-width: 640px) {
  .logo-text { display: none; }
  .pagina { padding: 22px 16px 60px; }
  .cuprins ol { columns: 1; }
  .rezultate { position: fixed; left: 16px; right: 16px; top: 66px; min-width: 0; }
  .box { padding: 12px 14px; }
  .prev-next { flex-direction: column; }
  .prev-next a { max-width: none; }
}

/* ===== Printare ===== */
@media print {
  .topbar, .sidebar, .prev-next, .cuprins, .fundal { display: none !important; }
  body { background: #fff; }
  .pagina { padding: 0; }
  .sectiune { break-inside: avoid-page; }
}
