* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, sans-serif;
  background: #111;
  color: #eee;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header {
  background: linear-gradient(135deg, #050505 72%, #057d78 72%);
  padding: 14px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 4px;
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.top-row {
  padding: 4px 2px;
  justify-content: flex-start;
  gap: 8px;
}

.bottom-row {
  background: #174b49;
  border-bottom: solid #28c4bc 4px;
  padding: 8px 12px;
}

#logo-placeholder {
  height: 40px;
  color: #47e0ee;
  font-size: 30px;
  line-height: 40px;
  border-radius: 5px;
  padding-left: 5px;
  padding-right: 10px;
}

.header-icon-button,
.home-icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid #333;
  border-radius: 6px;
  background: #181818;
  color: #47e0ee;
  display: grid;
  place-items: center;
  padding: 0;
}

.header-icon-button:hover,
.home-icon-button:hover {
  background: #242424;
}

.satisfy-regular {
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 800;
  font-style: normal;
}

.channel {
  font-size: 14px;
  color: #eee;
  font-weight: bold;
}

#search,
#playlist-url {
  min-height: 42px;
  border-radius: 6px;
  border: 1px solid #555;
  background: #f7f7f7;
  color: #111;
  padding: 0 12px;
}

#search {
  width: min(48vw, 420px);
}

.menu-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
}

.menu-row button,
.playlist-loader button,
.admin-create-button,
.admin-playlist-form button,
.sort-controls-row button,
.seek-buttons button,
.video-actions button,
.channel-button {
  min-height: 40px;
  border: 1px solid #444;
  border-radius: 6px;
  background: #242424;
  color: #eee;
  padding: 0 8px;
  text-align: center;
}

.menu-row button {
  min-height: 48px;
  width: 100%;
  font-size: 13px;
  font-weight: 700;
}

.icon-nav-button {
  display: grid;
  place-items: center;
}

.menu-row button:hover,
.playlist-loader button:hover,
.admin-create-button:hover,
.admin-playlist-form button:hover,
.sort-controls-row button:hover,
.seek-buttons button:hover,
.video-actions button:hover,
.channel-button:hover {
  background: #343434;
}

.hidden {
  display: none;
}

#home-page,
#menu-page,
#admin-page,
#load-page {
  display: none;
  padding: 16px;
}

#search-page {
  display: none;
  padding: 16px;
}

.player-shell {
  display: grid;
  grid-template-columns: minmax(300px, 36vw) 1fr;
  min-height: calc(100vh - 118px);
}

.player-view-toggle {
  display: none;
  margin: 10px 0;
}

.sort-controls-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 8px 10px;
  background: #111;
  border-bottom: 1px solid #303030;
}

.sort-controls-row button {
  min-height: 34px;
  padding: 0 8px;
  font-size: 13px;
}

#edit-playlist.active-edit {
  background: #109f98;
  border-color: #39d4cc;
  color: #fff;
}

.load-panel,
.admin-panel {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 18px;
}

.search-panel {
  max-width: 720px;
  margin: 0 auto;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 18px;
}

.load-copy h2 {
  margin: 0 0 6px;
  font-size: 24px;
  letter-spacing: 0;
}

.load-copy p,
.admin-copy p,
.search-copy p {
  margin: 0 0 14px;
  color: #b9d9d6;
}

.admin-copy h2,
.search-copy h2 {
  margin: 0 0 6px;
  font-size: 24px;
  letter-spacing: 0;
}

.admin-create-button {
  width: 100%;
  min-height: 46px;
  margin-bottom: 10px;
}

.admin-create-button + .admin-create-button {
  margin-top: 0;
}

