/* ============================================================
   Kid Launcher CSS
   - Admin pages: clean, dense, desktop-friendly
   - Kid pages: huge tap targets, no scroll, full-bleed
   ============================================================ */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
body { background: #f4f6fb; color: #1f2733; min-height: 100vh; }
a { color: #2b6cb0; text-decoration: none; }
a:hover { text-decoration: underline; }

.flashes { position: fixed; top: 12px; right: 12px; z-index: 50; display: grid; gap: 8px; }
.flash { padding: 10px 14px; border-radius: 8px; font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.12); }
.flash.success { background: #d1fae5; color: #065f46; }
.flash.error { background: #fee2e2; color: #991b1b; }

/* Kid mode: auto-fade flashes so toasts don't linger */
.kid-page .flashes { top: 24px; right: 24px; }
.kid-page .flash {
  font-size: 20px; padding: 14px 22px; border-radius: 14px;
  animation: kidFlashFade 3s ease forwards;
}
@keyframes kidFlashFade {
  0%   { opacity: 0; transform: translateY(-8px); }
  10%  { opacity: 1; transform: translateY(0); }
  80%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(-8px); pointer-events: none; }
}

/* ---------- Buttons ---------- */
.big-btn {
  display: inline-block; padding: 16px 28px; font-size: 22px; font-weight: 600;
  background: #2b6cb0; color: #fff; border: none; border-radius: 12px; cursor: pointer;
  text-decoration: none; min-height: 56px;
}
.big-btn:hover { background: #1e4e8c; }
.big-btn.small { padding: 10px 16px; font-size: 16px; min-height: 40px; }
.link-btn { background: none; border: none; color: #2b6cb0; cursor: pointer; padding: 0; font-size: inherit; }
.link-btn.danger { color: #b91c1c; }
.link-btn:hover { text-decoration: underline; }

/* ---------- PIN entry / setup ---------- */
.pin-page, .setup-page {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background: linear-gradient(135deg, #2b6cb0 0%, #6b46c1 100%);
}
.pin-shell, .setup-shell {
  background: #fff; padding: 40px; border-radius: 24px; max-width: 420px; width: calc(100% - 32px);
  box-shadow: 0 20px 50px rgba(0,0,0,.25); text-align: center;
}
.pin-shell h1, .setup-shell h1 { margin: 0 0 24px; font-size: 28px; }
.setup-shell p { color: #4b5563; margin-bottom: 24px; }
.setup-shell label { display: block; text-align: left; margin: 16px 0; font-weight: 500; }
.pin-input {
  width: 100%; padding: 18px; font-size: 32px; text-align: center; letter-spacing: .5em;
  border: 2px solid #d1d5db; border-radius: 12px; margin: 16px 0; background: #f9fafb;
}
.pin-input:focus { outline: none; border-color: #2b6cb0; background: #fff; }
.kid-link { display: inline-block; margin-top: 24px; font-size: 14px; color: #6b7280; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-12px); }
  75% { transform: translateX(12px); }
}
.shake { animation: shake .35s ease-in-out 2; }

/* ---------- Admin layout ---------- */
.admin-page { background: #f4f6fb; }
.admin-header {
  background: #1f2733; color: #fff; padding: 12px 24px;
  display: flex; align-items: center; gap: 24px; box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
.admin-brand { color: #fff; font-weight: 700; font-size: 18px; text-decoration: none; }
.admin-nav { display: flex; gap: 18px; flex: 1; }
.admin-nav a { color: #cbd5e1; }
.admin-nav a:hover { color: #fff; text-decoration: none; }
.admin-main { max-width: 1100px; margin: 0 auto; padding: 24px; }
.admin-main h1 { font-size: 28px; margin-top: 0; }
.admin-main h2 { font-size: 20px; margin-top: 32px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 32px; }
.card {
  background: #fff; padding: 24px; border-radius: 12px; text-align: center;
  border: 1px solid #e5e7eb; color: inherit; text-decoration: none;
}
.card:hover { border-color: #2b6cb0; }
.card-num { font-size: 40px; font-weight: 700; color: #2b6cb0; }
.card-label { font-size: 16px; color: #6b7280; margin-top: 4px; }
.now-playing .ok { color: #059669; font-weight: 600; }
.now-playing .bad { color: #b91c1c; font-weight: 600; }

/* ---------- Remote ---------- */
#now-playing { margin-bottom: 24px; }
.now-playing-card {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 12px;
  padding: 16px; min-height: 96px;
}
.now-playing-card.offline { background: #fef2f2; border-color: #fecaca; }
.np-empty, .np-idle {
  display: flex; flex-direction: column; gap: 4px;
  color: #4b5563; font-size: 16px;
}
.np-empty strong, .np-idle strong { color: #1f2733; font-size: 18px; }
.np-empty.error strong { color: #991b1b; }
.np-empty p { margin: 0; font-size: 14px; }
.np-now { display: flex; gap: 16px; align-items: center; }
.np-poster {
  width: 72px; height: 108px; object-fit: cover; border-radius: 6px;
  background: #ddd; flex: 0 0 auto;
}
.np-info { flex: 1; min-width: 0; }
.np-title { font-size: 18px; font-weight: 600; margin-bottom: 4px; }
.np-meta { font-size: 14px; color: #4b5563; margin-bottom: 6px; }
.np-time { font-size: 13px; color: #6b7280; font-variant-numeric: tabular-nums; margin-bottom: 6px; }
.np-bar { height: 4px; background: #e5e7eb; border-radius: 2px; overflow: hidden; }
.np-bar-fill { height: 100%; background: #2b6cb0; transition: width .4s ease; }

.remote-block { margin-bottom: 20px; }
.remote-block h2 { font-size: 16px; text-transform: uppercase; letter-spacing: .08em; color: #6b7280; margin: 16px 0 10px; }
.remote-row { display: flex; gap: 10px; flex-wrap: wrap; }
.remote-btn {
  flex: 1 1 80px; min-width: 80px; min-height: 80px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  background: #fff; border: 1px solid #d1d5db; border-radius: 12px;
  font-size: 14px; cursor: pointer; padding: 10px;
  transition: transform .08s ease, background .15s ease;
}
.remote-btn:hover { background: #f3f4f6; }
.remote-btn:active { transform: scale(0.96); background: #e5e7eb; }
.rb-icon { font-size: 28px; line-height: 1; }
.rb-label { font-size: 12px; color: #4b5563; }
.toggle-btn.on  { background: #d1fae5; border-color: #059669; }
.toggle-btn.off { background: #fee2e2; border-color: #fecaca; }
.on-pill  { background: #059669; color: #fff; padding: 1px 6px; border-radius: 99px; font-size: 10px; margin-left: 4px; }
.off-pill { background: #9ca3af; color: #fff; padding: 1px 6px; border-radius: 99px; font-size: 10px; margin-left: 4px; }

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 80px);
  grid-template-rows: repeat(3, 80px);
  gap: 6px; justify-content: start; margin-bottom: 10px;
}
.dpad-btn {
  background: #fff; border: 1px solid #d1d5db; border-radius: 12px;
  font-size: 22px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform .08s ease, background .15s ease;
}
.dpad-btn:active { transform: scale(0.94); background: #e5e7eb; }
.dpad-up    { grid-column: 2; grid-row: 1; }
.dpad-left  { grid-column: 1; grid-row: 2; }
.dpad-ok    { grid-column: 2; grid-row: 2; background: #2b6cb0; color: #fff; border-color: #2b6cb0; font-size: 16px; }
.dpad-right { grid-column: 3; grid-row: 2; }
.dpad-down  { grid-column: 2; grid-row: 3; }

@media (max-width: 600px) {
  .remote-btn { min-height: 72px; }
  .dpad { grid-template-columns: repeat(3, 72px); grid-template-rows: repeat(3, 72px); }
}

/* ---------- Presets ---------- */
.presets-section {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 12px;
  padding: 20px; margin-bottom: 24px;
}
.presets-section h2 { margin-top: 0; }
.presets-list { display: flex; flex-wrap: wrap; gap: 12px; margin: 12px 0 16px; }
.preset-pill {
  display: flex; align-items: center; gap: 10px;
  background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 999px;
  padding: 6px 6px 6px 16px;
}
.preset-pill.current { background: #d1fae5; border-color: #059669; }
.preset-info { display: flex; flex-direction: column; line-height: 1.2; }
.preset-info strong { font-size: 14px; }
.preset-info small  { font-size: 11px; color: #6b7280; }
.preset-pill form { margin: 0; }
.preset-pill .big-btn.small { padding: 6px 14px; min-height: 32px; font-size: 13px; }
.preset-pill .link-btn.danger { font-size: 22px; padding: 0 8px; line-height: 1; }
.preset-save-form { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.preset-save-form input {
  flex: 1; min-width: 200px;
  padding: 10px 12px; font-size: 16px;
  border: 1px solid #d1d5db; border-radius: 8px;
}

/* ---------- Tiles management ---------- */
.tile-section { background: #fff; border-radius: 12px; padding: 20px; margin-bottom: 24px; border: 1px solid #e5e7eb; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.section-head h2 { margin: 0; }
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; min-height: 50px; }
.tile-card {
  background: #f9fafb; border-radius: 8px; overflow: hidden; border: 1px solid #e5e7eb;
  display: flex; flex-direction: column; position: relative;
  cursor: grab; touch-action: manipulation;
  transition: box-shadow .15s ease, transform .08s ease;
}
.tile-card:active { cursor: grabbing; }
.tile-card:hover { box-shadow: 0 6px 16px rgba(0,0,0,.10); border-color: #c4cdd9; }
.tile-card.hidden-tile { opacity: 0.5; }
/* SortableJS drag states */
.tile-ghost    { opacity: 0.35; }
.tile-chosen   { box-shadow: 0 12px 24px rgba(0,0,0,.18); transform: scale(1.02); }
.tile-dragging { box-shadow: 0 16px 32px rgba(0,0,0,.25); }
.admin-thumb {
  display: block; width: 100%; aspect-ratio: 1/1;
  overflow: hidden; background: #ddd;
}
.admin-thumb.cat-shows { aspect-ratio: 4/3; }
.admin-thumb img {
  width: 100%; height: 100%;
  object-fit: cover; display: block;
}
.tile-meta { padding: 8px; }
.tile-title { font-size: 14px; font-weight: 600; margin-bottom: 6px; line-height: 1.2; }
.tile-actions { display: flex; gap: 12px; font-size: 13px; }
.tile-actions form { margin: 0; }
.empty { color: #9ca3af; font-style: italic; padding: 16px; }

/* ---------- Add/Edit tile ---------- */
.add-tile-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 24px; margin-top: 16px; }
@media (max-width: 800px) { .add-tile-grid { grid-template-columns: 1fr; } }
.search-input {
  width: 100%; padding: 12px 16px; font-size: 18px; border: 2px solid #d1d5db;
  border-radius: 10px; margin-bottom: 16px;
}
.search-input:focus { outline: none; border-color: #2b6cb0; }
.search-results { max-height: 60vh; overflow: auto; }
.search-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.search-card {
  background: #fff; border: 2px solid #e5e7eb; border-radius: 8px; padding: 0; cursor: pointer;
  overflow: hidden; text-align: left;
}
.search-card:hover { border-color: #2b6cb0; }
.search-card.picked { border-color: #059669; box-shadow: 0 0 0 3px #d1fae5; }
.search-card img { width: 100%; aspect-ratio: 2/3; object-fit: cover; display: block; background: #ddd; }
.search-card .no-poster {
  width: 100%; aspect-ratio: 2/3; background: #6b7280; color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 40px; font-weight: 700;
}
.search-card-meta { padding: 6px 8px; font-size: 12px; }
.search-card-meta strong { display: block; line-height: 1.2; margin-bottom: 2px; }
.search-card-meta small { color: #6b7280; }

.edit-form, #tile-form { display: grid; gap: 14px; max-width: 500px; }
.edit-form label, #tile-form label { display: grid; gap: 4px; font-weight: 500; }
.edit-form label.checkbox, #tile-form label.checkbox { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.edit-form input[type="text"], .edit-form input[type="number"],
#tile-form input[type="text"], #tile-form input[type="number"] {
  padding: 10px; font-size: 16px; border: 1px solid #d1d5db; border-radius: 8px;
}
.picked-preview {
  display: flex; gap: 12px; align-items: center; padding: 12px;
  background: #f3f4f6; border-radius: 8px; min-height: 72px;
}
.picked-preview.empty { color: #9ca3af; font-style: italic; justify-content: center; }
.picked-preview img { width: 60px; height: 90px; object-fit: cover; border-radius: 4px; }

/* Image picker */
.image-picker { border: 1px solid #e5e7eb; border-radius: 12px; padding: 16px; margin: 0; background: #fafbff; }
.image-picker legend { font-weight: 600; padding: 0 6px; }
.image-picker summary { cursor: pointer; padding: 6px 0; font-weight: 500; }
.image-picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin-top: 12px; }
.image-pick-form { margin: 0; }
.image-pick-card {
  width: 100%; padding: 0; border: 2px solid #e5e7eb; border-radius: 8px;
  background: #fff; cursor: pointer; overflow: hidden; text-align: left;
  display: block;
}
.image-pick-card:hover { border-color: #2b6cb0; }
.image-pick-card.current { border-color: #059669; box-shadow: 0 0 0 3px #d1fae5; }
.image-pick-card img { width: 100%; height: 110px; object-fit: cover; display: block; background: #ddd; }
.image-pick-meta { display: block; padding: 6px 8px; font-size: 12px; color: #4b5563; }
.image-pick-meta small { display: block; color: #9ca3af; }

/* Crop editor */
.crop-editor { border: 1px solid #e5e7eb; border-radius: 12px; padding: 16px; margin: 0; background: #fafbff; }
.crop-editor legend { font-weight: 600; padding: 0 6px; }
.crop-editor .hint { color: #6b7280; font-size: 13px; margin: 4px 0 12px; }
.crop-stage {
  width: 280px; aspect-ratio: 1/1;
  background: #2a2a2a; overflow: hidden;
  border-radius: 12px; cursor: grab; touch-action: none;
  user-select: none; -webkit-user-select: none;
}
.crop-stage.cat-shows { aspect-ratio: 4/3; width: 320px; }
.crop-stage:active { cursor: grabbing; }
.crop-stage img {
  width: 100%; height: 100%;
  object-fit: cover;
  pointer-events: none;
  -webkit-user-drag: none;
  transition: transform .05s linear;
}
.crop-editor label { display: block; margin-top: 12px; font-weight: 500; }
.crop-editor input[type="range"] { width: 280px; display: block; margin-top: 4px; }
#crop-reset { margin-top: 8px; }

/* ---------- Settings ---------- */
.settings-block { background: #fff; padding: 20px; border-radius: 12px; margin-bottom: 20px; border: 1px solid #e5e7eb; }
.settings-block h2 { margin-top: 0; }
.settings-block label { display: block; margin: 12px 0; }
.settings-block input, .settings-block select {
  width: 100%; max-width: 400px; padding: 10px; font-size: 16px; border: 1px solid #d1d5db; border-radius: 8px; margin-top: 4px;
}
.test-cast-form { display: flex; gap: 12px; align-items: center; margin-top: 12px; }
.hint { color: #6b7280; font-size: 14px; }

/* ============================================================
   Kid mode
   ============================================================ */
.kid-page {
  background: #fff7e6;
  height: 100vh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}
.kid-page img,
.kid-page svg,
.kid-page .poster-tile,
.kid-page .cat-btn {
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  user-select: none;
  -webkit-user-select: none;
}
.kid-page .poster-frame img {
  pointer-events: none; /* taps fall through to the parent button */
}

.kid-shell {
  display: grid;
  grid-template-columns: 200px 1fr;
  height: 100vh;
}

.kid-sidebar {
  background: #fde68a;
  display: flex; flex-direction: column;
  padding: 24px 12px; gap: 16px;
}

.cat-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; min-height: 110px;
  background: #fff; border: 4px solid transparent; border-radius: 24px;
  padding: 12px; cursor: pointer;
  font-size: 24px; font-weight: 700; color: #1f2733;
  transition: transform .12s ease;
}
.cat-btn:active { transform: scale(0.96); }
.cat-btn.active { border-color: #2b6cb0; }
.cat-btn .cat-icon { width: 56px; height: 56px; }
.cat-btn .cat-label { font-size: 22px; }
.cat-btn.cat-movies { background: #ffe4e1; }
.cat-btn.cat-shows  { background: #d4f1ff; }
.cat-btn.cat-songs  { background: #fff4c2; }
.cat-btn.cat-books  { background: #d4f7d4; }
.cat-btn.cat-movies.active, .cat-btn.cat-shows.active,
.cat-btn.cat-songs.active, .cat-btn.cat-books.active { border-color: #1f2733; }

.kid-grid {
  padding: 24px;
  overflow: hidden;
  display: flex; flex-direction: column;
  min-height: 0;
}
.grid-wrap {
  flex: 1; display: flex; flex-direction: column;
  min-height: 0; overflow: hidden;
}
.poster-grid {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 24px;
  justify-content: center;
}
.poster-form { margin: 0; height: 100%; min-height: 0; }
.poster-tile {
  display: flex; flex-direction: column;
  width: 100%; height: 100%;
  padding: 0; background: none; border: none; cursor: pointer;
  border-radius: 18px; overflow: hidden; box-shadow: 0 6px 20px rgba(0,0,0,.18);
  transition: transform .15s ease;
  min-height: 0;
}
.poster-tile:active { transform: scale(0.95); }
.poster-frame {
  display: block; flex: 1; min-height: 0;
  width: 100%; aspect-ratio: 1/1;
  overflow: hidden; background: #444;
}
.poster-frame.cat-shows { aspect-ratio: 4/3; }
.poster-frame img {
  width: 100%; height: 100%;
  object-fit: cover; display: block;
}
.poster-title {
  display: block; padding: 12px;
  background: #fff; color: #1f2733; font-size: 20px; font-weight: 700;
  text-align: center; line-height: 1.2;
}

.empty-grid {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; text-align: center; color: #6b7280;
}
.empty-grid p { font-size: 24px; }

.page-nav {
  flex: 0 0 auto;
  display: flex; justify-content: center; align-items: center; gap: 48px;
  padding: 16px 0 8px;
}
.page-btn {
  width: 120px; height: 120px;
  display: flex; align-items: center; justify-content: center;
  background: #fff; border: 5px solid #fde68a;
  border-radius: 50%; cursor: pointer;
  font-size: 56px; color: #1f2733;
  box-shadow: 0 6px 18px rgba(0,0,0,.14);
  transition: transform .1s ease;
}
.page-btn:active { transform: scale(0.92); background: #fef3c7; }
.page-btn:disabled { opacity: 0.2; cursor: default; box-shadow: none; }
.page-indicator {
  font-size: 36px; font-weight: 800; color: #1f2733;
  min-width: 100px; text-align: center;
  font-variant-numeric: tabular-nums;
}

.kid-error { padding: 60px 32px; text-align: center; }
.kid-error h1 { font-size: 36px; }
.kid-error p { font-size: 22px; color: #4b5563; max-width: 600px; margin: 16px auto; }
