/* =========================================================
   Atalaya — navegador de escritorio para el celular
   Tokens → base → estructura → componentes → hojas → movimiento
   ========================================================= */

:root {
  /* Superficies: grafito frío; el escritorio (stage) es el plano más hondo */
  --desk: oklch(0.135 0.008 255);
  --bg: oklch(0.175 0.010 255);
  --surface: oklch(0.215 0.012 255);
  --surface-2: oklch(0.255 0.014 255);
  --surface-3: oklch(0.30 0.016 255);
  --line: oklch(0.36 0.014 255 / 0.55);
  --line-strong: oklch(0.45 0.016 255 / 0.7);

  --text: oklch(0.955 0.004 255);
  --text-2: oklch(0.78 0.010 255);
  --text-3: oklch(0.68 0.012 255);

  /* Acento ámbar: la luz de la atalaya */
  --accent: oklch(0.80 0.145 68);
  --accent-strong: oklch(0.84 0.15 72);
  --accent-soft: oklch(0.80 0.145 68 / 0.16);
  --on-accent: oklch(0.22 0.04 60);

  --danger: oklch(0.70 0.17 25);
  --danger-soft: oklch(0.70 0.17 25 / 0.14);
  --warn: oklch(0.82 0.14 85);
  --warn-soft: oklch(0.82 0.14 85 / 0.13);
  --ok: oklch(0.78 0.13 155);

  --chrome: oklch(0.175 0.010 255 / 0.86);
  --scrim: oklch(0.08 0.01 255 / 0.55);
  --shadow-frame: 0 1px 2px oklch(0 0 0 / 0.4), 0 12px 32px -8px oklch(0 0 0 / 0.55);
  --shadow-sheet: 0 -8px 40px -12px oklch(0 0 0 / 0.6);

  /* Tipografía del sistema: ya trae tamaño óptico y tracking por tamaño */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, monospace;

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --tap: 44px;

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  color-scheme: dark;
}

:root[data-theme="light"] {
  --desk: oklch(0.90 0.006 255);
  --bg: oklch(0.975 0.003 255);
  --surface: oklch(1 0 0);
  --surface-2: oklch(0.955 0.005 255);
  --surface-3: oklch(0.92 0.007 255);
  --line: oklch(0.80 0.008 255 / 0.7);
  --line-strong: oklch(0.70 0.01 255 / 0.8);

  --text: oklch(0.21 0.012 255);
  --text-2: oklch(0.42 0.014 255);
  --text-3: oklch(0.50 0.014 255);

  --accent: oklch(0.62 0.15 58);
  --accent-strong: oklch(0.56 0.15 55);
  --accent-soft: oklch(0.70 0.15 62 / 0.16);
  --on-accent: oklch(0.99 0.01 70);

  --danger: oklch(0.55 0.19 27);
  --danger-soft: oklch(0.60 0.19 27 / 0.12);
  --warn: oklch(0.58 0.13 75);
  --warn-soft: oklch(0.80 0.14 85 / 0.22);
  --ok: oklch(0.55 0.13 155);

  --chrome: oklch(0.975 0.003 255 / 0.86);
  --scrim: oklch(0.2 0.01 255 / 0.32);
  --shadow-frame: 0 1px 2px oklch(0.2 0.02 255 / 0.12), 0 12px 32px -10px oklch(0.2 0.02 255 / 0.28);
  --shadow-sheet: 0 -8px 40px -12px oklch(0.2 0.02 255 / 0.25);

  color-scheme: light;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

::selection { background: var(--accent-soft); color: var(--text); }

button, input, a { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
button:disabled { cursor: default; }
a { color: var(--accent); text-underline-offset: 3px; }
input { caret-color: var(--accent); }

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }

.ico {
  width: 22px; height: 22px;
  flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

[hidden] { display: none !important; }

code { font-family: var(--mono); font-size: 0.92em; }

/* Barras de scroll discretas */
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Estructura ---------- */
.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto 0 minmax(0, 1fr) auto;
  grid-template-areas: "tabs" "addr" "prog" "stage" "bar";
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
}

.tabbar     { grid-area: tabs; }
.addressrow { grid-area: addr; }
.progress   { grid-area: prog; }
.stage      { grid-area: stage; }
.toolbar    { grid-area: bar; }

/* Celular en horizontal: la barra de herramientas sube junto a la dirección */
@media (orientation: landscape) and (max-height: 520px) {
  .app {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "tabs tabs" "addr bar" "prog prog" "stage stage";
    grid-template-rows: auto auto 0 minmax(0, 1fr);
  }
  .toolbar { padding: 0 4px 0 0 !important; border-top: 0 !important; gap: 0; background: var(--chrome) !important; }
  .toolbar .tool span:not(.res-text) { display: none; }
  .toolbar .tool { flex: none; min-width: var(--tap); min-height: var(--tap); padding: 0 6px; }
  .toolbar .res-chip { padding: 0 12px; margin: 0 4px; }
  .toolbar .badge { top: 0; left: calc(50% + 4px); }
  .stage { padding-bottom: var(--safe-b); }
}

/* ---------- Pestañas ---------- */
.tabbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(var(--safe-t) + 6px) 6px 2px 6px;
  background: var(--bg);
}