.admin-playlist-form {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.admin-playlist-form.hidden {
  display: none;
}

.admin-playlist-form label {
  display: grid;
  gap: 5px;
  color: #d9ffff;
  font-size: 13px;
  min-width: 0;
}

.admin-playlist-form input {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  border-radius: 6px;
  border: 1px solid #555;
  background: #f7f7f7;
  color: #111;
  padding: 0 12px;
}

.admin-confirmed-playlist {
  display: grid;
  gap: 3px;
  min-width: 0;
  border: 1px solid #30625f;
  border-radius: 6px;
  background: #102826;
  padding: 10px;
}

.admin-confirmed-playlist strong {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.admin-confirmed-link {
  color: #64b8b1;
  font-size: 11px;
  line-height: 1.25;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.admin-confirmed-playlist span,
.admin-status {
  color: #9fd8d4;
  font-size: 13px;
}

.admin-confirmed-playlist .admin-confirmed-link {
  color: #64b8b1;
  font-size: 11px;
}

.admin-status {
  margin-top: 12px;
  min-height: 22px;
}

.admin-playlist-manager {
  display: grid;
  gap: 10px;
  margin: 10px 0 12px;
}

.admin-playlist-manager.hidden {
  display: none;
}

.admin-manager-heading {
  display: grid;
  gap: 3px;
  color: #d9ffff;
}

.admin-manager-heading span {
  color: #9fd8d4;
  font-size: 13px;
}

.admin-managed-playlist {
  display: grid;
  gap: 8px;
  border: 1px solid #333;
  border-radius: 6px;
  background: #202020;
  padding: 10px;
}

.admin-managed-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.admin-managed-copy strong {
  overflow-wrap: anywhere;
}

.admin-managed-copy span {
  color: #9fd8d4;
  font-size: 12px;
  line-height: 1.25;
}

.search-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.search-controls button {
  min-height: 42px;
  border: 1px solid #444;
  border-radius: 6px;
  background: #242424;
  color: #eee;
  padding: 0 12px;
}

.search-controls button:hover {
  background: #343434;
}

.playlist-panel {
  border-right: 1px solid #303030;
  background: #171717;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.playlist-loader {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.load-status {
  margin-top: 12px;
  min-height: 22px;
  color: #9fd8d4;
  font-size: 14px;
}

.search-status {
  margin-top: 12px;
  min-height: 22px;
  color: #9fd8d4;
  font-size: 14px;
}

.playlist-count {
  color: #9fd8d4;
  font-size: 13px;
  padding: 0 12px 10px;
}

#video-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 10px 12px;
  overflow-y: auto;
  max-height: calc(100vh - 136px);
}

.video-card {
  background: linear-gradient(135deg, #262626 15%, #1b1b1b 15%, #161616 92%, #292929 92%);
  border: 1px solid #303030;
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 8px;
  align-items: center;
  padding: 7px;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.video-card:hover {
  transform: translateY(-1px);
  border-color: #5c807e;
}

.video-card.dragging {
  opacity: 0.45;
}

.video-card img {
  width: 58px;
  height: 58px;
  object-fit: cover;
  border-radius: 6px;
  background: #222;
}

.video-meta {
  min-width: 0;
}

.video-card h3 {
  font-size: 13px;
  line-height: 1.25;
  margin: 2px 0 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

#player-page.is-editing .video-card h3 {
  margin-bottom: 6px;
}

.video-channel {
  font-size: 12px;
  color: #aaa;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.video-actions {
  display: none;
  grid-template-columns: 86px minmax(48px, 1fr) minmax(62px, 1fr) 34px 34px;
  gap: 6px;
  align-items: stretch;
}

#player-page.is-editing .video-actions {
  display: grid;
}

.video-actions button,
.order-control input {
  min-height: 28px;
  padding: 0 6px;
  font-size: 12px;
  box-sizing: border-box;
}

.order-control {
  display: grid;
  grid-template-columns: 40px 44px;
  align-items: center;
  align-self: center;
  gap: 4px;
  min-width: 0;
  color: #d9ffff;
  font-size: 11px;
}

.video-actions [data-place="top"] {
  grid-column: 2;
}

.video-actions [data-place="bottom"] {
  grid-column: 3;
}

.video-actions [data-move="up"] {
  grid-column: 4;
}

.video-actions [data-move="down"] {
  grid-column: 5;
}

.order-control input {
  width: 100%;
  min-width: 0;
  height: 28px;
  border: 1px solid #444;
  border-radius: 6px;
  background: #101010;
  color: #fff;
  text-align: center;
  line-height: 28px;
}

.current-video {
  background: linear-gradient(135deg, #6e7614 15%, #394f07 15%, #39450d 92%, #6e7614 92%);
}

.played-video {
  background: linear-gradient(135deg, #12766e 15%, #064d49 15%, #073f48 92%, #12766e 92%);
}

.loop-video {
  background: linear-gradient(135deg, #c95109 15%, #873507 15%, #783108 92%, #c95109 92%);
}

.error-video {
  background: linear-gradient(135deg, #6c1680 15%, #351044 15%, #27134d 92%, #6c1680 92%);
}

.now-playing-panel {
  min-width: 0;
  padding: 20px;
  display: grid;
  grid-template-rows: auto auto auto auto auto;
  align-content: start;
  align-items: center;
  justify-items: center;
  gap: 18px;
  background:
    linear-gradient(145deg, rgba(8, 44, 42, 0.78), rgba(16, 16, 16, 0.86)),
    #121212;
}

.art-stage {
  width: 130px;
  height: 130px;
  display: grid;
  place-items: center;
}

.player-thumbnail {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: #222;
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.42);
}

.player-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.track-copy {
  text-align: center;
  width: min(100%, 760px);
}

#channel-name {
  font-size: 15px;
  color: #a8d8d4;
  margin-bottom: 6px;
}

#player-title {
  margin: 0;
  font-size: 20px;
  line-height: 1.12;
  letter-spacing: 0;
}

.playback-state {
  min-height: 34px;
  color: #90f5eb;
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: center;
}

#waveform-container {
  display: none;
  width: 86px;
  height: 32px;
  gap: 3px;
  align-items: center;
}

.waveform-bar {
  width: 8px;
  height: 26px;
  background-color: #63e8df;
  animation: bounce 1s infinite ease-in-out;
  border-radius: 2px;
}

.waveform-bar:nth-child(1) { animation-delay: 0s; }
.waveform-bar:nth-child(2) { animation-delay: 0.1s; }
.waveform-bar:nth-child(3) { animation-delay: 0.2s; }
.waveform-bar:nth-child(4) { animation-delay: 0.3s; }
.waveform-bar:nth-child(5) { animation-delay: 0.4s; }
.waveform-bar:nth-child(6) { animation-delay: 0.5s; }
.waveform-bar:nth-child(7) { animation-delay: 0.6s; }
.waveform-bar:nth-child(8) { animation-delay: 0.7s; }

@keyframes bounce {
  0%, 100% { transform: scaleY(0.45); }
  50% { transform: scaleY(1); }
}

#progress-line {
  display: grid;
  grid-template-columns: 46px minmax(120px, 680px) 46px;
  align-items: center;
  width: min(100%, 820px);
  gap: 10px;
}

#time-start,
#time-end {
  font-size: 14px;
  color: #ccc;
  text-align: center;
}

#progress-container {
  height: 14px;
  background: #444;
  position: relative;
  border-radius: 6px;
  cursor: pointer;
  touch-action: none;
}

#progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 6px;
  background: linear-gradient(90deg, #7d268f, #28c4bc);
}

#progress-thumb {
  position: absolute;
  top: 50%;
  left: 0%;
  transform: translate(-50%, -50%);
  width: 34px;
  height: 34px;
  background: #fff;
  border-radius: 5px;
  pointer-events: auto;
  touch-action: none;
}

.controls-buttons {
  width: min(100%, 820px);
  display: grid;
  gap: 10px;
}

.play-control-row,
.transport-control-row {
  display: grid;
  gap: 10px;
}

.play-control-row {
  grid-template-columns: minmax(180px, 360px);
  justify-content: center;
}

.transport-control-row {
  grid-template-columns: repeat(3, minmax(80px, 1fr));
}

.round-button {
  border: none;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #eee;
  transition: transform 0.15s ease, background 0.15s ease;
}

.round-button:hover {
  transform: scale(1.04);
}

.play-button {
  background: #109a91;
  width: 100%;
  height: 72px;
}

.play-button:hover {
  background: #22bdb2;
}

.secondary-button,
.loop-button,
.shuffle-button {
  background: #4a4a4a;
  width: 100%;
  height: 58px;
}

.secondary-button:hover,
.shuffle-button:hover {
  background: #666;
}

.loop-button:hover,
.loop-button.active-loop {
  background: #d65a11;
}

.shuffle-button.active-shuffle {
  background: #145f5a;
}

.seek-buttons {
  width: min(100%, 820px);
  display: grid;
  gap: 8px;
}

.seek-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.seek-buttons button {
  min-width: 0;
}

.home-section,
.menu-section {
  background: #1a1a1a;
  border: 1px solid #333;
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 12px;
}

.placeholder-list {
  list-style: none;
  padding-left: 0;
  margin: 0;
  display: grid;
  gap: 7px;
}

.placeholder-list li {
  padding: 0;
  border-bottom: none;
}

.placeholder-list li:last-child {
  border-bottom: none;
}

