:root {
  --bg: #F4F1EA;
  --ink: #2B2B2B;
  --ink-soft: #6B6B6B;
  --panel: #FFFFFF;
  --line: #E2DDD3;
  --accent: #4A7FB5;
  --danger: #B5544A;
  --gap: 10px;
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Arial Rounded MT Bold", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body { overflow: hidden; }

button { font: inherit; color: inherit; }

/* ---------- Cuadrícula principal ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: var(--gap);
  height: 100dvh;
  padding: calc(var(--gap) + var(--safe-top)) var(--gap) calc(var(--gap) + var(--safe-bottom));
}

.tile {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: 1fr auto;
  align-items: center;
  gap: 0 6px;
  padding: 8px 12px;
  border: none;
  border-radius: var(--radius);
  background: var(--tile, #A8D8EA);
  box-shadow: 0 5px 0 rgba(0, 0, 0, .12);
  cursor: pointer;
  min-height: 80px;
  overflow: hidden;
  transition: transform .12s ease, box-shadow .12s ease;
  touch-action: manipulation;
}

.tile:active, .tile.pressed {
  transform: translateY(4px) scale(.98);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .12);
}

.tile:focus-visible { outline: 4px solid var(--accent); outline-offset: 2px; }

.tile .num {
  grid-row: 1 / span 2;
  font-size: clamp(44px, 13vw, 84px);
  font-weight: 800;
  line-height: 1;
  min-width: 1.1em;
  text-align: center;
}

.tile .pic {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 0;
  font-size: clamp(34px, 10vw, 64px);
  line-height: 1;
}

.tile .pic img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 10px;
}

.tile .label {
  font-size: clamp(13px, 3.8vw, 18px);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hide-labels .tile .label { display: none; }
.hide-labels .tile { grid-template-rows: 1fr; }

/* ---------- Zona del modo adulto ---------- */
.adult-hotspot {
  position: fixed;
  top: calc(4px + var(--safe-top));
  right: 4px;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid rgba(0, 0, 0, .08);
  border-radius: 50%;
  background: rgba(255, 255, 255, .75);
  opacity: .7;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  z-index: 5;
}

.adult-hotspot span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 18px; filter: grayscale(1); }
.adult-hotspot svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.adult-hotspot .ring-bg { fill: none; }
.adult-hotspot .ring {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 94.25;
  stroke-dashoffset: 94.25;
}
.adult-hotspot.holding { opacity: 1; }

/* ---------- Reproductor ---------- */
.player {
  position: fixed;
  inset: 0;
  background: #1E1E1E;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .35s ease;
}
.player.visible { opacity: 1; }
.player[hidden] { display: none; }

.player video { width: 100%; height: 100%; object-fit: contain; background: #1E1E1E; }

.player-btn.home {
  position: absolute;
  top: calc(14px + var(--safe-top));
  left: 14px;
  width: 72px;
  height: 72px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, .92);
  font-size: 36px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .2);
  touch-action: manipulation;
}
.player-btn.home:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, .2); }

.end-choices {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  background: rgba(30, 30, 30, .55);
}
.end-choices[hidden] { display: none; }

.big-choice {
  width: 128px;
  height: 128px;
  border: none;
  border-radius: 32px;
  background: #fff;
  font-size: 64px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .25);
  touch-action: manipulation;
}
.big-choice:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0, 0, 0, .25); }

/* ---------- Panel modo adulto ---------- */
.adult-panel {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  -webkit-user-select: text;
  user-select: text;
}
.adult-panel[hidden] { display: none; }

.adult-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.adult-header h1 { margin: 0; font-size: 22px; }

.adult-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px calc(32px + var(--safe-bottom));
  -webkit-overflow-scrolling: touch;
}

.options, .slot-editor {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 14px;
}
.options summary { font-size: 18px; cursor: pointer; margin-bottom: 8px; }

.toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  font-size: 16px;
  border-bottom: 1px solid var(--line);
}
.toggle input { width: 24px; height: 24px; accent-color: var(--accent); flex-shrink: 0; }

.slot-editors { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.slot-editor { margin: 0; }

.slot-head { display: flex; align-items: center; gap: 12px; }
.slot-preview {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 14px;
  background: var(--tile);
  min-width: 104px;
  height: 64px;
}
.slot-preview .num { font-size: 34px; font-weight: 800; }
.slot-preview .pic { font-size: 32px; display: flex; height: 100%; align-items: center; }
.slot-preview .pic img { max-height: 48px; max-width: 48px; border-radius: 6px; object-fit: contain; }

.label-input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
}

