/* Layout: barra superior + vista; en estudio, tres columnas (materias | visual | explicación) que se apilan en móvil. */
:root {
  --bg: #f3f5f6;
  --surface: #ffffff;
  --surface-2: #e9eef0;
  --ink: #15212b;
  --ink-2: #4a5965;
  --line: #d3dce1;
  --accent: #0d6b84;
  --accent-ink: #ffffff;
  --accent-soft: #d9ecf1;
  --muscle: #a8443b;
  --bone: #c9b98f;
  --ok: #1f7a4d;
  --ok-soft: #dcefe4;
  --warn: #8a5a00;
  --warn-soft: #f8ecd2;
  --bad: #a3322a;
  --bad-soft: #f6dedb;
  --viewer-bg: #1d2a33;
  --f-display: "Source Serif 4", Georgia, "Times New Roman", serif;
  --f-body: "Public Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --r: 6px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11181d; --surface: #182229; --surface-2: #213039; --ink: #e6edf1; --ink-2: #a3b3bd;
    --line: #2d3d47; --accent: #5cb8d1; --accent-ink: #0b1b21; --accent-soft: #173a46;
    --muscle: #e07b70; --bone: #d9cba5; --ok: #6cc597; --ok-soft: #163527; --warn: #e3b558; --warn-soft: #3a2e14;
    --bad: #f08a80; --bad-soft: #3e1d1a; --viewer-bg: #0c1317; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11181d; --surface: #182229; --surface-2: #213039; --ink: #e6edf1; --ink-2: #a3b3bd;
  --line: #2d3d47; --accent: #5cb8d1; --accent-ink: #0b1b21; --accent-soft: #173a46;
  --muscle: #e07b70; --bone: #d9cba5; --ok: #6cc597; --ok-soft: #163527; --warn: #e3b558; --warn-soft: #3a2e14;
  --bad: #f08a80; --bad-soft: #3e1d1a; --viewer-bg: #0c1317; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--f-body); }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--f-display); font-weight: 650; line-height: 1.2; text-wrap: balance; margin: 0; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; font-family: var(--f-body); font-weight: 700; }
p { margin: 0; }
code, .mono { font-family: var(--f-mono); font-size: 0.85em; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }

.shell { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 24px; padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-mark { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--accent); box-shadow: inset 0 0 0 4px var(--surface), inset 0 0 0 9px var(--muscle); }
.brand-name { font-family: var(--f-display); font-weight: 650; font-size: 1.15rem; }
.brand-tag { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--warn); background: var(--warn-soft); padding: 2px 6px; border-radius: 4px; }
.mainnav { display: flex; flex-wrap: wrap; gap: 2px; }
.mainnav a { text-decoration: none; color: var(--ink-2); padding: 6px 10px; border-radius: var(--r); font-weight: 500; }
.mainnav a:hover { background: var(--surface-2); color: var(--ink); }
.mainnav a[aria-current="page"] { background: var(--accent-soft); color: var(--ink); }
.demo-banner { background: var(--warn-soft); color: var(--ink); padding: 6px 20px; font-size: 0.85rem; border-bottom: 1px solid var(--line); }
.view { flex: 1; padding: 20px; outline: none; display: flex; flex-direction: column; gap: 20px; max-width: 1500px; width: 100%; margin: 0 auto; }

