/* ---------------- temas (web/temas.js) ---------------- */
body { transition: background-color .4s; font-family: var(--sans); }
#themeBtn svg { transition: scale .45s cubic-bezier(.34, 1.9, .5, 1), rotate .6s cubic-bezier(.34, 1.56, .64, 1); }
#themeBtn:hover svg { scale: 1.2; rotate: -20deg; }
.fx-on #themeBtn svg { animation: thSpin 6s cubic-bezier(.34, 1.56, .64, 1) infinite; }
@keyframes thSpin { 0%, 80%, 100% { rotate: 0deg; scale: 1; } 86% { rotate: -28deg; scale: 1.18; } 92% { rotate: 10deg; scale: .95; } 96% { rotate: -3deg; scale: 1.02; } }

/* selector */
#themePop { position: fixed; z-index: 95; max-height: min(78vh, 760px); display: none; flex-direction: column; padding: 12px; border-radius: 16px;
  background: rgba(var(--float-rgb), .97); border: 1px solid rgba(var(--hi-rgb), .08); backdrop-filter: blur(16px) saturate(1.3); -webkit-backdrop-filter: blur(16px) saturate(1.3);
  box-shadow: 0 26px 60px rgba(var(--shadow-rgb), .6), 0 0 34px rgba(var(--acc-rgb), .16); color: var(--text); font-family: var(--sans); }
#themePop.on { display: flex; animation: thIn .5s cubic-bezier(.34, 1.56, .64, 1); transform-origin: top right; }
@keyframes thIn { 0% { opacity: 0; scale: .86; translate: 0 -8px; } 100% { opacity: 1; scale: 1; translate: 0 0; } }
.th-h { display: flex; align-items: center; gap: 10px; padding: 0 4px 10px; font-size: 13px; }
.th-h b { color: var(--hi); }
.th-h > span { color: var(--muted); font-size: 11.5px; flex: 1; }
.th-h em { font-style: normal; color: var(--acc); font-weight: 700; }
.th-q { display: flex; align-items: center; gap: 6px; height: 30px; padding: 0 9px; border-radius: 9px; background: rgba(var(--hi-rgb), .05); border: 1px solid rgba(var(--hi-rgb), .08); color: var(--muted); }
.th-q:focus-within { border-color: rgba(var(--acc-rgb), .6); box-shadow: 0 0 0 3px rgba(var(--acc-rgb), .14); color: var(--acc); }
.th-q input { width: 190px; background: none; border: 0; outline: 0; color: var(--text); font: 500 12px var(--sans); }
.th-cats { display: flex; flex-wrap: wrap; gap: 5px; padding: 0 2px 10px; }
.th-cats button { height: 26px; padding: 0 11px; border-radius: 999px; border: 1px solid rgba(var(--hi-rgb), .09); background: rgba(var(--hi-rgb), .03); color: color-mix(in srgb, var(--muted) 70%, var(--text));
  font: 600 11.5px var(--sans); transition: background .15s, color .15s, scale .4s cubic-bezier(.34, 1.9, .5, 1); }
.th-cats button:hover { scale: 1.06; color: var(--hi); }
.th-cats button.on { color: var(--on-acc); background: linear-gradient(135deg, var(--acc), var(--acc2)); border-color: transparent; box-shadow: 0 0 14px rgba(var(--acc-rgb), .45); }
.th-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(172px, 1fr)); gap: 8px; overflow-y: auto; padding: 2px 4px 4px 2px; min-height: 0; }
.th-c { position: relative; display: flex; flex-direction: column; gap: 6px; padding: 6px; border-radius: var(--th-r); text-align: left; background: rgba(var(--hi-rgb), .03);
  border: 1px solid rgba(var(--hi-rgb), .07); color: var(--text); cursor: pointer;
  animation: thCard .45s cubic-bezier(.34, 1.56, .64, 1) both; animation-delay: calc(var(--i) * 18ms);
  transition: border-color .2s, box-shadow .25s, scale .45s cubic-bezier(.34, 1.9, .5, 1); }
