:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #68747e;
  --line: #d8d0c2;
  --surface: #fffdf8;
  --accent: #c62828;
  --blue: #12334b;
  --gold: #d89b2b;
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  padding: 32px 20px 56px;
  background:
    linear-gradient(rgba(18, 51, 75, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(18, 51, 75, 0.045) 1px, transparent 1px),
    radial-gradient(circle at 85% 0%, rgba(198, 40, 40, 0.14), transparent 24%),
    #eee9df;
  background-size:
    28px 28px,
    28px 28px,
    auto,
    auto;
  color: var(--ink);
  line-height: 1.5;
}

main {
  max-width: 980px;
  margin: 0 auto;
}

/* ---------- Cabecera ---------- */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  position: relative;
  padding: 24px 26px 26px 106px;
  border: 1px solid #102c41;
  border-top: 5px solid var(--accent);
  background: var(--blue);
  color: #fffdf8;
  box-shadow: 8px 8px 0 rgba(18, 51, 75, 0.12);
  overflow: hidden;
}

.page-header::after {
  content: "CLASSIFIED // EARTH-616";
  position: absolute;
  right: 20px;
  bottom: 8px;
  color: rgba(255, 253, 248, 0.35);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 9px;
  letter-spacing: 0.12em;
}

.hero-mark {
  position: absolute;
  top: 22px;
  left: 24px;
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border: 3px solid var(--gold);
  border-radius: 50%;
  color: var(--gold);
  font-family: Impact, "Arial Narrow", sans-serif;
  font-size: 32px;
  line-height: 1;
  transform: rotate(-8deg);
}

.eyebrow {
  margin: 0 0 4px;
  color: #f1c15a;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: #fffdf8;
  font-family: Impact, "Arial Narrow", sans-serif;
  font-size: 44px;
  font-weight: 400;
  letter-spacing: 0.01em;
  line-height: 1.1;
  text-transform: uppercase;
  -webkit-text-stroke: 2px #0b0b0b;
  text-shadow:
    -2px -2px 0 #0b0b0b,
    2px -2px 0 #0b0b0b,
    -2px 2px 0 #0b0b0b,
    2px 2px 0 #0b0b0b,
    4px 4px 0 var(--accent);
}

.lede {
  max-width: 62ch;
  margin: 8px 0 0;
  color: #c7d2d9;
  font-size: 14px;
}

.lede code {
  padding: 1px 5px;
  border: 1px solid rgba(241, 193, 90, 0.5);
  border-radius: 3px;
  background: rgba(255, 253, 248, 0.08);
  color: #f1c15a;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12.5px;
}

.header-side {
  display: grid;
  justify-items: end;
  gap: 10px;
}

.theme-form {
  display: flex;
  gap: 6px;
}

