/* Presentazo — control remoto (celular) */

:root {
  --bg: #000;
  --surface: #111113;
  --surface-2: #1b1b1e;
  --surface-3: #262629;
  --line: rgba(255, 255, 255, .07);
  --text: #f5f5f7;
  --muted: #8e8e93;
  --accent: #ff3b30;
  --ok: #34c759;
  --warn: #ff9f0a;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --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;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  position: fixed;
  inset: 0;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 var(--font);
  letter-spacing: -.01em;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
  pointer-events: none;
}

[hidden] { display: none !important; }
.muted { color: var(--muted); }

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: var(--safe-t) var(--safe-r) 0 var(--safe-l);
}

/* ---------------------------------------------------------- cabecera */

.top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 56px;
  padding: 0 12px 0 14px;
}

.status {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  max-width: 100%;
  padding: 0 12px 0 10px;
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
}
.status .dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.app[data-conn="connected"] .status .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(52, 199, 89, .22); }
.app[data-conn="waiting"] .status .dot,
.app[data-conn="connecting"] .status .dot,
.app[data-conn="reconnecting"] .status .dot,
.app[data-conn="offline"] .status .dot { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
#status-text { overflow: hidden; text-overflow: ellipsis; }

.timer {
  min-width: 76px;
  height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  color: var(--muted);
  transition: color .2s ease, background .2s ease;
}
.timer.running { color: var(--text); }
.timer:active { background: var(--surface); }

.icon-btn {
  justify-self: end;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--muted);
}
.icon-btn:active { background: var(--surface); color: var(--text); }

.target {
  height: 22px;
  padding: 0 18px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.target.warn { color: var(--warn); }

/* ---------------------------------------------------------- vistas */

.views {
  position: relative;
  flex: 1;
  min-height: 0;
}

.view {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  gap: 10px;
  padding: 8px 14px 12px;
}
.app[data-view="slides"] .view[data-view="slides"],
.app[data-view="pointer"] .view[data-view="pointer"],
.app[data-view="mouse"] .view[data-view="mouse"],
.app[data-view="keys"] .view[data-view="keys"] {
  display: flex;
  animation: fade .18s ease;
}

@keyframes fade { from { opacity: 0; transform: translateY(4px); } }
@keyframes pulse { 50% { opacity: .35; } }

/* pulsado genérico */
.chip, .prev, .next, .mini-nav button, .mouse-buttons button, .keys button, .tool, .segmented button {
  transition: transform .12s ease, background .15s ease, color .15s ease;
}
.chip:active, .prev:active, .mini-nav button:active, .mouse-buttons button:active, .keys button:active, .tool:active {
  transform: scale(.96);
  background: var(--surface-3);
}

/* ---------------------------------------------------------- diapositivas */

.quick {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 70px;
  border-radius: 20px;
  background: var(--surface);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--muted);
}
.chip svg { color: var(--text); }
.chip.on { background: var(--text); color: #000; }
.chip.on svg { color: #000; }
.chip.on .fillable { fill: currentColor; }

.prev {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 84px;
  flex: none;
  border-radius: 24px;
  background: var(--surface);
  font-size: 16px;
  font-weight: 500;
}
.prev svg { width: 26px; height: 26px; }

.next {
  position: relative;
  flex: 1;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 30px;
  background: linear-gradient(180deg, #1f1f22 0%, #161618 100%);
  box-shadow: inset 0 0 0 1px var(--line);
  touch-action: none;
  overflow: hidden;
}
.next svg { width: 72px; height: 72px; stroke-width: 1.6; }
.next-label { font-size: 19px; font-weight: 600; letter-spacing: -.02em; }
.next-hint { font-size: 12.5px; color: var(--muted); }
.next::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 2px var(--accent);
  opacity: 0;
  transition: opacity .35s ease;
  pointer-events: none;
}
.next.pressed { transform: scale(.985); background: linear-gradient(180deg, #27272b, #1c1c1f); }
.next.flash::after { opacity: .9; transition: none; }

/* ---------------------------------------------------------- superficies táctiles */

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 4px;
  border-radius: 14px;
  background: var(--surface);
}
.segmented button {
  height: 36px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
}
.segmented button[aria-pressed="true"] {
  background: var(--surface-3);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}

.pad {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: 28px;
  background:
    radial-gradient(circle at 1px 1px, rgba(255, 255, 255, .07) 1px, transparent 1.5px) 0 0 / 22px 22px,
    var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
  touch-action: none;
  overflow: hidden;
}
.pad-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  font-size: 14px;
  line-height: 1.45;
  color: var(--muted);
  pointer-events: none;
  transition: opacity .25s ease;
}
.pad-hint svg { width: 30px; height: 30px; opacity: .7; }
.pad-hint span { white-space: pre-line; }
.pad-wrap .pad-hint { padding-right: 64px; }
.pad.active .pad-hint { opacity: 0; }
.pad.air { background: radial-gradient(circle at 50% 45%, rgba(255, 59, 48, .14), transparent 60%), var(--surface); }

.touch-dot {
  position: absolute;
  left: 0;
  top: 0;
  width: 64px;
  height: 64px;
  margin: -32px 0 0 -32px;
  border-radius: 50%;
  background: rgba(255, 59, 48, .14);
  box-shadow: inset 0 0 0 1.5px rgba(255, 59, 48, .55);
  opacity: 0;
  transition: opacity .2s ease;
  pointer-events: none;
}
.pad.active .touch-dot { opacity: 1; }
#mouse-dot { background: rgba(255, 255, 255, .08); box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .3); }

.pen-tools {
  display: none;
  align-items: center;
  gap: 8px;
  height: 48px;
  padding: 0 6px 0 12px;
  border-radius: 16px;
  background: var(--surface);
}
.app[data-ptr="pen"] .pen-tools { display: flex; }
.swatches { display: flex; flex: 1; gap: 12px; }
.swatches button {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--sw);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .25);
  transition: transform .15s ease;
}
.swatches button[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--sw); transform: scale(.92); }
.tool {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  color: var(--muted);
}