/* Elementos comunes */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-decoration: none; color: var(--ink); font-weight: 500; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.small { padding: 3px 9px; font-size: 0.85rem; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.muted { color: var(--ink-2); }
.small { font-size: 0.85rem; }
.panel > .btn, .stack > .btn, .panel > a.btn { align-self: flex-start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 0.75rem; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.chip.info { background: var(--accent-soft); color: var(--ink); border-color: transparent; }
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip.plain::before { display: none; }
.eyebrow { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.09em; color: var(--ink-2); font-weight: 600; }
.notice { border-left: 3px solid var(--warn); background: var(--warn-soft); padding: 8px 12px; border-radius: 0 var(--r) var(--r) 0; font-size: 0.9rem; }
.notice.info { border-color: var(--accent); background: var(--accent-soft); }
.notice.ok { border-color: var(--ok); background: var(--ok-soft); }
.notice.bad { border-color: var(--bad); background: var(--bad-soft); }
.sim-label { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--warn); }
table.data { border-collapse: collapse; width: 100%; font-size: 0.88rem; }
table.data th, table.data td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-2); font-weight: 600; }
.table-wrap { overflow-x: auto; }
.num { font-variant-numeric: tabular-nums; }
input[type="text"], input[type="search"], input[type="number"], textarea, select {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 7px 10px; width: 100%;
}
textarea { min-height: 90px; resize: vertical; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--ink-2); }
.choice { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--r); cursor: pointer; background: var(--surface); }
.choice:hover { border-color: var(--accent); }
.choice input { margin-top: 4px; }
.choice.correct { border-color: var(--ok); background: var(--ok-soft); }
.choice.wrong { border-color: var(--bad); background: var(--bad-soft); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Mi semestre */
.hero-sem { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.course-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.course-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; display: flex; flex-direction: column; gap: 8px; text-decoration: none; color: var(--ink); }
.course-card:hover { border-color: var(--accent); }
.course-card .meter { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.course-card .meter span { display: block; height: 100%; background: var(--accent); }
.catalog { columns: 2 240px; column-gap: 24px; }
.catalog label { display: flex; gap: 8px; align-items: baseline; break-inside: avoid; padding: 2px 0; font-size: 0.9rem; }

/* Estudio: tres columnas */
.study { display: grid; grid-template-columns: 240px minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.study-side, .study-aside { position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow: auto; }
.study.hide-side { grid-template-columns: minmax(0, 1fr) 340px; }
.study.hide-side .study-side { display: none; }
.study.hide-aside { grid-template-columns: 240px minmax(0, 1fr); }
.study.hide-aside .study-aside { display: none; }
.study.hide-side.hide-aside { grid-template-columns: minmax(0, 1fr); }
.lesson-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.lesson-list a { display: block; padding: 6px 8px; border-radius: var(--r); text-decoration: none; color: var(--ink); font-size: 0.9rem; }
.lesson-list a:hover { background: var(--surface-2); }
.lesson-list a[aria-current="true"] { background: var(--accent-soft); font-weight: 600; }
.lesson-list .pending { color: var(--ink-2); font-size: 0.85rem; padding: 4px 8px; }
.modes { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.modes button { border: 0; background: none; padding: 8px 12px; cursor: pointer; border-bottom: 3px solid transparent; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.modes button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.stepper { display: flex; gap: 6px; flex-wrap: wrap; }
.stepper span { font-size: 0.78rem; padding: 3px 8px; border-radius: 4px; background: var(--surface-2); color: var(--ink-2); }
.stepper span.done { background: var(--ok-soft); color: var(--ok); }
.stepper span.now { background: var(--accent); color: var(--accent-ink); }
.mobile-tabs { display: none; }

/* Visor 3D */
.viewer-wrap { position: relative; background: var(--viewer-bg); border-radius: var(--r); overflow: hidden; min-height: 420px; height: 62vh; }
.viewer-wrap canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.viewer-wrap.fullscreen { position: fixed; inset: 0; z-index: 50; height: auto; border-radius: 0; }
.viewer-hud { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; justify-content: space-between; gap: 8px; pointer-events: none; flex-wrap: wrap; }
.viewer-hud > * { pointer-events: auto; }
.viewer-hud .btn { background: rgba(255,255,255,0.92); color: #15212b; border-color: transparent; }
.viewer-status { position: absolute; bottom: 10px; left: 10px; right: 10px; color: #e8eef2; font-size: 0.8rem; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; pointer-events: none; }
.viewer-status span { background: rgba(0,0,0,0.45); padding: 3px 8px; border-radius: 4px; }
.viewer-error { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(320px, calc(100% - 32px)); background: var(--surface); color: var(--ink); border-radius: var(--r); padding: 14px; box-shadow: 0 6px 24px rgba(0,0,0,0.35); z-index: 5; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.viewer-error p { margin: 0; }
.rel-list { margin: 0; padding-left: 1.1em; display: flex; flex-direction: column; gap: 4px; }
.label-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.label-layer .lbl { position: absolute; transform: translate(-50%, -120%); background: rgba(255,255,255,0.95); color: #15212b; font-size: 0.75rem; font-weight: 600; padding: 2px 7px; border-radius: 4px; white-space: nowrap; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.label-layer .lbl.sel { background: #0d6b84; color: #fff; }
.viewer-fallback { color: #e8eef2; padding: 24px; display: flex; flex-direction: column; gap: 8px; }
.tree { list-style: none; margin: 0; padding: 0; font-size: 0.88rem; }
.tree ul { list-style: none; margin: 0; padding-left: 14px; }
.tree details > summary { cursor: pointer; padding: 3px 4px; font-weight: 600; }
.tree .node { display: flex; align-items: center; gap: 6px; padding: 2px 4px; border-radius: 4px; }
.tree .node:hover { background: var(--surface-2); }
.tree .node.sel { background: var(--accent-soft); }
.tree .node button.name { border: 0; background: none; text-align: left; padding: 2px 0; cursor: pointer; flex: 1; min-width: 0; }
.tree .node .vis { border: 0; background: none; cursor: pointer; color: var(--ink-2); font-size: 0.75rem; padding: 2px 4px; }
.tree .node.unavail .name { color: var(--ink-2); font-style: italic; }
.swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; flex: none; }
.ficha dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 12px; margin: 0; font-size: 0.88rem; }
.ficha dt { color: var(--ink-2); }
.ficha dd { margin: 0; overflow-wrap: anywhere; }
.atlas-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.atlas-layout .panel.scroll { max-height: calc(100vh - 140px); overflow: auto; position: sticky; top: 76px; }

/* Widgets de lecciones */
.widget { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.widget svg { width: 100%; height: auto; display: block; }
.svg-text { fill: var(--ink); font-family: var(--f-body); font-size: 12px; }
.svg-muted { fill: var(--ink-2); font-family: var(--f-body); font-size: 11px; }
.svg-axis { stroke: var(--ink-2); stroke-width: 1; }
.svg-grid { stroke: var(--line); stroke-width: 1; }
.controls-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px 16px; }
.controls-grid input[type="range"] { width: 100%; }
.order-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.order-list li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.order-list li.correct { border-color: var(--ok); background: var(--ok-soft); }
.order-list li.wrong { border-color: var(--bad); background: var(--bad-soft); }
.order-list li .txt { flex: 1; min-width: 0; }
.order-list li[draggable="true"] { cursor: grab; }
.data-table input { width: 6.5em; padding: 4px 6px; }
.data-table input.invalid { border-color: var(--bad); background: var(--bad-soft); }
.zone { cursor: pointer; }
.zone:hover, .zone:focus-visible { stroke: var(--accent); stroke-width: 3; outline: none; }
.zone.picked { stroke: var(--accent); stroke-width: 3; }
.pending-asset { border: 2px dashed var(--line); border-radius: var(--r); padding: 16px; color: var(--ink-2); display: flex; flex-direction: column; gap: 6px; justify-content: center; min-height: 160px; }

.tutor-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.tutor-log { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow: auto; }
.tutor-msg { background: var(--surface-2); border-radius: var(--r); padding: 8px 10px; font-size: 0.9rem; }
.note-item { border: 1px solid var(--line); border-radius: var(--r); padding: 10px; display: flex; flex-direction: column; gap: 6px; background: var(--surface); }
.result-item { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: var(--ink); }
a.result-item:hover { border-color: var(--accent); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; }
.kpi b { display: block; font-size: 1.5rem; font-family: var(--f-display); font-variant-numeric: tabular-nums; }

@media (max-width: 1180px) {
  .study { grid-template-columns: minmax(0, 1fr) 320px; }
  .study .study-side { display: none; }
  .atlas-layout { grid-template-columns: 260px minmax(0, 1fr); }
  .atlas-layout .ficha-col { grid-column: 1 / -1; }
}
@media (max-width: 820px) {
  .view { padding: 14px 16px; }
  .hero-sem { grid-template-columns: minmax(0, 1fr); }
  .study, .study.hide-side, .study.hide-aside { grid-template-columns: minmax(0, 1fr); }
  .study-side, .study-aside, .atlas-layout .panel.scroll { position: static; max-height: none; }
  .study .study-aside { display: none; }
  .study.show-aside-mobile .study-aside { display: flex; }
  .study.show-aside-mobile .study-main { display: none; }
  .mobile-tabs { display: flex; position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px)); gap: 4px; z-index: 15; margin: 0 -16px -14px; }
  .mobile-tabs button { flex: 1; border: 0; background: none; padding: 8px 4px; font-weight: 600; color: var(--ink-2); border-radius: var(--r); font-size: 0.85rem; }
  .mobile-tabs button[aria-selected="true"] { background: var(--accent-soft); color: var(--ink); }
  .atlas-layout { grid-template-columns: minmax(0, 1fr); }
  .atlas-layout > .stack { order: -1; }
  .viewer-hud { gap: 4px; }
  .viewer-hud .btn.small { padding: 2px 7px; font-size: 0.78rem; }
  .viewer-status span:last-child { display: none; }
  .viewer-status { font-size: 0.7rem; }
  .topbar { position: static; }
  .demo-banner { font-size: 0.78rem; }
  .viewer-wrap { height: 56vh; min-height: 320px; }
  .mainnav a { padding: 5px 8px; font-size: 0.9rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
