:root {
  --bg: #111217;
  --surface: #1a1c23;
  --surface-2: #23262f;
  --surface-3: #2d313c;
  --border: #2f3340;
  --text: #eceef3;
  --text-muted: #9aa0ae;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --accent-text: #ffffff;
  --success: #3ba55d;
  --danger: #e5484d;
  --warning: #e8a33d;
  --gold: #f0b429;
  --tile-l: 30%;
  --tile-s: 38%;
  --radius: 12px;
  --shadow: 0 8px 24px rgb(0 0 0 / 0.35);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f8;
    --surface: #ffffff;
    --surface-2: #eef0f4;
    --surface-3: #e2e5ec;
    --border: #dcdfe6;
    --text: #1c1e24;
    --text-muted: #626877;
    --tile-l: 92%;
    --tile-s: 60%;
    --shadow: 0 8px 24px rgb(20 24 40 / 0.12);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

svg { width: 18px; height: 18px; flex: none; }

button { font: inherit; color: inherit; }

/* ---- buttons ---------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-2); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-3); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }
.btn-small { padding: 6px 12px; font-size: 13px; }
.btn-small svg { width: 14px; height: 14px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- login ------------------------------------------------------------ */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 36px 28px;
  text-align: center;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 12px 0 8px; font-size: 24px; }
.login-card p { margin: 0 0 24px; color: var(--text-muted); }
.login-card .btn { width: 100%; }
.login-logo {
  display: inline-grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
}
.login-logo svg { width: 30px; height: 30px; }
/* logo.jpg from the sounds folder, when there is one */
.brand-mark.has-logo, .login-logo.has-logo { background: none; overflow: hidden; }
.brand-mark.has-logo img, .login-logo.has-logo img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---- top bar ---------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 24px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
}
.voice-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--warning);
  background: color-mix(in srgb, var(--warning) 14%, transparent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.voice-pill span { overflow: hidden; text-overflow: ellipsis; }
.voice-pill.is-connected { color: var(--success); background: color-mix(in srgb, var(--success) 14%, transparent); }
.voice-pill svg { width: 16px; height: 16px; }
.user { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.user img { border-radius: 50%; background: var(--surface-3); }
.user img:not([src]) { visibility: hidden; }

/* ---- now playing ------------------------------------------------------ */

.nowbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 24px 0;
  padding: 10px 12px 10px 16px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 16%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--border));
}
.nowbar.is-idle { background: var(--surface); border-color: var(--border); }
.nowbar.is-idle .nowbar-text strong { color: var(--text-muted); font-weight: 500; }
.nowbar.is-idle .eq i { animation: none; height: 4px; background: var(--text-muted); }
.nowbar { min-height: 58px; }
.nowbar-text { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nowbar-text span { color: var(--text-muted); }
.nowbar-text .now-more {
  margin-left: 8px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 35%, transparent);
}
.eq { display: flex; align-items: flex-end; gap: 3px; height: 16px; }
.eq i { width: 3px; background: var(--accent); border-radius: 2px; animation: eq 0.9s ease-in-out infinite; }
.eq i:nth-child(2) { animation-delay: -0.3s; }
.eq i:nth-child(3) { animation-delay: -0.6s; }
@keyframes eq { 0%, 100% { height: 4px; } 50% { height: 16px; } }

/* ---- toolbar + chips -------------------------------------------------- */

.toolbar { display: flex; gap: 10px; padding: 16px 24px 0; }
.search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-muted);
}
.search:focus-within { border-color: var(--accent); }
.search input {
  flex: 1;
  min-width: 0;
  padding: 10px 0;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  outline: none;
}
.search kbd {
  font: 12px ui-monospace, monospace;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
}

