:root {
  --bg: #0b0f14;
  --bg-2: #121a23;
  --bg-3: #18222d;
  --line: #24313d;
  --txt: #eaf2f8;
  --txt-dim: #93a7b6;
  --green: #a78bfa;
  --blue: #60a5fa;
  --danger: #ff6b6b;
  --radius: 14px;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--txt);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.screen { display: none; }
.screen.active { display: flex; }

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }

input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--txt);
  font: inherit;
  outline: none;
}
input:focus { border-color: var(--blue); }

label { display: block; margin: 0 0 14px; font-size: 14px; color: var(--txt-dim); }
label input { margin-top: 6px; }
label.row { display: flex; align-items: center; gap: 10px; color: var(--txt); }
label.row input { width: auto; }

.primary {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  background: linear-gradient(135deg, #a78bfa, #6d28d9);
  color: #150a2b;
  font-weight: 700;
  margin-top: 4px;
}
.primary:disabled { opacity: .6; }

.link { color: var(--blue); padding: 10px 0; }
.muted { color: var(--txt-dim); }
.small { font-size: 12px; }
.error { color: var(--danger); min-height: 20px; margin: 10px 0 0; font-size: 14px; }
.hidden { display: none !important; }

/* ---------- login ---------- */
#login { align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 420px; }
.brand { display: block; width: 180px; margin: 0 auto 6px; }
.login-card form { margin-top: 18px; }
.servers { margin-top: 8px; display: grid; gap: 8px; }
.servers button {
  text-align: left;
  padding: 12px;
  border-radius: 10px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  font-size: 14px;
}

/* ---------- app ---------- */
#app { flex-direction: column; height: 100%; }
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(180deg, #0d1219, rgba(13, 18, 25, .92));
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-logo { height: 30px; }
.tabs { display: flex; gap: 6px; flex: 1; }
.tab { padding: 8px 14px; border-radius: 999px; color: var(--txt-dim); font-weight: 600; }
.tab.active { background: var(--bg-3); color: var(--txt); }
.icon-btn { padding: 8px; border-radius: 10px; font-size: 18px; line-height: 1; }
.icon-btn svg { width: 22px; height: 22px; fill: var(--txt-dim); display: block; }

.searchbar { display: flex; gap: 8px; align-items: center; padding: 10px 14px; background: var(--bg-2); }

main { flex: 1; display: flex; min-height: 0; }
.categories {
  width: 180px;
  flex: 0 0 180px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  padding: 8px;
  background: var(--bg-2);
}
.categories button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--txt-dim);
  font-size: 14px;
}
.categories button.active { background: var(--bg-3); color: var(--txt); }

.content { flex: 1; overflow-y: auto; padding: 14px; -webkit-overflow-scrolling: touch; }
.status { color: var(--txt-dim); font-size: 14px; margin-bottom: 10px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}
.card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  text-align: left;
  display: flex;
  flex-direction: column;
}
.card .thumb {
  aspect-ratio: 16 / 10;
  background: #0d141b center/contain no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #2c3d4d;
  font-size: 18px;
}
.card .name {
  padding: 8px 10px;
  font-size: 13px;
  line-height: 1.25;
  max-height: 3.6em;
  overflow: hidden;
}
.card .fav { position: absolute; }
.card .meta { padding: 0 10px 10px; color: var(--txt-dim); font-size: 11px; }

.bottombar {
  display: flex;
  gap: 8px;
  padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg-2);
}
.chip {
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--bg-3);
  color: var(--txt-dim);
  font-size: 13px;
}
.chip.active { color: var(--txt); border: 1px solid var(--green); }

/* ---------- arranque ---------- */
#boot { align-items: center; justify-content: center; padding: 24px; }
.boot-inner { text-align: center; }
.boot-inner .brand { width: 170px; }

/* ---------- dispositivo por aprovar ---------- */
#pending { align-items: center; justify-content: center; padding: 24px; text-align: center; }
#pending h2 { font-size: 19px; margin: 14px 0 6px; }
.device-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 34px;
  letter-spacing: .22em;
  font-weight: 700;
  color: var(--green);
  margin: 14px 0 6px;
  padding: 12px 10px;
  border-radius: 14px;
  background: #0f151c;
  border: 1px solid var(--line);
}

/* ---------- aviso rápido ---------- */
.toast {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(92vw, 460px);
  padding: 10px 16px;
  border-radius: 999px;
  background: #16202b;
  border: 1px solid var(--line);
  color: var(--txt);
  font-size: 13px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
}

/* ---------- dica de instalação ---------- */
.install-tip {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: 16px;
  background: #16202b;
  border: 1px solid var(--line);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .45);
}
.install-tip .install-logo { width: 42px; height: 42px; border-radius: 10px; flex: 0 0 auto; }
.install-tip .install-body { flex: 1; min-width: 0; }
.install-tip strong { display: block; font-size: 14px; margin-bottom: 2px; }
.install-tip p { margin: 0; font-size: 12px; line-height: 1.35; color: var(--txt-dim); }
.install-tip .install-btn {
  padding: 9px 14px;
  border-radius: 999px;
  background: linear-gradient(135deg, #a78bfa, #6d28d9);
  color: #150a2b;
  font-weight: 700;
  font-size: 13px;
  flex: 0 0 auto;
}
.install-tip .install-btn.hidden { display: none; }
.install-tip .install-close {
  position: absolute;
  top: -8px;
  right: -6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--txt-dim);
  font-size: 12px;
  line-height: 1;
}

@media (min-width: 700px) {
  .install-tip { left: auto; right: 20px; bottom: 20px; width: 380px; }
}

/* ---------- player ---------- */
.player { position: fixed; inset: 0; background: #000; flex-direction: column; z-index: 50; }
.player video { flex: 1; width: 100%; background: #000; }
.player-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
  background: linear-gradient(180deg, rgba(0,0,0,.75), transparent);
}
.player-title { flex: 1; font-weight: 600; font-size: 15px; text-shadow: 0 1px 4px #000; }
.player-info {
  position: absolute;
  bottom: 10px; left: 0; right: 0;
  text-align: center;
  font-size: 12px;
  color: #b9c9d6;
  text-shadow: 0 1px 4px #000;
  pointer-events: none;
  padding: 0 12px;
  opacity: 1;
  transition: opacity .35s ease;
}
.player-info.fade { opacity: 0; }

/* ---------- settings ---------- */
.drawer { position: fixed; inset: 0; background: rgba(0,0,0,.6); align-items: flex-end; z-index: 40; }
.drawer-inner {
  width: 100%;
  background: var(--bg-2);
  border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
}
.drawer h2 { margin: 0 0 14px; font-size: 18px; }
#account { margin: 0 0 18px; font-size: 14px; }
#account div { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }
#account dt { color: var(--txt-dim); }
#account dd { margin: 0; text-align: right; }

.diag {
  white-space: pre-wrap;
  word-break: break-all;
  font-size: 11px;
  line-height: 1.35;
  color: var(--txt-dim);
  background: #0f151c;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  max-height: 180px;
  overflow: auto;
  margin: 10px 0 16px;
  min-height: 0;
}

@media (min-width: 700px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .categories { width: 220px; flex-basis: 220px; }
  .brand { width: 220px; }
}
@media (max-width: 560px) {
  main { flex-direction: column; }
  .categories {
    width: 100%;
    flex: 0 0 auto;
    display: flex;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 8px 10px;
    white-space: nowrap;
  }
  .categories button { width: auto; }
  .topbar { flex-wrap: wrap; }
  .topbar-logo { height: 24px; }
}
