* {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;
  --bg: #070b14;
  --surface: #0f1728;
  --surface-2: #151f34;
  --surface-3: #1c2942;
  --line: rgba(255, 255, 255, 0.1);
  --text: #f7f9ff;
  --muted: #9ca9bf;
  --accent: #7c5cff;
  --accent-2: #24d6c7;
  --danger: #ff7285;
  --radius: 20px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 80% -10%, rgba(124, 92, 255, 0.22), transparent 35rem),
    radial-gradient(circle at -10% 20%, rgba(36, 214, 199, 0.08), transparent 30rem),
    var(--bg);
  color: var(--text);
}

button,
input,
a {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

.app-shell {
  width: min(100%, 980px);
  min-height: 100dvh;
  margin: 0 auto;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  background: rgba(7, 11, 20, 0.9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 0;
  margin: 0 0 12px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  aspect-ratio: 1;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 13px;
  font-weight: 900;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 15px;
}

.brand small {
  margin-top: 1px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.primary-nav {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.primary-nav button {
  min-height: 44px;
  padding: 8px 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.primary-nav button.active {
  border-color: rgba(124, 92, 255, 0.75);
  background: rgba(124, 92, 255, 0.18);
  color: #fff;
}

.screen-stage {
  padding: 22px 16px calc(40px + env(safe-area-inset-bottom));
}

.screen {
  display: grid;
  gap: 18px;
}

.screen[hidden] {
  display: none;
}

.screen-heading,
.placeholder-row,
.player-meta,
.profile-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(26px, 7vw, 40px);
  line-height: 1;
}

h2 {
  margin-bottom: 7px;
  font-size: clamp(19px, 5vw, 26px);
}

p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.6;
}

.eyebrow,
.section-label {
  color: var(--accent-2);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.eyebrow {
  margin-bottom: 7px;
}

.phase-badge,
.reason-chip {
  flex: 0 0 auto;
  border: 1px solid rgba(124, 92, 255, 0.45);
  border-radius: 999px;
  background: rgba(124, 92, 255, 0.12);
  color: #d8d0ff;
  font-size: 11px;
  font-weight: 800;
  padding: 7px 10px;
}

.panel,
.player-panel,
.hero-panel,
.profile-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(21, 31, 52, 0.94), rgba(15, 23, 40, 0.94));
  box-shadow: 0 16px 46px rgba(0, 0, 0, 0.22);
}

.panel,
.player-panel {
  padding: 15px;
}

.panel.compact {
  display: grid;
  gap: 12px;
}

.player-panel {
  display: grid;
  gap: 12px;
}

.player-meta {
  align-items: flex-start;
}

.player-meta p {
  margin-top: 4px;
  font-size: 12px;
}

.player-frame {
  overflow: hidden;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #000;
}

.player-frame iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.player-placeholder[hidden],
.player-frame iframe[hidden] {
  display: none !important;
}

.player-placeholder {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  width: 100%;
  height: 100%;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  background:
    radial-gradient(
      circle at 50% 35%,
      rgba(124, 92, 255, 0.16),
      transparent 42%
    ),
    #070b13;
}

.player-placeholder strong {
  color: var(--text);
  font-size: 0.98rem;
}

.player-placeholder p {
  margin: 0;
  max-width: 32rem;
  line-height: 1.6;
}

.player-note {
  font-size: 12px;
}

.text-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: #d7d2ff;
  font-size: 12px;
  text-decoration: none;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

button.primary,
button.secondary,
button.ghost,
.button-link,
.mini {
  border-radius: 13px;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}

button.primary,
button.secondary,
.button-link {
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  font-weight: 800;
}

button.primary {
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), #5d8bff);
  color: #fff;
}

button.secondary,
.button-link.secondary {
  background: var(--surface-2);
  color: var(--text);
}

button.ghost {
  min-height: 44px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
}

button.large {
  width: min(100%, 420px);
  min-height: 58px;
  font-size: 17px;
}

button.full {
  width: 100%;
}

.hero-panel {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 44px 20px;
  text-align: center;
}

.hero-orb {
  display: grid;
  place-items: center;
  width: 118px;
  aspect-ratio: 1;
  border: 1px solid rgba(124, 92, 255, 0.45);
  border-radius: 36px;
  background:
    radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.22), transparent 25%),
    linear-gradient(135deg, #7254ff, #1bcbbb);
  box-shadow: 0 30px 70px rgba(74, 63, 255, 0.26);
  font-size: 44px;
  font-weight: 950;
  transform: rotate(-5deg);
}

.result-grid,
.creator-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.result-card,
.creator-card {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}

.result-card strong,
.creator-card strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-card small,
.creator-card small {
  color: var(--muted);
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.result-actions button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.result-actions button:first-child {
  grid-column: 1 / -1;
}

.sticky-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.party-list {
  display: grid;
  gap: 9px;
}

.creator-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 70px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}

.creator-row span:nth-child(2) {
  min-width: 0;
}

.creator-row strong,
.creator-row small {
  display: block;
}

