:root {
  --bg-deep: #0a0305;
  --bg-panel: #120608;
  --bg-elevated: #1a0a0e;
  --bg-row: #1f0c11;
  --bg-row-hover: #2a1016;
  --metal-1: #ff3b4a;
  --metal-2: #c41828;
  --metal-3: #7a0d18;
  --metal-shine: #ff8a94;
  --metal-chrome: #f2d7db;
  --text: #f7ecee;
  --text-dim: #b89aa0;
  --line: rgba(255, 90, 100, 0.18);
  --ok: #79c447;
  --danger: #ff5a5a;
  --radius: 16px;
  --radius-sm: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --topbar-h: 56px;
  --tabs-h: 48px;
  --dock-h: 44px;
  --player-h: min(36vh, 260px);
  --font: "Outfit", system-ui, sans-serif;
  --display: "Syne", "Outfit", sans-serif;
  --shadow-metal: 0 10px 40px rgba(140, 10, 25, 0.35);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  background: var(--bg-deep);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(196, 24, 40, 0.28), transparent 55%),
    radial-gradient(80% 50% at 100% 20%, rgba(255, 59, 74, 0.08), transparent 40%),
    linear-gradient(180deg, #14060a 0%, var(--bg-deep) 45%, #050203 100%);
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  background: none;
  border: 0;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.app {
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr) auto;
  position: relative;
  overflow: hidden;
  border-inline: 1px solid rgba(255, 255, 255, 0.03);
}

/* ===== Topbar ===== */
.topbar {
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) 14px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 20;
  background: linear-gradient(180deg, rgba(10, 3, 5, 0.92), rgba(10, 3, 5, 0.55));
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background:
    linear-gradient(145deg, var(--metal-shine) 0%, var(--metal-1) 28%, var(--metal-2) 62%, var(--metal-3) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    inset 0 -2px 4px rgba(0, 0, 0, 0.35),
    0 6px 18px rgba(196, 24, 40, 0.45);
  position: relative;
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 4px;
  border: 1.5px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}

.brand-name {
  font-family: var(--display);
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
  background: linear-gradient(180deg, #fff 0%, var(--metal-chrome) 40%, var(--metal-1) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-sub {
  font-size: 0.68rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--metal-shine);
  opacity: 0.85;
  font-weight: 600;
}

.topbar-actions {
  display: flex;
  gap: 4px;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--text);
  transition: background 0.15s, color 0.15s, transform 0.12s;
}

.icon-btn:hover,
.icon-btn.is-active {
  background: rgba(255, 59, 74, 0.14);
  color: var(--metal-shine);
}

.icon-btn:active {
  transform: scale(0.94);
}

/* ===== Player ===== */
.player-shell {
  padding: 0 12px;
}

.player-stage {
  position: relative;
  width: 100%;
  height: var(--player-h);
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  box-shadow: var(--shadow-metal);
  border: 1px solid var(--line);
}

.video-el,
.yt-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
  object-fit: contain;
}

.player-idle,
.player-loading,
.player-error {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  text-align: center;
  padding: 20px;
  background:
    radial-gradient(circle at 50% 35%, rgba(196, 24, 40, 0.35), transparent 55%),
    #080203;
  z-index: 2;
}

.idle-orb {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  margin-bottom: 6px;
  background: linear-gradient(145deg, var(--metal-shine), var(--metal-2) 55%, var(--metal-3));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 0 40px rgba(255, 59, 74, 0.35);
  animation: pulse 2.4s ease-in-out infinite;
}

.idle-title,
.boot-brand {
  font-family: var(--display);
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.idle-copy,
.boot-status,
.player-loading span,
.player-error p {
  color: var(--text-dim);
  font-size: 0.92rem;
}

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--metal-1);
  animation: spin 0.75s linear infinite;
  margin-bottom: 6px;
}

.btn-ghost {
  margin-top: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
}

.player-chrome {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  padding: 28px 12px 12px;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.82));
  pointer-events: none;
}

.player-chrome > * {
  pointer-events: auto;
}

