/*
 * Demo · un portfolio de ejemplo para ver a Codi en acción + panel de control.
 * Layout: sitio a la izquierda; panel fijo a la derecha en desktop,
 * hoja inferior deslizable en móvil. Codi siempre en la esquina inferior derecha.
 */
:root {
  --bg: #070707;            /* surface-dark */
  --surface: #111111;       /* neutral-500 */
  --surface-2: #17140c;     /* negro con sesgo dorado */
  --line: #2a2518;
  --fg: #f7f3e8;
  --muted: rgba(255, 255, 255, .64);
  --accent: #f1bd19;        /* primary-500 */
  --accent-soft: rgba(241, 189, 25, .12);
  --accent-deep: #ab8612;   /* primary-700 */
  --ink: #111111;
  --display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --body: "Figtree", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --panel-w: 360px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 400 16px/1.6 var(--body);
  -webkit-font-smoothing: antialiased;
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }
a { color: inherit; }
button, input, textarea { font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ---------- sitio ---------- */
.site {
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 0 140px;
  transition: margin-right .35s ease;
}
.wrap { max-width: 1040px; margin: 0 auto; }

.nav {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding-block: 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font: 600 17px var(--display); text-decoration: none; letter-spacing: -.01em; }
.brand svg { width: 30px; height: 30px; }
.nav__links { display: flex; gap: 22px; font-size: 14px; color: var(--muted); }
.nav__links a { text-decoration: none; transition: color .2s; }
.nav__links a:hover { color: var(--accent); }
.panel-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--fg);
  font: 500 13px var(--mono); padding: 8px 12px; border-radius: 10px; cursor: pointer;
}
.panel-toggle:hover { border-color: var(--accent); }

