:root {
  --bg: #f2f2f7; --card: #ffffff; --text: #000000; --muted: #8a8a8e; --line: #e5e5ea;
  --fill: rgba(120,120,128,.12);
  --accent: #007aff; --danger: #ff3b30; --exam: #ff3b30; --ok: #34c759;
  --radius: 12px; --tabh: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
/* Modo oscuro: se activa con data-theme="dark" en <html> (automático, o elegido en Ajustes) */
:root[data-theme="dark"] { --bg: #000000; --card: #1c1c1e; --text: #ffffff; --muted: #98989f; --line: #38383a;
  --fill: rgba(120,120,128,.24); --accent: #0a84ff; --danger: #ff453a; --exam: #ff453a; --ok: #30d158;
  color-scheme: dark; }
:root[data-theme="light"] { color-scheme: light; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; font-size: 16px; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; width: 100%; }
textarea { resize: vertical; }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login form { width: 100%; max-width: 320px; text-align: center; }
.login .logo { font-size: 56px; }
.login h1 { margin: 4px 0 24px; }
.login .btn { width: 100%; margin-top: 12px; }
.error { color: var(--danger); min-height: 1.4em; }

/* Layout */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-t) + 10px) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.top h1 { margin: 0; font-size: 28px; font-weight: 750; }
main { padding: 4px 16px calc(var(--tabh) + var(--safe-b) + 90px); max-width: 760px; margin: 0 auto; }
.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex;
  height: calc(var(--tabh) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; background: none; font-size: 11px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.tabs button span { font-size: 21px; filter: grayscale(1); opacity: .7; }
.tabs button.active { color: var(--accent); font-weight: 600; }
.tabs button.active span { filter: none; opacity: 1; }
.fab { position: fixed; right: 18px; bottom: calc(var(--tabh) + var(--safe-b) + 16px); z-index: 9;
  width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--accent); color: #fff;
  font-size: 30px; box-shadow: 0 6px 20px rgba(79,124,255,.4); }

/* Componentes */
.btn { border: 0; border-radius: 10px; padding: 11px 16px; background: var(--line); font-weight: 600; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: transparent; color: var(--danger); }
.btn.small { padding: 6px 10px; font-size: 14px; }
.icon-btn { border: 0; background: none; font-size: 22px; padding: 4px 8px; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  margin: 22px 4px 8px; font-weight: 650; }
.card { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 560; overflow-wrap: anywhere; }
.row .sub { font-size: 13px; color: var(--muted); }
.row.done .title { text-decoration: line-through; color: var(--muted); }
.bar { width: 4px; align-self: stretch; border-radius: 4px; flex: none; }
.check { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--muted); background: none;
  flex: none; display: grid; place-items: center; font-size: 14px; color: #fff; padding: 0; }
.check.on { background: var(--ok); border-color: var(--ok); }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px;
  background: var(--line); color: var(--muted); text-transform: uppercase; margin-right: 4px; }
