:root {
  --bg: #f3f6f9;
  --bg-grad: radial-gradient(1200px 500px at 85% -10%, #d7eef5 0%, transparent 60%), radial-gradient(900px 400px at -10% 10%, #e4ecf7 0%, transparent 55%);
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --border: #dde4ea;
  --text: #13222e;
  --muted: #5d6f7d;
  --primary: #0b6f8c;
  --primary-hover: #095c75;
  --primary-soft: #e3f3f8;
  --accent: #e2445c;
  --ok: #1d8a5b;
  --err-bg: #fdecee;
  --err-fg: #a12035;
  --info-bg: #e8f1fb;
  --info-fg: #1d4f86;
  --shadow: 0 1px 2px rgba(16, 34, 46, .05), 0 8px 24px rgba(16, 34, 46, .07);
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c141b;
    --bg-grad: radial-gradient(1200px 500px at 85% -10%, rgba(20, 163, 199, .14) 0%, transparent 60%), radial-gradient(900px 400px at -10% 10%, rgba(60, 90, 160, .12) 0%, transparent 55%);
    --surface: #131e27;
    --surface-2: #182632;
    --border: #243543;
    --text: #e6eef4;
    --muted: #93a6b5;
    --primary: #2fb3d6;
    --primary-hover: #52c4e2;
    --primary-soft: rgba(47, 179, 214, .12);
    --err-bg: rgba(226, 68, 92, .14);
    --err-fg: #ff9aa9;
    --info-bg: rgba(80, 140, 220, .14);
    --info-fg: #9cc4f5;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 28px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0c141b;
  --bg-grad: radial-gradient(1200px 500px at 85% -10%, rgba(20, 163, 199, .14) 0%, transparent 60%), radial-gradient(900px 400px at -10% 10%, rgba(60, 90, 160, .12) 0%, transparent 55%);
  --surface: #131e27;
  --surface-2: #182632;
  --border: #243543;
  --text: #e6eef4;
  --muted: #93a6b5;
  --primary: #2fb3d6;
  --primary-hover: #52c4e2;
  --primary-soft: rgba(47, 179, 214, .12);
  --err-bg: rgba(226, 68, 92, .14);
  --err-fg: #ff9aa9;
  --info-bg: rgba(80, 140, 220, .14);
  --info-fg: #9cc4f5;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 28px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  transition: background-color .2s, color .2s;
}
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.wrap { width: 100%; max-width: 860px; margin: 0 auto; padding: 0 16px; }

/* Barra superior */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-in { display: flex; align-items: center; justify-content: space-between; height: 64px; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; min-width: 0; }
.brand img { border-radius: 11px; box-shadow: 0 4px 12px rgba(11, 92, 116, .25); }
.brand-txt { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-txt strong { font-size: 16px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-txt small { font-size: 12.5px; color: var(--muted); }

.theme-btn {
  width: 40px; height: 40px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  display: grid; place-items: center; cursor: pointer; transition: border-color .15s, background .15s;
}
.theme-btn:hover { border-color: var(--primary); color: var(--primary); }
.theme-btn .i-moon { display: none; }
:root[data-theme="dark"] .theme-btn .i-sun { display: none; }
:root[data-theme="dark"] .theme-btn .i-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-btn .i-sun { display: none; }
  :root:not([data-theme="light"]) .theme-btn .i-moon { display: block; }
}

/* Contenido */
.main { flex: 1; padding-top: 44px; padding-bottom: 48px; }
.hero { text-align: center; margin-bottom: 28px; }
.hero h1 { font-size: clamp(26px, 5vw, 38px); line-height: 1.15; letter-spacing: -.025em; margin: 0 0 12px; font-weight: 700; }
.hero h1 span { color: var(--primary); }
.hero p { color: var(--muted); font-size: 16.5px; max-width: 560px; margin: 0 auto; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

.search-card { padding: 24px; max-width: 620px; margin: 0 auto; }
.search label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.search-row { display: flex; gap: 10px; }
.input-wrap { position: relative; flex: 1; min-width: 0; }
.input-wrap svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 22px; height: 22px; }
.input-wrap input {
  width: 100%; height: 52px; padding: 0 16px 0 46px;
  font: inherit; font-size: 18px; font-weight: 500; letter-spacing: .04em;
  color: var(--text); background: var(--surface-2);
  border: 1.5px solid var(--border); border-radius: 12px; outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.input-wrap input::placeholder { color: var(--muted); opacity: .7; letter-spacing: 0; font-weight: 400; }
.input-wrap input:focus { border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 4px var(--primary-soft); }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

.btn-primary {
  height: 52px; padding: 0 22px; border: 0; border-radius: 12px; cursor: pointer;
  background: var(--primary); color: #fff; font: inherit; font-weight: 600; font-size: 15.5px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap;
  transition: background .15s, transform .05s;
}
:root[data-theme="dark"] .btn-primary { color: #04141b; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-primary { color: #04141b; } }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: .75; cursor: progress; }
.btn-primary.loading svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.hint { margin: 10px 0 0; font-size: 13px; color: var(--muted); }

.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

/* Alertas */
.alert {
  display: flex; gap: 12px; align-items: flex-start;
  max-width: 620px; margin: 20px auto 0; padding: 14px 16px; border-radius: 12px; font-size: 14.5px;
}
.alert svg { margin-top: 1px; }
.alert-error { background: var(--err-bg); color: var(--err-fg); }
.alert-info { background: var(--info-bg); color: var(--info-fg); }

/* Resultados */
.results { margin-top: 32px; }
.results-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.avatar {
  width: 48px; height: 48px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: 20px;
  background: var(--primary-soft); color: var(--primary);
}
.results-head h2 { margin: 0; font-size: 20px; letter-spacing: -.01em; }
.results-head p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

.study-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.study { display: flex; align-items: center; gap: 16px; padding: 16px; transition: border-color .15s, transform .15s; }
.study:hover { border-color: color-mix(in srgb, var(--primary) 45%, var(--border)); }
.study-date {
  width: 64px; flex: none; text-align: center; padding: 8px 0; border-radius: 12px;
  background: var(--primary-soft); color: var(--primary); line-height: 1.1;
}
.study-date .d { display: block; font-size: 22px; font-weight: 700; }
.study-date .m { display: block; font-size: 11.5px; font-weight: 600; opacity: .9; }
.study-body { flex: 1; min-width: 0; }
.study-body h3 { margin: 0 0 6px; font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.tags { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.tag {
  font-size: 11.5px; font-weight: 700; letter-spacing: .04em; padding: 2px 8px; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
}
.meta { font-size: 13px; color: var(--muted); }

.btn-view {
  display: inline-flex; align-items: center; gap: 8px; flex: none;
  padding: 11px 16px; border-radius: 11px; text-decoration: none; font-weight: 600; font-size: 14.5px;
  color: var(--primary); background: var(--primary-soft); border: 1px solid transparent;
  transition: background .15s, color .15s;
}
.btn-view:hover { background: var(--primary); color: #fff; }
:root[data-theme="dark"] .btn-view:hover { color: #04141b; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-view:hover { color: #04141b; } }
.study-actions { display: flex; flex-direction: column; gap: 8px; flex: none; }
.btn-view.btn-inf { color: var(--ok); background: color-mix(in srgb, var(--ok) 13%, transparent); }
.btn-view.btn-inf:hover { background: var(--ok); color: #fff; }
.note { margin: 16px 0 0; text-align: center; color: var(--muted); font-size: 13px; }

/* Características */
.features { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 36px; }
.feat {
  display: flex; gap: 12px; padding: 16px; border-radius: 14px;
  border: 1px dashed var(--border); color: var(--muted); font-size: 13.5px;
}
.feat svg { color: var(--primary); width: 24px; height: 24px; }
.feat strong { display: block; color: var(--text); font-size: 14.5px; margin-bottom: 2px; }

.footer { border-top: 1px solid var(--border); padding: 18px 0; font-size: 13px; color: var(--muted); }
.footer .wrap { display: flex; flex-wrap: wrap; gap: 4px 8px; justify-content: center; text-align: center; }

/* Móvil */
@media (max-width: 720px) {
  .features { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .main { padding-top: 28px; }
  .brand-txt small { display: none; }
  .search-card { padding: 18px; }
  .search-row { flex-direction: column; }
  .btn-primary { width: 100%; }
  .study { flex-wrap: wrap; gap: 12px 14px; }
  .study-date { width: 56px; }
  .study-body { flex: 1 1 calc(100% - 72px); }
  .study-actions { width: 100%; }
  .btn-view { width: 100%; justify-content: center; padding: 13px 16px; }
  .footer .sep { display: none; }
}