.field-title { margin: 14px 0 6px; font-size: 14px; color: var(--ink-soft); }
.video-status { font-size: 13px; }

.emoji-row { display: flex; flex-wrap: wrap; gap: 6px; }
.emoji-row button {
  width: 44px;
  height: 44px;
  font-size: 26px;
  border: 2px solid transparent;
  border-radius: 10px;
  background: var(--bg);
  padding: 0;
}
.emoji-row button.selected { border-color: var(--accent); background: #E6EEF7; }

.color-row { display: flex; flex-wrap: wrap; gap: 8px; }
.color-row button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid transparent;
  padding: 0;
}
.color-row button.selected { border-color: var(--ink); }

.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 11px 16px;
  font-size: 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.danger { margin-top: 14px; color: var(--danger); border-color: var(--danger); background: transparent; }

@media (prefers-reduced-motion: reduce) {
  .tile, .player { transition: none; }
}

/* ---------- YouTube ---------- */
.yt-holder { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.yt-holder[hidden] { display: none; }
.yt-holder iframe { width: 100%; height: 100%; border: 0; }

/* Botón de YouTube sin conexión: apagado */
.tile.offline { opacity: .35; filter: grayscale(.8); }
.tile.offline::after {
  content: '📶';
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 18px;
}

/* ---------- Teclado de PIN ---------- */
.pin-pad {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(244, 241, 234, .97);
}
.pin-pad[hidden] { display: none; }
.pin-box { width: 100%; max-width: 320px; text-align: center; }
.pin-title { font-size: 22px; margin: 0 0 16px; }
.pin-dots { display: flex; justify-content: center; gap: 12px; min-height: 18px; }
.pin-dots span { width: 16px; height: 16px; border-radius: 50%; background: var(--ink); }
.pin-error { min-height: 22px; color: var(--danger); margin: 10px 0; font-size: 15px; }
.pin-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pin-keys button {
  height: 68px;
  font-size: 28px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  touch-action: manipulation;
}
.pin-keys button:active { background: #E6EEF7; }
.pin-keys button[data-k="ok"] { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- Panel: estado y vídeo ---------- */
.adult-header { gap: 10px; }
.adult-header h1 { flex: 1; }
.save-status { font-size: 14px; color: var(--ink-soft); }
.save-status.error { color: var(--danger); }
.hint { font-size: 14px; color: var(--ink-soft); margin: 12px 0 0; }

.segmented { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.segmented button {
  flex: 1;
  padding: 11px 6px;
  font-size: 15px;
  border: none;
  background: var(--bg);
}
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button[aria-checked="true"] { background: var(--accent); color: #fff; }

.video-pane { margin-top: 10px; }
.video-pane[hidden] { display: none; }
.video-status, .pic-status { font-size: 14px; color: var(--ink-soft); margin: 0 0 8px; }
.pic-status { align-self: center; margin: 0; }
.upload-progress { width: 100%; height: 14px; margin-top: 10px; accent-color: var(--accent); }

.yt-input {
  width: 100%;
  font: inherit;
  font-size: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
}
.yt-error { color: var(--danger); font-size: 14px; min-height: 0; margin: 6px 0 0; }
.yt-thumb { width: 100%; max-width: 240px; border-radius: 10px; margin-top: 8px; display: block; }
.yt-thumb[hidden] { display: none; }

/* ---------- Deslizar para refrescar (solo modo adulto) ---------- */
.adult-body { overscroll-behavior-y: contain; position: relative; }
.pull-indicator {
  height: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
}
.pull-indicator span {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin-bottom: 8px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 20px;
  transition: transform .2s ease;
}
.pull-indicator.ready span { transform: rotate(180deg); background: #E6EEF7; }
.pull-indicator.loading span { animation: spin .9s linear infinite; }
.pull-indicator.loading span::before { content: '↻'; }
.pull-indicator.loading span { font-size: 0; }
.pull-indicator.loading span::before { font-size: 22px; }
.pull-indicator.animate { transition: height .25s ease; }
@keyframes spin { to { transform: rotate(360deg); } }

.btn.refresh { margin-top: 14px; margin-right: 8px; }

.app-version { font-size: 13px; font-weight: normal; color: var(--ink-soft); margin-left: 6px; }
