:root {
  --theme-bg: #0d1119;
  --theme-bg-soft: #151b26;
  --theme-surface: rgba(20, 27, 39, 0.96);
  --theme-surface-2: rgba(29, 38, 54, 0.94);
  --theme-surface-3: #273247;
  --theme-text: #f5f7fb;
  --theme-muted: #b4bfd1;
  --theme-accent: #7da2ff;
  --theme-accent-strong: #557fe8;
  --theme-accent-text: #081122;
  --theme-border: rgba(183, 200, 231, 0.2);
  --theme-danger: #ef6461;
  --theme-success: #5bd59a;
  --theme-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.32);
  --theme-glow: rgba(125, 162, 255, 0.18);
  --theme-radius: 0.9rem;
  --theme-radius-sm: 0.55rem;
  --theme-space: clamp(0.8rem, 1.8vw, 1.35rem);
  color-scheme: dark;
  accent-color: var(--theme-accent);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --theme-bg: #edf2f8;
    --theme-bg-soft: #f7f9fc;
    --theme-surface: rgba(255, 255, 255, 0.96);
    --theme-surface-2: rgba(241, 245, 250, 0.96);
    --theme-surface-3: #dce5f0;
    --theme-text: #182334;
    --theme-muted: #526176;
    --theme-accent: #315fc2;
    --theme-accent-strong: #24499a;
    --theme-accent-text: #fff;
    --theme-border: rgba(35, 57, 89, 0.18);
    --theme-shadow: 0 1rem 3rem rgba(35, 57, 89, 0.14);
    --theme-glow: rgba(49, 95, 194, 0.13);
    color-scheme: light;
  }
}

:root[data-theme="day"] {
  --theme-bg: #edf2f8;
  --theme-bg-soft: #f7f9fc;
  --theme-surface: rgba(255, 255, 255, 0.96);
  --theme-surface-2: rgba(241, 245, 250, 0.96);
  --theme-surface-3: #dce5f0;
  --theme-text: #182334;
  --theme-muted: #526176;
  --theme-accent: #315fc2;
  --theme-accent-strong: #24499a;
  --theme-accent-text: #fff;
  --theme-border: rgba(35, 57, 89, 0.18);
  --theme-shadow: 0 1rem 3rem rgba(35, 57, 89, 0.14);
  --theme-glow: rgba(49, 95, 194, 0.13);
  color-scheme: light;
}

:root[data-theme="night"] {
  --theme-accent: #a7b8d8;
  --theme-accent-strong: #7488ad;
  --theme-glow: rgba(167, 184, 216, 0.15);
}

:root[data-theme="blue"] {
  --theme-bg: #071426;
  --theme-bg-soft: #0b2039;
  --theme-surface: rgba(9, 31, 57, 0.96);
  --theme-surface-2: rgba(14, 45, 77, 0.95);
  --theme-surface-3: #174d80;
  --theme-accent: #5fc7ff;
  --theme-accent-strong: #208ccc;
  --theme-accent-text: #04121d;
  --theme-border: rgba(95, 199, 255, 0.24);
  --theme-glow: rgba(95, 199, 255, 0.18);
}

:root[data-theme="red"] {
  --theme-bg: #1b0b0d;
  --theme-bg-soft: #2a1115;
  --theme-surface: rgba(43, 17, 22, 0.96);
  --theme-surface-2: rgba(64, 24, 31, 0.94);
  --theme-surface-3: #71303b;
  --theme-accent: #ff8b8b;
  --theme-accent-strong: #cf4f59;
  --theme-accent-text: #260508;
  --theme-border: rgba(255, 139, 139, 0.24);
  --theme-glow: rgba(255, 107, 107, 0.17);
}

:root[data-theme="green"] {
  --theme-bg: #071812;
  --theme-bg-soft: #0c271d;
  --theme-surface: rgba(10, 39, 28, 0.96);
  --theme-surface-2: rgba(16, 58, 42, 0.94);
  --theme-surface-3: #246c50;
  --theme-accent: #6de3a9;
  --theme-accent-strong: #2ba66f;
  --theme-accent-text: #03150d;
  --theme-border: rgba(109, 227, 169, 0.24);
  --theme-glow: rgba(109, 227, 169, 0.16);
}

:root[data-theme="purple"] {
  --theme-bg: #150b21;
  --theme-bg-soft: #211132;
  --theme-surface: rgba(35, 18, 52, 0.96);
  --theme-surface-2: rgba(52, 27, 76, 0.94);
  --theme-surface-3: #643b88;
  --theme-accent: #d49bff;
  --theme-accent-strong: #9d5bc9;
  --theme-accent-text: #1b0827;
  --theme-border: rgba(212, 155, 255, 0.25);
  --theme-glow: rgba(212, 155, 255, 0.17);
}

html {
  background: var(--theme-bg);
  color: var(--theme-text);
  scrollbar-color: var(--theme-accent-strong) var(--theme-bg-soft);
}

body {
  color: var(--theme-text) !important;
  background-color: var(--theme-bg) !important;
  background-image: linear-gradient(135deg, color-mix(in srgb, var(--theme-bg) 90%, transparent), color-mix(in srgb, var(--theme-bg-soft) 88%, transparent)), url('../img/p9.jpg') !important;
  background-repeat: repeat !important;
  background-size: auto !important;
  font-family: Inter, Roboto, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif !important;
}

a {
  color: var(--theme-accent) !important;
  text-underline-offset: 0.18em;
}

