/* ==========================================================================
   Kwaba Sync – Cyber-Voodoo
   Palette: Void / Crypt / Loa-Violet / Spirit-Green / Ritual-Gold / Bone
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@500;700;900&family=JetBrains+Mono:wght@400;600&display=swap');

:root {
  --void:      #08050d;
  --crypt:     #120b1c;
  --crypt-2:   #1b1129;
  --veil:      #251838;
  --loa:       #7b3fa0;
  --loa-lit:   #b478e8;
  --spirit:    #3ff0b0;
  --spirit-dim:#1d8f6b;
  --gold:      #e8c37a;
  --bone:      #ded6ea;
  --ash:       #8d80a3;
  --blood:     #d5486b;

  --display: 'Cinzel', 'Times New Roman', serif;
  --data: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --body: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  --r: 3px;
  --glow-spirit: 0 0 12px rgba(63, 240, 176, .35);
  --glow-loa: 0 0 18px rgba(180, 120, 232, .28);
  --hairline: 1px solid rgba(180, 120, 232, .22);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1100px 620px at 82% -8%, rgba(123, 63, 160, .30), transparent 62%),
    radial-gradient(760px 520px at 6% 104%, rgba(63, 240, 176, .10), transparent 60%),
    var(--void);
  color: var(--bone);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* Veve-Raster als ruhige Textur, nicht als Deko-Feuerwerk */