.now-playing {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.now-flag {
  font-size: 1.25rem;
  line-height: 1;
}

.now-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.now-text strong {
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.now-text span {
  font-size: 0.75rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chrome-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.chrome-btn {
  height: 40px;
  min-width: 40px;
  padding: 0 10px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
}

.chrome-btn.primary {
  background: linear-gradient(180deg, var(--metal-1), var(--metal-2));
  border-color: rgba(255, 180, 180, 0.35);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 6px 16px rgba(196, 24, 40, 0.4);
}

.chrome-btn.is-on {
  color: var(--metal-shine);
}

.chrome-btn span {
  display: none;
}

@media (min-width: 380px) {
  .chrome-btn.primary span {
    display: inline;
  }
}

/* ===== Search / Tabs ===== */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 0;
}

.search-input {
  flex: 1;
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  padding: 0 16px;
  outline: none;
}

.search-input:focus {
  border-color: rgba(255, 59, 74, 0.55);
  box-shadow: 0 0 0 3px rgba(196, 24, 40, 0.2);
}

.search-clear {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: var(--text-dim);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 10px 12px 0;
  height: auto;
  flex-shrink: 0;
  z-index: 6;
  position: relative;
}

.tab {
  height: 44px;
  border-radius: 999px;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.9rem;
  border: 1px solid transparent;
  transition: 0.15s ease;
  touch-action: manipulation;
}

.tab.is-active {
  color: #fff;
  background: linear-gradient(180deg, rgba(255, 59, 74, 0.28), rgba(122, 13, 24, 0.45));
  border-color: rgba(255, 90, 100, 0.35);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

/* ===== Content lists ===== */
.content {
  min-height: 0;
  height: 100%;
  overflow: hidden;
  position: relative;
  margin-top: 8px;
  z-index: 5;
}

.panel {
  display: none;
  height: 100%;
  min-height: 0;
  flex-direction: column;
  padding: 0 12px;
  overflow: hidden;
}

.panel.is-active {
  display: flex;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 2px 10px;
  flex-shrink: 0;
}

.panel-head h2 {
  font-size: 1rem;
  font-weight: 700;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.back-link {
  color: var(--metal-shine);
  font-weight: 600;
  font-size: 0.88rem;
  padding: 6px 8px;
  border-radius: 8px;
  min-height: 40px;
}

.back-link:hover {
  background: rgba(255, 59, 74, 0.12);
}

.count-pill {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--metal-chrome);
  background: rgba(255, 59, 74, 0.16);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
}

.list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding-bottom: calc(96px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.list::-webkit-scrollbar {
  width: 6px;
}

.list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 99px;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  min-height: 52px;
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.01));
  border: 1px solid rgba(255, 255, 255, 0.05);
  transition: background 0.12s, border-color 0.12s, transform 0.12s;
  flex-shrink: 0;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.row:hover,
.row:focus-visible {
  background: var(--bg-row-hover);
  border-color: rgba(255, 59, 74, 0.35);
  outline: none;
}

.row:active {
  transform: scale(0.99);
}

.row.is-playing {
  border-color: rgba(255, 59, 74, 0.65);
  background: linear-gradient(90deg, rgba(196, 24, 40, 0.28), rgba(255, 255, 255, 0.03));
  box-shadow: inset 3px 0 0 var(--metal-1);
}

.row-flag,
.row-badge {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 1.35rem;
}

.row-badge {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--metal-shine);
  background: linear-gradient(160deg, rgba(255, 59, 74, 0.3), rgba(122, 13, 24, 0.55));
}

.row-body {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.row-title {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-sub {
  font-size: 0.78rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-meta {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--metal-chrome);
  opacity: 0.8;
}

.empty-hint {
  color: var(--text-dim);
  text-align: center;
  padding: 28px 16px;
  font-size: 0.92rem;
}

/* ===== Dock ===== */
.dock {
  height: calc(var(--dock-h) + var(--safe-bottom));
  padding: 0 16px var(--safe-bottom);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(8, 2, 4, 0.9);
  backdrop-filter: blur(10px);
  font-size: 0.8rem;
  color: var(--text-dim);
}

.dock-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dock-live {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--metal-1);
  box-shadow: 0 0 10px var(--metal-1);
  animation: pulse 1.8s ease-in-out infinite;
}

.dock-live.is-idle {
  background: #666;
  box-shadow: none;
  animation: none;
}

/* ===== Boot ===== */
.boot {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  background:
    radial-gradient(circle at 50% 40%, rgba(196, 24, 40, 0.4), transparent 50%),
    #090204;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}

.boot.is-done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.boot-mark {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: linear-gradient(145deg, var(--metal-shine), var(--metal-2) 55%, var(--metal-3));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    0 12px 40px rgba(196, 24, 40, 0.45);
  animation: pulse 1.8s ease-in-out infinite;
}

/* ===== Landscape / Expand (WebView + PC) ===== */
body.is-expanded {
  background: #000;
}

body.is-expanded .app {
  max-width: none;
  grid-template-rows: 1fr;
}

body.is-expanded .topbar,
body.is-expanded .search-bar,
body.is-expanded .tabs,
body.is-expanded .content,
body.is-expanded .dock {
  display: none !important;
}

body.is-expanded .player-shell {
  padding: 0;
  height: 100%;
  height: 100dvh;
}

body.is-expanded .player-stage {
  height: 100%;
  border-radius: 0;
  border: 0;
  box-shadow: none;
}

body.is-expanded .player-chrome {
  padding-bottom: calc(12px + var(--safe-bottom));
}

body.is-expanded #btn-expand span {
  display: inline;
}

/* Desktop / tablet wider layout */
@media (min-width: 900px) {
  .app {
    max-width: 1180px;
    grid-template-columns: 1.2fr 0.9fr;
    grid-template-rows: auto auto 1fr auto;
    column-gap: 0;
    border-inline: 0;
  }

  .topbar {
    grid-column: 1 / -1;
  }

  .player-shell {
    grid-row: 2 / 4;
    padding: 0 0 12px 16px;
  }

  .player-stage {
    height: 100%;
    min-height: 420px;
  }

  .search-bar {
    grid-column: 2;
    padding-right: 16px;
  }

  .tabs {
    grid-column: 2;
    padding-right: 16px;
  }

  .content {
    grid-column: 2;
    padding-right: 16px;
    margin-top: 8px;
  }

  .dock {
    grid-column: 1 / -1;
  }

  :root {
    --player-h: auto;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  :root {
    --player-h: min(48vh, 180px);
  }

  .app {
    max-width: none;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    filter: brightness(1);
  }
  50% {
    transform: scale(1.04);
    filter: brightness(1.12);
  }
}

@media (max-width: 899px) {
  :root {
    --player-h: min(32vh, 220px);
  }

  .dock {
    z-index: 10;
  }
}
