:root {
  --bg: #0f0f10;
  --cell-bg: #1a1a1e;
  --border: #2a2a2f;
  --accent: #1DB954;
  --accent-secondary: #9146FF;
  --accent-tertiary: #80F5D2;
  --label-color: #bbb;
  --label-size: 0.9rem;
  --label-bg: #18181c;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; height: 100%;
  background: var(--bg); color: #eee;
  font-family: sans-serif; overflow: hidden;
}
#unlock-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; text-align: center; padding: 1rem; z-index: 10;
}
#unlock-overlay p { font-size: 1.2rem; margin-bottom: 1rem; }

#app-shell {
  display: flex; flex-direction: column;
  height: 100%; width: 100%; min-height: 0;
}
#screen-stack {
  position: relative; flex: 1 1 auto;
  width: 100%; min-height: 0;
}
#main-content {
  display: none; height: 100%; width: 100%;
  flex-direction: column; padding: 5px; gap: 5px;
}

#sound-containers { position: relative; display: flex; align-items: stretch; gap: 5px; flex: 1 1 auto; height: auto; min-height: 0; }

#blerp-container, #se-container, #streamlabs-container, #coord-container {
  background: var(--cell-bg);
  border-radius: 6px; overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: 0 2px 4px rgba(0,0,0,0.5);
  min-width: 0;
}
#blerp-container { flex: 1; border: .5px solid var(--accent); }
#se-container    { flex: 1; border: .5px solid var(--accent-secondary); }
#streamlabs-container { flex: 1; border: .5px solid var(--accent-tertiary); }
#coord-container { position: relative; flex: 1 1 auto; min-height: 0; border: 1px solid var(--border); -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }

#blerp-container, #se-container, #streamlabs-container {
  position: absolute; left: -10000px; top: 0;
  width: 360px; height: 200px; pointer-events: none;
}