body::before {
  content: '';
  position: fixed; inset: 0;
  background-image:
    linear-gradient(rgba(180, 120, 232, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(180, 120, 232, .045) 1px, transparent 1px);
  background-size: 44px 44px;
  pointer-events: none;
  z-index: 0;
}

a { color: var(--spirit); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: rgba(180, 120, 232, .4); }

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

/* ------------------------------------------------------------------ typography */

h1, h2, h3, .display {
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: .06em;
  margin: 0;
}

h1 { font-size: clamp(1.6rem, 3.4vw, 2.5rem); color: var(--gold); }
h2 { font-size: 1.1rem; color: var(--loa-lit); text-transform: uppercase; letter-spacing: .16em; }

.eyebrow {
  font-family: var(--data);
  font-size: .68rem;
  letter-spacing: .28em;
  text-transform: uppercase;
  color: var(--ash);
}

.mono { font-family: var(--data); }
.muted { color: var(--ash); }
.gold { color: var(--gold); }
.spirit { color: var(--spirit); }

/* ---------------------------------------------------------------------- shell */

.wrap { position: relative; z-index: 1; max-width: 1120px; margin: 0 auto; padding: 28px 20px 64px; }

.topbar {
  position: relative; z-index: 3;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 20px;
  background: linear-gradient(180deg, rgba(27, 17, 41, .96), rgba(18, 11, 28, .88));
  border-bottom: var(--hairline);
  backdrop-filter: blur(6px);
}
.topbar .brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.topbar .brand svg { width: 30px; height: 30px; flex: 0 0 auto; }
.topbar .brand b {
  font-family: var(--display); font-size: 1.02rem; letter-spacing: .2em;
  color: var(--gold); text-transform: uppercase; white-space: nowrap;
}
.topbar .sub { font-family: var(--data); font-size: .68rem; color: var(--ash); letter-spacing: .12em; }
.topbar .spacer { flex: 1; }
.topbar nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* --------------------------------------------------------------------- panels */

.panel {
  background: linear-gradient(180deg, rgba(27, 17, 41, .82), rgba(15, 9, 23, .82));
  border: var(--hairline);
  border-radius: var(--r);
  padding: 18px;
  position: relative;
}
.panel::after {
  /* Ritual-Gold-Ecke oben links: markiert jede Kammer */
  content: ''; position: absolute; top: 0; left: 0;
  width: 14px; height: 14px;
  border-top: 2px solid var(--gold); border-left: 2px solid var(--gold);
  opacity: .55;
}
.panel > header { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; }
.panel > header .spacer { flex: 1; }

.grid-2 { display: grid; gap: 18px; grid-template-columns: 1fr 1fr; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

/* --------------------------------------------------------------------- inputs */

label.field { display: block; margin-bottom: 12px; }
label.field span {
  display: block; font-family: var(--data); font-size: .68rem;
  letter-spacing: .18em; text-transform: uppercase; color: var(--ash); margin-bottom: 5px;
}

input[type=text], input[type=password], input[type=search], select, textarea {
  width: 100%;
  padding: 10px 12px;
  background: rgba(8, 5, 13, .85);
  border: 1px solid rgba(180, 120, 232, .28);
  border-radius: var(--r);
  color: var(--bone);
  font-family: var(--body);
  font-size: .95rem;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--spirit);
  box-shadow: var(--glow-spirit);
  outline: none;
}
input::placeholder { color: #5d5270; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px;
  font-family: var(--data); font-size: .78rem; letter-spacing: .12em; text-transform: uppercase;
  background: rgba(123, 63, 160, .18);
  color: var(--bone);
  border: 1px solid rgba(180, 120, 232, .45);
  border-radius: var(--r);
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s, box-shadow .15s;
}
.btn:hover:not(:disabled) { background: rgba(180, 120, 232, .3); border-color: var(--loa-lit); text-decoration: none; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(180deg, rgba(63, 240, 176, .22), rgba(29, 143, 107, .22));
  border-color: var(--spirit); color: #d7fff0;
}
.btn.primary:hover:not(:disabled) { background: rgba(63, 240, 176, .34); box-shadow: var(--glow-spirit); }
.btn.gold { border-color: var(--gold); color: var(--gold); background: rgba(232, 195, 122, .1); }
.btn.danger { border-color: var(--blood); color: #ffc9d6; background: rgba(213, 72, 107, .12); }
.btn.ghost { background: none; border-color: rgba(180, 120, 232, .25); }
.btn.sm { padding: 5px 9px; font-size: .68rem; }
.btn.icon { padding: 6px 8px; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.tight { gap: 6px; }

.switch { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--ash); cursor: pointer; }
.switch input { accent-color: var(--spirit); width: 16px; height: 16px; }

.notice {
  padding: 10px 12px; border-radius: var(--r); font-size: .88rem;
  border-left: 3px solid var(--blood); background: rgba(213, 72, 107, .12); color: #ffd3de;
}
.notice.ok { border-left-color: var(--spirit); background: rgba(63, 240, 176, .1); color: #cffbec; }
.notice.hidden { display: none; }

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

.gate { min-height: 100%; display: grid; place-items: center; padding: 40px 18px; }
.gate .card { width: 100%; max-width: 430px; }
.gate .sigil { display: grid; place-items: center; margin-bottom: 18px; }
.gate .sigil svg { width: 96px; height: 96px; filter: drop-shadow(0 0 16px rgba(180, 120, 232, .45)); }
.gate h1 { text-align: center; margin-bottom: 4px; }
.gate .tagline { text-align: center; margin-bottom: 22px; }
.tabs { display: flex; gap: 0; margin-bottom: 18px; border-bottom: var(--hairline); }
.tabs button {
  flex: 1; padding: 9px 0; background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--ash); font-family: var(--data); font-size: .74rem; letter-spacing: .18em;
  text-transform: uppercase; cursor: pointer;
}
.tabs button[aria-selected=true] { color: var(--gold); border-bottom-color: var(--gold); }

.room-list { display: grid; gap: 10px; }
.room-card {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 14px;
  border: var(--hairline); border-radius: var(--r);
  background: rgba(8, 5, 13, .5);
  transition: border-color .15s, background .15s;
}
.room-card:hover { border-color: var(--loa-lit); background: rgba(37, 24, 56, .6); }
.room-card .name { font-family: var(--display); font-size: 1.05rem; color: var(--bone); }
.room-card .meta { font-family: var(--data); font-size: .7rem; color: var(--ash); letter-spacing: .06em; }
.room-card .grow { flex: 1; min-width: 0; }

.badge {
  font-family: var(--data); font-size: .62rem; letter-spacing: .14em; text-transform: uppercase;
  padding: 2px 6px; border-radius: 2px;
  border: 1px solid rgba(180, 120, 232, .4); color: var(--loa-lit);
}
.badge.live { border-color: var(--spirit); color: var(--spirit); box-shadow: var(--glow-spirit); }
.badge.lock { border-color: var(--gold); color: var(--gold); }

/* ----------------------------------------------------------------- room layout */

/* Die Raumseite scrollt nicht: Buehne und Bedienleiste muessen immer sichtbar sein,
   gescrollt wird nur innerhalb von Playlist und Chat. */
body.room-page { height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
[hidden] { display: none !important; }

.room-shell {
  position: relative; z-index: 1;
  flex: 1 1 auto; min-height: 0; overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(320px, 23vw, 400px);
  gap: 14px;
  padding: 14px;
  align-items: stretch;
}

.stage { display: flex; flex-direction: column; gap: 10px; min-width: 0; min-height: 0; }

/* Haelt das 16:9-Fenster mittig und so gross wie der freie Platz erlaubt */
.screen-fit { position: relative; flex: 1 1 auto; min-height: 140px; }

.screen {
  position: absolute; inset: 0; margin: auto;
  aspect-ratio: 16 / 9;
  max-width: 100%; max-height: 100%;
  background: #000;
  border: var(--hairline);
  border-radius: var(--r);
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(8, 5, 13, .9), 0 18px 60px rgba(0, 0, 0, .6);
}

/* Beide Wiedergabe-Ebenen behalten immer ihre Groesse. Ein YT-Player, der in einem
   display:none-Element erzeugt wird, bleibt schwarz – darum visibility statt display. */
.screen .layer { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; }
.screen .layer.off { visibility: hidden; pointer-events: none; }
.screen .layer > div, .screen .layer iframe { width: 100%; height: 100%; border: 0; display: block; }
.screen video.layer { object-fit: contain; background: #000; }

.screen .veil {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: radial-gradient(circle at 50% 45%, rgba(37, 24, 56, .94), rgba(8, 5, 13, .98));
  text-align: center; padding: 20px;
}
.screen .veil.hidden { display: none; }
.screen .veil svg { width: clamp(64px, 14vh, 120px); height: clamp(64px, 14vh, 120px); opacity: .8; }
.screen .veil p { max-width: 44ch; color: var(--ash); font-size: .9rem; margin: 0; }
/* Klickfang, damit die YouTube-Oberflaeche die Synchronisation nicht unterlaeuft */
.screen .shield { position: absolute; inset: 0; z-index: 1; background: transparent; }

.now {
  display: flex; gap: 12px; align-items: center; flex: 0 0 auto;
  padding: 9px 12px; border: var(--hairline); border-radius: var(--r);
  background: rgba(27, 17, 41, .7);
}
.now .title { font-family: var(--display); font-size: 1rem; color: var(--gold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.now .who { font-family: var(--data); font-size: .68rem; color: var(--ash); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.now .grow { flex: 1; min-width: 0; }

.controls { flex: 0 0 auto; padding: 10px 12px; }

.bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.seek { flex: 1; min-width: 140px; }
input[type=range] { accent-color: var(--loa-lit); width: 100%; }
.time { font-family: var(--data); font-size: .74rem; color: var(--ash); white-space: nowrap; }

/* Signature: der Sync-Kreis. Zeigt Drift und Zustand ohne Text zu brauchen. */
.circle { width: 40px; height: 40px; flex: 0 0 auto; }
.circle .ring { fill: none; stroke-width: 3; stroke-linecap: round; transform-origin: 50% 50%; }
.circle .track { stroke: rgba(180, 120, 232, .18); }
.circle .arc { stroke: var(--spirit); transition: stroke .3s, stroke-dashoffset .3s; }
.circle.drift .arc { stroke: var(--gold); }
.circle.bad .arc { stroke: var(--blood); }
.circle.paused .arc { stroke: var(--loa-lit); }
.circle .glyph { fill: var(--bone); font-family: var(--data); font-size: 9px; text-anchor: middle; }
.circle.spin .arc { animation: revolve 2.4s linear infinite; }
@keyframes revolve { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .circle.spin .arc { animation: none; } }

/* Schmale Fenster und Hochformat: wieder normaler Seitenfluss */
@media (max-width: 1080px) {
  body.room-page { height: auto; overflow: auto; }
  .room-shell { grid-template-columns: 1fr; overflow: visible; }
  .screen-fit { aspect-ratio: 16 / 9; flex: none; }
  .side > .panel { max-height: none; }
  #queue { max-height: 46vh; }
  #chatlog { height: 40vh; }
}

/* ------------------------------------------------------------------- sidebar */

.side { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.side > .panel { padding: 13px; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }

#paneQueue, #paneChat { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
#paneRoom { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding-right: 4px; }

.pill-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.pill-tabs button {
  flex: 1; padding: 6px 4px; background: rgba(8, 5, 13, .6);
  border: 1px solid rgba(180, 120, 232, .2); border-radius: var(--r);
  color: var(--ash); font-family: var(--data); font-size: .68rem; letter-spacing: .1em;
  text-transform: uppercase; cursor: pointer;
}
.pill-tabs button[aria-selected=true] { color: var(--gold); border-color: var(--gold); background: rgba(232, 195, 122, .1); }

.scroll { overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--loa) transparent; }
.scroll::-webkit-scrollbar { width: 8px; }
.scroll::-webkit-scrollbar-thumb { background: rgba(123, 63, 160, .6); border-radius: 4px; }

#queue { flex: 1 1 auto; min-height: 90px; }
#chatlog { flex: 1 1 auto; min-height: 90px; }

.q-item {
  display: flex; gap: 9px; align-items: center;
  padding: 6px; border-radius: var(--r);
  border: 1px solid transparent;
  cursor: pointer; contain: layout style;
}
.q-item:hover { background: rgba(37, 24, 56, .8); border-color: rgba(180, 120, 232, .3); }
.q-item.current { background: rgba(63, 240, 176, .08); border-color: var(--spirit); }
.q-item.dragging { opacity: .4; }
.q-item.drop-above { border-top-color: var(--gold); }
.q-item .n { font-family: var(--data); font-size: .66rem; color: var(--ash); width: 2.4em; text-align: right; flex: 0 0 auto; }
.q-item .thumb { width: 56px; height: 32px; object-fit: cover; border-radius: 2px; background: #000; flex: 0 0 auto; }
.q-item .t { flex: 1; min-width: 0; font-size: .82rem; line-height: 1.3; max-height: 2.6em; overflow: hidden; }
.q-item .d { font-family: var(--data); font-size: .66rem; color: var(--ash); flex: 0 0 auto; }
.q-item .x { opacity: 0; }
.q-item:hover .x { opacity: 1; }

.who-list { display: flex; flex-wrap: wrap; gap: 6px; }
.who-chip {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--data); font-size: .7rem;
  padding: 3px 8px; border-radius: 12px;
  background: rgba(8, 5, 13, .6); border: 1px solid rgba(180, 120, 232, .3);
}
.who-chip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--spirit); box-shadow: var(--glow-spirit); }
.who-chip.buffering .dot { background: var(--gold); box-shadow: none; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }

.msg { margin-bottom: 7px; font-size: .87rem; word-wrap: break-word; }
.msg .u { font-family: var(--data); font-size: .72rem; color: var(--loa-lit); margin-right: 6px; }
.msg.system { color: var(--ash); font-style: italic; font-size: .8rem; }
.msg.mine .u { color: var(--spirit); }

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

#toasts {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  z-index: 50; display: grid; gap: 8px; justify-items: center; pointer-events: none;
}
.toast {
  padding: 9px 15px; border-radius: var(--r);
  background: rgba(18, 11, 28, .96); border: 1px solid var(--loa-lit);
  font-family: var(--data); font-size: .76rem; letter-spacing: .04em;
  box-shadow: var(--glow-loa); animation: rise .25s ease-out;
}
.toast.ok { border-color: var(--spirit); color: #cffbec; }
.toast.err { border-color: var(--blood); color: #ffd3de; }
.toast.wait { border-color: var(--gold); color: var(--gold); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* --------------------------------------------------------------------- tables */

table.data { width: 100%; border-collapse: collapse; font-size: .87rem; }
table.data th {
  text-align: left; font-family: var(--data); font-size: .66rem; letter-spacing: .16em;
  text-transform: uppercase; color: var(--ash); padding: 7px 8px; border-bottom: var(--hairline);
}
table.data td { padding: 7px 8px; border-bottom: 1px solid rgba(180, 120, 232, .1); }
table.data tr:hover td { background: rgba(37, 24, 56, .5); }

kbd {
  font-family: var(--data); font-size: .68rem; padding: 1px 5px;
  border: 1px solid rgba(180, 120, 232, .4); border-radius: 2px;
  background: rgba(8, 5, 13, .7); color: var(--bone);
}

.empty { padding: 26px 14px; text-align: center; color: var(--ash); font-size: .88rem; }
