:root {
    --bg: #121214;
    --bg-elev: #1d1d20;
    --bg-elev-2: #2a2a2e;
    --border: #333338;
    --text: #ececef;
    --text-dim: #9999a1;
    --accent: #e0334a;
    --accent-hover: #f24764;
    --accent-soft: rgba(224, 51, 74, 0.12);
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

/* ─── Buttons & Inputs ───────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    background: var(--bg-elev-2);
    color: var(--text);
    cursor: pointer;
    border-radius: var(--radius);
    font: inherit;
    transition: background 0.15s, border-color 0.15s, transform 0.05s;
    white-space: nowrap;
}
.btn:hover { background: #383840; }
.btn:active { transform: scale(0.98); }
.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 500;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-large { padding: 0.9rem 1.6rem; font-size: 1.1rem; }

.btn-icon {
    padding: 0.25rem 0.45rem;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-dim);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
}
.btn-icon:hover { background: var(--bg-elev-2); color: var(--text); }
.btn-icon.btn-remove:hover { color: var(--accent); }

input[type=text] {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    border-radius: var(--radius);
    font: inherit;
    min-width: 0;
}
input[type=text]:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
}

/* ─── Home & Join ────────────────────────────────────────────────────── */
.container {
    max-width: 600px;
    margin: 6rem auto;
    padding: 0 1.5rem;
    text-align: center;
}
.container h1 { font-size: 2.5rem; margin: 0 0 0.5rem; }
.lead { font-size: 1.15rem; color: var(--text-dim); margin: 0 0 2rem; }
.cta-form {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.cta-form input { flex: 1; min-width: 200px; max-width: 320px; }
.hint { color: var(--text-dim); font-size: 0.9rem; }

/* ─── Room: Header ───────────────────────────────────────────────────── */
.room-header {
    padding: 0.75rem 1rem;
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
}
.room-title { display: flex; align-items: baseline; gap: 0.75rem; }
.brand { font-weight: 600; }
.room-id { color: var(--accent); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9rem; }
.share { display: flex; gap: 0.5rem; flex: 1 1 300px; min-width: 0; }
.share input { flex: 1; min-width: 0; }
.me { color: var(--text-dim); font-size: 0.9rem; }
.me strong { color: var(--text); }

/* ─── Room: Layout ───────────────────────────────────────────────────── */
.room-main {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 1rem;
    padding: 1rem;
}
@media (max-width: 1100px) {
    .room-main { grid-template-columns: minmax(0, 1fr) 320px; }
}
@media (max-width: 900px) {
    .room-main { grid-template-columns: 1fr; padding: 0.5rem; gap: 0.5rem; }
}

/* ─── Player ─────────────────────────────────────────────────────────── */
.player-section {
    min-width: 0;
}
.player-wrap {
    position: relative;
    width: 100%;
    /* Verhindert, dass der Player vertikal aus dem Viewport rausragt:
       max-width wird aus verfügbarer Höhe × 16/9 berechnet. */
    max-width: calc((100vh - 180px) * 16 / 9);
    aspect-ratio: 16 / 9;
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
    margin-left: auto;
    margin-right: auto;
    box-shadow: var(--shadow);
}
#player { position: absolute; inset: 0; width: 100%; height: 100%; }
#player iframe { width: 100%; height: 100%; border: 0; }

.player-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}
.status { color: var(--text-dim); font-size: 0.85rem; }

.participants {
    margin-top: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-elev);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.participants strong { color: var(--text-dim); font-weight: 500; font-size: 0.9rem; }
.participants ul { list-style: none; padding: 0; margin: 0; display: flex; gap: 0.4rem; flex-wrap: wrap; }
.participants li {
    background: var(--bg-elev-2);
    padding: 0.2rem 0.6rem;
    border-radius: 99px;
    font-size: 0.85rem;
    transition: opacity 0.2s;
}

/* ─── Sidebar (Playlist + Chat) ──────────────────────────────────────── */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
}
.panel {
    background: var(--bg-elev);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    min-width: 0;
}
.panel h2 {
    margin: 0 0 0.75rem;
    font-size: 0.85rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
}

.add-form, .chat-form {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
}
.add-form input, .chat-form input { flex: 1; min-width: 0; }
.add-form .btn-primary, .chat-form .btn-primary {
    flex: 0 0 auto;
    width: 2.5rem;
    justify-content: center;
}

.add-error {
    color: var(--accent);
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}

#playlist {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 50vh;
    overflow-y: auto;
    overscroll-behavior: contain;
}
#playlist li {
    padding: 0.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 0.5rem;
    align-items: center;
    transition: background 0.15s;
}
#playlist li:last-child { border-bottom: none; }
#playlist li.is-current {
    background: var(--accent-soft);
    border-left: 3px solid var(--accent);
    padding-left: calc(0.5rem - 3px);
}
#playlist .item-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
#playlist .title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.95rem;
}
#playlist .added-by {
    color: var(--text-dim);
    font-size: 0.75rem;
}
#playlist .item-actions {
    display: flex;
    gap: 0.1rem;
    flex: 0 0 auto;
}
.empty-hint {
    color: var(--text-dim);
    font-size: 0.85rem;
    text-align: center;
    margin: 0.75rem 0 0;
}

/* ─── Chat ───────────────────────────────────────────────────────────── */
.chat-section {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 240px;
}
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--bg);
    border-radius: var(--radius);
    padding: 0.5rem 0.65rem;
    margin-bottom: 0.5rem;
    min-height: 160px;
    max-height: 35vh;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.chat-message {
    font-size: 0.9rem;
    line-height: 1.35;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
.chat-message .chat-name {
    color: var(--accent);
    font-weight: 600;
    margin-right: 0.4rem;
}
.chat-message.is-me .chat-name {
    color: var(--text-dim);
}
.chat-message .chat-text { color: var(--text); }

/* ─── Mobile-Polish ──────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .room-header {
        padding: 0.5rem 0.75rem;
        gap: 0.5rem;
    }
    .room-title { flex: 1 1 100%; }
    .share { flex: 1 1 100%; order: 3; }
    .me { order: 2; margin-left: auto; }
    .player-wrap {
        max-width: 100%;
        border-radius: 0;
    }
    .player-controls {
        gap: 0.5rem;
    }
    #playlist { max-height: 40vh; }
    .chat-messages { max-height: 30vh; min-height: 120px; }
}

@media (max-width: 500px) {
    .container { margin: 3rem auto; }
    .container h1 { font-size: 2rem; }
    .room-title { font-size: 0.9rem; }
    .btn { padding: 0.45rem 0.85rem; }
}

/* Touch-Optimierung: größere Tap-Targets auf Touch-Devices */
@media (hover: none) and (pointer: coarse) {
    .btn-icon { padding: 0.5rem 0.65rem; font-size: 1rem; }
    #playlist li { padding: 0.65rem 0.5rem; }
}

/* Scrollbar-Styling */
.chat-messages, #playlist {
    scrollbar-width: thin;
    scrollbar-color: var(--bg-elev-2) transparent;
}
.chat-messages::-webkit-scrollbar, #playlist::-webkit-scrollbar { width: 8px; }
.chat-messages::-webkit-scrollbar-thumb, #playlist::-webkit-scrollbar-thumb {
    background: var(--bg-elev-2);
    border-radius: 4px;
}
.chat-messages::-webkit-scrollbar-thumb:hover, #playlist::-webkit-scrollbar-thumb:hover {
    background: #404048;
}
