:root {
  color-scheme: dark;
  --bg: #0b0f1a;
  --card: #151b2d;
  --text: #edf0f7;
  --muted: #a4acc0;
  --accent: #4da3ff;
  --danger: #ff6f6f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(160deg, #090d16, #0f1730 70%);
  color: var(--text);
  min-height: 100vh;
}

.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 18px 14px 40px;
}

.card {
  background: rgba(21, 27, 45, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 12px;
  backdrop-filter: blur(4px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

h1, h2, h3 {
  margin: 6px 0;
}

label {
  display: block;
  margin: 8px 0 4px;
  color: var(--muted);
}

input, button, select {
  font: inherit;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #1f2840;
  color: var(--text);
  padding: 10px;
}

button {
  background: var(--accent);
  border: none;
  color: #09101d;
  font-weight: 600;
}

button.ghost {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text);
}

.inline {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

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

.error {
  color: var(--danger);
  min-height: 20px;
}

.hidden {
  display: none;
}

#player {
  width: 100%;
  margin-top: 8px;
}

.book-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  padding: 10px 0;
}

.book-main {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.book-meta {
  min-width: 0;
  flex: 1;
}

.book-cover-wrap {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  flex: 0 0 48px;
  display: grid;
  place-items: center;
}

.book-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.book-cover-fallback {
  font-size: 20px;
  line-height: 1;
}

.book-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-content: flex-start;
  gap: 8px;
  flex: 0 0 auto;
  max-width: 210px;
}

.book-actions button[data-play] {
  min-width: 74px;
  font-weight: 700;
}

.book-actions button {
  padding: 8px 10px;
  min-height: 36px;
  line-height: 1;
}

.book-menu {
  position: relative;
}

.book-menu[open] {
  z-index: 2;
}

.menu-trigger {
  list-style: none;
  cursor: pointer;
  user-select: none;
  min-width: 36px;
  text-align: center;
  font-size: 20px;
  padding: 6px 8px;
}

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

.book-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 110px;
  background: #151b2d;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.menu-item {
  width: 100%;
  text-align: left;
}

.star-btn {
  min-width: 36px;
  padding: 8px 10px;
  font-size: 18px;
  line-height: 1;
}

.star-btn.is-on {
  color: #ffd866;
  border-color: rgba(255, 216, 102, 0.8);
  background: rgba(255, 216, 102, 0.12);
}

.delete-btn {
  min-width: 30px;
  padding: 6px 8px;
  font-size: 20px;
  font-weight: 700;
  color: #ff9a9a !important;
  border-color: rgba(255, 111, 111, 0.7) !important;
  background: rgba(255, 111, 111, 0.12) !important;
}

.danger-item {
  color: #ff9a9a !important;
  border-color: rgba(255, 111, 111, 0.7) !important;
  background: rgba(255, 111, 111, 0.12) !important;
}

.small {
  font-size: 12px;
}

.book-progress {
  margin-top: 6px;
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.book-progress-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #4da3ff, #7bc4ff);
  transition: width 220ms ease;
}

.pill {
  display: inline-block;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(77, 163, 255, 0.2);
  border: 1px solid rgba(77, 163, 255, 0.6);
  color: #cce5ff;
}

.now-playing {
  display: flex;
  align-items: center;
  gap: 10px;
}

.now-playing-cover-wrap {
  width: 56px;
  height: 56px;
  flex-basis: 56px;
}

.card-subtle {
  margin-top: 10px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
}

.view-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.view-nav button {
  min-width: 88px;
}

.player-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.player-controls button {
  min-width: 78px;
}

.speed-wrap {
  margin-left: auto;
}

.player-controls label {
  margin: 0;
}

.speed-wrap select {
  min-width: 64px;
  text-align: center;
}

.library-tools {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 6px 0 10px;
  flex-wrap: wrap;
}

.library-tools input[type="text"],
.library-tools input:not([type]) {
  min-width: 220px;
  flex: 1;
}

#uploadStats {
  margin-top: 8px;
}

#uploadProgress {
  width: 100%;
  height: 12px;
}

@media (max-width: 640px) {
  .book-row {
    flex-direction: column;
    gap: 8px;
  }

  .book-actions {
    max-width: none;
    width: 100%;
    justify-content: flex-start;
    gap: 6px;
  }

  .book-actions button[data-play] {
    min-width: 90px;
  }

  .book-actions button:not([data-play]) {
    min-width: 34px;
    padding: 7px 9px;
    font-size: 13px;
  }

  .book-menu-panel {
    right: auto;
    left: 0;
  }

  .delete-btn {
    min-width: 28px !important;
    font-size: 18px !important;
    padding: 6px 8px !important;
  }

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

  .player-controls button {
    min-width: 0;
    width: 100%;
    padding: 9px 6px;
    font-size: 14px;
  }

  .speed-wrap {
    margin-left: 0;
    width: 100%;
  }

  .speed-wrap select {
    width: 100%;
    padding: 9px 6px;
    font-size: 14px;
  }
}