.tabstrip {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  padding: 2px;
  mask-image: linear-gradient(90deg, #000 calc(100% - 18px), transparent);
}
.tabstrip::-webkit-scrollbar { display: none; }

.tab {
  position: relative;
  flex: 0 0 auto;
  width: clamp(116px, 38vw, 200px);
  height: var(--tap);
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 12px;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text-2);
  scroll-snap-align: start;
  transition: background-color 160ms ease, color 160ms ease, transform 160ms var(--ease-out), opacity 200ms var(--ease-out);
  user-select: none;
  -webkit-user-select: none;
}
.tab.active {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line);
}
.tab:active { transform: scale(0.97); }
.tab.entering { opacity: 0; transform: scale(0.94); }
.tab.leaving { opacity: 0; transform: scale(0.94); pointer-events: none; }

.tab-select {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
}
.tab-mono {
  flex: none;
  width: 20px; height: 20px;
  display: grid; place-items: center;
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 11px; font-weight: 650; letter-spacing: 0.02em;
  text-transform: uppercase;
}
.tab.active .tab-mono { background: var(--accent-soft); color: var(--accent); }
.tab-title {
  min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13.5px; font-weight: 520; letter-spacing: 0.005em;
}
.tab.loading .tab-mono { animation: pulse 1.1s ease-in-out infinite; }

.tab-close {
  flex: none;
  width: 36px; height: var(--tap);
  display: grid; place-items: center;
  color: var(--text-3);
  border-radius: var(--r-sm);
}
.tab-close .ico { width: 16px; height: 16px; }
.tab-close:active { color: var(--text); }

.tab-new { flex: none; }

/* ---------- Barra de direcciones ---------- */
.addressrow {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 6px 8px;
  background: var(--bg);
}

.icon-btn {
  width: var(--tap); height: var(--tap);
  flex: none;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  color: var(--text-2);
  transition: transform 120ms var(--ease-out), background-color 160ms ease, color 160ms ease, opacity 160ms ease;
}
.icon-btn:active:not(:disabled) { transform: scale(0.92); background: var(--surface-2); color: var(--text); }
.icon-btn:disabled { opacity: 0.32; }
.icon-btn.accent { color: var(--accent); }
.icon-btn.small { width: 36px; height: 36px; }
.icon-btn.small .ico { width: 18px; height: 18px; }

@media (hover: hover) and (pointer: fine) {
  .icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
  .tab:hover:not(.active) { background: var(--surface); }
  .tool:hover { color: var(--text); }
  .action:hover, .preset:hover, .hist-item:hover { background: var(--surface-2); }
}

.omnibox {
  flex: 1;
  min-width: 0;
  height: var(--tap);
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 4px;
  padding: 0 4px 0 12px;
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
  transition: box-shadow 160ms ease, background-color 160ms ease;
}
.omnibox:focus-within {
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1.5px var(--accent);
}
.omni-lead { width: 18px; height: 18px; color: var(--text-3); }
.omnibox.secure .omni-lead { color: var(--ok); }
.omnibox.insecure .omni-lead { color: var(--warn); }

