:root {
  --bg: #0a1410;
  --panel: #11201a;
  --panel-2: #16352a;
  --accent: #16c47f;
  --accent-dim: #0f8f5c;
  --text: #e8f3ee;
  --muted: #7d9b8e;
  --danger: #ff6b6b;
  --radius: 14px;
}

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

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 17px;
}

body {
  padding-bottom: 220px; /* espacio para el player fijo */
  padding-top: env(safe-area-inset-top);
}

.muted { color: var(--muted); }
.center { text-align: center; }
.error { color: var(--danger); }

/* ---- Topbar ---- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; background: var(--panel);
  border-bottom: 1px solid #0006;
  padding-top: calc(14px + env(safe-area-inset-top));
}
.brand { font-weight: 700; font-size: 18px; flex: 0 0 auto; }
.topbar-actions { flex: 0 0 auto; display: flex; gap: 2px; }
.icon-btn {
  background: none; border: none; color: var(--text);
  font-size: 22px; padding: 6px 10px; cursor: pointer;
}
.acct-chip {
  flex: 1; min-width: 0; margin: 0 10px; text-align: center;
  font-size: 13px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---- Modal de cuentas ---- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: #000a; display: flex; align-items: flex-end; justify-content: center;
}
.modal.hidden { display: none; }
.modal-card {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  background: var(--panel); border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.modal-head h2 { margin: 0; font-size: 20px; }

.accounts-list { list-style: none; margin: 8px 0 0; padding: 0; }
.acct-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; margin: 8px 0;
  background: var(--bg); border-radius: var(--radius); border: 1px solid #2a4a3c;
}
.acct-item.active { border-color: var(--accent); }
.acct-main { flex: 1; min-width: 0; cursor: pointer; }
.acct-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-badge { font-size: 12px; color: var(--accent); flex: 0 0 auto; }
.acct-icon-btn { background: none; border: none; color: var(--muted); font-size: 18px; padding: 6px; cursor: pointer; }

.account-form { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.account-form input {
  padding: 13px 14px; border-radius: var(--radius);
  border: 1px solid #2a4a3c; background: var(--bg); color: var(--text); font-size: 16px;
}
#acct-paste { border-style: dashed; }
.form-actions { display: flex; gap: 8px; }
.form-actions .primary-btn {
  flex: 1; padding: 14px; border-radius: var(--radius); border: none;
  background: var(--accent); color: #04130c; font-weight: 700; font-size: 16px; cursor: pointer;
}
.acct-msg { margin: 4px 2px 0; min-height: 18px; font-size: 14px; }
.acct-msg.ok { color: var(--accent); }
.acct-msg.err { color: var(--danger); }
.hidden { display: none; }

/* ---- Controles de búsqueda ---- */
.controls-row {
  display: flex; gap: 10px; padding: 14px 16px;
}
#search, #category {
  flex: 1; min-width: 0;
  padding: 13px 14px; border-radius: var(--radius);
  border: 1px solid #2a4a3c; background: var(--panel);
  color: var(--text); font-size: 16px;
}
#category { flex: 0 0 34%; }
#refresh-btn { flex: 0 0 auto; font-size: 20px; }
#refresh-btn.spinning { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Listas de canales ---- */
.section-title {
  font-size: 14px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 18px 16px 8px;
}
.channel-list { list-style: none; margin: 0; padding: 0 10px; }
.channel {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; margin: 6px 0;
  background: var(--panel); border-radius: var(--radius);
  cursor: pointer; transition: background .12s;
}
.channel:active { background: var(--panel-2); }
.channel.playing { outline: 2px solid var(--accent); }
.channel img {
  width: 38px; height: 38px; object-fit: contain;
  border-radius: 8px; background: #0006; flex: 0 0 auto;
}
.channel .ch-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel .ch-epg { display: block; font-size: 13px; color: var(--muted); }
.fav-star {
  font-size: 22px; padding: 4px 8px; background: none; border: none;
  color: #3c5a4c; cursor: pointer;
}
.fav-star.on { color: #ffcf4a; }

/* ---- Player ---- */
.player {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--panel); border-top: 1px solid #0006;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 24px #0008;
}
.player.hidden { display: none; }

/* Video de sincronización (se muestra para calzar el marcador, luego se colapsa) */
.video-wrap { margin: -2px -4px 10px; position: relative; }
.video-wrap.hidden { display: none; }
.video-wrap video {
  width: 100%; max-height: 40vh; background: #000;
  border-radius: 10px; display: block; object-fit: contain;
}
.video-hint {
  display: block; text-align: center; font-size: 12px; color: var(--muted); margin-top: 6px;
}
.mode-btn { color: var(--accent); border-color: var(--accent-dim); font-weight: 600; }
.pstatus { margin-top: 8px; min-height: 16px; font-size: 13px; }
.player-info {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 12px;
}
.now-name { font-weight: 700; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.offset { font-variant-numeric: tabular-nums; color: var(--accent); font-size: 15px; flex: 0 0 auto; margin-left: 10px; transition: transform .1s; }
.offset.flash { animation: offset-flash .35s ease-out; }
@keyframes offset-flash {
  0% { transform: scale(1); color: #fff; }
  40% { transform: scale(1.25); color: #fff; }
  100% { transform: scale(1); color: var(--accent); }
}

.sync-row {
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.sync-btn {
  flex: 1; padding: 16px 0; border-radius: var(--radius);
  border: 1px solid #2a4a3c; background: var(--panel-2);
  color: var(--text); font-size: 16px; font-weight: 600; cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.sync-btn.small { font-size: 14px; opacity: .9; }
.sync-btn:active { background: var(--accent-dim); }
.play-btn {
  flex: 0 0 auto; width: 64px; height: 56px; border-radius: var(--radius);
  border: none; background: var(--accent); color: #04130c;
  font-size: 24px; font-weight: 700; cursor: pointer;
}
.play-btn:active { background: var(--accent-dim); }

.player-foot {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 12px;
}
.ghost-btn {
  background: none; border: 1px solid #2a4a3c; color: var(--muted);
  padding: 8px 12px; border-radius: 10px; font-size: 14px; cursor: pointer;
}
.ghost-btn:active { color: var(--text); }

/* ---- Login ---- */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
}
.login-card {
  width: 100%; max-width: 360px; text-align: center;
  background: var(--panel); padding: 36px 28px; border-radius: 20px;
}
.login-logo { font-size: 56px; }
.login-card h1 { margin: 8px 0 4px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }
.login-card input {
  padding: 15px; border-radius: var(--radius); border: 1px solid #2a4a3c;
  background: var(--bg); color: var(--text); font-size: 17px;
}
.login-card button {
  padding: 15px; border-radius: var(--radius); border: none;
  background: var(--accent); color: #04130c; font-size: 17px; font-weight: 700; cursor: pointer;
}
