:root {
  --bg: #0d1014;
  --panel: #151a21;
  --panel-2: #1c232c;
  --field: #10151b;
  --line: #2a3340;
  --line-2: #3a4656;
  --text: #f3f5f8;
  --text-2: #c7cfda;
  --muted: #9aa5b4;
  --faint: #6b7686;
  --amber: #ffb224;
  --amber-soft: #ffd07a;
  --amber-bg: #2a2110;
  --red: #ff8f86;
  --green: #34d6b6;
  --green-bg: #10241f;
  --green-line: #1f6b5a;
  --line-top: #222a35;
  --bad-bg: #2a1412;
  --bad-line: #7a2f28;
  --bad-text: #ffc9c4;
  --banner-text: #e6d3a6;
  color-scheme: dark;
  --font: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Bricolage Grotesque", "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.4; }
button, input { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.35; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
h1, h2, p { margin: 0; }
.boot { padding: 40px 20px; text-align: center; color: var(--muted); }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }

/* ---------- header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px 16px; padding: 14px 32px; border-bottom: 1px solid var(--line-top); }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand img { height: 46px; width: auto; display: block; }
.brand .rule { width: 1px; height: 38px; background: var(--line); }
.brand .name { font-family: var(--display); font-weight: 700; font-size: 24px; letter-spacing: -0.01em; line-height: 1.1; }
.brand .sub { font-size: 13px; color: var(--muted); }
.nav { display: flex; gap: 6px; }
.nav a { min-height: 44px; padding: 0 16px; border-radius: 12px; color: var(--muted); font-weight: 600; display: flex; align-items: center; text-decoration: none; border: 1px solid transparent; }
.nav a[aria-current="page"] { background: var(--panel-2); border-color: var(--line); color: var(--text); }
.who { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.who .hi { display: flex; align-items: center; gap: 8px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--line); display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.badge { font-size: 12px; font-weight: 700; border-radius: 999px; padding: 3px 10px; border: 1px solid var(--line-2); color: var(--text-2); white-space: nowrap; }
.badge.master { color: var(--amber-soft); background: var(--amber-bg); border-color: var(--amber); }
.badge.good { color: var(--green); background: var(--green-bg); border-color: var(--green-line); }
.badge.warn { color: var(--amber-soft); background: var(--amber-bg); border-color: var(--amber); }
.badge.dashed { border-style: dashed; color: var(--muted); }

/* ---------- buttons ---------- */
.btn { min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line-2); background: transparent; color: var(--text-2); font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.small { font-size: 14px; padding: 0 14px; }
.btn.ghost { border-color: var(--line); }
.btn.danger { border-color: transparent; color: var(--red); }
.btn.amber-outline { border-color: var(--amber); background: var(--amber-bg); color: var(--amber-soft); }
.btn.primary { border: 0; background: var(--amber); color: #1b1200; font-weight: 700; }
.btn.block { width: 100%; min-height: 54px; border-radius: 14px; font-size: 17px; }
.btn.google { background: #fff; color: #1f1f1f; border: 0; min-height: 52px; border-radius: 14px; font-size: 16px; font-weight: 600; width: 100%; text-decoration: none; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: transparent; color: var(--text-2); display: inline-flex; align-items: center; justify-content: center; padding: 0; flex: none; }
.icon-btn.bare { border-color: transparent; }
.icon-btn.fav-on { color: var(--amber); border-color: transparent; }
.icon-btn.fav-off { color: var(--muted); border-color: transparent; }
.icon-btn.del { color: var(--red); border-color: transparent; }
.icon-btn.fade { border-color: transparent; color: var(--muted); }
.icon-btn.fade .ramp { fill: none; }
.icon-btn.fade[aria-pressed="true"] { color: var(--amber); }
.icon-btn.fade[aria-pressed="true"] .ramp { fill: currentColor; }
.arch-btn { margin-left: auto; width: 44px; height: 44px; padding: 0; justify-content: center; border: 0; border-radius: 12px; background: transparent; color: var(--amber-soft); font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; flex: none; }
.fades { display: flex; gap: 0; margin: 2px 0 -4px -8px; }
.fades .icon-btn { width: 40px; height: 36px; }
.arch-btn:disabled { opacity: 0.4; }

/* ---------- layout ---------- */
.page { width: 100%; max-width: 1200px; margin: 0 auto; padding: 28px 32px 56px; display: flex; flex-direction: column; gap: 20px; }
.cols { display: flex; flex-wrap: wrap; gap: 28px; align-items: flex-start; }
.col-main { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.col-side { flex: 1 1 320px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.page-head h1 { font-family: var(--display); font-weight: 700; font-size: 34px; letter-spacing: -0.02em; line-height: 1.1; }
.page-head p { margin-top: 6px; color: var(--muted); font-size: 15px; }
.head-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.count { padding: 8px 14px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); font-family: var(--mono); font-size: 13px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.card h2 { font-family: var(--display); font-weight: 700; font-size: 20px; }
.card .row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.muted { color: var(--muted); }
.small-text { font-size: 14px; color: var(--muted); }
.body-text { font-size: 14px; color: var(--text-2); line-height: 1.45; }

/* ---------- banners ---------- */
.banner { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 14px 18px; border-radius: 16px; background: var(--amber-bg); border: 1px solid var(--amber); }
.banner svg { flex: none; color: var(--amber); }
.banner .t { font-family: var(--display); font-weight: 700; font-size: 18px; color: var(--amber-soft); }
.banner .d { font-size: 14px; color: var(--banner-text); margin-top: 2px; }
.banner .grow { flex: 1 1 260px; min-width: 0; }
.banner.info { background: var(--panel); border-color: var(--line-2); }
.banner.info .t { color: var(--text); }
.banner.info .d { color: var(--muted); }
.banner.info svg { color: var(--muted); }

/* ---------- playlist rows ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 14px; padding: 12px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; position: relative; }
.row.dragging-others { transition: transform 0.16s ease; }
.row.dragging { z-index: 5; border-color: var(--amber); box-shadow: 0 14px 34px rgba(0, 0, 0, 0.35); cursor: grabbing; transition: none; }
.row.dragging .grip { cursor: grabbing; color: var(--amber); }
body.is-dragging { user-select: none; -webkit-user-select: none; cursor: grabbing; }
@media (prefers-reduced-motion: reduce) { .row.dragging-others { transition: none; } }
.grip { display: flex; align-items: center; justify-content: center; color: var(--text-2); width: 36px; min-height: 48px; margin-left: -6px; border-radius: 10px; cursor: grab; touch-action: none; flex: none; }
.grip:hover { color: var(--amber); background: var(--panel-2); }
.num { width: 20px; text-align: right; font-family: var(--mono); font-size: 13px; color: var(--muted); }
.play { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text); display: flex; align-items: center; justify-content: center; padding: 0; flex: none; }
.play.on { background: var(--amber); border-color: var(--amber); color: #1b1200; }
.meta { flex: 1 1 160px; min-width: 0; }
.meta .title { font-weight: 600; font-size: 16px; overflow-wrap: anywhere; }
.meta .file { font-size: 13px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.dur { font-family: var(--mono); font-size: 14px; color: var(--muted); }
.controls { flex: 1 1 100%; margin-left: -8px; padding-left: 0; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.chip { min-height: 44px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line-2); background: transparent; color: var(--muted); font-size: 14px; font-weight: 600; }
.chip[aria-pressed="true"] { border-color: var(--amber); background: var(--amber-bg); color: var(--amber-soft); }
.empty { padding: 40px 20px; text-align: center; border: 1px dashed var(--line-2); border-radius: 16px; color: var(--muted); }

/* ---------- add music / switches / stats ---------- */
.drop { border: 2px dashed var(--line-2); border-radius: 16px; padding: 26px 16px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.drop.over { border-color: var(--amber); background: var(--amber-bg); }
.drop.off { opacity: 0.5; }
.drop svg { color: var(--amber); }
.drop .big { font-weight: 600; }
.switch { min-height: 44px; min-width: 64px; border: 0; background: transparent; padding: 0; display: flex; align-items: center; justify-content: center; }
.switch .track { width: 52px; height: 30px; border-radius: 999px; background: var(--line); display: flex; align-items: center; padding: 0 3px; }
.switch .knob { width: 24px; height: 24px; border-radius: 50%; background: var(--muted); }
.switch[aria-checked="true"] .track { background: var(--amber); justify-content: flex-end; }
.switch[aria-checked="true"] .knob { background: #1b1200; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.stat { background: var(--panel-2); border-radius: 12px; padding: 12px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-family: var(--mono); font-size: 18px; margin-top: 4px; }
.notice { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 14px; background: var(--green-bg); border: 1px solid var(--green-line); }
.notice svg { color: var(--green); flex: none; }
.notice .t { font-weight: 700; color: var(--green); }
.notice .d { font-size: 14px; color: var(--text-2); }
.notice.bad { background: var(--bad-bg); border-color: var(--bad-line); }
.notice.bad svg, .notice.bad .t { color: var(--red); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.pair { display: flex; gap: 10px; flex-wrap: wrap; }
.pair .btn { flex: 1 1 120px; min-height: 52px; border-radius: 14px; font-size: 16px; }
.last { font-size: 13px; color: var(--muted); }
.last b { color: var(--text-2); font-weight: 600; }

/* ---------- people ---------- */
.legend { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.legend > div { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; }
.legend > div.m { border-color: var(--amber); }
.legend .h { font-weight: 700; font-size: 15px; }
.legend .m .h { color: var(--amber-soft); }
.legend .b { font-size: 14px; color: var(--text-2); margin-top: 4px; }
.section-h { font-family: var(--display); font-weight: 700; font-size: 20px; margin: 4px 0 10px; }
.section-h span { font-family: var(--mono); font-size: 13px; color: var(--muted); font-weight: 500; margin-left: 6px; }
.person { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 14px; padding: 12px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; }
.person.invited { border-style: dashed; border-color: var(--line-2); }
.person .avatar.m { background: var(--amber-bg); border: 1px solid var(--amber); color: var(--amber-soft); }
.person .meta .title { font-size: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--muted); }
.input { min-height: 48px; width: 100%; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--field); color: var(--text); }
.input::placeholder { color: var(--faint); }
.invite-box { font-size: 14px; color: var(--text-2); background: var(--panel-2); border-radius: 12px; padding: 12px 14px; line-height: 1.45; overflow-wrap: anywhere; user-select: all; }
.log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.log li { font-size: 14px; color: var(--text-2); overflow-wrap: anywhere; }
.log .when { font-family: var(--mono); font-size: 12px; color: var(--muted); display: block; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login .card { max-width: 420px; width: 100%; gap: 18px; align-items: stretch; text-align: center; padding: 28px 24px; }
.login img { height: 72px; width: auto; margin: 0 auto; display: block; }
.login h1 { font-family: var(--display); font-weight: 700; font-size: 30px; letter-spacing: -0.02em; }
.login .sub { color: var(--muted); font-size: 15px; margin-top: 4px; }
.login .err { padding: 12px 14px; border-radius: 12px; background: var(--bad-bg); border: 1px solid var(--bad-line); color: var(--bad-text); font-size: 14px; text-align: left; }
.login .dev { border-top: 1px solid var(--line); padding-top: 14px; display: flex; flex-direction: column; gap: 8px; text-align: left; }
.login .dev a { color: var(--amber-soft); }

/* ---------- toast ---------- */
#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 20; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 460px); pointer-events: none; }
#toast .msg { pointer-events: auto; padding: 12px 16px; border-radius: 14px; background: var(--panel-2); border: 1px solid var(--line-2); box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5); font-size: 15px; }
#toast .msg.bad { border-color: var(--bad-line); background: var(--bad-bg); color: var(--bad-text); }

/* ---------- phone ---------- */
@media (max-width: 720px) {
  .top { padding: 12px 16px; }
  .brand img { height: 34px; }
  .brand .rule { height: 28px; }
  .brand .name { font-size: 20px; }
  .brand .sub { display: none; }
  .nav { order: 3; width: 100%; }
  .nav a { flex: 1; justify-content: center; }
  .who .hi .hello { display: none; }
  .page { padding: 18px 16px 48px; }
  .page-head h1 { font-size: 26px; }
  .legend { grid-template-columns: 1fr; }
  .row { gap: 8px 8px; padding: 12px 12px; }
  .row .num { width: 14px; }
  .row .meta { min-width: 0; flex: 1 1 0; }
  .stats { gap: 8px; }
}

.strong { font-weight: 600; }
.center { text-align: center; }
.mt6 { margin-top: 6px; }
.mt10 { margin-top: 10px; }
.notice .t.plain { color: var(--text); }

/* ---------- refinements ---------- */
.page-head > div:first-child { flex: 1 1 320px; min-width: 0; }
.controls.confirm { display: flex; }
.stat .v { white-space: nowrap; }

@media (max-width: 720px) {
  .who .hi { display: none; }
  .brand { flex: 1 1 auto; }
  .controls:not(.confirm) { display: flex; flex-wrap: nowrap; gap: 6px; width: 100%; padding-left: 0; }
  .controls:not(.confirm) .icon-btn { width: 40px; height: 40px; flex: none; }
  .row { padding: 12px; }
  .dur { margin-left: auto; }
}

@media (max-width: 720px) {
  .who .avatar { display: none; }
  .top { gap: 8px 10px; }
}

@media (max-width: 720px) {
  .person .meta .file { font-size: 12px; overflow-wrap: anywhere; }
  .person .meta { flex-basis: 140px; }
}

/* ---------- favorites ---------- */
.icon-btn.park { color: var(--amber-soft); }
.controls.fav { margin-left: auto; }
.row .badge { flex: none; }
@media (max-width: 720px) {
  .controls.fav { display: flex; flex: 1 1 100%; margin-left: 0; justify-content: flex-start; }
  .controls.fav .icon-btn { width: 44px; }
}

/* ---------- backup ---------- */
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

/* ---------- light theme ---------- */
:root[data-theme="light"] {
  --bg: #e6e8ec;
  --panel: #ffffff;
  --panel-2: #eef1f5;
  --field: #f7f9fb;
  --line: #d9dfe7;
  --line-2: #c3ccd8;
  --text: #12161c;
  --text-2: #38424f;
  --muted: #576170;
  --faint: #8a94a3;
  --amber-soft: #8a5200;
  --amber-bg: #fff2d4;
  --red: #c4321f;
  --green: #0b7a60;
  --green-bg: #e2f6ef;
  --green-line: #8fd3bd;
  --line-top: #dde3ea;
  --bad-bg: #fdeceb;
  --bad-line: #efb1aa;
  --bad-text: #8f2216;
  --banner-text: #6b4a10;
  color-scheme: light;
}
:root[data-theme="light"] img[src$="km-logo-white.png"] { filter: invert(1); }

/* ---------- theme toggle ---------- */
.login { position: relative; }
.theme-fixed { position: fixed; top: 14px; right: 14px; }

/* ---------- shuffle ---------- */
.btn.shuf { display: inline-flex; align-items: center; gap: 8px; }
.row.dancing { z-index: 3; position: relative; }

/* ---------- hear the ending / banner actions ---------- */
.icon-btn.ending { width: 36px; height: 36px; border-radius: 50%; color: var(--muted); }
.banner-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
@media (max-width: 720px) { .banner { flex-wrap: wrap; } .banner-actions { width: 100%; } }

/* ---------- title / artist ---------- */
.meta .artist { font-size: 14px; color: var(--text); opacity: 0.85; margin-top: 2px; overflow-wrap: anywhere; }
.icon-btn.info { border-radius: 50%; width: 28px; height: 28px; min-height: 28px; padding: 0; vertical-align: middle; margin-left: 4px; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; }
.meta-edit { flex: 1 1 100%; display: grid; gap: 10px; padding-top: 6px; border-top: 1px solid var(--line); }
@media (min-width: 721px) { .meta-edit { padding-left: 179px; } }

/* ---------- sound quality ---------- */
.qopt { display: flex; flex-direction: column; gap: 2px; text-align: left; width: 100%; min-height: 56px; padding: 10px 14px; border-radius: 14px; border: 1px solid var(--line-2); background: transparent; color: var(--text); }
.qopt[aria-pressed="true"] { border-color: var(--amber); background: var(--amber-bg); }
.qopt.ro[aria-current="true"] { border-color: var(--amber); background: var(--amber-bg); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }

/* heart, archive and X share the line with the fade icons */
.row > .controls:not(.confirm):not(.fav) { position: absolute; left: 4px; right: 4px; bottom: 4px; height: 44px; margin: 0; padding: 0; width: auto; flex-wrap: nowrap; justify-content: space-between; pointer-events: none; }
.row > .controls:not(.confirm):not(.fav) > * { pointer-events: auto; }
.row > .controls:not(.confirm):not(.fav) .arch-btn { margin-left: auto; }

.icon-btn.plusminus { border-color: var(--line-2); color: var(--text-2); }
.icon-btn.plusminus.add { border: 0; background: var(--amber); color: #1b1200; }
.icon-btn.plusminus:disabled { opacity: 0.4; }
.controls.fav:not(.confirm) { display: flex; align-items: center; justify-content: flex-start; }
.controls.fav:not(.confirm) .icon-btn.del { margin-left: auto; }

.btn.lock-icon { width: 48px; padding: 0; }
.btn.lock-icon svg { width: 20px; height: 20px; }

.row.editing > .controls { display: none; }
.meta-edit .pair { gap: 8px; }
.meta-edit .pair .btn { flex: 0 0 auto; min-height: 40px; padding: 0 18px; border-radius: 12px; font-size: 15px; }

/* ---------- account menu ---------- */
.usermenu { position: relative; }
.user-btn { min-height: 44px; max-width: 190px; padding: 0 12px; display: inline-flex; align-items: center; gap: 6px; border-radius: 12px; border: 1px solid var(--line-2); background: transparent; color: var(--text); font-weight: 600; font-size: 15px; }
.user-btn .user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-btn[aria-expanded="true"] { background: var(--panel-2); }
.menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 270px; max-width: 90vw; padding: 6px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line-2); box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45); display: flex; flex-direction: column; gap: 2px; }
.menu-who .small-text { font-size: 13px; }
.menu-who { padding: 10px 12px 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; overflow-wrap: anywhere; }
.menu-item { min-height: 48px; padding: 0 12px; border: 0; border-radius: 10px; background: transparent; color: var(--text); font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 12px; text-align: left; width: 100%; }
.menu-item:hover { background: var(--panel-2); }

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

/* heart sits beside the archive icon, all three at the right */
.row > .controls:not(.confirm):not(.fav) { justify-content: flex-end; }
.row > .controls:not(.confirm):not(.fav) [data-act="love"] { margin-left: auto; }
.row > .controls:not(.confirm):not(.fav) .arch-btn { margin-left: 0; }

@media (max-width: 720px) {
  .row > .controls:not(.confirm):not(.fav) { gap: 0; }
  .row > .controls:not(.confirm):not(.fav) .icon-btn, .row > .controls:not(.confirm):not(.fav) .arch-btn { width: 34px; }
  .fades .icon-btn { width: 36px; }
  .fades { margin-left: -6px; }
}

@media (max-width: 400px) {
  .row > .controls:not(.confirm):not(.fav) .icon-btn, .row > .controls:not(.confirm):not(.fav) .arch-btn { width: 30px; }
  .fades .icon-btn { width: 32px; }
  .fades { margin-left: -8px; }
}
