:root {
  color-scheme: light;
  --bg: #f4f0e7;
  --surface: #fffdf8;
  --surface-2: #ebe4d7;
  --ink: #20231f;
  --muted: #6a6d65;
  --line: #ddd3c4;
  --brand: #2f5b45;
  --brand-2: #20382d;
  --accent: #c36f35;
  --accent-2: #e0a45e;
  --danger: #a33b2f;
  --ok: #367852;
  --shadow: 0 22px 70px rgba(58, 45, 30, .14);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a {
  color: var(--brand);
}

.page {
  min-height: 100vh;
  padding: 28px;
}

.shell {
  width: min(1180px, 100%);
  margin: 0 auto;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 800;
  font-size: 20px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 900;
}

.brand-mark.image-mark {
  background: #fff;
  padding: 4px;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.player-brand {
  display: block;
}

.player-brand-logo {
  width: min(300px, 100%);
  height: auto;
  display: block;
}

.player-brand-icon {
  width: 42px;
  height: 42px;
  object-fit: contain;
  display: none;
}

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab,
.button,
button,
input[type="submit"] {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
}

.tab.active,
.button.primary,
button.primary,
input[type="submit"].primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.button.accent,
button.accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.small-button,
.button.small-button,
button.small-button {
  min-height: 32px;
  padding: 6px 10px;
  border-radius: 7px;
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
}

button:disabled,
.button:disabled {
  cursor: wait;
  opacity: .78;
}

.download-button {
  white-space: nowrap;
}

.button-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .22);
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .04em;
}

.button-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, .35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.button.danger,
button.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 18px;
}

.col-4 {
  grid-column: span 4;
}

.col-5 {
  grid-column: span 5;
}

.col-7 {
  grid-column: span 7;
}

.col-8 {
  grid-column: span 8;
}

