:root {
    --panel: rgba(8, 12, 20, .80);
    --panel-2: rgba(20, 28, 45, .92);
    --border: rgba(53, 96, 255, .82);
    --text: #f5f7ff;
    --muted: #b9c3d6;
    --accent: #3b72ff;
    --accent-hover: #295ee0;
    --zoom: 1;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    min-height: 100vh;
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    background: #090d14 url('body-background.jpg') center center / cover fixed no-repeat;
}
button, input { font: inherit; }

.page-shell {
    width: min(1180px, calc(100% - 24px));
    margin: 0 auto;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 72px;
    padding: 12px 16px;
    background: #0b111d;
    border: 1px solid rgba(75, 119, 255, .35);
    border-bottom: 0;
}
.brand { font-weight: 800; font-size: 22px; }

.login-button,
.toolbar button,
.smiley-panel button {
    border: 1px solid var(--border);
    background: var(--panel-2);
    color: var(--text);
    border-radius: 8px;
    padding: 9px 12px;
    cursor: pointer;
}
.login-button:hover, .toolbar button:hover, .smiley-panel button:hover { background: rgba(50, 73, 112, .96); }

.radio-player {
    width: 100%;
    padding: 6px 10px;
    background: #0b111d;
    border-left: 1px solid rgba(75, 119, 255, .35);
    border-right: 1px solid rgba(75, 119, 255, .35);
    overflow: hidden;
}
.radio-player iframe { display: block; width: 100%; height: 120px; border: 0; }

/* Nur dieser Bereich bekommt dein Bild als Hintergrund.
   Auf großen Bildschirmen ist der Bereich exakt 800 x 600 px. */
.visual-chat-area {
    position: relative;
    width: min(800px, 100%);
    aspect-ratio: 4 / 3;
    margin: 0 auto;
    background: #10151f url('background.jpg') center center / cover no-repeat;
    border: 1px solid rgba(75, 119, 255, .35);
    overflow: hidden;
}

/* Kleine linke Box auf dem Bild = Userliste */
.user-panel {
    position: absolute;
    left: 1.3%;
    bottom: 1.3%;
    width: 27.4%;
    height: 52%;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: rgba(3, 7, 15, .78);
    box-shadow: 0 0 16px rgba(40, 79, 255, .35);
    overflow: hidden;
}

/* Große rechte Box auf dem Bild = Chatbox */
.chat-wrap {
    position: absolute;
    right: 1.5%;
    bottom: 1.3%;
    width: 67.2%;
    height: 52%;
    display: flex;
    flex-direction: column;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: rgba(3, 7, 15, .78);
    box-shadow: 0 0 16px rgba(40, 79, 255, .35);
    overflow: hidden;
}

.panel-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 9px 10px;
    font-weight: 700;
    border-bottom: 1px solid rgba(100, 130, 180, .25);
    background: rgba(17, 26, 43, .92);
}
.online-count { font-size: 12px; color: #9bd8a3; font-weight: 400; }
.user-list { padding: 8px; max-height: calc(100% - 42px); overflow-y: auto; }
.user-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 8px;
    border-radius: 8px;
    word-break: break-word;
}
.user-row.current-user { background: rgba(60, 102, 210, .2); }
.user-row small { margin-left: auto; color: var(--muted); }
.online-dot { width: 9px; height: 9px; border-radius: 50%; background: #4fe06d; box-shadow: 0 0 8px rgba(79,224,109,.75); flex: 0 0 auto; }

.toolbar {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding: 6px;
    background: rgba(17, 26, 43, .92);
    border-bottom: 1px solid rgba(100, 130, 180, .25);
}
.toolbar button { padding: 6px 9px; font-size: 13px; }
.smiley-panel {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 1000;
    width: 340px;
    max-width: calc(100vw - 32px);
    max-height: 300px;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(7, minmax(36px, 1fr));
    gap: 6px;
    background: rgba(16, 27, 48, .98);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 10px 28px rgba(0, 0, 0, .55);
}
.smiley-panel[hidden] { display: none; }
.smiley-panel button {
    width: 100%;
    min-width: 36px;
    min-height: 38px;
    padding: 4px;
    font-size: 21px;
    line-height: 1;
}
@media (max-width: 430px) {
    .smiley-panel {
        width: min(300px, calc(100vw - 24px));
        grid-template-columns: repeat(6, minmax(34px, 1fr));
    }
}

.messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 10px;
    font-size: calc(14px * var(--zoom));
    line-height: 1.4;
    background: rgba(5, 10, 18, .42);
}
.message {
    margin-bottom: 6px;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 0;
    word-break: break-word;
}
.message .name {
    color: #9fc7ff;
    font-weight: inherit;
    font-style: inherit;
    text-decoration: inherit;
}
.message .body {
    display: inline;
}
.message-time {
    margin-left: 0;
    color: var(--muted);
    font-size: .9em;
    font-variant-numeric: tabular-nums;
    font-weight: inherit;
    font-style: inherit;
    text-decoration: inherit;
}