.mini-nav {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr;
  gap: 8px;
}
.mini-nav button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 64px;
  border-radius: 20px;
  background: var(--surface);
  font-size: 14px;
  font-weight: 500;
}
.mini-nav button svg { width: 26px; height: 26px; }
.mini-nav .air { color: var(--muted); }
.mini-nav .air svg { width: 22px; height: 22px; }
.mini-nav .air.on { background: var(--accent); color: #fff; }

/* ---------------------------------------------------------- mouse */

.pad-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
}
.pad-wrap .pad { flex: 1; }
.scroll-strip {
  position: absolute;
  top: 10px;
  right: 10px;
  bottom: 10px;
  width: 40px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  background: var(--surface-2);
  color: var(--muted);
  touch-action: none;
}
.scroll-strip.active { background: var(--surface-3); color: var(--text); }

.mouse-buttons {
  display: grid;
  grid-template-columns: 1fr .8fr 1fr;
  gap: 8px;
}
.mouse-buttons button {
  height: 64px;
  border-radius: 20px;
  background: var(--surface);
  font-size: 14px;
  font-weight: 500;
}
.mouse-buttons #m-hold { color: var(--muted); }
.mouse-buttons #m-hold.on { background: var(--text); color: #000; }

/* ---------------------------------------------------------- teclado */

.kbd-wrap { position: relative; }
.kbd-ph {
  position: absolute;
  left: 19px;
  top: 16px;
  font-size: 17px;
  line-height: 1.45;
  color: #5a5a5f;
  pointer-events: none;
  opacity: 0;
}
.kbd-wrap.empty .kbd-ph { opacity: 1; }

textarea {
  display: block;
  width: 100%;
  min-height: 120px;
  padding: 16px 18px;
  border: 0;
  border-radius: 22px;
  background: var(--surface);
  color: var(--text);
  font: 17px/1.45 var(--font);
  resize: none;
  outline: none;
  box-shadow: inset 0 0 0 1px var(--line);
  -webkit-user-select: text;
  user-select: text;
}
textarea:focus { box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .25); }
.hint { margin: 0 4px; font-size: 12.5px; color: var(--muted); }

.keys {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.keys button {
  display: grid;
  place-items: center;
  height: 58px;
  border-radius: 16px;
  background: var(--surface);
  font-size: 14px;
  font-weight: 500;
}

/* ---------------------------------------------------------- pestañas */

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(6px + var(--safe-b));
  border-top: 1px solid var(--line);
  background: rgba(0, 0, 0, .9);
}
.tabs button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 0;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  color: #6c6c70;
  transition: color .15s ease;
}
.tabs button[aria-selected="true"] { color: var(--text); }
.tabs button svg { width: 24px; height: 24px; }

