:root {
  --bg: #10110f;
  --panel: rgba(245, 235, 215, 0.08);
  --panel-strong: rgba(245, 235, 215, 0.14);
  --text: #f7efe0;
  --muted: #b8aa92;
  --gold: #e4b45f;
  --red: #a63d2f;
  --green: #8ebf73;
  --line: rgba(247, 239, 224, 0.16);
  --shadow: rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 16% 12%, rgba(228, 180, 95, 0.18), transparent 28rem),
    radial-gradient(circle at 90% 8%, rgba(166, 61, 47, 0.2), transparent 32rem),
    linear-gradient(135deg, #11130f 0%, #1d1713 52%, #0b0c0c 100%);
  color: var(--text);
  font-family: "Avenir Next", "Trebuchet MS", Verdana, sans-serif;
  min-height: 100vh;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 999px;
  background: var(--gold);
  color: #19140d;
  cursor: pointer;
  font-weight: 800;
  padding: 0.75rem 1.1rem;
  box-shadow: 0 12px 30px var(--shadow);
}

button.secondary {
  background: var(--panel-strong);
  color: var(--text);
  border: 1px solid var(--line);
}

button.compact {
  padding: 0.55rem 0.85rem;
  box-shadow: none;
  white-space: nowrap;
}

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

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.28);
  padding: 0.72rem 0.85rem;
}

main {
  padding: clamp(0.35rem, 1vw, 0.75rem) clamp(0.55rem, 1.6vw, 1.25rem) 2rem;
}

.app-menu {
  position: fixed;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 40;
}

.app-menu summary {
  width: 2.7rem;
  height: 2.7rem;
  display: grid;
  place-content: center;
  gap: 0.22rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  cursor: pointer;
  list-style: none;
}

.app-menu summary::-webkit-details-marker {
  display: none;
}

.app-menu summary span {
  display: block;
  width: 1.05rem;
  height: 2px;
  border-radius: 99px;
  background: var(--text);
}

.app-menu-popover {
  position: absolute;
  top: calc(100% + 0.55rem);
  right: 0;
  width: min(220px, calc(100vw - 1.5rem));
  display: grid;
  gap: 0.55rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(11, 12, 12, 0.94);
  box-shadow: 0 24px 70px var(--shadow);
}

.app-menu-popover button {
  width: 100%;
}

.eyebrow {
  color: var(--gold);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(360px, 0.62fr);
  gap: 1rem;
  width: min(100%, 1880px);
  margin: 0 auto;
  align-items: start;
}

.watch-panel {
  min-width: 0;
}

.library-panel,
.player-panel {
  border: 1px solid var(--line);
  background: rgba(11, 12, 12, 0.72);
  border-radius: 28px;
  box-shadow: 0 24px 72px var(--shadow);
}

.library-panel {
  padding: 0.85rem;
  min-height: min(760px, calc(100vh - 2rem));
  max-height: calc(100vh - 2rem);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0.75rem;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.75rem;
  align-items: center;
  color: var(--muted);
  margin-bottom: 1rem;
}

.movie-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  overflow: auto;
  padding-right: 0.35rem;
}

.movie-card {
  width: 100%;
  text-align: left;
  display: grid;
  grid-template-columns: 124px 1fr;
  gap: 0.85rem;
  border-radius: 20px;
  padding: 0.65rem;
  color: var(--text);
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid transparent;
  box-shadow: none;
}

.movie-card.selected {
  border-color: rgba(228, 180, 95, 0.55);
  background: rgba(228, 180, 95, 0.11);
}