/* Formatierung gilt fuer die komplette Chatzeile: Name + Text + Uhrzeit. */
.message.is-bold {
    font-weight: 700;
}
.message.is-italic {
    font-style: italic;
}
.message.is-underlined {
    text-decoration: underline;
}
.system-msg { color: var(--muted); font-style: italic; margin-bottom: 8px; }
.message.system-event {
    font-weight: 700;
    font-style: italic;
}
.message.system-event .message-time {
    margin-left: 4px;
}

.composer {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 7px;
    padding: 7px;
    background: rgba(17, 26, 43, .94);
    border-top: 1px solid rgba(100, 130, 180, .25);
}
.editor { min-height: 40px; max-height: 90px; overflow-y: auto; padding: 9px; border: 1px solid var(--border); border-radius: 7px; background: rgba(4, 10, 20, .9); color: var(--text); outline: none; font-size: calc(14px * var(--zoom)); }
.editor:empty::before { content: attr(data-placeholder); color: #7c899e; }
.primary { border: 0; border-radius: 7px; padding: 0 15px; min-height: 40px; background: var(--accent); color: white; cursor: pointer; font-weight: 700; }
.primary:hover { background: var(--accent-hover); }
.bottom-bar { min-height: 34px; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 9px; background: rgba(7, 12, 22, .94); border-top: 1px solid rgba(100, 130, 180, .25); color: var(--muted); font-size: 12px; }
.guest-link { color: #9fc7ff; }

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(0, 0, 0, .72);
}
.modal-backdrop[hidden] { display: none; }
.name-modal { position: relative; width: min(420px, 100%); padding: 24px; border: 1px solid var(--border); border-radius: 14px; background: #111b2c; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.name-modal h2 { margin: 0 0 8px; }
.name-modal p { color: var(--muted); line-height: 1.45; }
.name-modal label { display: block; margin: 16px 0 6px; }
.name-modal input { width: 100%; min-height: 44px; padding: 10px 12px; color: var(--text); background: #09111f; border: 1px solid var(--border); border-radius: 8px; outline: none; }
.modal-submit { width: 100%; margin-top: 14px; }
.modal-close { position: absolute; top: 10px; right: 12px; width: 40px; height: 40px; border: 0; border-radius: 8px; background: transparent; color: var(--text); font-size: 28px; cursor: pointer; }

@media (max-width: 760px) {
    .page-shell { width: 100%; }
    .visual-chat-area {
        width: 100%;
        aspect-ratio: 4 / 3;
    }
}

@media (max-width: 520px) {
    .topbar { align-items: flex-start; }
    .brand { font-size: 18px; }
    .composer { grid-template-columns: 1fr; }
    .bottom-bar { flex-wrap: wrap; }
}

/* Bedienleiste direkt unter dem Radio-Player */
.chat-controls {
    background: #0b111d;
    border-left: 1px solid rgba(75, 119, 255, .35);
    border-right: 1px solid rgba(75, 119, 255, .35);
    border-top: 1px solid rgba(75, 119, 255, .2);
}

.chat-controls .toolbar {
    border-bottom: 1px solid rgba(100, 130, 180, .25);
}

.chat-controls .composer {
    border-top: 0;
}


/* Im großen Feld bleibt ausschließlich der Chatverlauf. */
.chat-wrap .messages {
    width: 100%;
    height: 100%;
    flex: 1;
}


/* Uhrzeit und Login sitzen in derselben Leiste wie die Chat-Buttons. */
.toolbar-clock {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 33px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel-2);
    color: var(--muted);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.chat-controls .login-button {
    padding: 6px 10px;
    font-size: 13px;
}


/* Ausgeschriebene Toolbar-Beschriftungen */
.chat-controls .toolbar {
    align-items: center;
}
.chat-controls .toolbar button {
    white-space: nowrap;
}

@media (max-width: 520px) {
    .chat-controls .toolbar {
        gap: 6px;
    }
    .chat-controls .toolbar button,
    .toolbar-clock {
        font-size: 12px;
        padding: 6px 8px;
    }
}

/* ---------------------------------------------------------
   Einheitliche Breite und mittige Ausrichtung
   --------------------------------------------------------- */
.page-shell {
    width: min(800px, calc(100% - 24px));
    margin-left: auto;
    margin-right: auto;
}

.topbar,
.radio-player,
.chat-controls,
.visual-chat-area {
    width: 100%;
    margin-left: auto;
    margin-right: auto;
}

.visual-chat-area {
    max-width: 800px;
    aspect-ratio: 4 / 3;
}

/* Alle Elemente der Toolbar gleich breit */
.chat-controls .toolbar {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    align-items: stretch;
    gap: 5px;
}

.chat-controls .toolbar button,
.chat-controls .toolbar .toolbar-clock {
    width: 100%;
    min-width: 0;
    min-height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 6px 4px;
    font-size: 12px;
    white-space: nowrap;
}

.chat-controls .toolbar .toolbar-clock {
    border: 1px solid var(--border);
    background: var(--panel-2);
    color: var(--text);
    border-radius: 8px;
}

@media (max-width: 760px) {
    .page-shell {
        width: calc(100% - 16px);
    }

    .chat-controls .toolbar {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (max-width: 430px) {
    .chat-controls .toolbar {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* ---------------------------------------------------------
   Toolbar-Status, Smiley-Popup und Farbauswahl
   --------------------------------------------------------- */
.chat-controls .toolbar {
    overflow: visible;
}

.chat-controls .toolbar button.is-active,
.chat-controls .toolbar button[aria-pressed="true"] {
    background: var(--accent);
    border-color: #8fb0ff;
    color: #fff;
    box-shadow: inset 0 0 0 2px rgba(255,255,255,.16), 0 0 10px rgba(59,114,255,.42);
}

.smiley-control {
    position: relative;
    min-width: 0;
}

.smiley-control > #smileyBtn {
    width: 100%;
    height: 100%;
}

.smiley-control .smiley-panel {
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    width: 252px;
    max-width: min(252px, calc(100vw - 24px));
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 7px;
    background: rgba(16, 27, 48, .99);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 10px 28px rgba(0, 0, 0, .55);
}

.smiley-control .smiley-panel[hidden] {
    display: none;
}

.smiley-control .smiley-panel button {
    min-width: 0;
    min-height: 42px;
    padding: 6px;
    font-size: 20px;
}

.color-control {
    min-width: 0;
    min-height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 5px 6px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel-2);
    color: var(--text);
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}

.color-control input[type="color"] {
    width: 28px;
    height: 26px;
    padding: 0;
    border: 1px solid rgba(255,255,255,.25);
    border-radius: 5px;
    background: transparent;
    cursor: pointer;
}

.editor.format-bold { font-weight: 700; }
.editor.format-italic { font-style: italic; }
.editor.format-underlined { text-decoration: underline; }

/* Die komplette Chatzeile übernimmt auch die gewählte Farbe. */
.message .name,
.message .body,
.message .message-time {
    color: inherit;
}

.message .message-time {
    opacity: .82;
}

@media (max-width: 430px) {
    .smiley-control .smiley-panel {
        left: 0;
        transform: none;
    }
}


.login-error {
    margin-top: 10px;
    padding: 9px 10px;
    border: 1px solid #b94a48;
    border-radius: 6px;
    background: rgba(185, 74, 72, .16);
    color: #ffd8d7;
    font-size: 14px;
}