iframe { flex: 1; width: 100%; min-height: 0; border: none; background: #000; }

.iframe-label {
  padding: 4px 8px; text-align: center;
  color: var(--label-color); font-size: var(--label-size);
  background: var(--label-bg); border-top: 1px solid var(--border);
}

#coord-status {
  flex: 1; min-height: 0; overflow-y: auto;
  scroll-snap-type: y mandatory;
  font-size: 0.85rem;
}
.coord-card {
  min-height: 100%;
  scroll-snap-align: start;
  display: flex; flex-direction: column;
  padding: 8px 10px;
  border-bottom: 3px solid rgba(255,255,255,0.14);
  box-sizing: border-box;
}
.coord-active { background: rgba(29,185,84,0.15); flex-direction: row; align-items: stretch; gap: 8px; }
.coord-card-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.coord-active .coord-skip { flex: 0 0 auto; align-self: stretch; }
.coord-queued { background: rgba(255,255,255,0.04); }
.coord-played { opacity: 0.7; }
.coord-idle   { align-items: center; justify-content: center; color: #777; }
.coord-banner {
  padding: 5px 10px; font-weight: 600;
  background: rgba(211,31,44,0.18); color: #ff8a8a;
  scroll-snap-align: none;
}
.coord-warn { background: rgba(240,170,20,0.20); color: #ffcf6b; }
.coord-card-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; flex: 0 0 auto; }
.coord-name { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: #9aa; white-space: nowrap; }
.coord-name-blerp { color: #4ade80; }
.coord-name-se { color: #c4b5fd; }
.coord-name-streamlabs { color: #80f5d2; }
.coord-badge { color: #aaa; flex: 0 0 auto; font-size: 0.95rem; }
.coord-skip {
  display: flex; flex: 1; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 37px;
  background: #fff; color: #141414;
  border: none; border-radius: 5px;
  cursor: pointer;
  font-size: calc(0.9rem + 2px); font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.04em;
  box-shadow: 0 1px 4px rgba(0,0,0,0.45);
}
.coord-skip:hover { background: #ececec; }
.coord-skip:active { transform: scale(0.98); }
.coord-skip svg { width: 17px; height: 17px; fill: currentColor; }
.coord-card-body { flex: 1; min-height: 0; display: flex; gap: 10px; align-items: center; margin-top: 6px; }
.coord-img { width: 64px; height: 64px; border-radius: 6px; object-fit: cover; flex: 0 0 auto; background: #000; }
.coord-card-text { min-width: 0; display: flex; flex-direction: column; gap: 3px; overflow: hidden; }
.coord-user { color: #fff; font-weight: 700; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.coord-title { color: #e8e8e8; word-break: break-word; line-height: 1.25; }
.coord-detail { color: #9a9a9a; font-size: 0.8rem; }

#history-modal {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(10,10,12,0.97);
  display: flex; flex-direction: column;
  padding-top: 45px; padding-left: 45px;
}
#history-modal[hidden] { display: none; }
#history-head {
  display: flex; align-items: center; gap: 12px;
  flex: 0 0 85px; border-bottom: 1px solid var(--border);
}
#history-close {
  flex: 0 0 85px; width: 85px; height: 85px;
  background: #202024; color: #fff; border: none;
  font-size: 2rem; line-height: 1; cursor: pointer;
}
#history-close:hover { background: #2e2e34; }
#history-close:active { background: #3a3a42; }
#history-title { font-size: 1.1rem; font-weight: 700; color: #eee; }
#history-diag {
  margin-left: auto; margin-right: 12px; padding: 10px 16px;
  background: #202024; color: #9a9a9a; border: 1px solid var(--border);
  font-size: 0.9rem; cursor: pointer;
}
#history-list { flex: 1; min-height: 0; overflow-y: auto; padding: 10px; }
.hist-item {
  display: flex; flex-direction: column;
  padding: 8px 10px; border-bottom: 1px solid rgba(255,255,255,0.1);
  cursor: pointer;
}
.hist-item:hover { background: rgba(255,255,255,0.06); }
.hist-item:active { background: rgba(255,255,255,0.12); }
.hist-item .coord-user { font-size: calc(1rem + 2px); }
.cheer-badge {
  display: inline-flex; align-items: center; gap: 3px;
  background: var(--accent-secondary); color: #fff;
  padding: 0 5px; border-radius: 4px;
  font-weight: 700; vertical-align: middle;
}
.cheer-badge .bits-ico { width: 11px; height: 11px; fill: currentColor; }

#status-row { display: flex; flex-wrap: wrap; gap: 5px; flex: 0 0 auto; padding: 5px 5px 0; box-sizing: border-box; height: 62px; }
#status-row:empty { display: none; }
#status-warns {
  order: 10; flex: 1 1 100%; height: 26px; box-sizing: border-box;
  display: flex; flex-direction: column; gap: 5px;
  overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none;
}
#status-warns::-webkit-scrollbar { display: none; }
.status-badge {
  display: inline-flex; align-items: center;
  height: 26px; padding: 0 8px; border-radius: 0;
  font-size: 0.57rem; font-weight: 800;
  letter-spacing: 0.05em; text-transform: uppercase;
  white-space: nowrap;
  background: #202024; border: 1px solid var(--border); color: #9a9a9a;
  transition: background 0.45s linear, border-color 0.45s linear, color 0.45s linear;
}
.status-badge.st-ok   { background: rgba(29,185,84,0.10); border-color: var(--accent); color: #9cf3bd; }
.status-badge.st-warn { background: rgba(240,170,20,0.11); border-color: #f0aa14; color: #ffe0a0; }
.status-badge.st-bad  {
  background: rgba(211,31,44,0.12); border-color: #d31f2c; color: #ffb3b3;
  animation: st-bad-heartbeat 1.15s ease-in-out infinite;
  transform-origin: center;
}
.status-badge.st-off  { color: #b4b4b4; }
.status-badge[title] { cursor: pointer; }
#status-row [id^="badge-warn-"] { flex: 0 0 auto; width: 100%; justify-content: center; }
#audio-down, #sync-down {
  position: absolute; inset: 0; z-index: 8;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px; padding: 8px 12px;
  text-align: center; line-height: 1.15;
  color: #fff; background: rgba(150,16,26,0.96);
  border: 3px solid #ff3b47;
  animation: audio-down-pulse 1.1s ease-in-out infinite;
}
#sync-down { z-index: 7; }
@keyframes audio-down-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.75; }
}
.audio-down-title { font-size: 1.15rem; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase; }
.audio-down-why { font-size: 0.9rem; color: #ffd7d7; }
.audio-down-fix { font-size: 0.9rem; font-weight: 700; }
@media (max-width: 640px) {
  .audio-down-title { font-size: 1rem; }
  .audio-down-why, .audio-down-fix { font-size: 0.8rem; }
}
@keyframes st-bad-heartbeat {
  0%, 100% { transform: translateX(0) scale(1); }
  12% { transform: translateX(-3px) scale(1.055); }
  24% { transform: translateX(3px) scale(1.02); }
  36% { transform: translateX(-2px) scale(1.06); }
  48% { transform: translateX(2px) scale(1); }
  62% { transform: translateX(0) scale(1.035); }
  76% { transform: translateX(0) scale(1); }
}
@media (max-width: 640px) {
  .status-badge { font-size: 0.48rem; padding: 0 6px; height: 24px; }
  #status-row { height: 58px; }
  #status-warns { height: 24px; }
}

@media (max-width: 1300px) {
  #sound-containers { flex: 1 1 auto; height: auto; flex-wrap: wrap; align-items: flex-start; }
  #blerp-container, #se-container, #streamlabs-container {
    position: absolute; left: 0; top: 0;
    width: 360px; height: 200px;
    opacity: 0; z-index: -1;
    pointer-events: none;
  }
  #blerp-container .iframe-label, #se-container .iframe-label, #streamlabs-container .iframe-label { display: none; }
  #coord-container { flex: 1 1 100%; }
  #coord-container .iframe-label { display: none; }
  .coord-card { padding: 5px 8px; }
  .coord-card-body { gap: 7px; margin-top: 3px; align-items: center; }
  .coord-name { font-size: 0.6rem; }
  .coord-badge { font-size: 0.8rem; }
  .coord-img { width: 42px; height: 42px; }
  .coord-user { font-size: 0.85rem; }
  .coord-title {
    font-size: 0.72rem; line-height: 1.15;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }
  .coord-detail { font-size: 0.68rem; }
  .coord-skip { padding: 6px 8px; font-size: 0.72rem; }
  .coord-skip svg { width: 13px; height: 13px; }
}
#mute-cover {
  position: absolute; inset: 0;
  display: none; align-items: center; justify-content: center; gap: 0.5em;
  background: #d31f2c; color: #fff;
  font-weight: 800; font-size: clamp(1.1rem, 4vw, 2rem);
  letter-spacing: 0.06em; text-align: center;
  border-radius: 6px; padding: 8px; z-index: 5;
}
#mute-cover .cover-seg { display: none; align-items: center; }
#mute-cover .cover-seg svg { width: 1em; height: 1em; margin-right: 0.35em; flex: 0 0 auto; }
#sound-containers.muted #mute-cover { display: flex; }
#sound-containers.muted #cover-alerts { display: inline-flex; }

#control-buttons { flex: 0 0 150px; }
#master-mute { display: flex; height: 150px; font-size: 3rem; }
#player-settings-btn {
  width: 100%; height: 44px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; line-height: 1; color: var(--label-color);
  background: #202024; border: 1px solid var(--border); border-radius: 0;
  cursor: pointer; touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
}
#player-settings-btn:active { background: #3a3a42; }
#player-settings-btn[hidden] { display: none; }
@media (max-width: 1300px) and (min-width: 641px) {
  #control-buttons { flex: 0 0 150px; flex-direction: column; align-self: flex-start; }
  #master-mute { flex: 0 0 auto; width: 100%; height: 150px; }
}
@media (max-width: 640px) {
  #sound-containers { flex-direction: column; }
  #control-buttons { flex: 0 0 auto; flex-direction: row; align-self: stretch; }
  #master-mute { flex: 1 1 100%; width: auto; height: 64px; font-size: 1.8rem; }
  #player-settings-btn { width: 64px; height: 64px; flex: 0 0 auto; }
}

#player-setup {
  position: fixed; inset: 0; z-index: 45;
  background: rgba(10,10,12,0.97);
  display: flex; flex-direction: column; align-items: center;
  overflow-y: auto; padding: 24px 16px;
}
#player-setup[hidden] { display: none; }
.setup-box {
  width: 100%; max-width: 560px;
  display: flex; flex-direction: column; gap: 14px;
}
.setup-box h1 { font-size: 1.2rem; color: #fff; }
.setup-box p.setup-hint { font-size: 0.85rem; color: #9a9a9a; }
.setup-field { display: flex; flex-direction: column; gap: 4px; }
.setup-field label { font-size: 0.8rem; font-weight: 700; color: var(--label-color); text-transform: uppercase; letter-spacing: 0.05em; }
.setup-field input {
  width: 100%; padding: 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: #17171a; color: #eee; font-size: 15px;
}
.setup-field input:focus { outline: none; border-color: var(--accent); }
.setup-error { min-height: 1em; font-size: 0.8rem; color: #ff8a8a; }
.setup-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.setup-actions button {
  flex: 1 1 45%; padding: 12px;
  border: none; border-radius: 8px;
  font-size: 15px; font-weight: 700; cursor: pointer;
}
#setup-save { background: var(--accent); color: #000; }
#setup-close { background: #3a3a42; color: #fff; }
#setup-close[hidden] { display: none; }
.setup-copy { display: flex; flex-direction: column; gap: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.setup-copy button {
  padding: 12px; border: 1px solid var(--border); border-radius: 8px;
  background: #202024; color: #eee; font-size: 14px; font-weight: 700; cursor: pointer;
}
.setup-copy button:disabled { opacity: 0.4; cursor: default; }
.setup-copy button:active { background: #3a3a42; }

html[data-hub-alerts-only], html[data-hub-alerts-only] body { background: transparent; }
html[data-hub-alerts-only] #main-content { padding: 0; gap: 0; }
html[data-hub-alerts-only] #sound-containers {
  position: relative;
  flex: 1 1 auto; height: 100%; width: 100%;
  gap: 0;
}
html[data-hub-alerts-only] #blerp-container,
html[data-hub-alerts-only] #se-container,
html[data-hub-alerts-only] #streamlabs-container {
  position: absolute; left: 0;
  width: 100%; height: 50%;
  min-width: 0; min-height: 0; pointer-events: auto;
  border: none; border-radius: 0; box-shadow: none;
  background: transparent; opacity: 1;
  z-index: 1;
}
html[data-hub-alerts-only] #blerp-container { top: 0; }
html[data-hub-alerts-only] #se-container,
html[data-hub-alerts-only] #streamlabs-container { top: 50%; }
html[data-hub-alerts-only] #blerp-container.coord-front,
html[data-hub-alerts-only] #se-container.coord-front,
html[data-hub-alerts-only] #streamlabs-container.coord-front { z-index: 2; }
html[data-hub-alerts-only] #blerp-container iframe,
html[data-hub-alerts-only] #se-container iframe,
html[data-hub-alerts-only] #streamlabs-container iframe { background: transparent; pointer-events: auto; }
html[data-hub-alerts-only] #blerp-container .iframe-label,
html[data-hub-alerts-only] #se-container .iframe-label,
html[data-hub-alerts-only] #streamlabs-container .iframe-label { display: none; }
html[data-hub-alerts-only] #coord-container,
html[data-hub-alerts-only] #control-buttons, html[data-hub-alerts-only] #mute-cover,
html[data-hub-alerts-only] #mute-status, html[data-hub-alerts-only] #status-row,
html[data-hub-alerts-only] #player-setup { display: none !important; }
html[data-hub-audio-only], html[data-hub-audio-only] body { background: transparent; }
html[data-hub-audio-only] body { opacity: 0; pointer-events: none; }