.creator-row small {
  margin-top: 4px;
  color: var(--muted);
}

.creator-row.empty {
  opacity: 0.6;
  cursor: default;
}

.avatar-placeholder,
.creator-art {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.3), rgba(36, 214, 199, 0.14));
  color: #fff;
  font-weight: 900;
}

.avatar-placeholder {
  width: 44px;
  aspect-ratio: 1;
  border-radius: 14px;
}

.edit-row {
  display: grid;
  grid-template-columns: auto 1fr repeat(3, auto);
  align-items: center;
  gap: 7px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.edit-row:last-child {
  border-bottom: 0;
}

.drag-mark {
  color: var(--muted);
}

.mini {
  min-width: 44px;
  min-height: 44px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  background: var(--surface-3);
  font-size: 11px;
}

.mini.danger {
  color: var(--danger);
}

.search-box {
  display: grid;
  gap: 6px;
}

.search-box span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.search-box input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0a1020;
  color: var(--text);
}

.filter-row {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.filter-row::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.chip.active {
  border-color: rgba(36, 214, 199, 0.45);
  color: #dffffc;
}

.creator-card {
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.creator-art {
  aspect-ratio: 16 / 10;
  border-radius: 12px;
  font-size: 28px;
}

.profile-panel {
  justify-content: flex-start;
  padding: 16px;
}

.profile-avatar {
  display: grid;
  place-items: center;
  width: 76px;
  aspect-ratio: 1;
  border-radius: 24px;
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.5), rgba(36, 214, 199, 0.28));
  font-size: 30px;
  font-weight: 900;
}

.content-outline {
  display: grid;
  gap: 10px;
}

.outline-card {
  display: grid;
  gap: 8px;
  width: 100%;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: 16px;
  z-index: 50;
  width: min(calc(100% - 32px), 460px);
  margin: 0 auto;
  padding: 13px 15px;
  border: 1px solid rgba(124, 92, 255, 0.55);
  border-radius: 14px;
  background: rgba(21, 31, 52, 0.96);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.38);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

@media (min-width: 720px) {
  .app-header {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 20px;
    padding-right: 24px;
    padding-left: 24px;
  }

  .brand {
    margin-bottom: 0;
  }

  .primary-nav {
    width: 500px;
  }

  .screen-stage {
    padding-right: 24px;
    padding-left: 24px;
  }

  .result-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .creator-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .sticky-actions {
    grid-template-columns: 2fr 1fr;
  }
}

@media (max-width: 430px) {
  .screen-heading {
    align-items: flex-start;
  }

  .action-grid {
    grid-template-columns: 1fr;
  }

  .edit-row {
    grid-template-columns: auto 1fr auto;
  }

  .edit-row .mini:nth-of-type(2),
  .edit-row .mini:nth-of-type(3) {
    grid-row: 2;
  }

  .edit-row .mini:nth-of-type(2) {
    grid-column: 2;
  }

  .edit-row .mini:nth-of-type(3) {
    grid-column: 3;
  }
}


.home-now-playing {
  min-width: 0;
}

.home-now-playing h2,
.home-now-playing p {
  overflow: hidden;
  text-overflow: ellipsis;
}

.home-now-playing h2 {
  margin-top: 5px;
}

