:root {
  --barH: 170px;
  --blue: #34bdf0;
  --blue-glow: rgba(52, 189, 240, 0.45);
  --stroke: #c9cbcd;
  --ink: #5d5f61;
  --ink-soft: #8f9193;
  --cursor: url("../assets/cursor.svg") 11 3, default;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  font-family: "Nunito", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background-color: #eceeef;
  background-image:
    repeating-linear-gradient(180deg, rgba(255,255,255,.6) 0 2px, rgba(255,255,255,0) 2px 5px),
    linear-gradient(180deg, #f6f7f8 0%, #e5e7e9 100%);
  overflow: hidden;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: var(--cursor);
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: var(--cursor);
}

/* ---------- Fundido de entrada / salida ---------- */
#fade {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #fff;
  pointer-events: none;
  transition: opacity .7s ease;
}
body.ready #fade { opacity: 0; }
body.leaving #fade { opacity: 1; transition-duration: .45s; }

/* ---------- Grilla de canales ---------- */
#menu {
  position: fixed;
  inset: 0 0 var(--barH) 0;
  display: grid;
  place-items: center;
}

.grid {
  --gap: clamp(10px, 1.7vw, 26px);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
  width: min(88vw, calc((100vh - var(--barH) - 90px) * 2.02));
}
.grid.slide-next { animation: slideNext .35s ease both; }
.grid.slide-prev { animation: slidePrev .35s ease both; }

.tile {
  --r: clamp(10px, 1.35vw, 20px);
  position: relative;
  aspect-ratio: 1.55 / 1;
  border-radius: var(--r);
  background: linear-gradient(180deg, #ffffff, #f1f2f3);
  border: 3px solid var(--stroke);
  box-shadow: 0 2px 5px rgba(0,0,0,.07);
  transition:
    transform .22s cubic-bezier(.34, 1.56, .64, 1),
    border-color .15s ease,
    box-shadow .15s ease;
  animation: tileIn .55s cubic-bezier(.34, 1.4, .64, 1) backwards;
  animation-delay: calc(var(--i) * 35ms + 200ms);
}
.tile:hover,
.tile:focus-visible {
  outline: none;
  z-index: 2;
  transform: scale(1.07);
  border-color: var(--blue);
  box-shadow:
    0 0 0 3px rgba(52, 189, 240, .25),
    0 0 20px var(--blue-glow),
    0 8px 20px rgba(0,0,0,.12);
}
.tile:active { transform: scale(1.03); }
.tile.lifted { visibility: hidden; }

.screen {
  position: absolute;
  inset: 4px;
  border-radius: calc(var(--r) - 5px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .2em;
}
/* brillo tipo burbuja */
.screen::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg,
    rgba(255,255,255,.5) 0%,
    rgba(255,255,255,.12) 46%,
    rgba(255,255,255,0) 50%);
}

.noise {
  background-color: #d4d5d6;
  background-image: var(--noise);
  background-size: 128px 128px;
  animation: static .45s steps(1) infinite;
}
.tile.empty .screen { opacity: .85; }

.tile .icon {
  font-size: clamp(22px, 3.1vw, 50px);
  line-height: 1;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.2));
}
.tile .name {
  font-weight: 800;
  font-size: clamp(11px, 1.05vw, 17px);
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,.35);
  padding: 0 .5em;
  text-align: center;
}

.tile img.icon {
  height: 58%;
  max-width: 80%;
  object-fit: contain;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.18));
}
.screen.light .name {
  color: #0d3b6e;
  text-shadow: 0 1px 0 rgba(255,255,255,.8);
  line-height: 1.15;
}

/* ---------- Flechas de página ---------- */
.page-arrow {
  position: absolute;
  top: 50%;
  width: 46px;
  height: 70px;
  transform: translateY(-50%);
  transition: transform .2s cubic-bezier(.34, 1.56, .64, 1);
}
.page-arrow.left { left: 1.2vw; }
.page-arrow.right { right: 1.2vw; }
.page-arrow:hover { transform: translateY(-50%) scale(1.15); }
.page-arrow svg { width: 100%; height: 100%; overflow: visible; }
.page-arrow path {
  fill: none;
  stroke: var(--blue);
  stroke-width: 9;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 4px var(--blue-glow));
}