#address {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  background: transparent;
  /* 16px mínimo: iOS no hace zoom al enfocar */
  font-size: 16px;
  letter-spacing: 0;
  text-overflow: ellipsis;
}
#address:focus-visible { outline: none; }
#address::placeholder { color: var(--text-3); }
.omni-clear { width: 36px; height: 36px; display: grid; place-items: center; color: var(--text-3); border-radius: var(--r-sm); }
.omni-clear .ico { width: 16px; height: 16px; }

#btn-reload.spinning .ico { animation: spin 0.8s linear infinite; }

/* ---------- Indicador de carga ---------- */
.progress { position: relative; z-index: 5; }
.progress-bar {
  position: absolute; left: 0; right: 0; top: -2px; height: 2px;
  background: var(--accent);
  transform-origin: 0 50%;
  transform: scaleX(0);
  opacity: 0;
  box-shadow: 0 0 8px var(--accent);
}
.progress.active .progress-bar {
  opacity: 1;
  transform: scaleX(0.82);
  transition: transform 6s cubic-bezier(0.1, 0.7, 0.2, 1), opacity 120ms ease;
}
.progress.done .progress-bar {
  opacity: 0;
  transform: scaleX(1);
  transition: transform 220ms var(--ease-out), opacity 300ms ease 200ms;
}

/* ---------- Escenario ---------- */
.stage {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 1px 1px, oklch(0.5 0.01 255 / 0.12) 1px, transparent 0) 0 0 / 18px 18px,
    var(--desk);
  border-top: 1px solid var(--line);
}

.views, .view, .scroller { position: absolute; inset: 0; }

.view {
  opacity: 0;
  visibility: hidden;
  transform: translateX(var(--from, 0));
  transition: opacity 200ms var(--ease-out), transform 260ms var(--ease-out), visibility 0s linear 260ms;
}
.view.active {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity 200ms var(--ease-out), transform 260ms var(--ease-out), visibility 0s;
}

.scroller { overflow: hidden; }
.view.real .scroller {
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.sizer { position: relative; }
.frame {
  position: absolute; top: 0; left: 0;
  transform-origin: 0 0;
  background: #fff;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: var(--shadow-frame);
}
.view.real .frame { border-radius: 0; }
.frame iframe {
  display: block;
  width: 100%; height: 100%;
  border: 0;
  background: #fff;
}

/* Mensaje de bloqueo / tiempo de espera */
.notice {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  padding: 24px;
  background: color-mix(in oklch, var(--desk) 88%, transparent);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  z-index: 3;
  animation: fade-in 220ms var(--ease-out);
}
.notice-card {
  width: min(420px, 100%);
  padding: 22px 20px 18px;
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line), var(--shadow-frame);
  text-align: left;
}
.notice-icon {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: var(--warn-soft);
  color: var(--warn);
  margin-bottom: 14px;
}
.notice h2 { margin: 0 0 6px; font-size: 18px; line-height: 1.25; font-weight: 650; letter-spacing: -0.01em; text-wrap: balance; }
.notice p { margin: 0 0 6px; color: var(--text-2); font-size: 14.5px; text-wrap: pretty; }
.notice .notice-url { font-family: var(--mono); font-size: 12.5px; color: var(--text-3); word-break: break-all; margin-bottom: 16px; }
.notice .row-actions { margin-top: 16px; }

/* Aviso flotante */
.hint {
  position: absolute;
  left: 12px; right: 12px; bottom: 12px;
  z-index: 4;
  display: flex; align-items: center; gap: 10px;
  padding: 6px 6px 6px 14px;
  border-radius: var(--r-md);
  background: var(--chrome);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  backdrop-filter: blur(16px) saturate(160%);
  box-shadow: inset 0 0 0 1px var(--line), 0 8px 24px -8px oklch(0 0 0 / 0.5);
  animation: rise-in 260ms var(--ease-out);
  max-width: 560px; margin: 0 auto;
}
.hint > .ico { color: var(--warn); width: 18px; height: 18px; }
.hint p { flex: 1; margin: 0; font-size: 13px; line-height: 1.35; color: var(--text-2); }