.theme-select {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.theme-button {
  display: grid;
  width: 32px;
  height: 30px;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(255, 253, 248, 0.35);
  border-radius: 3px;
  background: rgba(255, 253, 248, 0.08);
  color: #fffdf8;
  font-size: 18px;
  line-height: 1;
}

.theme-button:hover,
.theme-button[aria-pressed="true"] {
  border-color: var(--gold);
  background: rgba(241, 193, 90, 0.22);
  color: var(--gold);
}

.badge {
  flex: 0 0 auto;
  padding: 6px 12px;
  border: 1px solid transparent;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.5;
  white-space: nowrap;
}

.badge::after {
  content: " ▸";
}

.badge[aria-expanded="true"]::after {
  content: " ▾";
}

.badge.loading {
  border-color: #6b8190;
  background: rgba(255, 253, 248, 0.08);
  color: #dbe5e8;
}

.badge.available {
  border-color: #78c091;
  background: #e6f4e9;
  color: #23683a;
}

.badge.unavailable {
  border-color: #f08c8c;
  background: #fff0ef;
  color: #a51f1f;
}

/* ---------- Métricas ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin: 24px 0;
  border: 1px solid var(--line);
  border-radius: 0 0 4px 4px;
  background: var(--surface);
  box-shadow: 4px 4px 0 rgba(18, 51, 75, 0.08);
}

.stat {
  padding: 12px 16px;
  border-right: 1px solid var(--line);
}

.stat:last-child {
  border-right: 0;
}

.stat dt {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.stat dd {
  margin: 2px 0 0;
  color: var(--blue);
  font-family: Impact, "Arial Narrow", sans-serif;
  font-size: 27px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

/* ---------- Layout ---------- */

.columns {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.columns:has(.side[hidden]) {
  grid-template-columns: minmax(0, 1fr);
}

.side {
  display: grid;
  gap: 20px;
}

.side[hidden] {
  display: none;
}

.card {
  padding: 18px;
  border: 1px solid var(--line);
  border-top: 3px solid var(--blue);
  border-radius: 4px;
  background: var(--surface);
  box-shadow: 4px 4px 0 rgba(18, 51, 75, 0.08);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.card-header h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--blue);
  letter-spacing: 0.1em;
}

.pill {
  padding: 2px 9px;
  border-radius: 3px;
  background: #f5dfaa;
  color: #815b16;
  font-size: 11px;
  font-weight: 700;
}

/* ---------- Formulario ---------- */

.add-form {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

input[type="text"],
select {
  padding: 9px 11px;
  border: 1px solid #c8c0b2;
  border-radius: 3px;
  background: #f7f3eb;
  color: inherit;
  font: inherit;
  font-size: 14px;
}

input[type="text"] {
  flex: 1;
  min-width: 0;
}

input[type="text"]:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

button {
  padding: 9px 16px;
  border: 0;
  border-radius: 3px;
  background: var(--accent);
  color: #ffffff;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

button:not(.badge):hover {
  background: #9f1f1f;
}

button.ghost {
  padding: 4px 10px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

button.ghost:hover {
  background: #f3e8d4;
  color: var(--ink);
}

/* ---------- Lista de películas ---------- */

.movie-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.movie-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-radius: 3px;
  border-bottom: 1px solid #e7dfd2;
  transition:
    background 160ms ease,
    transform 160ms ease;
}

.movie-list li:hover {
  background: #f7efe2;
  transform: translateX(3px);
}

.movie-list li:last-child {
  border-bottom: 0;
}

.movie-list input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.movie-id {
  color: var(--accent);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  font-weight: 600;
}

.movie-title {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
}

.movie-list li.done .movie-title {
  color: var(--muted);
  text-decoration: line-through;
}

.phase-note {
  margin: -4px 0 14px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.phase-note strong {
  color: var(--ink);
}

.phase {
  padding: 2px 9px;
  border: 1px solid transparent;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 700;
  text-transform: capitalize;
}

.phase-1 {
  border-color: #d8d0c2;
  background: #f3efe7;
  color: #68747e;
}

.phase-2 {
  border-color: #d6b96d;
  background: #fff5d8;
  color: #815b16;
}

.phase-3 {
  border-color: #efaaa4;
  background: #fff0ef;
  color: #a51f1f;
}

/* Resalta la fila que acaba de tocar el agente. */
.movie-list li.flash {
  animation: flash 1.4s ease-out;
}

@keyframes flash {
  from {
    background: #e0f2fe;
  }
  to {
    background: transparent;
  }
}

.empty {
  margin: 0;
  padding: 18px 8px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

/* ---------- Herramientas ---------- */

.tool-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tool-list li {
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #f7f3eb;
}

.tool-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--blue);
}

.tool-tag {
  padding: 1px 6px;
  border-radius: 3px;
  background: #e6f4e9;
  color: #23683a;
  font-family: inherit;
  font-size: 9px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.tool-tag.declarative {
  background: #f5dfaa;
  color: #815b16;
}

.tool-desc {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

/* ---------- Consola ---------- */

.console {
  height: 200px;
  padding: 12px;
  border-radius: 3px;
  border: 1px solid #102c41;
  background: #0b1f2d;
  color: #d6e0e3;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
  overflow-y: auto;
  white-space: pre-wrap;
}

.console .time {
  color: #7d9aa8;
}

.console .call {
  color: #f1c15a;
}

/* ---------- Sugerencias ---------- */

.prompts {
  margin-top: 24px;
}

.prompts h2 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--blue);
}

.prompts ul {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.prompts li {
  display: flex;
}

.prompt-copy {
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface);
  color: var(--blue);
  font-size: 13px;
  font-weight: 400;
  text-align: left;
}

.prompt-copy:hover {
  border-color: var(--gold);
  background: #fff8e6;
  color: var(--ink);
}

.prompt-copy.copied {
  border-color: #78c091;
  background: #e6f4e9;
  color: #23683a;
}

.prompt-copy.copied::after {
  content: "  ✓ Copiado";
  font-size: 11px;
  font-weight: 700;
}

.prompt-copy.copy-failed {
  border-color: #f08c8c;
  background: #fff0ef;
  color: #a51f1f;
}

/* ---------- Footer ---------- */

.site-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.site-footer p {
  margin: 0;
}

.site-footer ul {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.site-footer a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

.site-footer ul a {
  display: flex;
  color: var(--muted);
}

.site-footer ul a:hover {
  color: var(--accent);
}

.site-footer svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

@media (max-width: 800px) {
  .page-header {
    padding: 22px 18px 24px 88px;
  }

  .hero-mark {
    left: 18px;
    width: 52px;
    height: 52px;
    font-size: 28px;
  }

  .header-side {
    justify-items: start;
  }

  .columns {
    grid-template-columns: 1fr;
  }

  .stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .stat:nth-child(2) {
    border-right: 0;
  }

  .stat:nth-child(-n + 2) {
    border-bottom: 1px solid #e2e8f0;
  }
}

@media (max-width: 560px) {
  body {
    padding: 16px 12px 40px;
  }

  .page-header {
    display: block;
    padding: 82px 18px 22px;
  }

  .hero-mark {
    top: 18px;
    left: 18px;
  }

  .header-side {
    margin-top: 16px;
  }

  h1 {
    font-size: 32px;
  }

  .add-form {
    flex-wrap: wrap;
  }

  .add-form input[type="text"] {
    flex-basis: 100%;
  }
}

/* ---------- Tema oscuro (lo aplica la tool declarativa set_theme) ---------- */

[data-theme="oscuro"] {
  color-scheme: dark;
  --ink: #e8edf0;
  --muted: #9eb0b8;
  --line: #294456;
  --surface: #102938;
  --accent: #ed4b4b;
  --blue: #d9e8ed;
  --gold: #f1c15a;
}

[data-theme="oscuro"] body {
  background:
    linear-gradient(rgba(217, 232, 237, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(217, 232, 237, 0.035) 1px, transparent 1px),
    radial-gradient(circle at 85% 0%, rgba(237, 75, 75, 0.16), transparent 24%),
    #071923;
  background-size:
    28px 28px,
    28px 28px,
    auto,
    auto;
}

[data-theme="oscuro"] .page-header {
  border-color: #081923;
  background: #0d2a3b;
}

[data-theme="oscuro"] .card,
[data-theme="oscuro"] .stats {
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.18);
}

[data-theme="oscuro"] h1,
[data-theme="oscuro"] .card-header h2,
[data-theme="oscuro"] .prompts h2,
[data-theme="oscuro"] .stat dd,
[data-theme="oscuro"] .tool-name,
[data-theme="oscuro"] .prompts li {
  color: var(--blue);
}

[data-theme="oscuro"] .lede {
  color: #94a3b8;
}

[data-theme="oscuro"] .lede code,
[data-theme="oscuro"] .tool-list li,
[data-theme="oscuro"] input[type="text"],
[data-theme="oscuro"] input[type="search"],
[data-theme="oscuro"] select {
  border-color: #294456;
  background: #0d2331;
  color: var(--ink);
}

[data-theme="oscuro"] .stat,
[data-theme="oscuro"] .movie-list li,
[data-theme="oscuro"] .stat:nth-child(-n + 2) {
  border-color: #1e293b;
}

[data-theme="oscuro"] .pill,
[data-theme="oscuro"] .phase-2 {
  border-color: #806727;
  background: #3b321b;
  color: #f1c15a;
}

[data-theme="oscuro"] .phase-1 {
  border-color: #294456;
  background: #0d2331;
  color: #9eb0b8;
}

[data-theme="oscuro"] .phase-3 {
  border-color: #8f3535;
  background: #3d1719;
  color: #ffaaa4;
}

[data-theme="oscuro"] .tool-name {
  color: #d9e8ed;
}

[data-theme="oscuro"] .tool-tag {
  background: #173c2a;
  color: #8bd7a2;
}

[data-theme="oscuro"] .tool-tag.declarative {
  background: #3b321b;
  color: #f1c15a;
}

[data-theme="oscuro"] .console {
  background: #06151e;
}

[data-theme="oscuro"] .prompts li {
  color: #cbd5e1;
}

[data-theme="oscuro"] button.ghost:hover {
  background: #183747;
}

[data-theme="oscuro"] .badge.loading {
  border-color: #334155;
  background: #111c33;
  color: #94a3b8;
}

[data-theme="oscuro"] .badge.available {
  border-color: #14532d;
  background: #052e1a;
  color: #4ade80;
}

[data-theme="oscuro"] .badge.unavailable {
  border-color: #7f1d1d;
  background: #350f0f;
  color: #fca5a5;
}
