/* =========================================================
   PocketDeck — estética oscura premium, mobile-first
   ========================================================= */
:root {
  --bg: #000;
  --bg-2: #0a0a0a;
  --surface: #0f0f0f;
  --surface-2: #181818;
  --line: rgba(255,255,255,.14);
  --text: #fff;
  --muted: #8c8c8c;
  --accent: #fff;
  --accent-2: #fff;
  --danger: #fff;
  --ok: #fff;
  --radius: 10px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --gutter: 16px;
  --card-w: clamp(150px, 42vw, 230px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
[hidden] { display: none !important; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button { font: inherit; color: inherit; }

/* ---------- Vista biblioteca ---------- */
.view { position: fixed; inset: 0; }
#library {
  display: flex; flex-direction: column;
  padding: calc(var(--sat) + 10px) calc(var(--sar) + var(--gutter)) calc(var(--sab) + 10px) calc(var(--sal) + var(--gutter));
  overflow-y: auto; overflow-x: hidden;
}

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -.02em; }
.brand h1 { font-weight: 300; letter-spacing: .02em; text-transform: uppercase; font-size: 17px; }
.brand h1 b { font-weight: 800; }
.brand-mark {
  width: 22px; height: 28px; border-radius: 4px;
  border: 2px solid var(--text);
  position: relative;
}
.brand-mark::after { content: ""; position: absolute; inset: 3px 3px 11px; border-radius: 1px; background: var(--text); }
.status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.pill { padding: 3px 9px; border-radius: 99px; background: var(--surface); border: 1px solid var(--line); }
.pill:empty:not(.dot) { display: none; }
.pill.dot { width: 8px; height: 8px; padding: 0; border: 0; background: var(--text); }
.pill.dot.off { background: transparent; box-shadow: inset 0 0 0 1.5px var(--muted); }
#clock { font-weight: 600; color: var(--text); }

.toolbar { display: flex; gap: 10px; margin-top: 14px; }
.search {
  flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0;
  background: transparent; border: 1px solid var(--line); border-radius: var(--radius); padding: 0 12px; height: 46px;
  color: var(--muted); transition: border-color .2s;
}
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; color: var(--text); font-size: 16px; }
.search input::-webkit-search-cancel-button { filter: invert(.7); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 46px; padding: 0 16px; border-radius: var(--radius); border: 1px solid var(--line);
  background: transparent; cursor: pointer; font-weight: 600; white-space: nowrap;
  transition: transform .12s, background .2s, border-color .2s, opacity .2s;
}
.btn:active { transform: scale(.96); }
.btn:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.icon { width: 52px; padding: 0; }
.btn.danger { border-color: var(--text); font-weight: 700; }
.btn.ghost { background: rgba(0,0,0,.7); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); height: 40px; padding: 0 12px; font-size: 14px; }
@media (max-width: 400px) { #addBtn span { display: none; } #addBtn { width: 46px; padding: 0; } }

.filters { display: flex; gap: 8px; margin: 14px calc(-1 * var(--gutter)) 0; padding: 0 var(--gutter) 4px; overflow-x: auto; scrollbar-width: none; flex: none; }
.filters::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 34px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line);
  background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; letter-spacing: .04em; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip small { opacity: .7; font-weight: 500; }
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ---------- Carrusel horizontal ---------- */
.shelf { flex: 1; display: flex; flex-direction: column; justify-content: center; min-height: 300px; }
.carousel {
  display: flex; gap: 18px; align-items: center;
  overflow-x: auto; overflow-y: visible;
  scroll-snap-type: x mandatory; scroll-behavior: smooth;
  margin: 0 calc(-1 * var(--gutter) - var(--sar)) 0 calc(-1 * var(--gutter) - var(--sal));
  padding: 28px calc(50vw - var(--card-w) / 2);
  scrollbar-width: none; outline: none;
}
.carousel::-webkit-scrollbar { display: none; }
.card {
  position: relative; flex: none; width: var(--card-w); aspect-ratio: 5 / 7;
  scroll-snap-align: center; border-radius: var(--radius); overflow: hidden; cursor: pointer;
  background: var(--surface-2); border: 0; padding: 0;
  box-shadow: none;
  transform: scale(.88); opacity: .5;
  transition: transform .3s cubic-bezier(.2,.8,.2,1), opacity .3s, filter .3s, box-shadow .3s;
}
.card img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.card .sys {
  position: absolute; left: 8px; top: 8px; padding: 2px 8px; border-radius: 8px;
  background: rgba(0,0,0,.8); font-size: 10px; font-weight: 700; letter-spacing: .08em;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.card.active {
  transform: scale(1.04); opacity: 1; filter: none;
  box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--text);
}

.empty { text-align: center; padding: 24px; color: var(--muted); max-width: 440px; margin: 0 auto; }
.empty h2 { color: var(--text); margin: 18px 0 6px; font-size: 20px; }
.empty.small { padding: 40px 0; }
.empty-art {
  width: 120px; height: 160px; margin: 0 auto; border-radius: 16px;
  border: 1.5px dashed rgba(255,255,255,.3);
  background: transparent;
  position: relative;
}
.empty-art::after { content: "+"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 46px; color: rgba(255,255,255,.35); }