.poster-fallback {
  aspect-ratio: 16 / 9;
  border-radius: 14px;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  background: linear-gradient(145deg, #3c1f16, #db9a45);
  color: #1b120b;
  font-size: 2rem;
  font-weight: 1000;
}

.poster-fallback span {
  position: relative;
  z-index: 1;
}

.movie-thumb {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.movie-title {
  font-weight: 900;
  letter-spacing: -0.02em;
}

.movie-meta,
.movie-path,
.mode-note {
  color: var(--muted);
  font-size: 0.86rem;
}

.movie-path {
  overflow-wrap: anywhere;
  margin: 0.2rem 0;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.chips span,
.technical span {
  border: 1px solid var(--line);
  color: var(--muted);
  background: rgba(0, 0, 0, 0.2);
  border-radius: 999px;
  padding: 0.24rem 0.5rem;
  font-size: 0.74rem;
}

.chips .good {
  color: var(--green);
}

.chips .warn {
  color: var(--gold);
}

.player-panel {
  padding: clamp(0.7rem, 1.6vw, 1.15rem);
}

.player-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.65rem;
}

.player-header h2 {
  margin: 0.15rem 0 0.25rem;
  font-size: clamp(1.1rem, 2vw, 1.9rem);
  letter-spacing: -0.04em;
  line-height: 1.04;
}

.player-header p {
  color: var(--muted);
  overflow-wrap: anywhere;
  margin: 0;
  font-size: 0.86rem;
}

.technical {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: flex-end;
  align-content: flex-start;
}

.video-shell {
  width: 100%;
  aspect-ratio: var(--movie-aspect, 16 / 9);
  max-height: min(78vh, 920px);
  overflow: hidden;
  border-radius: 22px;
  background: #000;
  border: 1px solid rgba(255, 255, 255, 0.09);
  display: grid;
  place-items: center;
}

video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.playback-debug {
  margin-top: 1rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.24);
  padding: 0.85rem;
}

.playback-debug.has-error {
  border-color: rgba(166, 61, 47, 0.65);
  background: rgba(166, 61, 47, 0.14);
}

.playback-debug summary {
  cursor: pointer;
  color: var(--gold);
  font-weight: 900;
}

.playback-debug p {
  color: var(--muted);
  font-size: 0.85rem;
}

.debug-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.6rem 0 0.75rem;
}

.debug-toolbar p {
  flex: 1;
  margin: 0;
}

.debug-toolbar span {
  color: var(--gold);
  font-size: 0.82rem;
  font-weight: 900;
}

.playback-debug textarea {
  width: 100%;
  min-height: 340px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  padding: 0.85rem;
}

.controls-grid {
  margin-top: 0.8rem;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.7rem;
}

label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.error-banner,
.empty {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 18px;
  background: rgba(166, 61, 47, 0.2);
  border: 1px solid rgba(166, 61, 47, 0.45);
}

.token-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.token-card {
  width: min(560px, 100%);
  border-radius: 34px;
  border: 1px solid var(--line);
  background: rgba(11, 12, 12, 0.82);
  padding: clamp(1.5rem, 5vw, 3rem);
  box-shadow: 0 30px 90px var(--shadow);
}

.token-card h1 {
  margin: 0.3rem 0 0.7rem;
  font-size: clamp(2rem, 5vw, 4rem);
  letter-spacing: -0.07em;
  line-height: 0.94;
}

.token-card p {
  color: var(--muted);
}

.token-card code {
  color: var(--text);
}

.token-card form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.token-error {
  margin-top: 1rem;
  padding: 0.8rem 0.9rem;
  border: 1px solid rgba(166, 61, 47, 0.5);
  border-radius: 14px;
  background: rgba(166, 61, 47, 0.18);
  color: #ffd6ce;
  font-weight: 700;
}

.token-footnote {
  margin-top: 1rem;
  font-size: 0.82rem;
  line-height: 1.5;
}

@media (max-width: 1120px) {
  .player-header {
    align-items: stretch;
    flex-direction: column;
  }

  .app-menu {
    top: 0.55rem;
    right: 0.55rem;
  }

  .layout,
  .controls-grid {
    grid-template-columns: 1fr;
  }

  .library-panel {
    position: static;
    min-height: 45vh;
    max-height: 58vh;
  }

  .movie-list {
    grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  }

  .debug-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .token-card form {
    grid-template-columns: 1fr;
  }
}