@keyframes thCard { 0% { opacity: 0; scale: .8; } 100% { opacity: 1; scale: 1; } }
.th-c:hover { scale: 1.05; border-color: color-mix(in srgb, var(--acc) 60%, transparent); box-shadow: 0 0 22px color-mix(in srgb, var(--acc) 30%, transparent); z-index: 1; }
.th-c:active { scale: .95; transition-duration: .06s; }
.th-c.on { border-color: var(--acc); box-shadow: 0 0 0 1px var(--acc) inset, 0 0 24px color-mix(in srgb, var(--acc) 35%, transparent); }
.th-pv { display: block; height: 62px; border-radius: max(0px, calc(var(--th-r) - 3px)); overflow: hidden; box-shadow: 0 0 0 1px rgba(var(--hi-rgb), .06) inset; }
.th-pv svg { width: 100%; height: 100%; display: block; transition: scale .6s cubic-bezier(.34, 1.56, .64, 1); }
.th-c:hover .th-pv svg { scale: 1.1; }
.th-t { display: flex; flex-direction: column; gap: 1px; padding: 0 3px 2px; }
.th-t b { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.th-t em { font-style: normal; font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.th-ok { position: absolute; top: 10px; right: 10px; width: 18px; height: 18px; border-radius: 50%; display: none; place-items: center; font-style: normal;
  font-size: 10px; font-weight: 800; color: var(--on-acc); background: var(--acc); box-shadow: 0 0 12px var(--acc); }
.th-c.on .th-ok { display: grid; animation: thOk 2.6s cubic-bezier(.34, 1.56, .64, 1) infinite; }
@keyframes thOk { 0%, 60%, 100% { scale: 1; } 66% { scale: 1.3; } 72% { scale: .9; } 78% { scale: 1.06; } 84% { scale: 1; } }

/* la onda que deja puesto el tema nuevo */
.th-wave { position: fixed; inset: 0; z-index: 120; pointer-events: none; clip-path: circle(0 at var(--x) var(--y));
  animation: thWave .55s cubic-bezier(.65, 0, .35, 1) forwards; }
.th-wave.out { animation: thWaveOut .6s ease forwards; clip-path: circle(150% at var(--x) var(--y)); }
@keyframes thWave { to { clip-path: circle(150% at var(--x) var(--y)); } }
@keyframes thWaveOut { from { opacity: 1; } to { opacity: 0; } }

/* ---------------- cómo flotan los paneles, según el tema ---------------- */
/* lo que flota: leyendas, barra de dibujo, barra del dibujo, menús, calendario, carteles */
:is(body.panel-solid, body.panel-outline, body.panel-neon) :is(#legend, #drawbar, #htBar, #htSet, #taLeg .tl, #cal, #clHud, #drawbar .htg-fly, #tip, .dt-pop, #fxMenu, .micro-pop) {
  backdrop-filter: none !important; -webkit-backdrop-filter: none !important; }
body.panel-solid :is(#legend, #drawbar, #htBar, #htSet, #taLeg .tl, #cal, #clHud, #drawbar .htg-fly, #tip, .dt-pop, #fxMenu, .micro-pop) {
  background: rgb(var(--float-rgb)) !important; box-shadow: 0 8px 24px rgba(var(--shadow-rgb), .45) !important; }
body.panel-outline :is(#legend, #drawbar, #htBar, #htSet, #taLeg .tl, #cal, #clHud, #drawbar .htg-fly, #tip, .dt-pop, #fxMenu, .micro-pop) {
  background: rgba(var(--float-rgb), .55) !important; border: 1px solid rgba(var(--acc-rgb), .45) !important; box-shadow: none !important; }
body.panel-neon :is(#legend, #drawbar, #htBar, #htSet, #taLeg .tl, #cal, #clHud, #drawbar .htg-fly, #tip, .dt-pop, #fxMenu, .micro-pop) {
  background: rgba(var(--float-rgb), .9) !important; border: 1px solid rgba(var(--acc-rgb), .7) !important;
  box-shadow: 0 0 16px rgba(var(--acc-rgb), .35), inset 0 0 14px rgba(var(--acc-rgb), .08) !important; }
body.panel-neon #top { box-shadow: 0 1px 0 rgba(var(--acc-rgb), .6), 0 6px 24px rgba(var(--acc-rgb), .12); }
/* esquinas rectas (Terminal, Retro, Terminal ámbar) o bien redondas (Vidrio, Polar) */
body.ui-sharp *:not(svg):not(svg *):not(.dot):not(.live-dot):not(.sw-dot):not(.th-ok):not(.ta-tg i):not(.switch)::after,
body.ui-sharp *:not(svg):not(svg *):not(.dot):not(.live-dot):not(.sw-dot):not(.th-ok):not(.ta-tg i) { border-radius: 0 !important; }
body.ui-soft :is(#legend, #drawbar, #htBar, #htSet, #cal, #drawbar .htg-fly, .icon-btn, .seg, .ctl, .ta-row, .ta-item, .layer) { border-radius: 16px !important; }

/* tema claro: la barra de arriba y lo que flota sobre el gráfico (leyendas, barras, pastillas, carteles) quedan oscuros,
   así que ahí adentro los colores por función vuelven a ser los de un tema oscuro (paleta fija, igual que --top-bg claro en temas.js) */
/* (un tema propio claro con barra de arriba clara, .top-own, usa sus propios colores también ahí) */
.theme-light:not(.top-own) :is(#top, #legend, #drawbar, #taLeg, #htBar, #htSet, #cal, #clHud, #tip, #toasts, #htEdit, #htToast, #rpHint, #rpBar, #topBack, #zenBack, #zenLupa) {
  --bg: #131722; --surface: #131722; --surface-2: #1e222d; --surface-3: #2a2e39; --surface-4: #363a45; --line: #2a2e39; --line-2: #363a45;
  --text: #d1d4dc; --muted: #868993; --faint: #5d606b; --hi: #ffffff; --hi-rgb: 255, 255, 255; --soft: #e2e8f0;
  --neutral: #94a3b8; --neutral-2: #64748b; --neutral-3: #475569; --shadow-rgb: 0, 0, 0; --text-rgb: 209, 212, 220; --bg-rgb: 19, 23, 34;
  color: var(--text); }
.theme-light :is(#legend, #drawbar) { box-shadow: 0 8px 22px rgba(var(--shadow-rgb), .18); }
/* tema claro: los paneles y menús grandes que no están sobre el gráfico se ven claros (fondo del tema, letra oscura) */
.theme-light :is(#themePop, #sxPop, #cpk, #prPop, .sim-toast, #ofLogin, #thEd) { --float-rgb: var(--bg-rgb); }
.theme-light :is(#themePop, #sxPop, #cpk, #prPop, #thEd) { box-shadow: 0 22px 56px rgba(var(--shadow-rgb), .22), 0 0 0 1px var(--line-2); }
/* botón de venta del simulador: relleno de color oscurecido en temas claros, letra clara */
.theme-light .sim-sell { color: var(--ink); }

/* «Crear tema» y el lápiz de los temas propios */
.th-add { border-style: dashed; border-color: rgba(var(--acc-rgb), .45); }
.th-add .th-pv { display: grid; place-items: center; color: var(--acc); background: rgba(var(--acc-rgb), .07); box-shadow: none; }
.th-add:hover .th-pv svg { scale: 1.25; rotate: 90deg; }
.th-add .th-pv svg { width: 26px; height: 26px; transition: scale .45s cubic-bezier(.34, 1.9, .5, 1), rotate .5s cubic-bezier(.34, 1.56, .64, 1); }
.th-ed { position: absolute; top: 10px; left: 10px; width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; font-size: 12px;
  color: var(--hi); background: rgba(var(--float-rgb), .85); border: 1px solid rgba(var(--hi-rgb), .15); opacity: 0; transition: opacity .15s, scale .35s cubic-bezier(.34, 1.9, .5, 1); }
.th-c:hover .th-ed { opacity: 1; }
.th-ed:hover { scale: 1.18; color: var(--on-acc); background: var(--acc); }

/* editor de temas propios: panel a la derecha, el gráfico se ve en vivo al lado */
#thEd { position: fixed; z-index: 96; top: 60px; right: 12px; bottom: 12px; width: 352px; max-width: calc(100vw - 24px); display: none; flex-direction: column;
  border-radius: 16px; background: rgba(var(--float-rgb), .97); border: 1px solid rgba(var(--hi-rgb), .1); color: var(--text); font-family: var(--sans);
  backdrop-filter: blur(16px) saturate(1.3); -webkit-backdrop-filter: blur(16px) saturate(1.3); box-shadow: 0 26px 60px rgba(var(--shadow-rgb), .6), 0 0 30px rgba(var(--acc-rgb), .14); }
#thEd.on { display: flex; animation: teIn .45s cubic-bezier(.34, 1.56, .64, 1); }
@keyframes teIn { 0% { opacity: 0; translate: 24px 0; } 100% { opacity: 1; translate: 0 0; } }
.te-h { display: flex; align-items: center; padding: 12px 14px 8px; font-size: 13.5px; }
.te-h b { color: var(--hi); flex: 1; }
.te-x { width: 26px; height: 26px; border-radius: 8px; border: 0; background: none; color: var(--muted); cursor: pointer; }
.te-x:hover { color: var(--hi); background: rgba(var(--hi-rgb), .08); }
.te-top { display: flex; gap: 10px; padding: 0 14px 10px; border-bottom: 1px solid rgba(var(--hi-rgb), .07); }
.te-pv { flex: 0 0 112px; height: 76px; border-radius: 10px; overflow: hidden; box-shadow: 0 0 0 1px rgba(var(--hi-rgb), .1) inset; }
.te-pv svg { width: 100%; height: 100%; display: block; }
.te-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.te-meta .te-r { flex-direction: column; align-items: stretch; gap: 3px; padding: 0; }
.te-name { height: 28px; padding: 0 8px; border-radius: 8px; background: rgba(var(--hi-rgb), .05); border: 1px solid rgba(var(--hi-rgb), .1); color: var(--hi); font: 600 12.5px var(--sans); outline: 0; }
.te-name:focus { border-color: rgba(var(--acc-rgb), .6); }
.te-body { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 10px 10px; }
.te-s { border-radius: 10px; margin-top: 6px; background: rgba(var(--hi-rgb), .025); border: 1px solid rgba(var(--hi-rgb), .06); }
.te-s summary { cursor: pointer; padding: 8px 10px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); list-style: none; }
.te-s summary::before { content: "▸"; display: inline-block; width: 14px; transition: rotate .2s; }
.te-s[open] summary::before { rotate: 90deg; }
.te-s summary:hover { color: var(--hi); }
.te-r { display: flex; align-items: center; gap: 8px; padding: 4px 10px; font-size: 12px; }
.te-r > span { flex: 1; min-width: 0; color: var(--text); }
.te-meta .te-r > span { font-size: 10.5px; color: var(--muted); }
.te-sw { position: relative; width: 26px; height: 22px; border-radius: 6px; background: var(--c); box-shadow: 0 0 0 1px rgba(var(--hi-rgb), .25) inset; cursor: pointer; flex: none; }
.te-sw input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.te-hex { width: 74px; height: 22px; padding: 0 6px; border-radius: 6px; background: rgba(var(--hi-rgb), .04); border: 1px solid rgba(var(--hi-rgb), .1); color: var(--text); font: 500 11px var(--mono); outline: 0; }
.te-hex:focus { border-color: rgba(var(--acc-rgb), .6); }
.te-r input[type=range] { width: 108px; accent-color: var(--acc); }
.te-r output { width: 32px; text-align: right; font: 500 11px var(--mono); color: var(--muted); }
.te-r .sx { flex: none; width: 140px; }
.te-meta .te-r .sx { width: auto; }
.te-chk input { accent-color: var(--acc); width: 15px; height: 15px; }
.te-f { display: flex; align-items: center; gap: 8px; padding: 10px 14px 12px; border-top: 1px solid rgba(var(--hi-rgb), .07); }
.te-f span { flex: 1; }
.te-f button { height: 30px; padding: 0 14px; border-radius: 9px; border: 1px solid rgba(var(--hi-rgb), .12); background: rgba(var(--hi-rgb), .04); color: var(--text); font: 600 12px var(--sans); cursor: pointer; }
.te-f button:hover { color: var(--hi); border-color: rgba(var(--hi-rgb), .25); }
.te-f .te-ok { color: var(--on-acc); border-color: transparent; background: linear-gradient(135deg, var(--acc), var(--acc2)); box-shadow: 0 0 14px rgba(var(--acc-rgb), .35); }
.te-f .te-del { color: var(--bear); border-color: color-mix(in srgb, var(--bear) 40%, transparent); }

@media (prefers-reduced-motion: reduce) { #themePop.on, #thEd.on, .th-c, .th-c.on .th-ok, .th-wave, #themeBtn svg { animation: none !important; } .th-wave { display: none; } }