.home-mock-note {
  display: block;
  max-width: 640px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.favorite-button.active {
  border-color: rgba(255, 114, 133, 0.5);
  background: rgba(255, 114, 133, 0.12);
  color: #ffd8de;
}

.favorite-button.active::first-letter {
  color: var(--danger);
}


.result-card.in-party {
  border-color: rgba(36, 214, 199, 0.42);
  background: linear-gradient(180deg, rgba(36, 214, 199, 0.08), var(--surface));
}

.result-card .result-reason {
  min-height: 2.8em;
  color: #c9d2e3;
  line-height: 1.4;
}

.result-actions button.active {
  border-color: rgba(36, 214, 199, 0.48);
  background: rgba(36, 214, 199, 0.12);
  color: #dffffc;
}

.queue-context {
  color: #dffffc;
}


.party-summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.party-summary-row strong {
  display: block;
  margin-top: 4px;
  font-size: 24px;
}

.party-summary-row small {
  max-width: 58%;
  color: var(--muted);
  text-align: right;
  line-height: 1.5;
}

.party-status {
  color: var(--accent-2);
  font-size: 11px;
  font-weight: 800;
}

.party-empty {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 160px;
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 18px;
  background: rgba(15, 23, 40, 0.55);
  color: var(--muted);
  text-align: center;
}

.party-empty strong {
  color: var(--text);
}

@media (max-width: 430px) {
  .party-summary-row {
    align-items: flex-start;
  }

  .party-summary-row small {
    max-width: 55%;
  }
}


.party-edit-list {
  display: grid;
  gap: 0;
}

.party-edit-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.party-edit-row:last-child {
  border-bottom: 0;
}

.party-edit-identity {
  min-width: 0;
}

.party-edit-identity strong,
.party-edit-identity small {
  display: block;
}

.party-edit-identity small {
  margin-top: 4px;
  color: var(--muted);
}

.party-edit-controls {
  display: grid;
  grid-template-columns: repeat(2, auto);
  gap: 6px;
  justify-content: end;
}

.party-edit-controls .detail-control,
.party-edit-controls .remove-control {
  grid-column: span 2;
}

.move-stack {
  display: grid;
  gap: 5px;
}

.move-stack .mini {
  min-width: 38px;
}

@media (max-width: 430px) {
  .party-edit-row {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .party-edit-controls {
    grid-column: 2;
    justify-content: start;
  }
}


.directory-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 4px;
}

.directory-summary strong {
  font-size: 14px;
}

.creator-card {
  position: relative;
}

.creator-card .creator-state-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.creator-state-badge {
  display: inline-flex;
  align-items: center;
  min-height: 23px;
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
}

.creator-state-badge.favorite {
  color: #ffd8de;
}

.creator-state-badge.party {
  color: #dffffc;
}

.creator-state-badge.discovered {
  color: #d8d0ff;
}

.directory-empty {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 180px;
  padding: 28px;
  border: 1px dashed var(--line);
  border-radius: 18px;
  background: rgba(15, 23, 40, 0.55);
  color: var(--muted);
  text-align: center;
}

.directory-empty strong {
  color: var(--text);
}


.creator-detail-profile {
  align-items: flex-start;
}

.creator-detail-identity {
  min-width: 0;
}

.creator-detail-identity .creator-state-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.creator-detail-section {
  display: grid;
  gap: 10px;
}

.detail-section-heading h2 {
  margin-top: 5px;
  margin-bottom: 0;
}

.creator-video-feature,
.creator-video-row {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.creator-video-feature {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 16px;
  border-radius: 18px;
}

.creator-video-feature strong,
.creator-video-feature small,
.creator-video-row strong,
.creator-video-row small {
  display: block;
}

.creator-video-feature small,
.creator-video-row small {
  margin-top: 5px;
  color: var(--muted);
}

.creator-video-play {
  display: grid;
  place-items: center;
  min-width: 54px;
  min-height: 44px;
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 900;
}

.creator-video-list {
  display: grid;
  gap: 8px;
}

.creator-video-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: 15px;
}

.creator-video-index {
  display: grid;
  place-items: center;
  width: 34px;
  aspect-ratio: 1;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

#creator-detail-party.active {
  border-color: rgba(36, 214, 199, 0.48);
  background: rgba(36, 214, 199, 0.12);
  color: #dffffc;
}


button,
a,
input {
  touch-action: manipulation;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(36, 214, 199, 0.72);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}


/* P4-04 runtime/player state surfaces */
.runtime-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.runtime-status > div {
  display: grid;
  gap: 5px;
}

.runtime-status strong {
  font-size: 0.98rem;
}

.runtime-status p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.runtime-status[data-runtime-state="ready"] {
  border-color: rgba(83, 211, 169, 0.34);
}

.runtime-status[data-runtime-state="partial"] {
  border-color: rgba(255, 201, 93, 0.42);
}

.runtime-status[data-runtime-state="empty"],
.runtime-status[data-runtime-state="error"] {
  border-color: rgba(255, 119, 141, 0.38);
}

.player-fallback {
  margin-top: 12px;
  padding: 14px;
  border: 1px solid rgba(255, 119, 141, 0.38);
  border-radius: 14px;
  background: rgba(36, 20, 31, 0.86);
}

.player-fallback > div:first-child {
  display: grid;
  gap: 6px;
}

.player-fallback p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.player-fallback-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

@media (max-width: 640px) {
  .runtime-status {
    align-items: stretch;
    flex-direction: column;
  }

  .runtime-status > button {
    width: 100%;
  }

  .player-fallback-actions {
    flex-direction: column;
  }

  .player-fallback-actions > * {
    width: 100%;
  }
}

/* P5-05 viewer-state backup */
.backup-panel {
  margin-top: 4px;
}

.backup-json-field {
  display: grid;
  gap: 7px;
}

.backup-json-field > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.backup-json-field textarea {
  width: 100%;
  min-height: 220px;
  box-sizing: border-box;
  resize: vertical;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #0a1020;
  color: var(--text);
  font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-wrap: normal;
  white-space: pre;
}

.backup-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.backup-actions [data-backup-import] {
  grid-column: 1 / -1;
}

.backup-status {
  min-height: 1.5em;
  font-size: 12px;
}

.backup-status[data-state="success"] {
  color: var(--accent-2);
}

.backup-status[data-state="error"] {
  color: var(--danger);
}

.backup-json-field textarea:focus-visible {
  outline: 3px solid rgba(36, 214, 199, 0.72);
  outline-offset: 3px;
}

@media (max-width: 430px) {
  .backup-actions {
    grid-template-columns: 1fr;
  }

  .backup-actions [data-backup-import] {
    grid-column: auto;
  }
}

