:root {
  --bg: #0b0d12;
  --fg: #f1ede6;
  --muted: rgba(241, 237, 230, 0.6);
  --glass: rgba(18, 20, 28, 0.62);
  --line: rgba(255, 255, 255, 0.1);
  --accent: #d9ad55;
  --accent-2: #c2263a;
  --radius: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#app { position: fixed; inset: 0; }

#stage {
  position: absolute;
  inset: 0;
  z-index: 0;
  isolation: isolate;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
#stage canvas { display: block; }
.labels-layer { position: absolute; inset: 0; pointer-events: none; }

/* Top bar */
.topbar {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px 32px;
  background: linear-gradient(to bottom, rgba(11, 13, 18, 0.85), rgba(11, 13, 18, 0));
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.logo {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.02em;
  color: var(--fg);
  text-decoration: none;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--glass);
  white-space: nowrap;
}
.logo span { color: var(--accent); }
h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.langs {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.langs button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: 600 12px/1 inherit;
  font-family: inherit;
  padding: 7px 9px;
  border-radius: 7px;
  cursor: pointer;
}
.langs button:hover { color: var(--fg); }
.langs button[aria-pressed="true"] { background: rgba(255, 255, 255, 0.12); color: var(--fg); }

.hint {
  position: absolute;
  top: 78px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
}

/* Bottom controls */
.bottom {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 24px 20px calc(14px + var(--safe-b));
  background: linear-gradient(to top, rgba(11, 13, 18, 0.8), rgba(11, 13, 18, 0));
  pointer-events: none;
}
.bottom > * { pointer-events: auto; }
.panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: var(--radius);
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--fg);
  font: 600 13px/1 inherit;
  font-family: inherit;
  padding: 9px 12px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: rgba(255, 255, 255, 0.1); }
.btn[aria-pressed="true"]:not(.primary) { border-color: rgba(217, 173, 85, 0.55); color: var(--accent); }
.btn.primary { background: var(--accent-2); border-color: transparent; }
.btn.primary:hover { background: #d33045; }
.btn .ico { font-size: 11px; width: 10px; text-align: center; }
.btn:focus-visible, .langs button:focus-visible, .logo:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.vol { display: inline-flex; align-items: center; gap: 8px; padding: 0 6px; color: var(--muted); font-size: 13px; }
.vol input { width: 110px; accent-color: var(--accent); }

.credit { font-size: 11px; opacity: 0.5; padding-bottom: 4px; }
.credit:hover { opacity: 0.85; }
.credit a { color: var(--fg); text-decoration: none; }
.credit a:hover { text-decoration: underline; }

/* Player */
.player { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.btn.sq { width: 34px; height: 34px; padding: 0; justify-content: center; font-size: 15px; }
.track-btn { max-width: 260px; text-align: left; padding: 6px 10px; }
.track-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.track-title, .track-artist { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track-artist { font-size: 11px; font-weight: 500; color: var(--muted); }
.caret { color: var(--muted); font-size: 11px; }
.tempo { display: inline-flex; align-items: center; gap: 4px; }
.tempo-val { min-width: 62px; text-align: center; font-size: 12px; color: var(--muted); }
.tempo-val b { color: var(--fg); font-size: 14px; font-variant-numeric: tabular-nums; }

/* Track sheet */
.sheet {
  position: absolute;
  left: 20px;
  bottom: 88px;
  width: min(480px, calc(100% - 40px));
  height: min(72vh, 680px);
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  background: rgba(16, 18, 26, 0.94);
  border: 1px solid var(--line);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 5;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 4px 18px; }
.sheet-head h2 { margin: 0; font-size: 16px; }
.sheet-tools { display: flex; gap: 8px; padding: 6px 14px 8px; }
.search {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
}
.search:focus-within { border-color: rgba(217, 173, 85, 0.6); }
.search-ico { padding: 0 4px 0 10px; color: var(--muted); font-size: 16px; }
.search input {
  flex: 1;
  min-width: 0;
  height: 36px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--fg);
  font: 14px/1 inherit;
  font-family: inherit;
}
.search input::placeholder { color: rgba(241, 237, 230, 0.4); }
.search input::-webkit-search-cancel-button { filter: invert(1) opacity(0.5); }
.search-key {
  margin-right: 8px;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
  font: 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.search:focus-within .search-key { display: none; }
.chips {
  display: flex;
  gap: 6px;
  padding: 0 14px 10px;
  overflow-x: auto;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: 600 12px/1.2 inherit;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.chip small { font-size: 10px; opacity: 0.7; font-variant-numeric: tabular-nums; }
.chip:hover { color: var(--fg); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #151518; }
.track-list { flex: 1; min-height: 0; border-top: 1px solid var(--line); }
.track.active { background: rgba(255, 255, 255, 0.09); border-color: rgba(255, 255, 255, 0.18); }
.empty { margin: 24px 12px; color: var(--muted); text-align: center; }
.sheet-foot { margin: 0; padding: 8px 18px 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.track-list { overflow-y: auto; padding: 0 10px 12px; overscroll-behavior: contain; }
.track-list h3 {
  margin: 12px 8px 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}
.track {
  appearance: none;
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "t bpm" "a bpm";
  align-items: center;
  column-gap: 12px;
  text-align: left;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--fg);
  font-family: inherit;
  cursor: pointer;
}
.track:hover { background: rgba(255, 255, 255, 0.06); }
.track[aria-pressed="true"] { background: rgba(217, 173, 85, 0.12); border-color: rgba(217, 173, 85, 0.4); }
.track .t { grid-area: t; font-size: 14px; font-weight: 600; }
.track .a { grid-area: a; font-size: 12px; color: var(--muted); }
.track .bpm { grid-area: bpm; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.track .bpm::after { content: " BPM"; }
.track:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* 3D labels */
.lbl {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px 3px 3px;
  border-radius: 999px;
  background: rgba(10, 12, 18, 0.62);
  border: 1px solid var(--line);
  color: var(--fg);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.lbl kbd {
  font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #111;
  background: var(--accent);
  border-radius: 999px;
  padding: 4px 7px;
}

/* Loader / fallback */
.loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.loader span {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

@media (pointer: coarse) {
  .lbl { padding-left: 8px; }
  .lbl kbd { display: none; }
}

@media (max-width: 720px) {
  .topbar { padding: 12px 12px 28px; }
  .tagline { display: none; }
  h1 { font-size: 15px; }
  .logo { font-size: 15px; padding: 5px 8px; }
  .brand { gap: 10px; }
  .hint { top: 62px; font-size: 11px; }
  .bottom { flex-direction: column; align-items: stretch; padding: 16px 12px calc(8px + var(--safe-b)); gap: 6px; }
  .panel { justify-content: center; }
  .btn { padding: 8px 10px; font-size: 12px; }
  .vol input { width: 80px; }
  .credit { text-align: center; }
  .player { width: 100%; justify-content: center; }
  .track-btn { flex: 1; max-width: none; }
  .sheet { left: 8px; right: 8px; width: auto; bottom: auto; top: 60px; height: calc(100% - 230px); min-height: 300px; }
  .search-key { display: none; }
}

@media (max-width: 420px) {
  h1 { display: none; }
  #reset { display: none; }
}
