:root {
  color-scheme: dark;
  --bg: #07080d; --surface: #10121b; --card: #161926; --line: #242838;
  --text: #eef1f8; --muted: #949bb3;
  --blue: #5b9dff; --green: #45d483; --yellow: #ffc94d; --orange: #ff8a66; --violet: #c792ff; --teal: #55e0cc;
  --r: 16px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { scrollbar-gutter: stable; }
body { margin: 0; background: var(--bg) radial-gradient(900px 500px at 10% -10%, #14244a66, transparent 70%) no-repeat; color: var(--text); font: 15px/1.5 system-ui, -apple-system, sans-serif; min-height: 100dvh; }
body.locked { overflow: hidden; }
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button, summary, a { touch-action: manipulation; }
a { color: var(--blue); }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

#lock { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: var(--bg); padding: 16px; }
body:not(.locked) #lock { display: none; }
.lock-box { width: 100%; max-width: 320px; background: var(--card); border: 1px solid var(--line); border-radius: 24px; padding: 28px 22px; display: grid; gap: 10px; justify-items: center; text-align: center; }
.lock-box h1 span, .brand span { color: var(--blue); }
.lock-box p { color: var(--muted); }
#dots { display: flex; gap: 16px; padding: 8px 0 2px; }
#dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); }
#dots i.on { background: var(--blue); border-color: var(--blue); }
.pad { display: grid; grid-template-columns: repeat(3, 72px); gap: 12px; user-select: none; }
.pad button { height: 64px; border-radius: 18px; border: 1px solid var(--line); background: var(--surface); font-size: 1.5rem; font-weight: 750; cursor: pointer; }
.pad button:active { background: var(--blue); color: #04101f; }
.error { color: var(--orange) !important; min-height: 1.5em; font-size: .85rem; }

input, select { width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 11px 13px; font-size: 16px; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px 16px; font-weight: 700; cursor: pointer; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #04101f; }
.btn.ok { background: var(--green); border-color: var(--green); color: #04170c; }
.btn.warn { background: var(--yellow); border-color: var(--yellow); color: #1d1400; }
.btn.danger { color: var(--orange); }
.btn.small { padding: 6px 11px; font-size: .8rem; border-radius: 9px; }

.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 20px; justify-content: space-between; padding: calc(12px + env(safe-area-inset-top)) max(16px, calc((100% - 1100px) / 2)) 12px; background: #07080df5; border-bottom: 1px solid var(--line); }
.brand { font-weight: 850; font-size: 1.15rem; }
.sync { font-size: .7rem; font-weight: 800; text-transform: uppercase; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 3px 10px; white-space: nowrap; }
.sync.on { color: var(--green); border-color: #45d48355; }
.nav { position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(6, 1fr); background: var(--surface); border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); }
.nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; border-radius: 12px; text-decoration: none; color: var(--muted); font-size: .65rem; font-weight: 750; }
.nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav a[aria-current] { color: var(--blue); background: #5b9dff1a; }

main { max-width: 1132px; margin: 0 auto; padding: 18px 16px calc(100px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
.head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.head h2 { font-size: 1.35rem; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-content: start; }
.panel h3 { font-size: .95rem; }
.muted { color: var(--muted); font-size: .85rem; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 16px; }

.degree { grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 16px; --c: var(--orange); }
.degree.lic { --c: var(--blue); }
.ring { width: 104px; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; background: radial-gradient(closest-side, var(--surface) 77%, transparent 79% 99%, var(--surface)), conic-gradient(var(--c) calc(var(--p) * 1%), var(--line) 0); font-weight: 850; font-size: 1.4rem; }
.degree dl { margin: 8px 0 0; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; font-size: .85rem; }
.degree dt { color: var(--muted); }
.degree dd { margin: 0; font-weight: 800; text-align: right; }
.degree .left { grid-column: 1 / -1; font-size: .82rem; color: var(--c); border-top: 1px dashed var(--line); padding-top: 10px; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; }
.stat b { display: block; font-size: 1.5rem; }
.stat span { color: var(--muted); font-size: .75rem; font-weight: 700; }

.rows { display: grid; gap: 8px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; text-align: left; width: 100%; background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--c, var(--line)); border-radius: 12px; padding: 10px 12px; cursor: pointer; }
.row b { font-size: .88rem; display: block; }
.row small { color: var(--muted); }

.bar { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; position: relative; }
.bar i { display: block; height: 100%; width: calc(var(--p) * 1%); background: var(--c, var(--yellow)); border-radius: inherit; }
.bar.marked::after { content: ''; position: absolute; left: 40%; inset-block: 0; width: 3px; background: var(--text); }

.tools { display: grid; gap: 10px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip { white-space: nowrap; border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 7px 14px; font-size: .82rem; font-weight: 750; cursor: pointer; color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

details.year { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
details.year summary { cursor: pointer; padding: 14px 16px; font-weight: 850; display: flex; justify-content: space-between; gap: 10px; list-style: none; }
details.year summary::-webkit-details-marker { display: none; }
details.year summary span::after { content: ' ▾'; }
details.year:not([open]) summary span::after { content: ' ▸'; }
details.year summary span { color: var(--muted); font-size: .82rem; }
.term { padding: 0 12px 14px; }
.term h4 { margin: 0 4px 8px; font-size: .7rem; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); gap: 10px; }

.st-bloqueada { --c: #4a5068; } .st-disponible { --c: var(--blue); } .st-cursando { --c: var(--yellow); } .st-regular { --c: var(--orange); } .st-aprobada { --c: var(--green); }
.subject { text-align: left; background: var(--card); border: 1px solid color-mix(in srgb, var(--c) 40%, var(--line)); border-radius: 14px; padding: 12px; cursor: pointer; display: grid; gap: 6px; align-content: start; }
.subject.st-aprobada { background: #102a20; }
.subject.st-bloqueada .name { color: var(--muted); }
.subject .meta { display: flex; justify-content: space-between; gap: 8px; font-size: .68rem; font-weight: 800; text-transform: uppercase; color: var(--c); }
.st-bloqueada .meta { color: var(--muted); }
.name { font-weight: 750; font-size: .9rem; line-height: 1.3; }
.tags { display: flex; flex-wrap: wrap; gap: 5px; }
.tag { font-size: .68rem; font-weight: 750; border-radius: 6px; padding: 2px 7px; border: 1px solid var(--line); color: var(--muted); }
.tag.ok { color: var(--green); border-color: #45d48344; }
.grade { background: #0008; border-radius: 7px; padding: 0 8px; color: var(--green); font-size: .8rem; }

.week { display: grid; gap: 8px; }
.day { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 8px; align-items: start; }
.day > b { font-size: .75rem; text-transform: uppercase; color: var(--muted); padding-top: 5px; }
.day.busy > b { color: var(--teal); }
.slot { border-left: 3px solid var(--c); background: var(--surface); border-radius: 8px; padding: 5px 9px; font-size: .75rem; overflow-wrap: anywhere; }
.slot b { display: block; }
.free { color: var(--muted); font-size: .82rem; padding-top: 4px; }
.item { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--c, var(--line)); border-radius: 14px; padding: 14px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 7px; align-content: start; overflow-wrap: anywhere; }
.item .actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center; margin-top: 4px; }
.item.done { --c: var(--green); }
.item.open { --c: var(--green); }
.tag.alert { color: var(--orange); border-color: #ff8a6655; }
.item.done .name { text-decoration: line-through; color: var(--muted); }

dialog { width: 100%; max-width: 520px; max-height: 90dvh; margin: auto auto 0; padding: 0; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 24px 24px 0 0; overscroll-behavior: contain; }
dialog[open] { animation: up .2s ease-out; }
dialog::backdrop { background: #000b; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); }
form.sheet-body { padding: 0; }
.sheet-body ul { margin: 0; padding-left: 18px; font-size: .85rem; }
.buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.buttons .wide { grid-column: 1 / -1; }
.field { display: grid; gap: 5px; font-size: .75rem; font-weight: 750; color: var(--muted); position: relative; }
.field input, .field select { color: var(--text); }
.suggest { display: grid; max-height: 200px; overflow-y: auto; border: 1px solid var(--blue); border-radius: 12px; background: var(--card); }
.suggest:empty { display: none; }
.suggest button { text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 10px 12px; font-size: .85rem; cursor: pointer; }

#toast { position: fixed; z-index: 60; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); width: max-content; max-width: 90vw; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 750; font-size: .85rem; opacity: 0; pointer-events: none; transition: opacity .2s; }
#toast.show { opacity: 1; }

.cols { align-items: start; }
.fold { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); min-width: 0; }
.fold summary { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px; min-height: 48px; }
.fold summary::-webkit-details-marker { display: none; }
.fold summary b { font-size: .92rem; min-width: 0; overflow-wrap: anywhere; }
.fold summary span { color: var(--muted); font-size: .76rem; font-weight: 750; white-space: nowrap; }
.fold summary span::after { content: ' ▸'; }
.fold[open] > summary span::after { content: ' ▾'; }
.fold-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 0 10px 10px; }
.cert { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: grid; gap: 8px; overflow-wrap: anywhere; }
.cert.done { border-color: #45d48366; }
.cert.done .name { text-decoration: line-through; color: var(--muted); }
.cert-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.cert-actions .btn:first-of-type { margin-left: auto; }
.head > * { min-width: 0; }
.nav a { min-width: 0; overflow: hidden; white-space: nowrap; }

/* Celular: menos relleno y letra más compacta para que nada se pise. */
@media (max-width: 819px) {
  body { font-size: 14px; }
  .top { padding: calc(8px + env(safe-area-inset-top)) 12px 8px; gap: 10px; }
  .brand { font-size: 1rem; }
  main { padding: 12px 10px calc(84px + env(safe-area-inset-bottom)); gap: 12px; }
  .cols { gap: 10px; }
  .head h2 { font-size: 1.15rem; }
  .panel { padding: 12px; gap: 10px; }
  .degree { gap: 10px 12px; }
  .degree .muted { display: none; }
  .degree dl { margin-top: 4px; font-size: .8rem; }
  .degree .left { font-size: .76rem; padding-top: 8px; }
  .ring { width: 76px; font-size: 1.1rem; }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .stat { padding: 8px 4px; text-align: center; border-radius: 12px; }
  .stat b { font-size: 1.15rem; }
  .stat span { display: block; font-size: .62rem; line-height: 1.2; overflow-wrap: anywhere; }
  .btn { padding: 8px 12px; }
  .item { padding: 11px; gap: 6px; }
  .subject { padding: 9px 11px; gap: 4px; }
  .name { font-size: .85rem; }
  .term { padding: 0 8px 10px; }
  .grid { gap: 7px; }
  .day { grid-template-columns: 70px minmax(0, 1fr); padding: 7px 8px; }
  .nav { padding: 4px 2px calc(4px + env(safe-area-inset-bottom)); grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .nav a { font-size: clamp(8px, 2.7vw, 11px); letter-spacing: -.2px; }
  .nav svg { width: 20px; height: 20px; }
}
@media (max-width: 359px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ring { width: 64px; font-size: .95rem; }
  .sync { display: none; }
}

@media (min-width: 640px) {
  .stats { grid-template-columns: repeat(4, 1fr); }
  .tools { grid-template-columns: minmax(220px, 320px) minmax(0, 1fr); align-items: center; }
}
@media (min-width: 820px) and (max-width: 999px) {
  .brand { display: none; }
  .nav a svg { display: none; }
}
@media (min-width: 820px) {
  .nav { position: static; display: flex; gap: 4px; background: none; border: 0; padding: 0; margin-left: auto; }
  .nav a { flex-direction: row; gap: 8px; padding: 8px 14px; font-size: .85rem; }
  main { padding-bottom: 50px; }
  #toast { bottom: 24px; }
  dialog { margin: auto; border-radius: 24px; }
  .week { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .day { grid-template-columns: minmax(0, 1fr); align-content: start; min-height: 130px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