/* ---------------------------------------------------------- pantalla de conexión */

.gate {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-t)) 32px calc(24px + var(--safe-b));
  background: var(--bg);
  text-align: center;
  transition: opacity .3s ease, visibility .3s;
}
.app.ready .gate { opacity: 0; visibility: hidden; pointer-events: none; }
.app.instant .gate, .app.instant .view { transition: none; animation: none !important; }
.gate-inner { display: flex; flex-direction: column; align-items: center; max-width: 320px; }
.gate-logo { border-radius: 22px; margin-bottom: 22px; }
.gate h1 { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: -.025em; }
.gate p { margin: 8px 0 0; font-size: 15px; line-height: 1.5; color: var(--muted); }
.gate-credit { position: absolute; bottom: calc(18px + var(--safe-b)); font-size: 12px; color: #48484a; }

.spinner {
  width: 26px;
  height: 26px;
  margin-top: 26px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, .12);
  border-top-color: var(--text);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 50px;
  margin-top: 24px;
  padding: 0 26px;
  border-radius: 16px;
  background: var(--surface-2);
  font-size: 16px;
  font-weight: 600;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--text); color: #000; }
.btn.danger { color: var(--accent); }

/* ---------------------------------------------------------- ajustes (hoja inferior) */

.sheet {
  width: 100%;
  max-width: 560px;
  margin: auto auto 0;
  padding: 8px 20px calc(18px + var(--safe-b));
  border: 0;
  border-radius: 26px 26px 0 0;
  background: var(--surface);
  color: var(--text);
}
.sheet[open] { animation: rise .28s cubic-bezier(.2, .8, .2, 1); }
.sheet::backdrop { background: rgba(0, 0, 0, .55); }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.sheet form { display: flex; flex-direction: column; }
.sheet-handle { width: 38px; height: 5px; margin: 0 auto 14px; border-radius: 3px; background: var(--surface-3); }
.sheet h2 { margin: 0 0 8px; font-size: 20px; font-weight: 650; letter-spacing: -.02em; }
.field { display: flex; flex-direction: column; gap: 10px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.field-row { display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
.field output { color: var(--muted); font-variant-numeric: tabular-nums; }
.sheet .btn { width: 100%; margin-top: 12px; }
.sheet .btn.danger { margin-top: 18px; background: var(--surface-2); }
.credit { margin: 16px 0 0; text-align: center; font-size: 12px; color: var(--muted); }
.credit a { color: inherit; }

input[type="range"] {
  width: 100%;
  height: 28px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
}
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--surface-3); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px;
  height: 26px;
  margin-top: -11px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .4);
}

.switch {
  -webkit-appearance: none;
  appearance: none;
  flex: none;
  position: relative;
  width: 50px;
  height: 30px;
  margin: 0;
  border-radius: 999px;
  background: var(--surface-3);
  transition: background .2s ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .3);
  transition: transform .22s cubic-bezier(.3, .7, .4, 1);
}
.switch:checked { background: var(--ok); }
.switch:checked::after { transform: translateX(20px); }

/* ---------------------------------------------------------- aviso */

.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-t) + 64px);
  z-index: 20;
  max-width: calc(100% - 48px);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(38, 38, 41, .96);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transform: translate(-50%, -8px);
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* tablets: columna centrada del tamaño de un celular grande */
@media (min-width: 700px) and (min-height: 600px) {
  .app { inset: 0 max(0px, calc((100% - 600px) / 2)); }
}

/* pantallas bajas: compactar */
@media (max-height: 640px) {
  .chip { height: 60px; }
  .prev { height: 68px; }
  .mini-nav button, .mouse-buttons button { height: 56px; }
  .keys button { height: 50px; }
}

/* horizontal: dos columnas en la vista de diapositivas */
@media (orientation: landscape) and (max-height: 500px) {
  .view[data-view="slides"] { display: none; }
  .app[data-view="slides"] .view[data-view="slides"] {
    display: grid;
    grid-template-columns: 1fr 1.6fr;
    grid-template-rows: auto 1fr;
  }
  .quick { grid-column: 1 / -1; }
  .prev { height: auto; }
  .next { min-height: 0; }
  .chip { height: 48px; flex-direction: row; }
  .top { height: 46px; }
}
