:root {
  --bg: #111214;
  --surface: #1a1b1f;
  --raised: #26282d;
  --raised-hover: #31343a;
  --line: #26282d;
  --line-strong: #3a3d44;
  --text: #ffffff;
  --text-soft: #d0d2d6;
  --muted: #a3a6ad;
  --unplayed: #5c5f66;
  --played: #ffffff;
  --hover: #8e9199;
  --accent: #e8772e;
  --danger: #ff6b5e;
  --radius: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Bai Jamjuree', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--text); }
a:hover { color: var(--text-soft); }
img { display: block; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid #8fa8e8; outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.site-header {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px;
  padding: 18px max(16px, 5%); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 10px; text-decoration: none; }
.brand-name { font-size: 24px; font-weight: 700; letter-spacing: 0.05em; color: var(--text); }
.brand-sub { font-size: 15px; color: var(--muted); }
.site-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 24px; font-size: 15px; }
.site-nav a { color: var(--muted); text-decoration: none; }
.site-nav a:hover { color: var(--text); }
.inline { display: inline; margin: 0; }
.link-btn { background: none; border: none; padding: 0; color: var(--muted); font-size: inherit; text-decoration: none; }
.link-btn:hover { color: var(--text); }

/* ---------- page ---------- */
.page { width: 100%; max-width: 1180px; margin: 0 auto; padding: 32px 24px 140px; display: flex; flex-direction: column; gap: 40px; }
.page.narrow { max-width: 440px; }
.section { display: flex; flex-direction: column; gap: 28px; }
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 16px; }
.section-head h1, .section-head h2 { margin: 0; font-size: 30px; font-weight: 700; }
.cards { display: flex; flex-direction: column; gap: 44px; }
.empty { padding: 80px 0; text-align: center; }
.empty h1 { font-size: 30px; font-weight: 600; margin: 0 0 8px; }
.more { margin: 0; }
.more a { color: var(--muted); }
.description { max-width: 720px; color: var(--text-soft); font-size: 16px; line-height: 1.65; white-space: normal; }