a:hover { color: color-mix(in srgb, var(--theme-accent) 72%, white) !important; }

h1, h2, h3, h4, h5, h6, label, .marc {
  color: var(--theme-text) !important;
}

h1, h2, h3 {
  letter-spacing: -0.025em;
}

hr {
  border: 0;
  border-block-start: 1px solid var(--theme-border);
}

#header,
#footer,
header {
  color: var(--theme-text) !important;
  background: var(--theme-surface) !important;
  border-color: var(--theme-border) !important;
  box-shadow: 0 0.5rem 2rem rgba(0, 0, 0, 0.14);
  backdrop-filter: blur(14px);
}

#ibar,
#dbar,
#cont {
  color: var(--theme-text);
}

#ibar,
#dbar {
  background: color-mix(in srgb, var(--theme-surface) 76%, transparent);
  border: 1px solid var(--theme-border);
  border-radius: var(--theme-radius);
  margin-block: var(--theme-space);
}

#cont {
  padding-block: var(--theme-space);
}

#form_frame,
#pagina_blanca,
#pagina_interior,
#panel,
#panel_categorias,
#panel_hilos,
#panel_respuestas,
#panel_respuestas_form,
.inli,
.tchat,
#chatbox,
#wrapper,
.logs,
fieldset {
  color: var(--theme-text) !important;
  background: var(--theme-surface) !important;
  border: 1px solid var(--theme-border) !important;
  border-radius: var(--theme-radius) !important;
  box-shadow: var(--theme-shadow);
}

#form_frame,
#pagina_blanca,
#pagina_interior,
#panel,
#panel_categorias,
#panel_hilos,
#panel_respuestas,
#panel_respuestas_form {
  padding: clamp(1rem, 2.5vw, 1.75rem) !important;
}

table {
  border-color: var(--theme-border) !important;
}

th {
  color: var(--theme-text);
  background: var(--theme-surface-3);
}

td {
  border-color: var(--theme-border) !important;
}

input,
select,
textarea,
button:not(.dplayer *),
.aigblue,
.canal,
.donate,
.btnNavMenu {
  min-block-size: 2rem;
  border: 1px solid var(--theme-border) !important;
  border-radius: var(--theme-radius-sm) !important;
  font: inherit;
}

input:not([type="submit"], [type="button"], [type="reset"], [type="checkbox"], [type="radio"]),
textarea,
select {
  color: var(--theme-text) !important;
  background: var(--theme-bg-soft) !important;
  padding: 0.55rem 0.7rem !important;
}

button:not(.dplayer *),
input[type="submit"],
input[type="button"],
.aigblue,
.canal,
.btnNavMenu {
  color: var(--theme-accent-text) !important;
  background: linear-gradient(145deg, var(--theme-accent), var(--theme-accent-strong)) !important;
  box-shadow: 0 0.25rem 0.8rem var(--theme-glow) !important;
  padding: 0.32rem 0.68rem !important;
  cursor: pointer;
  transform: none !important;
}

button:not(.dplayer *):hover,
input[type="submit"]:hover,
.aigblue:hover,
.canal:hover,
.btnNavMenu:hover {
  filter: brightness(1.08);
}

button:not(.dplayer *):active,
input[type="submit"]:active,
.aigblue:active,
.canal:active {
  translate: 0 1px;
}

button:not(.dplayer *)[style*="#B12525"],
button:not(.dplayer *)[style*="#ff0000"],
.bred {
  color: white !important;
  background: var(--theme-danger) !important;
}

:where(a, button, input, select, textarea):focus-visible {
  outline: 3px solid var(--theme-accent) !important;
  outline-offset: 3px;
}

.listado,
.msgln,
.chat-connection,
small {
  color: var(--theme-muted) !important;
}

#chatbox {
  scrollbar-gutter: stable;
}

.msgln {
  margin-block: 0.2rem;
  padding: 0.36rem 0.5rem;
  border-radius: 0.4rem;
}

.msgln:hover {
  background: var(--theme-glow);
}

#video-play,
video:not(.dplayer-video) {
  overflow: hidden;
  border-radius: var(--theme-radius-sm);
  background: #000;
}


.theme-picker {
  position: fixed;
  inset-inline-end: max(0.75rem, env(safe-area-inset-right));
  inset-block-end: max(0.75rem, env(safe-area-inset-bottom));
  z-index: 1200;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.55rem;
  color: var(--theme-text);
  background: var(--theme-surface);
  border: 1px solid var(--theme-border);
  border-radius: 999px;
  box-shadow: var(--theme-shadow);
  backdrop-filter: blur(14px);
}

.theme-picker label {
  font-size: 0.82rem;
  font-weight: 700;
}

.theme-picker select {
  min-block-size: 2rem;
  inline-size: auto;
  padding-block: 0.25rem !important;
  font-size: 0.85rem;
}

@media (max-width: 1100px) {
  #ibar,
  #dbar {
    margin-inline: var(--aig-gutter, 0.75rem);
  }
}

@media (max-width: 640px) {
  .theme-picker {
    inset-inline: 0.6rem;
    inset-block-end: 0.6rem;
    justify-content: center;
    border-radius: var(--theme-radius-sm);
  }

  #footer {
    padding-block-end: 5rem !important;
  }
}

@media (forced-colors: active) {
  * { forced-color-adjust: auto; }
  .theme-picker { border: 1px solid CanvasText; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
