:root {
  --bg: #F3F2EE;
  --surface: #FFFFFF;
  --ink: #16161A;
  --muted: #5B5A55;
  --soft: #3F3E3A;
  --line: #E4E1D9;
  --line-2: #DAD7CE;
  --chip: #ECEAE4;
  --accent: #C2410C;
  --accent-ink: #9A3412;
  --accent-soft: #FDE8DC;
  --ok: #0F766E;
  --ok-soft: #DDF1EC;
  --ok-ink: #0B5049;
  --danger: #B91C1C;
  --danger-soft: #FEE2E2;
  --radius: 16px;
  --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: "Space Grotesk", Inter, system-ui, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; min-height: 100dvh; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--display); margin: 0; letter-spacing: -0.3px; }
p { margin: 0; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#app { max-width: 560px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.view { flex: 1; padding: calc(16px + var(--safe-top)) 20px calc(110px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 16px; }
.view.no-nav { padding-bottom: calc(32px + var(--safe-bottom)); }
.view.with-footer { padding-bottom: calc(110px + var(--safe-bottom)); }

/* ---------- Header ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topbar .brand { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.brand-name { font-family: var(--display); font-size: 30px; font-weight: 700; letter-spacing: -0.6px; }
.brand-name span { color: var(--accent); }
.subtitle { font-size: 14px; color: var(--muted); }
.backbar { display: flex; align-items: center; gap: 4px; margin: -8px -12px 0; }
.backbar h1 { font-size: 20px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-title { font-size: 28px; font-weight: 700; }
.section-title { font-family: var(--display); font-size: 18px; font-weight: 700; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.section-title small { font-family: var(--font); font-size: 13px; color: var(--muted); font-weight: 600; }

/* ---------- Buttons ---------- */
.icon-btn { width: 44px; height: 44px; border-radius: 999px; border: 0; background: transparent; display: inline-flex; align-items: center; justify-content: center; color: var(--ink); cursor: pointer; flex-shrink: 0; text-decoration: none; position: relative; }
.icon-btn:active { background: var(--chip); }
.btn { height: 48px; padding: 0 18px; border-radius: 14px; border: 0; font-size: 15px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent-ink); }
.btn-dark { background: var(--ink); color: #fff; }
.btn-outline { background: var(--surface); color: var(--ink); border: 1.5px solid var(--ink); }
.btn-ghost { background: var(--surface); color: var(--soft); border: 1px solid var(--line-2); }
.btn-danger { background: var(--surface); color: var(--danger); border: 1px solid #F3C4C4; }
.btn-block { width: 100%; }
.btn-sm { height: 40px; padding: 0 14px; border-radius: 999px; font-size: 13px; }
.btn-link { background: none; border: 0; color: var(--accent); font-weight: 600; cursor: pointer; padding: 8px 0; font-size: 14px; }

/* ---------- Avatars ---------- */
.avatar { width: 40px; height: 40px; border-radius: 999px; color: #fff; font-weight: 600; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; text-decoration: none; }
.avatar.xs { width: 24px; height: 24px; font-size: 10px; }
.avatar.sm { width: 32px; height: 32px; font-size: 12px; }
.avatar.lg { width: 72px; height: 72px; font-size: 24px; }
.avatar.vacant { background: transparent; border: 1.5px dashed var(--accent); color: var(--accent); }

/* ---------- Search / chips ---------- */
.search { position: relative; }
.search svg { position: absolute; left: 14px; top: 14px; color: var(--muted); pointer-events: none; }
.search input { width: 100%; height: 48px; border-radius: 14px; border: 1px solid var(--line-2); background: var(--surface); padding: 0 14px 0 44px; font-size: 16px; }
.chips-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.chip-row { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -20px; padding: 2px 20px; }
.chip-row::-webkit-scrollbar { display: none; }
.chip-wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { height: 38px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 500; white-space: nowrap; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 600; }
.chip.accent[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); }

.tag { font-size: 13px; padding: 6px 10px; border-radius: 999px; background: var(--chip); color: var(--ink); white-space: nowrap; }
.tag.me { background: var(--ink); color: #fff; }
.tag.open { font-weight: 600; padding: 5px 10px; border: 1.5px dashed var(--accent); color: var(--accent); background: transparent; }
.tag.outline { background: var(--surface); border: 1px solid var(--line-2); font-size: 12px; font-weight: 500; }
.badge { font-size: 12px; font-weight: 600; padding: 5px 9px; border-radius: 999px; white-space: nowrap; background: var(--accent-soft); color: var(--accent-ink); }
.badge.full { background: var(--ok-soft); color: var(--ok-ink); }
.badge.date { background: var(--ink); color: #fff; display: inline-flex; align-items: center; gap: 4px; }
.badge.closed { background: var(--chip); color: var(--soft); }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
a.card { text-decoration: none; color: var(--ink); }
a.card:active { background: #FBFAF8; }
.song-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.song-badges { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; }
.tag.style { font-size: 12px; font-weight: 600; padding: 4px 9px; background: var(--surface); border: 1px solid var(--line-2); color: var(--soft); }
.song-title { font-family: var(--display); font-size: 19px; font-weight: 700; line-height: 1.2; }
.song-artist { font-size: 14px; color: var(--muted); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.meta { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.meta .dot { width: 3px; height: 3px; border-radius: 9px; background: currentColor; }
.list { display: flex; flex-direction: column; gap: 12px; }
.row-card { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }

.progress { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress > div { height: 100%; border-radius: 999px; background: var(--accent); transition: width .3s; }
.progress.full > div { background: var(--ok); }

/* ---------- Song detail ---------- */
.detail-title { font-size: 30px; line-height: 1.1; font-weight: 700; letter-spacing: -0.5px; }
.slots { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.slot { padding: 14px; border-top: 1px solid #EEEBE4; display: flex; flex-direction: column; gap: 10px; }
.slot:first-child { border-top: 0; }
.slot-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.slot-name { font-size: 16px; font-weight: 600; }
.slot-count { font-size: 13px; color: var(--muted); font-weight: 600; }
.member { display: flex; align-items: center; gap: 12px; }
.member-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.member-info a { color: var(--ink); text-decoration: none; font-size: 15px; font-weight: 600; }
.member-info span { font-size: 13px; color: var(--muted); }
.member-info .you { color: var(--accent); font-weight: 600; }
.owner-box { display: flex; align-items: center; gap: 10px; }
.owner-box a { color: var(--ink); text-decoration: none; font-weight: 600; font-size: 14px; }
.description { font-size: 15px; line-height: 1.5; color: var(--soft); white-space: pre-line; }
.actions-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .legend { font-size: 13px; font-weight: 600; }
.field .hint, .legend .hint { font-weight: 400; color: var(--muted); }
.input, .select, .textarea { width: 100%; min-height: 48px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--surface); padding: 0 14px; font-size: 16px; }
.textarea { padding: 12px 14px; resize: vertical; min-height: 96px; line-height: 1.45; }
.input:focus, .select:focus, .textarea:focus, .search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
legend { padding: 0; margin-bottom: 8px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid #EEEBE4; cursor: pointer; }
.switch-row:first-of-type { border-top: 0; }
.switch-row span { font-size: 15px; }
.switch-row small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.switch { appearance: none; -webkit-appearance: none; width: 48px; height: 28px; border-radius: 999px; background: var(--line-2); position: relative; cursor: pointer; flex-shrink: 0; transition: background .2s; margin: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 999px; background: #fff; transition: transform .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch:checked { background: var(--ok); }
.switch:checked::after { transform: translateX(20px); }
.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.slot-editor { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.slot-edit-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px 10px 16px; border-top: 1px solid #EEEBE4; }
.slot-edit-row:first-child { border-top: 0; }
.slot-edit-row .name { flex: 1; min-width: 0; font-size: 15px; font-weight: 600; }
.slot-edit-row .name small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 40px; height: 40px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface); font-size: 20px; line-height: 1; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.stepper button:disabled { opacity: .35; cursor: default; }
.stepper output { min-width: 28px; text-align: center; font-weight: 700; font-size: 16px; }
.add-other { display: flex; gap: 8px; }
.add-other .input { flex: 1; }

/* ---------- Auth ---------- */
.auth { justify-content: center; gap: 24px; }
.auth-hero { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.auth-logo { width: 64px; height: 64px; border-radius: 18px; }
.auth-hero h1 { font-size: 36px; letter-spacing: -0.8px; }
.auth-hero h1 span { color: var(--accent); }
.auth-switch { text-align: center; font-size: 14px; color: var(--muted); }
.level-row { display: flex; align-items: center; gap: 10px; }
.level-row .name { flex: 1; font-weight: 600; font-size: 15px; }
.level-row .select { width: auto; min-width: 150px; min-height: 40px; font-size: 14px; }

/* ---------- Footer action bar ---------- */
.footer-bar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); padding: 12px 20px calc(16px + var(--safe-bottom)); z-index: 20; }
.footer-bar > div { max-width: 520px; margin: 0 auto; display: flex; gap: 10px; }

/* ---------- Bottom nav ---------- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,.96); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-top: 1px solid var(--line); padding: 6px 8px calc(8px + var(--safe-bottom)); z-index: 20; }
.tabbar > div { max-width: 560px; margin: 0 auto; display: flex; justify-content: space-around; align-items: center; }
.tab { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 60px; padding: 6px 0; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 500; position: relative; }
.tab[aria-current="page"] { color: var(--accent); font-weight: 600; }
.tab-plus { width: 54px; height: 54px; border-radius: 18px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; text-decoration: none; box-shadow: 0 4px 12px rgba(194,65,12,.3); }
.dot-badge { position: absolute; top: 0; right: 10px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; border: 2px solid #fff; }
.icon-btn .dot-badge { top: 2px; right: 0; }

/* ---------- Notifications ---------- */
.notif { display: flex; gap: 12px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--ink); position: relative; }
.notif.unread { border-color: #F2C9B3; background: #FFFBF8; }
.notif.unread::after { content: ""; position: absolute; top: 18px; right: 14px; width: 8px; height: 8px; border-radius: 9px; background: var(--accent); }
.notif-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; padding-right: 10px; }
.notif-title { font-size: 14px; font-weight: 600; line-height: 1.35; }
.notif-text { font-size: 14px; line-height: 1.4; color: var(--soft); }
.notif-date { font-size: 12px; color: var(--muted); }
.notif-icon { width: 40px; height: 40px; border-radius: 999px; background: var(--chip); color: var(--ink); display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }

/* ---------- Chat ---------- */
.chat-view { padding-bottom: calc(96px + var(--safe-bottom)); gap: 12px; }
.chat-list { display: flex; flex-direction: column; gap: 10px; }
.msg { display: flex; gap: 8px; align-items: flex-end; max-width: 88%; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.bubble { background: var(--surface); border: 1px solid var(--line); border-radius: 18px 18px 18px 6px; padding: 10px 14px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.msg.mine .bubble { background: var(--ink); color: #fff; border-color: var(--ink); border-radius: 18px 18px 6px 18px; }
.bubble .who { font-size: 12px; font-weight: 600; color: var(--accent); }
.bubble .txt { font-size: 15px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble .when { font-size: 11px; color: var(--muted); align-self: flex-end; }
.msg.mine .bubble .when { color: #B9B8B2; }
.day-sep { align-self: center; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--chip); padding: 4px 10px; border-radius: 999px; }
.composer { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); padding: 10px 12px calc(10px + var(--safe-bottom)); z-index: 20; }
.composer form { max-width: 536px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; min-height: 44px; max-height: 140px; border-radius: 22px; border: 1px solid var(--line-2); padding: 11px 16px; font-size: 16px; resize: none; line-height: 1.3; background: var(--bg); }
.composer button { width: 44px; height: 44px; border-radius: 999px; border: 0; background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; }
.composer button:disabled { opacity: .5; }

/* ---------- Misc ---------- */
.empty { text-align: center; padding: 40px 16px; color: var(--muted); display: flex; flex-direction: column; gap: 12px; align-items: center; }
.empty svg { color: var(--line-2); }
.empty strong { color: var(--ink); font-size: 16px; }
.notice { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 14px; font-size: 14px; line-height: 1.4; }
.notice.ok { background: var(--ok-soft); color: var(--ok-ink); }
.notice.info { background: var(--accent-soft); color: var(--accent-ink); }
.notice.err { background: var(--danger-soft); color: #7F1D1D; }
.notice svg { flex-shrink: 0; margin-top: 1px; }
.notice .btn { margin-top: 8px; }
.loader { display: flex; justify-content: center; padding: 48px 0; }
.loader::after { content: ""; width: 28px; height: 28px; border-radius: 99px; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { height: 140px; border-radius: var(--radius); background: linear-gradient(90deg, #ECEAE4 0%, #F6F5F1 50%, #ECEAE4 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.toast-wrap { position: fixed; left: 0; right: 0; bottom: calc(96px + var(--safe-bottom)); display: flex; justify-content: center; pointer-events: none; z-index: 50; padding: 0 16px; }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 14px; font-size: 14px; max-width: 480px; box-shadow: 0 6px 20px rgba(0,0,0,.2); animation: pop .2s ease-out; }
.toast.err { background: var(--danger); }
@keyframes pop { from { transform: translateY(10px); opacity: 0; } }
.profile-head { display: flex; align-items: center; gap: 16px; }
.profile-head h1 { font-size: 24px; }
.kv { font-size: 14px; color: var(--muted); }
.divider { height: 1px; background: var(--line); margin: 4px 0; }
.install-card { background: var(--ink); color: #fff; border: 0; }
.install-card p { color: #D7D6D0; font-size: 14px; line-height: 1.45; }
.install-card .btn-primary { align-self: flex-start; }
.tabs { display: flex; background: var(--chip); border-radius: 12px; padding: 4px; gap: 4px; }
.tabs button { flex: 1; height: 38px; border: 0; border-radius: 9px; background: transparent; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.chat-cta { display: flex; flex-direction: row; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); }
.chat-cta .notif-icon { background: var(--accent-soft); color: var(--accent); }
.chat-cta div { flex: 1; }
.chat-cta strong { display: block; font-size: 15px; }
.chat-cta span { font-size: 13px; color: var(--muted); }

@media (min-width: 600px) {
  .view { padding-left: 24px; padding-right: 24px; }
}

/* Concert */
.concert { gap: 12px; }
.concert.highlight { border-color: #F2C9B3; background: #FFFBF8; }
.concert-head { display: flex; gap: 12px; align-items: center; }
.concert-head .notif-icon { background: var(--accent-soft); color: var(--accent); }
.concert-head div { display: flex; flex-direction: column; gap: 2px; }
.concert-head strong { font-size: 16px; }
.date-form { display: flex; gap: 8px; flex-wrap: wrap; }
.date-form .input { flex: 1 1 200px; }
.notice p { margin-top: 2px; }

/* Invitations */
.invite-card { border-color: #F2C9B3; background: #FFFBF8; }
.invite-card .concert-head a.kv { text-decoration: none; }
.invite-toggle { display: inline-flex; align-items: center; gap: 6px; align-self: flex-start; }
.invite-list { display: flex; flex-direction: column; gap: 12px; padding: 4px 0 2px; border-top: 1px dashed var(--line-2); padding-top: 12px; }
.invite-list .member-info span { line-height: 1.35; }
.invite-list .plays { color: var(--ok-ink); }
.invite-sent .member-info span { color: var(--accent-ink); }
.invite-empty { padding: 4px 0; }