/* ---------- Barra inferior ---------- */
#bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--barH);
  animation: barIn .6s cubic-bezier(.2, .8, .2, 1) .1s backwards;
}
#barShape {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 -2px 6px rgba(0,0,0,.08));
}
#barLine {
  stroke: var(--blue);
  stroke-width: 3;
  stroke-linejoin: round;
}

#clock {
  position: absolute;
  left: 50%;
  top: calc(var(--y0, 62px) + var(--barH) * .03);
  transform: translateX(-50%);
  font-size: calc(var(--barH) * .34);
  font-weight: 600;
  line-height: 1;
  color: #8d8f91;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
  text-shadow: 0 1px 0 #fff;
}
#colon { animation: blink 1s steps(1) infinite; }

#date {
  position: absolute;
  left: 50%;
  top: calc(var(--y0, 62px) + var(--barH) * .41);
  transform: translateX(-50%);
  font-size: calc(var(--barH) * .13);
  font-weight: 700;
  color: #9a9c9e;
  white-space: nowrap;
  text-shadow: 0 1px 0 #fff;
}

.round-btn {
  position: absolute;
  left: var(--btnX);
  top: var(--btnY);
  width: var(--btnD);
  height: var(--btnD);
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 28%, #ffffff 0%, #f4f4f4 55%, #dcdddf 100%);
  border: 3px solid #c2c4c6;
  box-shadow: 0 2px 6px rgba(0,0,0,.14), inset 0 -3px 6px rgba(0,0,0,.05);
  color: #8e9092;
  font-weight: 800;
  font-size: calc(var(--btnD) * .27);
  letter-spacing: -.02em;
  transition: transform .2s cubic-bezier(.34, 1.56, .64, 1), border-color .15s, box-shadow .15s;
}
.round-btn:hover,
.round-btn:focus-visible {
  outline: none;
  transform: scale(1.08);
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(52,189,240,.25), 0 0 16px var(--blue-glow);
}
.round-btn svg { width: 44%; overflow: visible; }
.round-btn svg rect,
.round-btn svg path {
  fill: none;
  stroke: currentColor;
  stroke-width: 4;
  stroke-linejoin: round;
  stroke-linecap: round;
}

/* ---------- Globo con el nombre del canal ---------- */
#tooltip {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  padding: 6px 16px;
  background: #fff;
  border: 2px solid #cfd1d3;
  border-radius: 999px;
  color: var(--ink);
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,.12);
  opacity: 0;
  transform: translate(-50%, calc(-100% - 22px)) scale(.9);
  transition: opacity .12s, transform .12s;
}
#tooltip.show {
  opacity: 1;
  transform: translate(-50%, calc(-100% - 22px)) scale(1);
}

#toast {
  position: fixed;
  z-index: 90;
  top: 24px;
  left: 50%;
  padding: 10px 22px;
  background: #fff;
  border: 2px solid var(--stroke);
  border-radius: 999px;
  font-weight: 700;
  color: var(--ink);
  box-shadow: 0 6px 18px rgba(0,0,0,.12);
  opacity: 0;
  transform: translate(-50%, -12px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Pantalla del canal (zoom) ---------- */
#channel {
  --chBarH: 150px;
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(236, 238, 239, 0);
  transition: background .35s ease;
}
#channel[hidden] { display: none; }
#channel.open { background: rgba(236, 238, 239, 1); }

#channelScreen {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: calc(100% - var(--chBarH));
  overflow: hidden;
  transform-origin: 0 0;
  transition:
    transform .45s cubic-bezier(.2, .8, .2, 1),
    border-radius .45s cubic-bezier(.2, .8, .2, 1);
}
#channelScreen.noise { background-size: 192px 192px; }
#channelScreen::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255,255,255,.28) 0%, rgba(255,255,255,0) 50%);
}

