:root {
  color-scheme: dark;
  --bg: #171719;
  --panel: #222225;
  --panel-2: #2a2a2e;
  --line: #3c3c42;
  --text: #fff8eb;
  --muted: #bbb7af;
  --red: #e83128;
  --red-dark: #a61d19;
  --orange: #ff7a18;
  --focus: #ffbd70;
  --green: #61d18b;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { min-height: 100vh; margin: 0; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; }
[hidden] { display: none !important; }

.primary, .secondary, .danger-outline {
  display: inline-flex; align-items: center; justify-content: center; min-height: 48px; border-radius: 10px;
  border: 2px solid transparent; padding: .7rem 1rem; font-weight: 800; cursor: pointer;
}
.primary { background: var(--orange); color: #171719; }
.secondary { background: #303035; border-color: #4a4a51; color: var(--text); }
.danger-outline { background: transparent; border-color: var(--red); color: #ffb0aa; }
.primary:active, .secondary:active, .danger-outline:active { transform: translateY(1px); }
.touch-button { min-height: 52px; }
.wide { width: 100%; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 .35rem; color: var(--orange); font-size: .75rem; font-weight: 900; letter-spacing: .14em; }
.form-message { min-height: 1.5em; color: #ff9b95; font-weight: 700; }

.brand { display: flex; align-items: center; gap: .7rem; min-width: max-content; }
.brand img { width: 92px; height: 48px; border-radius: 8px; object-fit: cover; }
.brand span { display: flex; flex-direction: column; line-height: 1; }
.brand small { color: var(--orange); font-size: .62rem; font-weight: 900; letter-spacing: .11em; }
.brand strong { margin-top: .27rem; font-size: 1.42rem; letter-spacing: -.04em; }

/* Login */
.login-screen { display: grid; place-items: center; padding: 1.25rem; }
.login-card { width: min(430px, 100%); padding: clamp(1.2rem, 4vw, 2rem); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 22px 60px #0008; }
.login-graphic { display: block; width: 100%; height: 130px; margin-bottom: 1.4rem; object-fit: cover; border-radius: 12px; }
.login-card h1 { margin: 0; font-size: 2.7rem; letter-spacing: -.065em; }
.login-card > .muted { margin: .35rem 0 1.5rem; }
.login-card label, .category-controls label { display: grid; gap: .45rem; margin-bottom: 1rem; color: var(--muted); font-weight: 750; }
.login-card input, .category-controls input, .category-controls select {
  width: 100%; min-height: 52px; border: 2px solid var(--line); border-radius: 10px; background: #111113; color: var(--text); padding: .7rem .8rem;
}

/* Soundboard */
.board-screen { overflow-x: hidden; }
.control-bar {
  position: sticky; top: 0; z-index: 30; min-height: 68px; display: flex; align-items: center; gap: .75rem;
  padding: max(.55rem, env(safe-area-inset-top)) .8rem .55rem; background: #171719f5; border-bottom: 1px solid var(--line); backdrop-filter: blur(10px);
}
.connection { display: grid; grid-template-columns: auto auto; align-items: center; gap: .1rem .4rem; margin-left: auto; color: var(--muted); font-size: .78rem; }
.connection b { grid-column: 2; color: var(--text); font-size: .82rem; }
.status-dot { width: .7rem; height: .7rem; grid-row: 1 / 3; border-radius: 50%; background: #777; }
.status-dot.online { background: var(--green); box-shadow: 0 0 0 3px #61d18b22; }
.status-dot.offline { background: var(--red); }
.audio-gate { display: flex; align-items: center; justify-content: center; gap: .8rem; padding: .65rem 1rem; background: #3c2518; border-bottom: 1px solid #724325; }
.audio-gate button { min-height: 50px; padding: .5rem 1.1rem; border: 0; border-radius: 10px; background: var(--orange); color: #171719; font-weight: 950; cursor: pointer; }
.audio-gate span { color: #f2cfa9; font-size: .85rem; }
.category-tabs { position: sticky; top: 68px; z-index: 25; display: flex; gap: .5rem; overflow-x: auto; padding: .65rem .8rem; background: #202023; border-bottom: 1px solid var(--line); scrollbar-width: thin; }
.category-tab { min-height: 50px; flex: 0 0 auto; padding: .55rem 1rem; border: 2px solid var(--tab-color, var(--orange)); border-radius: 999px; background: transparent; color: var(--text); font-weight: 850; cursor: pointer; }
.category-tab.active { background: var(--tab-color, var(--orange)); color: #101012; }
.board-main { padding: .8rem; }
.board-toolbar { position: sticky; top: 131px; z-index: 20; display: grid; grid-template-columns: minmax(190px, 1.4fr) minmax(220px, 1fr) auto auto; gap: .7rem; align-items: stretch; margin: -.1rem -.1rem .8rem; padding: .1rem .1rem .7rem; background: var(--bg); }
.stop-all { min-height: 64px; border: 0; border-bottom: 5px solid var(--red-dark); border-radius: 11px; background: var(--red); color: white; font-size: clamp(1.2rem, 3vw, 1.75rem); font-weight: 1000; letter-spacing: .025em; cursor: pointer; }
.stop-all:active { border-bottom-width: 1px; transform: translateY(4px); }
.volume-control { min-height: 64px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .65rem; padding: .5rem .8rem; background: var(--panel); border: 1px solid var(--line); border-radius: 11px; font-weight: 800; }
.volume-control input { width: 100%; min-height: 36px; accent-color: var(--orange); }
.volume-control output { min-width: 3ch; color: var(--orange); }
.toggle-control { min-height: 64px; display: flex; align-items: center; gap: .55rem; padding: .5rem .8rem; background: var(--panel); border: 1px solid var(--line); border-radius: 11px; font-weight: 750; }
.toggle-control input { width: 26px; height: 26px; accent-color: var(--orange); }
.sync-panel { display: grid; grid-template-columns: 1fr minmax(200px, 40%); gap: 1rem; align-items: center; margin-bottom: .8rem; padding: .75rem 1rem; border-radius: 10px; background: #28231f; border: 1px solid #60442b; }
.sync-panel div { display: flex; flex-direction: column; gap: .2rem; }
.sync-panel span { color: var(--muted); font-size: .82rem; }
.sync-panel progress { width: 100%; height: 16px; accent-color: var(--orange); }
.settings-panel { margin-bottom: .8rem; padding: 1rem; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.settings-panel h2 { margin: 0 0 .4rem; }
.settings-panel p { color: var(--muted); }
.settings-panel button { margin-right: .55rem; }
.sound-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(clamp(90px, 13vw, 170px), 1fr)); gap: clamp(.55rem, 1.2vw, .9rem); align-items: start; }
.sound-button {
  --button-color: #b94c31; aspect-ratio: 1 / 1; min-width: 90px; min-height: 90px; display: grid; place-items: center; padding: clamp(.55rem, 1.5vw, 1rem);
  overflow: hidden; border: 2px solid color-mix(in srgb, var(--button-color) 75%, white); border-bottom-width: 7px; border-radius: 14px;
  background: var(--button-color); color: #fff; text-shadow: 0 2px 3px #000a; box-shadow: inset 0 0 0 1px #ffffff1a, 0 4px 9px #0005;
  font-size: clamp(1rem, 2.2vw, 1.45rem); font-weight: 950; line-height: 1.05; text-align: center; cursor: pointer; touch-action: manipulation;
}
.sound-button span { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow-wrap: anywhere; }
.sound-button:active, .sound-button.playing { border-bottom-width: 2px; transform: translateY(5px); filter: brightness(1.18); }
.sound-button.loading { opacity: .55; }
.empty-state { padding: 3rem 1rem; text-align: center; color: var(--muted); }
.empty-state h2 { color: var(--text); }
.toast { position: fixed; z-index: 80; right: 1rem; bottom: max(1rem, env(safe-area-inset-bottom)); max-width: min(430px, calc(100vw - 2rem)); padding: .8rem 1rem; border-radius: 10px; background: #fff3df; color: #201b17; box-shadow: 0 10px 35px #0008; font-weight: 800; opacity: 0; pointer-events: none; transform: translateY(10px); transition: .2s; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #ffb0aa; }

/* Admin */
.admin-header { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 72px; padding: .65rem clamp(.8rem, 3vw, 2rem); background: #171719f5; border-bottom: 1px solid var(--line); backdrop-filter: blur(10px); }
.header-actions { display: flex; gap: .6rem; }
.admin-main { width: min(1180px, 100%); margin: 0 auto; padding: clamp(1rem, 3vw, 2rem); }
.upload-workspace, .library-workspace, .trash-workspace { margin-bottom: 1.25rem; padding: clamp(1rem, 2.5vw, 1.6rem); border: 1px solid var(--line); border-radius: 15px; background: var(--panel); }
.upload-workspace h1, .section-heading h2 { margin: 0; letter-spacing: -.04em; }
.upload-workspace { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem 1.4rem; }
.category-controls { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.drop-zone { grid-column: 1 / -1; min-height: 170px; display: grid; place-content: center; gap: .35rem; padding: 1rem; border: 3px dashed #5a5550; border-radius: 14px; text-align: center; background: #1a1a1d; cursor: pointer; }
.drop-zone strong { font-size: 1.45rem; }
.drop-zone span { color: var(--muted); }
.drop-zone.dragging { border-color: var(--orange); background: #2e241c; }
.upload-queue { grid-column: 1 / -1; display: grid; gap: .45rem; }
.upload-row { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(150px, 2fr) auto; align-items: center; gap: .7rem; padding: .65rem .75rem; background: var(--panel-2); border-radius: 9px; }
.upload-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 750; }
.upload-row progress { width: 100%; accent-color: var(--orange); }
.upload-row b { color: var(--muted); font-size: .8rem; }
.upload-row.success b { color: var(--green); }
.upload-row.error b { color: #ff9b95; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.category-group + .category-group { margin-top: 1.3rem; }
.category-title { display: flex; align-items: center; gap: .55rem; margin: 0 0 .5rem; font-size: 1rem; }
.category-swatch { width: .8rem; height: .8rem; border-radius: 50%; background: var(--category-color); }
.file-list { display: grid; }
.file-row { display: grid; grid-template-columns: minmax(180px, 1fr) 100px 170px auto; align-items: center; gap: .8rem; min-height: 60px; padding: .45rem 0; border-top: 1px solid var(--line); }
.file-name { min-width: 0; }
.file-name strong, .file-name small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-name small, .file-meta { color: var(--muted); font-size: .8rem; }
.file-actions { display: flex; justify-content: flex-end; gap: .4rem; }
.file-actions button { min-height: 44px; padding: .5rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: #303035; cursor: pointer; }
.file-actions .delete { color: #ffaaa4; border-color: #74413e; }
.trash-workspace summary { display: flex; align-items: center; justify-content: space-between; min-height: 52px; cursor: pointer; font-size: 1.15rem; font-weight: 850; }
.trash-workspace summary b { color: var(--muted); font-size: .85rem; }

@media (max-width: 780px) {
  .control-bar .brand img { width: 55px; }
  .control-bar .brand small { display: none; }
  .control-bar .brand strong { font-size: 1.05rem; }
  .admin-link { display: none; }
  .board-toolbar { grid-template-columns: 1fr 1fr; }
  .stop-all, .volume-control { grid-column: span 1; }
  .sync-panel { grid-template-columns: 1fr; }
  .upload-workspace { grid-template-columns: 1fr; }
  .category-controls { grid-template-columns: 1fr; }
  .file-row { grid-template-columns: 1fr auto; }
  .file-meta { display: none; }
}

@media (max-width: 520px) {
  .control-bar { flex-wrap: wrap; }
  .control-bar .connection { order: 5; width: 100%; margin: 0; grid-template-columns: auto auto 1fr; }
  .connection b { grid-column: 3; grid-row: 1; text-align: right; }
  .category-tabs { top: 112px; }
  .board-toolbar { top: 175px; }
  .board-toolbar { grid-template-columns: 1fr; }
  .stop-all, .volume-control { grid-column: 1; }
  .audio-gate span { display: none; }
  .sound-grid { grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); }
  .admin-header .brand img { display: none; }
  .header-actions .secondary { display: none; }
  .file-row { grid-template-columns: minmax(0, 1fr); }
  .file-actions { justify-content: flex-start; }
}

@media (display-mode: standalone) {
  .board-screen { padding-bottom: env(safe-area-inset-bottom); }
}

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