.hero {
  display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 40px; align-items: center;
  padding-block: 72px 56px;
}
.eyebrow { font: 500 12px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
h1 {
  font: 700 clamp(36px, 5.4vw, 64px)/1.02 var(--display);
  letter-spacing: -.035em; margin: 14px 0 18px; text-wrap: balance;
}
h1 em { font-style: normal; color: var(--accent); }
.lead { color: var(--muted); max-width: 52ch; margin: 0; font-size: 17px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 28px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px; text-decoration: none; cursor: pointer;
  padding: 12px 18px; border-radius: 12px; font-weight: 600; font-size: 15px; border: 1px solid transparent;
}
.btn--primary { background: var(--accent); color: var(--ink); }
.btn--primary:hover { background: #f4ca47; }
.btn--ghost { border-color: var(--line); color: var(--fg); background: transparent; }
.btn--ghost:hover { border-color: var(--accent); }

.term {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden;
  font: 400 13px/1.7 var(--mono); min-width: 0;
}
.term__bar { display: flex; align-items: center; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.term__bar i { width: 9px; height: 9px; border-radius: 50%; background: var(--line); display: block; }
.term__bar span { margin-left: 8px; }
.term__body { padding: 14px 16px 18px; min-height: 172px; overflow-x: auto; }
.term__line { white-space: pre-wrap; color: var(--muted); }
.term__line b { color: var(--accent); font-weight: 500; }
.term__line:last-child { color: var(--fg); }

section { padding-block: 56px; border-top: 1px solid var(--line); }
h2 { font: 700 clamp(26px, 3.2vw, 36px)/1.1 var(--display); letter-spacing: -.025em; margin: 8px 0 10px; text-wrap: balance; }
.section-lead { color: var(--muted); margin: 0 0 26px; max-width: 60ch; }

.chips { display: flex; flex-wrap: wrap; gap: 10px; list-style: none; padding: 0; margin: 0; }
.chip {
  font: 500 14px var(--mono); padding: 10px 16px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); cursor: default; transition: border-color .2s, color .2s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px; overflow: hidden;
  display: flex; flex-direction: column; transition: transform .25s, border-color .25s;
}
.card:hover { transform: translateY(-4px); border-color: var(--accent-deep); }
.card__art { aspect-ratio: 16 / 10; max-width: 100%; background: var(--surface-2); display: grid; place-items: center; border-bottom: 1px solid var(--line); }
.card__art code { font: 500 clamp(20px, 3vw, 30px) var(--mono); color: var(--accent); }
.card__body { padding: 16px 18px 20px; display: flex; flex-direction: column; gap: 6px; }
.card__tag { font: 500 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.card__title { font: 600 19px/1.25 var(--display); margin: 0; }
.card__desc { color: var(--muted); margin: 0; font-size: 14px; }

.form { display: grid; gap: 12px; max-width: 560px; }
.form label { font: 500 12px var(--mono); color: var(--muted); letter-spacing: .04em; }
.form input, .form textarea {
  width: 100%; background: var(--surface); color: var(--fg); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; resize: vertical;
}
.form input:focus, .form textarea:focus { border-color: var(--accent); outline: none; }
.field { display: grid; gap: 6px; }

.footer { padding-block: 28px; border-top: 1px solid var(--line); color: var(--muted); font: 400 13px var(--mono); display: flex; flex-wrap: wrap; gap: 8px 24px; justify-content: space-between; }

/* ---------- panel de control ---------- */
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: var(--panel-w); z-index: 90;
  background: var(--surface); border-left: 1px solid var(--line);
  padding: calc(18px + env(safe-area-inset-top, 0px)) calc(18px + env(safe-area-inset-right, 0px)) calc(24px + env(safe-area-inset-bottom, 0px)) 18px;
  overflow-y: auto; display: flex; flex-direction: column; gap: 22px;
  transform: translateX(100%); transition: transform .35s ease;
}
.panel-open .panel { transform: none; }
.panel__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel__title { font: 700 18px var(--display); margin: 0; letter-spacing: -.01em; }
.panel__title small { display: block; font: 400 12px var(--mono); color: var(--muted); letter-spacing: 0; }
.icon-btn { border: 1px solid var(--line); background: transparent; color: var(--fg); border-radius: 10px; width: 34px; height: 34px; cursor: pointer; font-size: 16px; line-height: 1; }
.icon-btn:hover { border-color: var(--accent); }

.p-sec { display: grid; gap: 10px; }
.p-label { font: 500 11px var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }

.status { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 12px; align-items: center; font-size: 13px; }
.status dt { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.status dd { margin: 0; min-width: 0; }
.pill { display: inline-block; font: 500 12px var(--mono); background: var(--accent-soft); color: var(--accent); padding: 3px 10px; border-radius: 999px; }
.meter { height: 8px; border-radius: 99px; background: #1f1c14; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .6s ease; }
.meter--mood i { background: #f6d365; }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; }
.switch input { appearance: none; width: 40px; height: 22px; border-radius: 99px; background: #2a2518; position: relative; cursor: pointer; transition: background .2s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--fg); transition: transform .2s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); background: var(--ink); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 7px 12px; font: 500 12px var(--mono); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--ink); }

.faces { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.face-btn {
  display: grid; justify-items: center; gap: 4px; padding: 8px 4px 7px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; color: var(--muted);
  cursor: pointer; font: 400 11px var(--mono); min-width: 0;
}
.face-btn svg { width: 40px; height: 40px; }
.face-btn span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.face-btn:hover { border-color: var(--accent-deep); color: var(--fg); }
.face-btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: var(--surface-2); }

.scenes { display: flex; flex-wrap: wrap; gap: 6px; }
.scene-btn { border: 1px solid var(--line); background: transparent; color: var(--fg); border-radius: 999px; padding: 6px 12px; font: 400 12px var(--mono); cursor: pointer; }
.scene-btn:hover { border-color: var(--accent); color: var(--accent); }
.show-btn { width: 100%; justify-content: center; }
.hint { font: 400 12px var(--mono); color: var(--muted); margin: 0; }
kbd { font: 500 11px var(--mono); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 1px 5px; color: var(--fg); }

.log { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font: 400 12px/1.45 var(--mono); max-height: 260px; overflow-y: auto; }
.log li { display: grid; grid-template-columns: auto auto minmax(0, 1fr); gap: 8px; color: var(--muted); }
.log time { color: #6f6650; font-variant-numeric: tabular-nums; }
.log b { font-weight: 500; }
.log .k-percibe b { color: #f6d365; }
.log .k-decide b { color: var(--accent); }
.log .k-estado b { color: var(--fg); }
.log li span { overflow-wrap: anywhere; color: var(--fg); }

.stage-exit {
  position: fixed; z-index: 95; top: calc(16px + env(safe-area-inset-top, 0px)); left: calc(16px + env(safe-area-inset-left, 0px));
  display: none;
}
.is-stage .stage-exit { display: inline-flex; }
.is-showing .stage-exit { opacity: 0; transition: opacity .2s; }
.is-showing .stage-exit:hover, .is-showing .stage-exit:focus-visible { opacity: 1; }

/* modo dev (código Konami) */
.codi-devmode .card__art code { animation: dev-rgb 1.2s linear infinite; }
@keyframes dev-rgb { 0% { color: #f1bd19; } 33% { color: #fef8e8; } 66% { color: #ab8612; } 100% { color: #f1bd19; } }

/* ---------- desktop: el panel empuja el sitio ---------- */
@media (min-width: 1024px) {
  .panel-open .site { margin-right: var(--panel-w); }
  .panel-open .codi { --codi-right: calc(var(--panel-w) + 24px); }
  .panel-open .codi[data-mode="stage"] { right: var(--panel-w); }
  .panel__close { display: none; }
}

/* ---------- tablet y móvil ---------- */
@media (max-width: 1023px) {
  .panel {
    top: auto; left: 0; width: auto; height: min(58vh, 560px);
    border-left: 0; border-top: 1px solid var(--line); border-radius: 20px 20px 0 0;
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
    transform: translateY(100%);
    box-shadow: 0 -20px 50px rgba(0, 0, 0, .5);
  }
  .panel::before { content: ""; width: 40px; height: 4px; border-radius: 4px; background: var(--line); align-self: center; flex: none; margin-top: -6px; }
  .panel-open .codi { --codi-bottom: calc(min(58vh, 560px) + 14px); }
  .panel-open .codi[data-mode="stage"] { bottom: min(58vh, 560px); }
  .hero { grid-template-columns: minmax(0, 1fr); padding-block: 48px 40px; gap: 28px; }
  .cards { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .nav__links { display: none; }
  .faces { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .face-btn svg { width: 34px; height: 34px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .site, .panel, .card { transition: none; }
}