/* ---------- Inicio ---------- */
.home {
  position: absolute; inset: 0;
  z-index: 2;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg);
  animation: fade-in 200ms var(--ease-out);
}
.home-inner {
  max-width: 560px;
  margin: 0 auto;
  padding: 36px 16px calc(32px + var(--safe-b));
}
.home-head { margin-bottom: 28px; }
.home-mark {
  width: 44px; height: 44px; margin-bottom: 14px;
  fill: none; stroke: var(--accent); stroke-width: 2.25; stroke-linecap: round; stroke-linejoin: round;
}
.home-mark .dot { fill: var(--accent); stroke: none; }
.home h1 {
  margin: 0 0 6px;
  font-size: 34px; line-height: 1.05; font-weight: 720; letter-spacing: -0.025em;
}
.home-head p { margin: 0; color: var(--text-2); font-size: 16px; max-width: 34ch; text-wrap: pretty; }

.card-block {
  padding: 16px;
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
  margin-bottom: 16px;
}
.card-block.subtle { background: transparent; }
.block-head { display: flex; align-items: center; justify-content: space-between; min-height: 32px; margin-bottom: 8px; }
.block-head h2 { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: -0.005em; }

.text-btn {
  min-height: var(--tap); padding: 0 10px; margin-right: -10px;
  color: var(--accent); font-weight: 560; font-size: 14.5px;
  border-radius: var(--r-sm);
  transition: opacity 120ms ease;
}
.text-btn:active { opacity: 0.6; }
.text-btn.danger { color: var(--danger); }
.text-btn.push { margin-left: auto; }

.project-list, .test-list { list-style: none; margin: 0; padding: 0; }
.project-list li, .test-list li { display: flex; align-items: center; }
.project-list li + li, .test-list li + li { border-top: 1px solid var(--line); }