/* ---------- Detalles del juego seleccionado ---------- */
.details {
  display: flex; flex-direction: column; gap: 14px;
  background: var(--bg);
  border: 0; border-top: 1px solid var(--line); border-radius: 0; padding: 16px 0 4px;
  flex: none;
}
.details h2 { margin: 6px 0 2px; font-size: 20px; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.meta { margin: 0; color: var(--muted); font-size: 13px; }
.badge { display: inline-block; padding: 0; font-size: 11px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.details-actions { display: flex; gap: 10px; }
.btn.play {
  flex: 1; height: 54px; font-size: 16px; letter-spacing: .06em; text-transform: uppercase; border: 0;
  background: var(--text); color: var(--bg);
}
.btn.play svg { fill: currentColor; stroke: none; }
.btn.icon svg circle { fill: currentColor; stroke: none; }
@media (min-width: 720px) {
  .details { flex-direction: row; align-items: center; justify-content: space-between; max-width: 900px; width: 100%; margin: 0 auto; }
  .details-actions { flex: none; width: 300px; }
}

.hints { display: none; justify-content: center; gap: 22px; margin-top: 14px; color: var(--muted); font-size: 13px; }
.hints kbd {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 5px; margin-right: 4px;
  border-radius: 99px; border: 1px solid var(--text); color: var(--text); font: 700 11px system-ui;
}
@media (hover: hover) and (pointer: fine) and (min-height: 640px) { .hints { display: flex; } }

/* ---------- Hojas (bottom sheets) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.55);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .2s;
}
.sheet {
  width: 100%; max-width: 520px; max-height: 85vh; overflow-y: auto;
  background: var(--bg-2); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 16px 16px 0 0;
  padding: 10px calc(var(--gutter) + var(--sar)) calc(var(--sab) + 18px) calc(var(--gutter) + var(--sal));
  animation: up .25s cubic-bezier(.2,.8,.2,1);
}
@media (min-width: 600px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 16px; border-bottom: 1px solid var(--line); } }
.sheet-grab { width: 40px; height: 5px; border-radius: 9px; background: rgba(255,255,255,.2); margin: 0 auto 12px; }
.sheet h3 { margin: 0 0 4px; font-size: 18px; }
.sheet-text { margin: 0 0 14px; color: var(--muted); font-size: 14px; word-break: break-word; }
.sheet-text:empty { display: none; }
.sheet-body { display: grid; gap: 8px; }
.sheet-body .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.sheet-body .btn { width: 100%; justify-content: flex-start; }
.sheet-body .grid .btn { justify-content: center; flex-direction: column; height: 64px; gap: 2px; }
.sheet-body .grid .btn small { color: var(--muted); font-weight: 500; font-size: 11px; }
.sheet-body .grid .btn.current { background: var(--text); color: var(--bg); }
.sheet-body .grid .btn.current small { color: var(--bg); }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* ---------- Progreso / toast ---------- */
.progress {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--sab) + 20px); width: min(420px, calc(100% - 32px));
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px;
  font-size: 13px; color: var(--muted);
}
.progress .bar { height: 2px; border-radius: 0; background: var(--surface-2); overflow: hidden; margin-bottom: 8px; }
.progress .bar i { display: block; height: 100%; width: 0; background: var(--text); transition: width .25s; }
.toast {
  position: fixed; z-index: 70; left: 50%; top: calc(var(--sat) + 14px);
  transform: translate(-50%, -30px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); border: 0; border-radius: 99px; font-weight: 600;
  padding: 10px 16px; font-size: 14px; max-width: calc(100% - 32px); text-align: center;
  transition: transform .25s, opacity .25s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

/* ---------- Vista de partida ---------- */
.player { background: #000; z-index: 40; }
.frame-host { position: absolute; inset: 0; }
.frame-host iframe { width: 100%; height: 100%; border: 0; display: block; background: #000; }
.hud {
  position: absolute; z-index: 2; left: 0; right: 0; top: 0;
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--sat) + 8px) calc(var(--sar) + 10px) 10px calc(var(--sal) + 10px);
  background: rgba(0,0,0,.85); border-bottom: 1px solid var(--line);
  transition: transform .3s cubic-bezier(.2,.8,.2,1), opacity .3s;
}
.hud.hidden { transform: translateY(-110%); opacity: 0; pointer-events: none; }
.hud-title { flex: 1; min-width: 0; text-align: center; font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: rgba(255,255,255,.85); }
.btn.toggle[aria-pressed="false"] { opacity: .55; }
.btn.toggle[aria-pressed="false"] svg { stroke-dasharray: 2 3; }
@media (max-width: 480px) { .hud .btn span { display: none; } .hud .btn { width: 40px; padding: 0; } }
.hud-handle {
  position: absolute; z-index: 1; top: calc(var(--sat) + 2px); left: 50%; transform: translateX(-50%);
  width: 64px; height: 22px; border: 0; padding: 0; background: none; cursor: pointer;
}
.hud-handle::before { content: ""; display: block; width: 44px; height: 5px; margin: 0 auto; border-radius: 9px; background: rgba(255,255,255,.35); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