.tag.examen { background: color-mix(in srgb, var(--exam) 18%, transparent); color: var(--exam); }
.tag.trabajo { background: color-mix(in srgb, #d28b00 20%, transparent); color: #c27c00; }
.tag.cal { background: color-mix(in srgb, #8a63d2 18%, transparent); color: #8a63d2; }
.empty { text-align: center; color: var(--muted); padding: 22px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; }
.chips button { border: 1px solid var(--line); background: var(--card); border-radius: 20px;
  padding: 7px 14px; white-space: nowrap; font-size: 14px; }
.chips button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.seg { display: flex; background: var(--line); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 8px; padding: 8px 4px; font-size: 14px; }
.seg button.on { background: var(--card); font-weight: 650; box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* Exámenes destacados */
.exams { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.exam-card { flex: none; width: 150px; background: var(--card); border-radius: var(--radius); padding: 12px;
  border-top: 4px solid var(--exam); }
.exam-card .days { font-size: 26px; font-weight: 800; }
.exam-card .days small { font-size: 13px; font-weight: 500; color: var(--muted); }
.exam-card .t { font-weight: 600; font-size: 14px; margin-top: 4px; }

/* Calendario */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin: 6px 0 10px; }
.cal-head strong { font-size: 18px; }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); background: var(--card); border-radius: var(--radius);
  padding: 6px; gap: 2px; }
.grid .dow { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.grid .day { border: 0; background: none; aspect-ratio: 1 / 1.05; border-radius: 10px; display: flex;
  flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 6px; font-size: 15px; }
.grid .day.out { color: var(--muted); opacity: .45; }
.grid .day.today span:first-child { background: var(--accent); color: #fff; border-radius: 50%;
  width: 28px; height: 28px; display: grid; place-items: center; }
.grid .day.sel { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.dots { display: flex; gap: 3px; margin-top: 3px; flex-wrap: wrap; justify-content: center; max-width: 34px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; display: block; }

/* Apuntes */
.subjects { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.subject { border: 0; text-align: left; background: var(--card); border-radius: var(--radius); padding: 14px;
  border-left: 5px solid var(--c); min-height: 86px; }
.subject b { display: block; font-size: 16px; margin-bottom: 6px; }
.subject small { color: var(--muted); }
.file-ico { font-size: 26px; width: 34px; text-align: center; flex: none; }
.note-view { white-space: pre-wrap; background: var(--card); border-radius: var(--radius); padding: 16px; }
.search { margin-bottom: 10px; }

/* Hoja inferior (modal) */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0,0,0,.35); }
.sheet-panel { position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; overflow-y: auto;
  background: var(--bg); border-radius: 18px 18px 0 0; padding: 16px 16px calc(var(--safe-b) + 20px);
  max-width: 760px; margin: 0 auto; animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
.sheet-panel h3 { margin: 4px 0 8px; font-size: 20px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
.sheet-actions .btn { flex: 1; }
.inline { display: flex; gap: 10px; }
.inline > * { flex: 1; }
input[type=color] { padding: 2px; height: 44px; }
.toast { position: fixed; left: 50%; bottom: calc(var(--tabh) + var(--safe-b) + 84px); transform: translateX(-50%);
  background: #1b1d24; color: #fff; padding: 10px 16px; border-radius: 20px; font-size: 14px; z-index: 60;
  opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw; }
.toast.show { opacity: .95; }
.muted { color: var(--muted); font-size: 14px; }
code.link { display: block; word-break: break-all; font-size: 12px; background: var(--card); padding: 10px;
  border-radius: 10px; margin: 6px 0; }

/* v2: multiusuario */
.login input { margin-bottom: 10px; }
.linkbtn { border: 0; background: none; color: var(--accent); margin-top: 8px; font-size: 15px; }
.who { font-size: 12px; color: var(--muted); }
.share-ico { font-size: 13px; margin-left: 4px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--card);
  border-radius: 10px; padding: 12px; margin-top: 14px; }
.switch input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }
.meter { height: 8px; background: var(--line); border-radius: 5px; overflow: hidden; margin: 8px 0 4px; }
.meter i { display: block; height: 100%; background: var(--accent); }
.readonly { opacity: .85; }
.readonly input, .readonly select, .readonly textarea { pointer-events: none; background: transparent; }

/* v3: cabecera, tests */
.top-right { display: flex; align-items: center; gap: 4px; }
.group-title { font-size: 13px; font-weight: 650; color: var(--muted); margin: 14px 4px 6px; }
.quiz-q { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.quiz-q .qt { font-weight: 600; white-space: pre-wrap; margin-bottom: 10px; }
.quiz-q .qt small { color: var(--muted); font-weight: 400; }
.opt { display: flex; gap: 10px; align-items: flex-start; padding: 10px; border: 1px solid var(--line);
  border-radius: 10px; margin-top: 6px; cursor: pointer; }
.opt input { width: 20px; height: 20px; flex: none; margin: 1px 0 0; accent-color: var(--accent); }
.opt.right { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.opt.wrong { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.quiz-q.ok { box-shadow: inset 4px 0 0 var(--ok); }
.quiz-q.ko { box-shadow: inset 4px 0 0 var(--danger); }
.expl { margin-top: 10px; font-size: 14px; color: var(--muted); white-space: pre-wrap; }
.score { text-align: center; background: var(--card); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; }
.score b { font-size: 40px; display: block; }
.badge { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 8px; background: var(--line); }
.badge.good { background: color-mix(in srgb, var(--ok) 20%, transparent); color: var(--ok); }
.badge.bad { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
textarea.mono { font-family: ui-monospace, Menlo, monospace; font-size: 14px; }
.help { font-size: 13px; color: var(--muted); background: var(--card); border-radius: 10px; padding: 10px; white-space: pre-wrap;
  font-family: ui-monospace, Menlo, monospace; }
.errors { color: var(--danger); font-size: 14px; }

/* v4: formato de notas, varios */
.md h4, .md h5, .md h6 { margin: 14px 0 6px; } .md h4 { font-size: 20px; } .md h5 { font-size: 17px; } .md h6 { font-size: 15px; }
.md p { margin: 0 0 10px; } .md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md code { background: var(--line); padding: 1px 5px; border-radius: 5px; font-size: 14px; }
.md pre { background: var(--line); padding: 10px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
.md blockquote { margin: 0 0 10px; padding: 6px 12px; border-left: 4px solid var(--accent); color: var(--muted); }
.md table { border-collapse: collapse; margin: 0 0 10px; font-size: 14px; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; }
.md th { background: var(--line); }
.md a { color: var(--accent); }
.note-view.md { white-space: normal; }
details summary { cursor: pointer; padding: 8px 0; }
.tag + .tag { margin-left: 2px; }
.seg button { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 400px) { .seg button { font-size: 13px; } }

/* v5: estilo iOS */
html, body { font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased; }
input, select, textarea { border: 0; background: var(--fill); border-radius: 10px; padding: 11px 12px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 0; }
label { font-size: 13px; text-transform: uppercase; letter-spacing: .02em; margin: 14px 0 6px 4px; }
.top { background: color-mix(in srgb, var(--bg) 78%, transparent); backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px); padding-top: calc(var(--safe-t) + 14px); padding-bottom: 6px; }
.top h1 { font-size: 34px; font-weight: 700; letter-spacing: -.02em; }
.icon-btn { color: var(--accent); width: 36px; height: 36px; border-radius: 50%; background: var(--fill);
  display: inline-grid; place-items: center; padding: 0; font-size: 17px; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabs { background: color-mix(in srgb, var(--card) 80%, transparent); backdrop-filter: saturate(180%) blur(22px);
  -webkit-backdrop-filter: saturate(180%) blur(22px); border-top: .5px solid var(--line); }
.tabs button { font-size: 10px; font-weight: 500; gap: 3px; }
.tabs button svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round; }
.tabs button.active { font-weight: 600; }
.tabs button.active svg { fill: color-mix(in srgb, currentColor 18%, transparent); }
.btn { border-radius: 12px; background: var(--fill); color: var(--accent); font-weight: 600; padding: 13px 16px; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); background: var(--fill); }
.btn.small { padding: 7px 12px; border-radius: 16px; }
.btn:active, .row:active, .subject:active { opacity: .6; }
.fab { width: 54px; height: 54px; font-size: 30px; box-shadow: 0 4px 14px rgba(0,122,255,.38); }
h2 { font-size: 13px; font-weight: 400; letter-spacing: .02em; margin: 26px 16px 7px; }
.row { border-bottom: 0; position: relative; padding: 11px 16px; min-height: 48px; }
.row:not(:last-child)::after { content: ""; position: absolute; left: 16px; right: 0; bottom: 0; height: .5px; background: var(--line); }
.row .title { font-weight: 400; }
.row .sub { font-size: 14px; margin-top: 1px; }
.bar { width: 3px; }
.check { border-width: 1.5px; }
.tag { border-radius: 5px; font-weight: 600; }
.group-title { font-size: 13px; font-weight: 400; text-transform: uppercase; margin: 22px 16px 7px; }
.chips button { border: 0; background: var(--fill); border-radius: 16px; color: var(--text); }
.chips button.on { background: var(--accent); color: #fff; }
.seg { background: var(--fill); border-radius: 9px; padding: 2px; }
.seg button { border-radius: 7px; padding: 6px 4px; font-size: 13px; font-weight: 500; }
.seg button.on { background: var(--card); box-shadow: 0 3px 8px rgba(0,0,0,.12), 0 3px 1px rgba(0,0,0,.04); font-weight: 600; }
:root[data-theme="dark"] .seg button.on { background: #636366; }
.switch { border-radius: var(--radius); padding: 11px 16px; }
.switch input[type=checkbox] { appearance: none; -webkit-appearance: none; width: 51px; height: 31px; border-radius: 16px;
  background: var(--fill); position: relative; transition: background .2s; padding: 0; flex: none; outline: 0; }
.switch input[type=checkbox]::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px;
  border-radius: 50%; background: #fff; box-shadow: 0 3px 8px rgba(0,0,0,.15); transition: transform .2s; }
.switch input[type=checkbox]:checked { background: var(--ok); }
.switch input[type=checkbox]:checked::after { transform: translateX(20px); }
.exam-card { border-top: 0; border-radius: 14px; position: relative; overflow: hidden; }
.exam-card::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: var(--exam); }
.exam-card .days { font-weight: 700; letter-spacing: -.02em; }
.subject { border-left: 0; border-radius: 14px; position: relative; overflow: hidden; }
.subject::before { content: ""; position: absolute; left: 14px; top: 14px; width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.subject b { margin-top: 18px; font-weight: 600; }
.opt { border: 0; background: var(--fill); }
.cal-head strong { font-size: 20px; font-weight: 600; }
.grid { padding: 8px; }
.grid .day { border-radius: 50%; }
.grid .day.sel { background: none; }
.grid .day.sel span:first-child { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent);
  border-radius: 50%; width: 28px; height: 28px; display: grid; place-items: center; font-weight: 600; }
.grid .day.today.sel span:first-child, .grid .day.today span:first-child { background: var(--accent); color: #fff; }
.sheet-bg { background: rgba(0,0,0,.4); }
.sheet-panel { border-radius: 14px 14px 0 0; padding-top: 22px; }
.sheet-panel::before { content: ""; position: absolute; top: 7px; left: 50%; width: 36px; height: 5px; margin-left: -18px;
  border-radius: 3px; background: color-mix(in srgb, var(--muted) 45%, transparent); }
.sheet-panel h3 { font-size: 22px; font-weight: 700; }
.toast { background: color-mix(in srgb, #3a3a3c 92%, transparent); backdrop-filter: blur(12px); border-radius: 14px; }
.login .logo { font-size: 64px; }
.login h1 { font-size: 34px; letter-spacing: -.02em; }
