/* RockArcade — feito para Safari 12: sem flex gap, sem aspect-ratio, sem inset */
:root {
  --bg: #0d0f14;
  --panel: #161a23;
  --panel2: #1e2330;
  --line: #2a3142;
  --text: #eef1f7;
  --muted: #8b93a7;
  --accent: #ff3d6e;
  --focus: #ffd23f;
  --safe-t: env(safe-area-inset-top);
  --safe-b: env(safe-area-inset-bottom);
  --safe-l: env(safe-area-inset-left);
  --safe-r: env(safe-area-inset-right);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
  overflow: hidden;
}
button, .btn { font: inherit; color: inherit; border: 0; cursor: pointer; display: inline-block; }
.vh { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; left: -9999px; }

/* ---------- Biblioteca ---------- */
#library { position: absolute; top: 0; left: 0; right: 0; bottom: 0; display: -webkit-box; display: flex; -webkit-box-orient: vertical; flex-direction: column; }
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(18px + var(--safe-t)) calc(28px + var(--safe-r)) 10px calc(28px + var(--safe-l));
}
.brand { display: flex; align-items: center; }
.logo {
  width: 46px; height: 46px; border-radius: 13px; margin-right: 14px; position: relative;
  background: linear-gradient(135deg, #ff3d6e, #7b5cd6);
  box-shadow: 0 6px 18px rgba(255, 61, 110, .35);
}
.logo span, .logo:before, .logo:after { content: ""; position: absolute; background: #fff; border-radius: 2px; }
.logo:before { left: 10px; top: 21px; width: 14px; height: 4px; }
.logo:after { left: 15px; top: 16px; width: 4px; height: 14px; }
.logo span { width: 6px; height: 6px; border-radius: 50%; right: 11px; top: 16px; box-shadow: -5px 8px 0 #fff; }
h1 { margin: 0; font-size: 24px; letter-spacing: -.3px; }
.sub { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.offline.ok { color: #4ade80; }
.offline.warn { color: #fbbf24; }
.actions > * { margin-left: 10px; }
.primary, .ghost { padding: 11px 18px; border-radius: 12px; font-weight: 600; font-size: 15px; }
.primary { background: var(--accent); color: #fff; }
.ghost { background: var(--panel2); color: var(--text); }

.chips {
  display: flex; overflow-x: auto; -webkit-overflow-scrolling: touch;
  padding: 6px calc(28px + var(--safe-r)) 12px calc(28px + var(--safe-l)); flex-shrink: 0;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; margin-right: 8px; padding: 8px 14px; border-radius: 999px;
  background: var(--panel); color: var(--muted); font-size: 14px; font-weight: 600; border: 2px solid transparent;
}
.chip .n { opacity: .6; font-weight: 500; margin-left: 4px; }
.chip.on { background: var(--text); color: var(--bg); }

.grid {
  -webkit-box-flex: 1; flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 4px calc(28px + var(--safe-r)) 24px calc(28px + var(--safe-l));
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); grid-gap: 16px;
  align-content: start;
}
.card {
  position: relative; background: var(--panel); border-radius: 16px; overflow: hidden; text-align: left;
  border: 3px solid transparent; transition: transform .12s ease, border-color .12s ease; padding: 0; width: 100%;
}
.card:active { transform: scale(.97); }
.card.focus { border-color: var(--focus); transform: scale(1.03); box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.art { height: 104px; position: relative; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.art:after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 40px; background: linear-gradient(transparent, rgba(0,0,0,.25)); }
.art .init { font-size: 38px; font-weight: 800; color: rgba(255,255,255,.92); letter-spacing: -1px; text-shadow: 0 2px 10px rgba(0,0,0,.25); }
.art .badge {
  position: absolute; left: 10px; top: 10px; z-index: 1; font-size: 11px; font-weight: 700; letter-spacing: .3px;
  padding: 3px 8px; border-radius: 6px; background: rgba(0,0,0,.35); color: #fff; text-transform: uppercase;
}
.meta { padding: 10px 12px 12px; }
.title { font-size: 15px; font-weight: 650; line-height: 1.25; max-height: 2.5em; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tags { font-size: 12px; color: var(--muted); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.more {
  position: absolute; right: 6px; top: 6px; z-index: 2; width: 34px; height: 34px; border-radius: 10px;
  background: rgba(0,0,0,.3); color: #fff; font-size: 20px; line-height: 30px; text-align: center;
}

.empty { -webkit-box-flex: 1; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 0 60px; color: var(--muted); }
.empty[hidden] { display: none; }
.empty h2 { color: var(--text); margin: 18px 0 8px; }
.empty p { max-width: 560px; line-height: 1.5; margin: 6px 0; }
.empty .small { font-size: 13px; }
.empty-icon { width: 84px; height: 84px; border-radius: 24px; background: var(--panel2); position: relative; }
.empty-icon:before { content: "+"; position: absolute; left: 0; right: 0; top: 10px; text-align: center; font-size: 52px; color: var(--muted); }

.hints {
  display: flex; align-items: center; padding: 10px calc(28px + var(--safe-r)) calc(10px + var(--safe-b)) calc(28px + var(--safe-l));
  border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); flex-shrink: 0;
}
.hints > span { margin-right: 20px; }
.hints .pad-status { margin-left: auto; margin-right: 0; }
.pad-status.on { color: #4ade80; }
.k {
  display: inline-block; min-width: 22px; height: 22px; line-height: 22px; text-align: center; border-radius: 11px;
  background: var(--panel2); color: var(--text); font-size: 11px; margin-right: 6px; padding: 0 5px;
}

/* ---------- Modal ---------- */
.modal { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(5,6,10,.72); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 24px; }
.modal[hidden] { display: none; }
.sheet { background: var(--panel); border-radius: 20px; padding: 22px; width: 100%; max-width: 460px; max-height: 86vh; overflow-y: auto; -webkit-overflow-scrolling: touch; box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.sheet h3 { margin: 0 0 6px; font-size: 19px; }
.sheet p { margin: 0 0 14px; color: var(--muted); line-height: 1.45; font-size: 14px; }
.sheet .opt {
  display: block; width: 100%; text-align: left; padding: 13px 16px; border-radius: 12px; margin-top: 8px;
  background: var(--panel2); font-size: 16px; font-weight: 600; border: 2px solid transparent;
}
.sheet .opt.danger { color: #ff6b6b; }
.sheet .opt.focus { border-color: var(--focus); }
.sheet .help h4 { margin: 16px 0 6px; font-size: 15px; }
.sheet .help ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 14px; line-height: 1.5; }

.toast {
  position: fixed; left: 50%; bottom: calc(70px + var(--safe-b)); -webkit-transform: translateX(-50%); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 12px; font-weight: 600; font-size: 14px; z-index: 60;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); max-width: 80%; text-align: center;
}
.toast[hidden] { display: none; }

/* ---------- Player ---------- */
#player { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: #000; }
#player[hidden] { display: none; }
#game { position: absolute; top: var(--safe-t); bottom: var(--safe-b); left: var(--safe-l); right: var(--safe-r); }
.exit-hint {
  position: absolute; top: calc(14px + var(--safe-t)); left: 50%; -webkit-transform: translateX(-50%); transform: translateX(-50%);
  background: rgba(0,0,0,.6); color: #fff; padding: 8px 14px; border-radius: 10px; font-size: 13px; z-index: 30; pointer-events: none;
  -webkit-animation: fadeout 4s forwards; animation: fadeout 4s forwards;
}
@-webkit-keyframes fadeout { 0%, 75% { opacity: 1; } 100% { opacity: 0; } }
@keyframes fadeout { 0%, 75% { opacity: 1; } 100% { opacity: 0; } }
.exiting { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.85); z-index: 40; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff; }
.exiting[hidden] { display: none; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid rgba(255,255,255,.2); border-top-color: var(--accent); -webkit-animation: spin 1s linear infinite; animation: spin 1s linear infinite; margin-bottom: 14px; }
@-webkit-keyframes spin { to { -webkit-transform: rotate(360deg); } }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 700px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); grid-gap: 12px; }
  .hints > span:not(.pad-status) { display: none; }
  .actions .ghost { display: none; }
}