.chips {
  display: flex;
  flex-wrap: wrap; /* everyone visible at once, no sideways scrolling */
  gap: 8px;
  padding: 14px 24px 4px;
}
.chip {
  --hue: 235;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: none;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 14px;
}
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] {
  background: hsl(var(--hue) var(--tile-s) var(--tile-l));
  border-color: hsl(var(--hue) 60% 55%);
}
.chip-count { color: var(--text-muted); font-size: 12px; }
.chip-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
  background: hsl(var(--hue) 65% 58%);
}

/* Category pictures (avatar.jpg in a person's folder) */
.avatar {
  flex: none;
  border-radius: 50%;
  object-fit: cover;
  background: hsl(var(--hue) 40% 40%);
  box-shadow: 0 0 0 2px hsl(var(--hue) 65% 58%);
}
.avatar-small { width: 22px; height: 22px; }
.avatar-large { width: 40px; height: 40px; margin-right: 4px; }
.chip:has(.avatar) { padding-left: 5px; }
.recent-item .avatar-small { width: 20px; height: 20px; }

/* ---- sounds ----------------------------------------------------------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  grid-template-rows: auto auto auto auto 1fr;
  grid-template-areas:
    "sounds top"
    "sounds latest"
    "sounds recent"
    "sounds clips"
    "sounds request";
  gap: 14px 24px;
  padding: 12px 24px 40px;
  align-items: start;
}
#sounds { grid-area: sounds; }
.top-card { grid-area: top; margin-top: 14px; }
.recent { grid-area: recent; }
.latest { grid-area: latest; }
.new-tag {
  margin-left: 6px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  vertical-align: 1px;
}
.link-button {
  padding: 2px 4px;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.link-button:hover { text-decoration: underline; }
.request { grid-area: request; }

/* ---- clips ("Clip that") ---------------------------------------------- */
.clips { grid-area: clips; }
.clip-button { position: relative; }
.clip-button .live-dot {
  display: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f23f43;
  box-shadow: 0 0 0 0 rgb(242 63 67 / 0.6);
  animation: live 1.6s ease-out infinite;
}
.clip-button.is-live .live-dot { display: inline-block; }
.clip-button.is-busy { opacity: 0.6; pointer-events: none; }
@keyframes live { to { box-shadow: 0 0 0 7px rgb(242 63 67 / 0); } }
.clips-status { font-size: 12px; color: var(--text-muted); }
.clips-status.is-live { color: #f23f43; font-weight: 600; }
.clip-item { padding: 8px; border-radius: 8px; }
.clip-item + .clip-item { border-top: 1px solid var(--border); }
.clip-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.clip-head strong { font-weight: 600; }
.clip-head span { color: var(--text-muted); white-space: nowrap; }
.clip-tracks { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.clip-track {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  text-decoration: none;
}
.clip-track:hover { border-color: var(--accent); }
.clip-track.is-everyone { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.clip-track.is-quiet { opacity: 0.55; }
.request-form { display: flex; flex-direction: column; gap: 8px; }
.request-form textarea {
  width: 100%;
  box-sizing: border-box;
  min-height: 64px;
  padding: 8px 10px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
}
.request-form textarea:focus { border-color: var(--accent); }
.request-form textarea::placeholder { color: var(--text-muted); }
.request-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.request-count { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.request-count.is-near { color: var(--danger); }

.group { margin-top: 14px; }
.group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 700;
}
.group-count { color: var(--text-muted); font-weight: 500; font-size: 13px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.tile {
  position: relative;
  display: flex;
  min-height: 68px;
  border-radius: var(--radius);
  background: hsl(var(--hue) var(--tile-s) var(--tile-l));
  border: 1px solid hsl(var(--hue) 40% 50% / 0.35);
  overflow: hidden;
  transition: transform 0.1s, box-shadow 0.15s;
}
.tile:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.tile-play {
  flex: 1;
  min-width: 0;
  padding: 12px 8px 12px 14px;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
  font-weight: 600;
  line-height: 1.25;
}
.tile-play:active { transform: scale(0.98); }
.tile-name {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.tile-actions {
  flex: none;
  display: flex;
  flex-direction: column;
  width: 38px;
  border-left: 1px solid hsl(var(--hue) 40% 50% / 0.25);
  background: rgb(0 0 0 / 0.08);
}
.tile-fav, .tile-preview {
  flex: 1;
  border: 0;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.tile-fav { border-bottom: 1px solid hsl(var(--hue) 40% 50% / 0.2); }
.tile-fav:hover, .tile-preview:hover, .tile-preview[aria-pressed="true"] { color: var(--text); background: rgb(0 0 0 / 0.16); }
.tile-fav[aria-pressed="true"] { color: var(--gold); }
.tile-fav svg, .tile-preview svg { width: 16px; height: 16px; }

.chip-favourites svg { width: 16px; height: 16px; color: var(--gold); }

.tile.is-sending { opacity: 0.6; }
.tile.is-played::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: inset 0 0 0 2px hsl(var(--hue) 75% 62%);
  animation: played 0.9s ease-out forwards;
}
@keyframes played { from { opacity: 1; } to { opacity: 0; } }

.empty {
  margin-top: 24px;
  padding: 40px 20px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
}
.empty strong { color: var(--text); font-size: 16px; }
.empty p { margin: 6px auto 0; max-width: 420px; }

/* ---- recent ----------------------------------------------------------- */

.panel {
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}
.panel h2 { margin: 0 0 8px; font-size: 14px; color: var(--text-muted); font-weight: 600; }
.panel ol { list-style: none; margin: 0; padding: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.panel-head h2 { margin: 0; }

.segmented {
  display: flex;
  padding: 2px;
  border-radius: 8px;
  background: var(--surface-2);
}
.segmented button {
  border: 0;
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); }

.top-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: 8px;
  background: none;
  text-align: left;
  cursor: pointer;
}
.top-item:hover { background: var(--surface-2); }
.top-rank {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--surface-2);
}
.rank-1 .top-rank { background: var(--gold); color: #3b2a00; }
.rank-2 .top-rank { background: #c3c8d4; color: #2a2e38; }
.rank-3 .top-rank { background: #d29a68; color: #3a2210; }
.top-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.top-meta { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-count { flex: none; font-size: 13px; font-weight: 600; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.recent-item {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 8px;
  align-items: center;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: 8px;
  background: none;
  text-align: left;
  cursor: pointer;
}
.recent-item:hover { background: var(--surface-2); }
.recent-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.recent-meta { grid-column: 2; font-size: 12px; color: var(--text-muted); }
.recent-empty { color: var(--text-muted); font-size: 14px; padding: 4px 8px; }

/* ---- toasts ----------------------------------------------------------- */

.toasts {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  width: min(420px, calc(100vw - 32px));
}
.toast {
  padding: 11px 16px;
  border-radius: 10px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease-out;
  transition: opacity 0.3s, transform 0.3s;
}
.toast-error { background: color-mix(in srgb, var(--danger) 22%, var(--surface)); border-color: var(--danger); }
.toast-out { opacity: 0; transform: translateY(6px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---- small screens ---------------------------------------------------- */

@media (max-width: 860px) {
  /* Phones/tablets: leaderboard above the sounds, recent plays below. */
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
    grid-template-areas: "top" "sounds" "latest" "recent" "clips" "request";
  }
  .top-card { margin-top: 8px; }
}

@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; row-gap: 8px; }
  .voice-pill { order: 3; margin-left: 0; flex-basis: 100%; justify-content: center; }
  .user { margin-left: auto; }
  .user span { display: none; }
  .nowbar { margin: 12px 16px 0; }
  .nowbar-text span:not(.now-more) { display: none; }
  .toolbar { gap: 8px; }
  .toolbar { padding: 12px 16px 0; }
  .search kbd { display: none; }
  #random span, #clip span { display: none; }
  .chips { padding: 12px 16px 4px; gap: 6px; }
  .chips .chip { padding-top: 5px; padding-bottom: 5px; font-size: 13px; }
  .layout { padding: 8px 16px 32px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