#channelContent {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  opacity: 0;
  transition: opacity .2s ease;
}
#channel.open #channelContent { opacity: 1; transition: opacity .3s ease .3s; }

#channelContent .ch-icon {
  font-size: clamp(60px, 12vw, 150px);
  line-height: 1;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.22));
}
#channelContent h1 {
  margin: 0;
  font-size: clamp(30px, 5vw, 64px);
  font-weight: 800;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0,0,0,.3);
}
#channelContent p {
  margin: 0;
  max-width: 640px;
  font-size: clamp(16px, 1.8vw, 22px);
  font-weight: 600;
  color: rgba(255,255,255,.92);
  text-shadow: 0 1px 4px rgba(0,0,0,.3);
}
#channelScreen.noise h1,
#channelScreen.noise p { color: #6b6d6f; text-shadow: 0 1px 0 rgba(255,255,255,.7); }
#channelScreen.light h1 { color: #0d3b6e; text-shadow: none; }
#channelScreen.light p { color: #5d6670; text-shadow: none; }
#channelContent img.ch-icon {
  height: clamp(120px, 34vh, 320px);
  max-width: 70vw;
  object-fit: contain;
}

#channelBar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--chBarH);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8vw;
  background: linear-gradient(180deg, #fbfbfb 0%, #ececec 45%, #d4d6d8 100%);
  border-top: 3px solid var(--blue);
  box-shadow: 0 -2px 8px rgba(0,0,0,.08);
  transform: translateY(105%);
  transition: transform .4s cubic-bezier(.2, .8, .2, 1);
}
#channel.open #channelBar { transform: none; }

.ch-btn {
  width: min(36vw, 320px);
  height: 84px;
  border-radius: 26px;
  background: linear-gradient(180deg, #ffffff 0%, #f3f3f3 55%, #e2e3e4 100%);
  border: 3px solid #bfc1c3;
  box-shadow: 0 3px 8px rgba(0,0,0,.12);
  font-size: 26px;
  font-weight: 700;
  color: #5d5f61;
  transition: transform .2s cubic-bezier(.34, 1.56, .64, 1), border-color .15s, box-shadow .15s, opacity .2s;
}
.ch-btn:hover:not(:disabled),
.ch-btn:focus-visible {
  outline: none;
  transform: scale(1.06);
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(52,189,240,.25), 0 0 18px var(--blue-glow);
}
.ch-btn:disabled { opacity: .45; }

/* ---------- Animaciones ---------- */
@keyframes tileIn {
  from { opacity: 0; transform: scale(.82); }
  to   { opacity: 1; transform: scale(1); }
}
@keyframes barIn {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
@keyframes static {
  0%   { background-position: 0 0; }
  20%  { background-position: -37px 61px; }
  40%  { background-position: 53px -29px; }
  60%  { background-position: -71px -83px; }
  80%  { background-position: 19px 97px; }
}
@keyframes blink { 50% { opacity: .15; } }
@keyframes slideNext {
  from { opacity: 0; transform: translateX(6%); }
  to   { opacity: 1; transform: none; }
}
@keyframes slidePrev {
  from { opacity: 0; transform: translateX(-6%); }
  to   { opacity: 1; transform: none; }
}

/* ---------- Pantallas pequeñas ---------- */
@media (max-height: 650px), (max-width: 700px) {
  :root { --barH: 130px; }
  #channel { --chBarH: 120px; }
  .ch-btn { height: 66px; font-size: 21px; border-radius: 20px; }
}
@media (orientation: portrait) {
  .grid {
    grid-template-columns: repeat(3, 1fr);
    width: min(92vw, calc((100vh - var(--barH) - 48px) * .85));
  }
  .tile { aspect-ratio: 1.15 / 1; }
  .tile .icon { font-size: clamp(22px, 7vw, 46px); }
  .tile .name { font-size: clamp(11px, 2.6vw, 16px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