.col-12 {
  grid-column: span 12;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel.pad {
  padding: 22px;
}

.panel-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.header-actions,
.table-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.table-actions {
  gap: 6px;
}

.panel-body {
  padding: 22px;
}

.admin-filter {
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.search-form {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-form input[type="search"],
.search-form input[type="text"],
.search-form input[name="q"] {
  min-width: min(420px, 100%);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

h1,
h2,
h3 {
  line-height: 1.18;
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 46px);
}

h2 {
  font-size: 22px;
}

h3 {
  font-size: 17px;
}

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

.small {
  font-size: 13px;
}

.notice {
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff7e9;
  color: #4b3a24;
  margin-bottom: 18px;
}

.notice.ok {
  background: #eaf6ef;
  color: #1f5737;
}

.notice.error {
  background: #fdecea;
  color: #7a251d;
}

label {
  display: block;
  font-weight: 800;
  margin-bottom: 7px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  min-height: 42px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

textarea {
  min-height: 110px;
  resize: vertical;
}

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

.field.full {
  grid-column: 1 / -1;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
}

.checkline input {
  width: auto;
  min-height: auto;
}

.table-wrap {
  overflow: auto;
}

.sort-list {
  display: grid;
  gap: 10px;
}

.sort-row {
  display: grid;
  grid-template-columns: 42px 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(58, 45, 30, .06);
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}

.sort-row:hover {
  border-color: #c9bba6;
  box-shadow: 0 12px 32px rgba(58, 45, 30, .1);
}

.sort-row.dragging {
  opacity: .72;
  transform: scale(.99);
  border-color: var(--accent);
}

.drag-handle {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-content: center;
  gap: 4px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: #f7f2ea;
  cursor: grab;
  padding: 0;
  min-height: 42px;
}

.drag-handle:active {
  cursor: grabbing;
}

.drag-handle span {
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: #7b6f62;
  display: block;
}

.sort-index {
  color: var(--muted);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.embed-admin-box {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #faf7f0;
}

.embed-code {
  min-height: 92px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
}

.modal {
  width: min(620px, calc(100vw - 32px));
  max-height: min(760px, calc(100vh - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 90px rgba(32, 24, 16, .28);
}

.modal::backdrop {
  background: rgba(31, 45, 37, .54);
  backdrop-filter: blur(2px);
}

.modal-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-body {
  padding: 18px;
}

.modal-table {
  max-height: min(62vh, 520px);
}

.pagination {
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
}

.pagination-links {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.page-link {
  min-width: 32px;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.page-link.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.page-link.disabled {
  color: var(--muted);
  background: var(--surface-2);
  cursor: default;
}

.page-ellipsis {
  color: var(--muted);
  font-weight: 800;
  padding: 0 2px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  background: #faf7f0;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  background: var(--surface-2);
  color: var(--ink);
}

.badge.ok {
  background: #dcefe4;
  color: #1f5737;
}

.badge.warn {
  background: #f8e5c8;
  color: #7c4b1f;
}

.book-thumb {
  width: 54px;
  aspect-ratio: 3 / 4;
  border-radius: 7px;
  object-fit: cover;
  background: var(--surface-2);
  display: block;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
}

.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.player-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  align-items: start;
  background: #1f2d25;
  color: #fff;
}

.library {
  background: #1f2d25;
  color: #fff;
  padding: 24px;
  overflow: auto;
  border-right: 1px solid rgba(255, 255, 255, .08);
}

.library .muted {
  color: rgba(255, 255, 255, .66);
}

.library-list {
  display: grid;
  gap: 10px;
  margin-top: 20px;
}

.library-item {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, .14);
  background: rgba(255, 255, 255, .08);
  color: #fff;
  border-radius: 8px;
  padding: 10px;
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 12px;
  text-align: left;
}

.library-item.active {
  border-color: rgba(255, 255, 255, .82);
  background: #fff;
  color: var(--ink);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .16);
}

.library-item.active .muted {
  color: var(--muted);
}

.player-main {
  padding: clamp(22px, 4vw, 54px);
  display: grid;
  align-content: start;
}

.player-card {
  max-width: 880px;
  display: flex;
  flex-direction: column;
}

.hero-book {
  order: 1;
  display: grid;
  grid-template-columns: minmax(160px, 260px) 1fr;
  column-gap: clamp(22px, 4vw, 44px);
  row-gap: 0;
  align-items: center;
}

.hero-copy,
.audio-box {
  grid-column: 2;
}

.cover-large {
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 8px;
  object-fit: cover;
  box-shadow: 0 26px 90px rgba(0, 0, 0, .34);
  background: #31483b;
  grid-row: 1 / span 2;
}

.track-section {
  order: 3;
  margin-top: 28px;
}

.player-card > .download-panel {
  order: 2;
}

.track-list {
  display: grid;
  gap: 8px;
  max-height: none !important;
  overflow: visible !important;
  padding-right: 0 !important;
}

.track-button {
  width: 100%;
  border-color: rgba(255, 255, 255, .16);
  background: rgba(255, 255, 255, .08);
  color: #fff;
  justify-content: flex-start;
}

.track-button.active {
  background: #fff;
  color: var(--ink);
}

.audio-box {
  margin: 24px 0 18px;
}

audio {
  width: 100%;
}

.embed-body {
  min-height: 100vh;
  margin: 0;
  background: transparent;
  overflow: hidden;
}

.sample-embed {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: linear-gradient(135deg, #20382d, #2f5b45);
  color: #fff;
  border-radius: 8px;
}

.sample-cover {
  width: 92px;
  aspect-ratio: 3 / 4;
  border-radius: 8px;
  object-fit: cover;
  background: rgba(255, 255, 255, .12);
  box-shadow: 0 18px 42px rgba(0, 0, 0, .26);
}

.sample-cover-placeholder {
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 32px;
}

.sample-content {
  min-width: 0;
  display: grid;
  gap: 12px;
}

.sample-content p {
  margin: 0 0 4px;
  color: rgba(255, 255, 255, .7);
  font-size: 13px;
  font-weight: 800;
}

.sample-content h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.18;
}

.sample-player {
  display: grid;
  gap: 7px;
}

.sample-player span {
  font-size: 13px;
  font-weight: 900;
  color: #fff;
}

.sample-player audio {
  height: 36px;
}

.sample-empty {
  grid-template-columns: 1fr;
}

.sample-empty p {
  margin: 6px 0 0;
  color: rgba(255, 255, 255, .76);
}

.download-panel {
  margin-top: 18px;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 8px;
  padding: 16px;
  background: rgba(255, 255, 255, .07);
}

.download-status {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  color: rgba(255, 255, 255, .78);
  font-size: 13px;
}

.download-status strong {
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, .28);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.progress-shell {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .18);
  overflow: hidden;
  margin-top: 12px;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width .25s ease;
}

@media (max-width: 860px) {
  .page {
    padding: 16px;
  }

  .topbar,
  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .admin-filter,
  .pagination {
    align-items: stretch;
    flex-direction: column;
  }

  .search-form {
    flex-wrap: wrap;
    width: 100%;
  }

  .search-form input[name="q"] {
    flex: 1 1 220px;
    min-width: 0;
  }

  .grid,
  .form-grid,
  .player-layout,
  .hero-book {
    grid-template-columns: 1fr;
  }

  .player-layout {
    gap: 0;
    position: relative;
  }

  .col-4,
  .col-5,
  .col-7,
  .col-8,
  .col-12 {
    grid-column: span 1;
  }

  .library {
    max-height: none;
  }

  .library.single-book-library {
    min-height: 0;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px;
    overflow: visible;
    border-right: 0;
  }

  .library.single-book-library .player-brand {
    flex: 1 1 auto;
    margin: 0;
    min-width: 0;
  }

  .library.single-book-library .player-brand-logo {
    width: min(220px, calc(100vw - 170px));
    min-width: 160px;
  }

  .library.single-book-library form {
    flex: 0 0 auto;
    margin: 0 !important;
  }

  .library.single-book-library > .small,
  .library.single-book-library .library-list {
    display: none;
  }

  .sort-row {
    grid-template-columns: 42px 38px minmax(0, 1fr);
  }

  .sort-row .danger {
    grid-column: 3;
    justify-self: start;
  }

  .player-brand {
    display: flex;
  }

  .player-brand-logo {
    display: block;
    width: min(240px, 100%);
  }

  .player-brand-icon {
    display: none;
  }

  .sample-embed {
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 12px;
    padding: 12px;
  }

  .sample-cover {
    width: 72px;
  }

  .sample-content h1 {
    font-size: 17px;
  }

  .player-main {
    padding: 18px;
    align-content: start;
  }

  .library.single-book-library + .player-main {
    padding-top: 112px;
  }

  .hero-book {
    grid-template-columns: 96px minmax(0, 1fr);
    column-gap: 14px;
    row-gap: 16px;
    align-items: start;
  }

  .hero-copy {
    align-self: center;
    min-width: 0;
  }

  .hero-copy #author {
    margin-bottom: 4px !important;
    font-size: 14px;
  }

  .hero-copy #resume {
    margin-top: 7px !important;
    font-size: 14px;
    line-height: 1.3;
  }

  .cover-large {
    width: 100%;
    justify-self: start;
    grid-row: 1;
  }

  .audio-box,
  .download-panel {
    grid-column: 1 / -1;
  }

  .audio-box {
    margin: 0;
  }

  .track-section {
    order: 2;
    margin-top: 24px;
  }

  .player-card > .download-panel {
    order: 3;
    margin-top: 18px;
  }

  .player-card h1 {
    font-size: clamp(22px, 6vw, 28px);
    line-height: 1.08;
  }
}