/* ---------- track card ---------- */
.card { display: flex; flex-wrap: wrap; gap: 28px; align-items: flex-start; }
.cover { width: 200px; height: 200px; border-radius: var(--radius); object-fit: cover; background: var(--raised); flex: 0 0 auto; }
.card-big .cover { width: 320px; height: 320px; }
.thumb { display: none; }
.card-body { flex: 1 1 520px; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.card-head { display: flex; align-items: center; gap: 16px; }
.names { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.artist { font-size: 16px; font-weight: 600; color: var(--muted); }
.title { font-size: 22px; font-weight: 600; color: var(--text); text-decoration: none; margin: 0; line-height: 1.2; overflow-wrap: anywhere; }
a.title:hover { text-decoration: underline; text-underline-offset: 3px; }
.card-big .title { font-size: 30px; }
.tags { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 16px;
  background: var(--raised); color: #e2e3e6; font-size: 14px; font-weight: 500; white-space: nowrap;
}
.pill-accent { color: var(--accent); }

.btn-play {
  width: 64px; height: 64px; border-radius: 50%; border: none; background: #fff; color: var(--bg);
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; transition: transform .12s ease;
}
.btn-play:hover { transform: scale(1.05); }
.btn-play:active { transform: scale(0.97); }
.card-big .btn-play { width: 72px; height: 72px; }
.btn-play.small { width: 44px; height: 44px; }
.btn-play .i-pause, .is-playing .btn-play .i-play, .pb-toggle.is-playing .i-play { display: none; }
.is-playing .btn-play .i-pause, .pb-toggle.is-playing .i-pause { display: block; }
.pb-toggle .i-pause { display: none; }
.is-loading .btn-play { opacity: .75; }

.wave { position: relative; height: 80px; cursor: pointer; touch-action: none; border-radius: 4px; }
.card-big .wave { height: 110px; }
.wave canvas { width: 100%; height: 100%; display: block; }
.times { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: -6px; }

.card-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.btn-sq {
  min-width: 48px; height: 44px; padding: 0 12px; border-radius: var(--radius); border: none; background: var(--raised); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; font-size: 15px; font-weight: 500;
}
.btn-sq:hover { background: var(--raised-hover); color: var(--text); }
.stats { display: flex; align-items: center; gap: 18px; color: var(--muted); font-size: 16px; font-variant-numeric: tabular-nums; }
.stat { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- bottom player ---------- */
.playerbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: rgba(26, 27, 31, 0.97); border-top: 1px solid #2a2c31;
  backdrop-filter: blur(10px); padding-bottom: env(safe-area-inset-bottom);
}
.pb-progress { height: 3px; background: var(--line-strong); display: none; }
.pb-fill { height: 100%; width: 0; background: var(--played); }
.pb-inner { display: flex; align-items: center; gap: 16px; padding: 10px max(16px, 5%); }
.pb-controls { display: flex; align-items: center; gap: 4px; }
.btn-icon {
  width: 44px; height: 44px; border-radius: 50%; border: none; background: transparent; color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
}
.btn-icon:hover { background: var(--raised); }
.pb-now { display: flex; align-items: center; gap: 12px; flex: 0 1 280px; min-width: 0; }
.pb-cover { width: 44px; height: 44px; border-radius: 4px; object-fit: cover; flex: 0 0 auto; }
.pb-names { display: flex; flex-direction: column; min-width: 0; }
.pb-title { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pb-artist { font-size: 13px; color: var(--muted); }
.pb-time { flex: 1 1 240px; display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pb-bar { flex: 1; height: 16px; display: flex; align-items: center; cursor: pointer; position: relative; }
.pb-bar::before { content: ''; position: absolute; left: 0; right: 0; height: 4px; border-radius: 2px; background: var(--line-strong); }
.pb-bar-fill { position: relative; height: 4px; width: 0; border-radius: 2px; background: var(--played); }
.pb-actions { display: flex; }

/* ---------- share dialog ---------- */
.share-dialog {
  border: none; padding: 0; background: transparent; color: var(--text);
  width: min(440px, 100vw); max-width: 100vw; margin: auto;
}
.share-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.share-sheet { background: var(--surface); border-radius: 16px; padding: 16px 20px 24px; display: flex; flex-direction: column; gap: 14px; }
.share-top { display: flex; align-items: center; justify-content: space-between; }
.share-top h2 { margin: 0; font-size: 20px; font-weight: 600; }
.share-preview { display: flex; gap: 12px; align-items: center; padding: 10px; background: var(--bg); border: 1px solid #2a2c31; border-radius: 12px; }
.share-preview img { width: 56px; height: 56px; border-radius: 6px; object-fit: cover; }
.share-preview div { display: flex; flex-direction: column; min-width: 0; }
.sp-title { font-weight: 600; }
.sp-host { font-size: 13px; color: var(--muted); }
.share-row { display: flex; gap: 8px; }
.share-row .input { flex: 1; min-width: 0; }
.share-note { margin: 0; display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.share-buttons { display: flex; flex-direction: column; gap: 10px; }

@media (max-width: 640px) {
  .share-dialog { margin: auto 0 0; width: 100vw; }
  .share-sheet { border-radius: 20px 20px 0 0; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
}

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 20px); z-index: 50;
  background: #fff; color: var(--bg); padding: 10px 18px; border-radius: 22px; font-weight: 600; font-size: 15px;
  opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- forms & buttons ---------- */
.field-label { font-size: 14px; font-weight: 500; color: var(--text-soft); }
.input {
  width: 100%; height: 44px; padding: 0 12px; border-radius: var(--radius); border: 1px solid var(--line-strong);
  background: var(--bg); color: var(--text); font-size: 15px;
}
textarea.input { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.input-file { font-size: 14px; color: var(--muted); max-width: 100%; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 15px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: #fff; flex: 0 0 auto; }
.btn {
  height: 48px; padding: 0 22px; border-radius: 24px; border: none; font-size: 16px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
}
.btn-sm { height: 40px; padding: 0 16px; font-size: 14px; border-radius: 20px; }
.btn-primary { background: #fff; color: var(--bg); }
.btn-primary:hover { background: #e6e7ea; color: var(--bg); }
.btn-secondary { background: var(--raised); color: var(--text); }
.btn-secondary:hover { background: var(--raised-hover); color: var(--text); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.panel { background: var(--surface); border-radius: 12px; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.form h1 { margin: 0 0 4px; font-size: 26px; }
.error { margin: 0; color: var(--danger); }
.flash { margin: 0; padding: 12px 16px; border-radius: var(--radius); background: var(--raised); }
fieldset.radios { border: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
fieldset.radios legend { margin-bottom: 4px; }

/* ---------- admin ---------- */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center;
  padding: 36px 20px; border: 2px dashed var(--line-strong); border-radius: 14px; color: var(--text-soft); cursor: pointer;
}
.dropzone.over, .dropzone:hover { border-color: #fff; color: #fff; }
.uploads { list-style: none; margin: -20px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.uploads:empty { display: none; }
.uploads li { background: var(--surface); border-radius: var(--radius); padding: 10px 14px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.progress { height: 4px; border-radius: 2px; background: var(--line-strong); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: #fff; transition: width .15s linear; }
.uploads .err { color: var(--danger); }

.alist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.arow { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; padding: 10px 12px; border-radius: 10px; background: var(--surface); }
.arow.dragging { opacity: .4; }
.arow.drop-before { box-shadow: 0 -2px 0 #fff; }
.arow.drop-after { box-shadow: 0 2px 0 #fff; }
.grip { color: var(--muted); cursor: grab; display: flex; }
.athumb { width: 56px; height: 56px; border-radius: 6px; object-fit: cover; }
.ainfo { flex: 1 1 200px; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.atitle { font-size: 17px; font-weight: 600; text-decoration: none; overflow-wrap: anywhere; }
.abadges { display: flex; flex-wrap: wrap; gap: 6px; }
.aactions { display: flex; gap: 8px; align-items: center; }

.edit-grid { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
.edit-side { flex: 0 1 320px; min-width: 260px; display: flex; flex-direction: column; gap: 16px; }
.edit-main { flex: 1 1 480px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.edit-cover { width: 100%; height: auto; aspect-ratio: 1; border-radius: 12px; object-fit: cover; }
.linkbox { display: flex; flex-direction: column; gap: 6px; }
.replace-form { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.replace-form .progress { width: 100%; }
.versions { margin: 8px 0 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }
.danger { border: 1px solid #3a2523; }
.panel .btn-sm, .panel > .btn-primary { align-self: flex-start; }

/* ---------- small screens ---------- */
@media (max-width: 720px) {
  .page { padding: 20px 16px 140px; gap: 32px; }
  .site-header { padding: 14px 16px; }
  .brand-name { font-size: 20px; }
  .card { gap: 16px; }
  .card:not(.card-big) .cover { display: none; }
  .thumb { display: block; width: 52px; height: 52px; border-radius: 6px; object-fit: cover; flex: 0 0 auto; }
  .card-head { gap: 12px; }
  .card-big .cover { width: 100%; height: auto; aspect-ratio: 1; }
  .card-body { flex-basis: 100%; }
  .btn-play { width: 56px; height: 56px; }
  .card-big .btn-play { width: 64px; height: 64px; }
  .title { font-size: 19px; }
  .card-big .title { font-size: 24px; }
  .tags { display: none; }
  .wave { height: 64px; }
  .card-big .wave { height: 84px; }
  .pb-inner { gap: 10px; padding: 8px 12px; }
  .pb-progress { display: block; }
  .pb-time, .pb-prev, .pb-actions { display: none; }
  .pb-now { order: -1; flex: 1 1 auto; }
  .section-head h1, .section-head h2 { font-size: 24px; }
}