.channel-button {
  width: 100%;
  text-align: left;
  display: grid;
  gap: 5px;
  line-height: 1.15;
  position: relative;
  overflow: hidden;
  border-color: #3a5552;
  background:
    linear-gradient(135deg, rgba(22, 156, 149, 0.24) 0 18%, transparent 18%),
    linear-gradient(180deg, #252525, #1c1c1c);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  padding: 8px 14px;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.channel-button::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: #26c5bd;
}

.channel-button:hover {
  border-color: #38d7cf;
  background:
    linear-gradient(135deg, rgba(32, 190, 181, 0.28) 0 18%, transparent 18%),
    linear-gradient(180deg, #2a2a2a, #202020);
  transform: translateY(-1px);
}

.playlist-title-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.playlist-number {
  flex: 0 0 auto;
  color: #ffffff;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0;
}

.playlist-title {
  min-width: 0;
  color: #ffffff;
  font-size: 14px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.playlist-genres {
  color: #7df0e8;
  font-size: 10px;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.playlist-admin-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.playlist-admin-actions button {
  min-height: 34px;
  border: 1px solid #444;
  border-radius: 6px;
  background: #242424;
  color: #eee;
}

.playlist-admin-actions button:hover {
  background: #343434;
}

.playlist-admin-actions .danger-action {
  border-color: #6b3333;
  color: #ffd6d6;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

.feature-card {
  background: #202020;
  border: 1px solid #333;
  border-radius: 8px;
  color: #eee;
  aspect-ratio: 1;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.feature-card-title {
  font-size: 15px;
  font-weight: bold;
  margin-bottom: 5px;
}

.feature-card-subtitle {
  font-size: 12px;
  color: #b4f7ff;
}

#youtube-player-hidden {
  position: fixed;
  width: 1px;
  height: 1px;
  left: -9999px;
  bottom: 0;
  overflow: hidden;
}

@media (max-width: 820px) {
  .player-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
    min-height: 0;
  }

  .player-view-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 7px 10px;
    background: #111;
    border-bottom: 1px solid #303030;
  }

  .player-view-toggle button {
    min-height: 42px;
    border: 1px solid #3c3c3c;
    border-radius: 6px;
    background: #242424;
    color: #eee;
  }

  .player-view-toggle button.active-view {
    background: #109a91;
    border-color: #40d3ca;
    color: #fff;
  }

  .sort-controls-row {
    padding: 0 10px 10px;
  }

  #player-page[data-view="now"] .sort-controls-row {
    display: none;
  }

  .playlist-panel {
    border-right: none;
    border-bottom: none;
    min-height: 0;
    max-height: none;
  }

  #video-grid {
    max-height: calc(100svh - 222px);
    padding-bottom: 16px;
  }

  .now-playing-panel {
    min-height: auto;
    height: auto;
    max-height: none;
    padding: 16px 14px 16px;
    grid-template-rows: auto auto auto auto auto;
    align-content: start;
    gap: 10px;
    overflow: visible;
  }

  #player-page[data-view="now"] .playlist-panel {
    display: none;
  }

  #player-page[data-view="playlist"] .now-playing-panel {
    display: none;
  }

  .art-stage {
    width: min(12svh, 30vw, 106px);
    height: min(12svh, 30vw, 106px);
  }

  .player-thumbnail {
    box-shadow: 0 14px 44px rgba(0, 0, 0, 0.38);
  }

  .track-copy {
    width: 100%;
  }

  #channel-name {
    font-size: 11px;
    margin-bottom: 4px;
  }

  #player-title {
    font-size: 16px;
    line-height: 1.05;
  }

  .playback-state {
    min-height: 20px;
    font-size: 12px;
  }

  #waveform-container {
    height: 22px;
  }

  .waveform-bar {
    height: 18px;
  }

  #progress-line {
    grid-template-columns: 34px minmax(120px, 1fr) 34px;
    gap: 6px;
    margin-top: 16px;
    margin-bottom: 16px;
  }

  #time-start,
  #time-end {
    font-size: 11px;
    width: auto;
  }

  #progress-container {
    height: 12px;
  }

  #progress-thumb {
    width: 30px;
    height: 30px;
  }

  .controls-buttons {
    width: min(100%, 360px);
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .play-control-row {
    grid-template-columns: 1fr;
  }

  .transport-control-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
  }

  .round-button {
    border-radius: 8px;
    min-width: 0;
    width: 100%;
    height: 48px;
  }

  .play-button {
    width: 100%;
    height: 100px;
  }

  .play-button svg {
    width: 44px;
    height: 44px;
  }

  .secondary-button,
  .loop-button,
  .shuffle-button {
    width: 100%;
    height: 60px;
  }

  .secondary-button svg,
  .loop-button svg,
  .shuffle-button svg {
    width: 24px;
    height: 24px;
  }

  .seek-buttons {
    width: min(100%, 360px);
    display: grid;
    gap: 8px;
    margin-top: 2px;
  }

  .seek-row {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
  }

  .seek-buttons button {
    min-width: 0;
    min-height: 40px;
    padding: 0 4px;
    font-size: 11px;
  }

  #search {
    width: min(52vw, 260px);
  }
}

@media (max-width: 520px) {
  #admin-page,
  #load-page,
  #search-page,
  #menu-page,
  #home-page {
    padding: 12px;
  }

  .admin-panel,
  .load-panel,
  .search-panel {
    padding: 16px;
  }

  .header-row {
    align-items: stretch;
  }

  #logo-placeholder {
    font-size: 30px;
    flex: 0 0 auto;
  }

  .playlist-loader {
    grid-template-columns: 1fr;
  }

  .load-panel {
    padding: 14px;
  }

  .search-panel {
    padding: 14px;
  }

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

  .video-card {
    grid-template-columns: 48px 1fr;
  }

  .video-card img {
    width: 48px;
    height: 48px;
  }

  #player-title {
    font-size: 16px;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  #video-grid {
    max-height: calc(100svh + 116px);
  }
}