.site-link {
  flex: 1; min-width: 0;
  min-height: 52px;
  display: flex; align-items: center; gap: 12px;
  padding: 6px 0;
  text-align: left;
  border-radius: var(--r-sm);
  transition: opacity 120ms ease;
}
.site-link:active { opacity: 0.6; }
.site-mono {
  flex: none;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--surface-3);
  color: var(--text);
  font-weight: 650; font-size: 14px; text-transform: uppercase;
}
.site-text { min-width: 0; display: grid; }
.site-text b { font-weight: 560; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-text small { color: var(--text-3); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill {
  flex: none;
  padding: 3px 8px; border-radius: 99px;
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.01em;
  background: var(--surface-3); color: var(--text-2);
}
.pill.ok { background: color-mix(in oklch, var(--ok) 16%, transparent); color: var(--ok); }
.pill.no { background: var(--danger-soft); color: var(--danger); }

.project-list .row-btn { display: none; }
.project-list.editing .row-btn { display: grid; }
.row-btn { color: var(--text-3); }
.row-btn.del { color: var(--danger); }

.project-add { display: flex; gap: 8px; margin-top: 12px; }
.project-add input, .custom-size input, .rename-input {
  flex: 1; min-width: 0;
  height: var(--tap);
  padding: 0 12px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--line);
  font-size: 16px;
  transition: box-shadow 160ms ease;
}
.project-add input:focus, .custom-size input:focus, .rename-input:focus { box-shadow: inset 0 0 0 1.5px var(--accent); }
.project-add input::placeholder { color: var(--text-3); }

.empty { margin: 4px 0 0; color: var(--text-2); font-size: 14px; text-wrap: pretty; }
.field-error { margin: 8px 0 0; color: var(--danger); font-size: 13.5px; }

/* ---------- Botones ---------- */
.btn {
  min-height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0 16px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--text);
  font-weight: 580; font-size: 15px;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 120ms var(--ease-out), background-color 160ms ease, opacity 160ms ease;
  user-select: none; -webkit-user-select: none;
}
.btn .ico { width: 18px; height: 18px; }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: var(--on-accent); box-shadow: none; }
.btn.primary:active { background: var(--accent-strong); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 13.5px; }
.btn.wide { width: 100%; margin-top: 10px; }
.btn:disabled { opacity: 0.4; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.row-actions .btn { flex: 1 1 auto; }

/* ---------- Barra inferior ---------- */
.toolbar {
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  gap: 2px;
  padding: 4px 4px calc(var(--safe-b) + 4px);
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.tool {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  min-height: 52px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border-radius: var(--r-md);
  color: var(--text-2);
  font-size: 11px; font-weight: 560; letter-spacing: 0.01em;
  transition: transform 120ms var(--ease-out), color 160ms ease, background-color 160ms ease;
}
.tool:active { transform: scale(0.94); color: var(--text); }
.tool[aria-expanded="true"] { color: var(--accent); }

.res-chip {
  flex: 1.7 1 0;
  flex-direction: row;
  gap: 8px;
  margin: 4px 2px;
  min-height: var(--tap);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--text);
}
.res-chip .ico { width: 20px; height: 20px; color: var(--accent); }
.res-text { display: grid; text-align: left; line-height: 1.15; }
.res-text b { font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: 0; white-space: nowrap; }
.res-text small { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }

.badge {
  position: absolute; top: 4px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px;
  display: grid; place-items: center;
  border-radius: 99px;
  background: var(--danger); color: #fff;
  font: 700 10.5px/1 var(--font); font-style: normal; font-variant-numeric: tabular-nums;
  box-shadow: 0 0 0 2px var(--bg);
}

/* ---------- Hojas ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 40;
  background: var(--scrim);
  opacity: 0;
  transition: opacity 280ms var(--ease-out);
}
.scrim.open { opacity: 1; }

.sheet {
  position: fixed;
  z-index: 50;
  left: 0; right: 0; bottom: 0;
  margin: 0 auto;
  width: min(100%, 600px);
  max-height: min(86dvh, calc(100dvh - var(--safe-t) - 24px));
  display: flex; flex-direction: column;
  padding-left: var(--safe-l); padding-right: var(--safe-r);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  background: var(--surface);
  box-shadow: inset 0 1px 0 var(--line-strong), var(--shadow-sheet);
  transform: translateY(100%);
  transition: transform 340ms var(--ease-drawer);
  will-change: transform;
}
.sheet.open { transform: translateY(0); }
.sheet.dragging { transition: none; }

.sheet-grip {
  flex: none;
  height: 22px;
  display: grid; place-items: center;
  touch-action: none;
  cursor: grab;
}
.sheet-grip::before {
  content: ""; width: 38px; height: 5px; border-radius: 99px; background: var(--surface-3);
}
.sheet-head {
  flex: none;
  display: flex; align-items: center; gap: 4px;
  padding: 0 8px 6px 20px;
  touch-action: none;
}
.sheet-head h2 { flex: 1; margin: 0; font-size: 20px; line-height: 1.2; font-weight: 700; letter-spacing: -0.015em; }
.sheet-head .text-btn { margin-right: 0; }

.sheet-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 20px calc(var(--safe-b) + 24px);
}

.group-title {
  display: flex; align-items: center; gap: 8px;
  margin: 24px 0 10px;
  font-size: 13px; font-weight: 650; letter-spacing: 0.02em;
  color: var(--text-2);
}
.group-title .ico { width: 18px; height: 18px; color: var(--text-3); }
.group-title .text-btn { min-height: 32px; font-size: 13.5px; }

.note { margin: 14px 0 0; color: var(--text-3); font-size: 13px; line-height: 1.5; text-wrap: pretty; }

/* Lectura de tamaño */
.readout {
  display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px;
  padding: 4px 0 16px;
}
.readout-size { font-size: 30px; font-weight: 700; letter-spacing: -0.025em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.readout-meta { color: var(--text-2); font-size: 14px; font-variant-numeric: tabular-nums; }

/* Control segmentado con indicador deslizante */
.segmented {
  position: relative;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 3px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--line);
}
.segmented::before {
  content: "";
  position: absolute; top: 3px; bottom: 3px; left: 3px;
  width: calc((100% - 6px) / var(--count, 2));
  border-radius: 11px;
  background: var(--surface);
  box-shadow: 0 1px 2px oklch(0 0 0 / 0.25), inset 0 0 0 1px var(--line);
  transform: translateX(calc(100% * var(--index, 0)));
  transition: transform 260ms var(--ease-out);
}
:root[data-theme="light"] .segmented::before { background: #fff; }
.segmented button {
  position: relative;
  min-height: 40px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 0 8px;
  border-radius: 11px;
  color: var(--text-2);
  font-size: 14px; font-weight: 560;
  transition: color 160ms ease;
}
.segmented button .ico { width: 18px; height: 18px; }
.segmented button[aria-checked="true"] { color: var(--text); }

/* Lista de tamaños */
.preset-list { margin-top: 12px; display: grid; gap: 2px; }
.preset {
  min-height: 52px;
  display: flex; align-items: center; gap: 12px;
  padding: 0 12px;
  border-radius: var(--r-md);
  text-align: left;
  transition: background-color 140ms ease, transform 120ms var(--ease-out);
}
.preset:active { transform: scale(0.985); background: var(--surface-2); }
.preset-radio {
  flex: none; width: 20px; height: 20px; border-radius: 50%;
  box-shadow: inset 0 0 0 1.75px var(--line-strong);
  transition: box-shadow 160ms var(--ease-out);
}
.preset[aria-checked="true"] .preset-radio { box-shadow: inset 0 0 0 6px var(--accent); }
.preset-name { flex: 1; min-width: 0; font-weight: 560; }
.preset-size { color: var(--text-3); font-size: 13.5px; font-variant-numeric: tabular-nums; }

.custom-size {
  display: flex; align-items: flex-end; gap: 8px;
  margin-top: 8px; padding: 12px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  animation: fade-in 200ms var(--ease-out);
}
.custom-size label { flex: 1; min-width: 0; display: grid; gap: 4px; font-size: 12.5px; color: var(--text-2); font-weight: 560; }
.custom-size input { width: 100%; background: var(--surface); font-variant-numeric: tabular-nums; }
.custom-size .times { padding-bottom: 12px; color: var(--text-3); }

/* Estado */
.status { margin: 0; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0; border-radius: var(--r-md); background: var(--surface-2); overflow: hidden; }
.status dt, .status dd { margin: 0; padding: 11px 14px; font-size: 14px; border-top: 1px solid var(--line); }
.status dt:first-of-type, .status dt:first-of-type + dd { border-top: 0; }
.status dt { color: var(--text-2); white-space: nowrap; }
.status dd { font-variant-numeric: tabular-nums; word-break: break-all; text-align: right; }
.status dd.mono { font-family: var(--mono); font-size: 12.5px; text-align: left; }
.status dd small { display: block; color: var(--text-3); font-size: 12px; word-break: normal; text-align: left; margin-top: 2px; font-family: var(--font); }
.code-ok { color: var(--ok); font-weight: 650; }
.code-bad { color: var(--danger); font-weight: 650; }

/* Consola */
.console {
  max-height: 260px; overflow: auto;
  border-radius: var(--r-md);
  background: var(--desk);
  box-shadow: inset 0 0 0 1px var(--line);
  font: 12.5px/1.45 var(--mono);
}
.console-empty { padding: 14px; color: var(--text-2); font-family: var(--font); font-size: 13.5px; text-wrap: pretty; }
.console-line { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line); }
.console-line:first-child { border-top: 0; }
.console-line .lvl { font-weight: 700; font-size: 10.5px; padding-top: 2px; letter-spacing: 0.04em; }
.console-line.error { background: var(--danger-soft); }
.console-line.error .lvl { color: var(--danger); }
.console-line.warn { background: var(--warn-soft); }
.console-line.warn .lvl { color: var(--warn); }
.console-line .msg { white-space: pre-wrap; word-break: break-word; }
.console-line .src { display: block; color: var(--text-3); font-size: 11.5px; margin-top: 2px; }

/* Acciones */
.action-list { display: grid; gap: 2px; border-radius: var(--r-md); background: var(--surface-2); overflow: hidden; }
.action {
  min-height: 60px;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 14px;
  text-align: left;
  transition: background-color 140ms ease;
}
.action + .action { border-top: 1px solid var(--line); }
.action:active { background: var(--surface-3); }
.action > .ico { color: var(--accent); }
.action > span { flex: 1; min-width: 0; display: grid; gap: 2px; }
.action b { font-weight: 600; }
.action small { color: var(--text-2); font-size: 13px; line-height: 1.4; text-wrap: pretty; }
.action .chev { width: 18px; height: 18px; color: var(--text-3); }
.action:disabled { opacity: 0.5; }

/* Historial */
.hist-day { margin: 18px 0 6px; font-size: 13px; font-weight: 650; color: var(--text-2); letter-spacing: 0.02em; }
.hist-day:first-child { margin-top: 4px; }
.hist-list { list-style: none; margin: 0; padding: 0; border-radius: var(--r-md); background: var(--surface-2); overflow: hidden; }
.hist-list li { display: flex; align-items: center; }
.hist-list li + li { border-top: 1px solid var(--line); }
.hist-item { flex: 1; min-width: 0; min-height: 56px; display: flex; align-items: center; gap: 12px; padding: 8px 4px 8px 14px; text-align: left; transition: background-color 140ms ease; }
.hist-item:active { background: var(--surface-3); }
.hist-time { flex: none; width: 44px; color: var(--text-3); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.hist-text { min-width: 0; display: grid; }
.hist-text b { font-weight: 560; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-text small { color: var(--text-3); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Instrucciones */
.prose h3 { margin: 22px 0 8px; font-size: 16px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.prose h3:first-child { margin-top: 4px; }
.prose p { margin: 0 0 10px; color: var(--text-2); font-size: 14.5px; text-wrap: pretty; }
.prose ol { margin: 0 0 12px; padding: 0; list-style: none; counter-reset: step; display: grid; gap: 8px; }
.prose ol li { counter-increment: step; display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 10px; font-size: 14.5px; line-height: 1.45; }
.prose ol li::before {
  content: counter(step);
  width: 24px; height: 24px; display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-size: 12.5px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.prose .callout { padding: 12px 14px; border-radius: var(--r-md); background: var(--surface-2); color: var(--text-2); font-size: 13.5px; margin: 12px 0; }
.prose b { color: var(--text); font-weight: 600; }
.prose .host { font-family: var(--mono); font-size: 13px; color: var(--accent); word-break: break-all; }

/* Captura */
.shot-frame { border-radius: var(--r-md); overflow: hidden; background: var(--desk); box-shadow: inset 0 0 0 1px var(--line); margin-bottom: 14px; }
.shot-frame img { display: block; width: 100%; height: auto; }

/* Toast */
.toast {
  position: fixed; z-index: 70;
  left: 50%; bottom: calc(var(--safe-b) + 84px);
  max-width: calc(100% - 32px);
  padding: 11px 16px;
  border-radius: var(--r-md);
  background: var(--text); color: var(--bg);
  font-size: 14px; font-weight: 560;
  box-shadow: 0 10px 30px -10px oklch(0 0 0 / 0.5);
  transform: translate(-50%, 0);
  transition: opacity 200ms var(--ease-out), transform 240ms var(--ease-out);
}
.toast.enter { opacity: 0; transform: translate(-50%, 8px); }

/* Renombrar pestaña / proyecto en línea */
.rename-input { height: 40px; }

/* Cambio de tema suave */
html.theme-fade, html.theme-fade * {
  transition: background-color 240ms ease, color 240ms ease, border-color 240ms ease, box-shadow 240ms ease !important;
}

/* ---------- Animaciones ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: 0.45; } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes rise-in { from { opacity: 0; transform: translateY(8px); } }

@media (prefers-reduced-motion: reduce) {
  .view, .view.active { transform: none !important; transition: opacity 150ms ease, visibility 0s; }
  .sheet { transition: opacity 180ms ease, visibility 0s; transform: none !important; opacity: 0; }
  .sheet.open { opacity: 1; }
  .tab, .btn, .icon-btn, .tool, .preset { transition: background-color 120ms ease, color 120ms ease, opacity 150ms ease; }
  .tab:active, .btn:active, .icon-btn:active, .tool:active, .preset:active { transform: none !important; }
  .tab.entering, .tab.leaving { transform: none; }
  .segmented::before { transition: none; }
  .hint { animation: fade-in 150ms ease; }
  .progress.active .progress-bar { transition: opacity 120ms ease; transform: scaleX(0.6); }
  #btn-reload.spinning .ico { animation: pulse 1.2s ease-in-out infinite; }
}

@media (prefers-reduced-transparency: reduce) {
  .hint, .notice { -webkit-backdrop-filter: none; backdrop-filter: none; background: var(--surface); }
  .notice { background: var(--desk); }
}

@media (prefers-contrast: more) {
  :root { --line: oklch(0.6 0.01 255); --text-3: var(--text-2); }
}
