:root {
    --bg: #050508;
    --panel: rgba(10, 12, 22, 0.86);
    --panel-solid: #0c0f1c;
    --line: rgba(255, 255, 255, 0.1);
    --text: #eeeeee;
    --muted: #8a8fb0;
    --green: #00ff88;
    --yellow: #ffe066;
    --orange: #ffaa00;
    --violet: #b04dff;
    --cyan: #00e5ff;
    --hajime: #5bc0ff;
    --sage: #c77dff;
    --people: #ffb35c;
    --user: #00ff88;
}

body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: var(--bg);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: var(--text);
}

#canvas-container {
    width: 100vw;
    height: 100vh;
    position: absolute;
    inset: 0;
    z-index: 1;
}

#canvas-container canvas {
    touch-action: none;
    display: block;
}

[hidden] {
    display: none !important;
}

/* --- PANELS --- */
.panel {
    position: absolute;
    z-index: 10;
    box-sizing: border-box;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
}

#world-panel {
    top: 16px;
    left: 16px;
    width: 300px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    padding: 16px 18px;
}

#side-panel {
    top: 16px;
    right: 16px;
    bottom: 16px;
    width: 390px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

h2 {
    margin: 0 0 4px 0;
    font-size: 18px;
    color: #ffffff;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.species-label {
    font-size: 11px;
    color: var(--muted);
    font-weight: bold;
    letter-spacing: 0.4px;
}

.logout-link {
    color: var(--muted);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
}

.icon-button {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #ffffff;
    border-radius: 6px;
    width: 34px;
    height: 34px;
    font-size: 16px;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.2s;
}

.panel-summary {
    display: none;
    margin-top: 8px;
    font-size: 13px;
    font-weight: bold;
    color: var(--green);
}

#world-panel.collapsed .panel-details { display: none; }
#world-panel.collapsed .panel-summary { display: block; }
#world-panel.collapsed #panel-toggle { transform: rotate(180deg); }

.group-title {
    margin: 14px 0 4px;
    font-size: 10px;
    font-weight: bold;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--muted);
    border-bottom: 1px solid var(--line);
    padding-bottom: 3px;
}

.data-field {
    margin: 5px 0;
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.data-label { color: var(--muted); }
.data-value { font-weight: bold; color: #ffffff; text-align: right; }
.accent-yellow { color: var(--yellow); }
.accent-green { color: var(--green); }

.skill-item {
    font-size: 13px;
    margin: 4px 0;
    font-weight: bold;
    color: #666688;
}

/* --- UHR OBEN MITTIG --- */
#top-bar {
    position: absolute;
    z-index: 9;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
}

#portrait-btn {
    background: rgba(5, 8, 20, 0.6);
    border: 1px solid var(--line);
    color: #ffffff;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
}

#portrait-btn.active { background: var(--hajime); color: #04121f; }

#world-clock {
    background: rgba(5, 8, 20, 0.6);
    border: 1px solid var(--line);
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: bold;
    white-space: nowrap;
}

/* --- TABS --- */
.tabs {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 8px 0;
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}

.tab {
    flex: 1;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--muted);
    padding: 8px 4px 10px;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    white-space: nowrap;
}

.tab.active { color: #ffffff; border-bottom-color: var(--violet); }
.tab[data-tab="hajime"].active { border-bottom-color: var(--hajime); }
.tab[data-tab="sage"].active { border-bottom-color: var(--sage); }
.tab[data-tab="population"].active { border-bottom-color: var(--people); }
.tab .badge { margin-left: 4px; }

.mobile-only { display: none; }

.tab-pane {
    display: none;
    flex: 1;
    min-height: 0;
    flex-direction: column;
    padding: 12px 14px 14px;
    gap: 10px;
}

.tab-pane.active { display: flex; }

.mind-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    flex-shrink: 0;
}

.mind-name { font-size: 16px; font-weight: bold; }
.mind-sub, .mind-emotion { font-size: 12px; color: var(--muted); text-align: right; }
.mind-emotion { color: var(--yellow); font-weight: bold; }

.segmented {
    display: flex;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 3px;
    flex-shrink: 0;
}

.segment {
    flex: 1;
    background: none;
    border: none;
    color: var(--muted);
    padding: 7px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
}

.segment.active { background: rgba(255, 255, 255, 0.12); color: #ffffff; }

.badge {
    display: inline-block;
    min-width: 16px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--violet);
    color: #ffffff;
    font-size: 11px;
    line-height: 16px;
    text-align: center;
}

.view {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* --- GEDANKENLOG --- */
.log-section {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    margin-bottom: 8px;
    border-left: 3px solid var(--line);
}

.log-section summary {
    cursor: pointer;
    padding: 8px 10px;
    font-size: 11px;
    font-weight: bold;
    letter-spacing: 0.4px;
    color: var(--muted);
    text-transform: uppercase;
    list-style-position: inside;
}

.log-section:nth-child(1) { border-left-color: #6b7cff; }
.log-section:nth-child(2) { border-left-color: var(--green); }
.log-section:nth-child(3) { border-left-color: var(--cyan); }
.log-section:nth-child(4) { border-left-color: var(--orange); }
.log-section:nth-child(5) { border-left-color: var(--violet); }

.log-list, .need-list {
    list-style: none;
    margin: 0;
    padding: 0 10px 8px;
    max-height: 170px;
    overflow-y: auto;
}

.log-list li {
    font-size: 13px;
    line-height: 1.4;
    padding: 4px 0;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.06);
}

.log-list li:last-child { border-bottom: none; }
.log-list[data-log="unspoken"] li { font-style: italic; color: #b9c2ff; }
.log-list[data-log="spoken"] li { color: #d8ffe9; }

.log-time {
    color: var(--muted);
    font-size: 11px;
    font-style: normal;
    margin-right: 6px;
}

.empty { color: var(--muted); font-size: 12px; font-style: italic; padding: 2px 0 6px; }

.need-list li { padding: 5px 0; font-size: 13px; }

.need-row { display: flex; justify-content: space-between; gap: 8px; }
.need-label { font-weight: bold; }
.need-note { color: var(--muted); font-size: 12px; margin-top: 2px; }

.need-bar {
    height: 5px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.1);
    margin-top: 4px;
    overflow: hidden;
}

.need-bar > span {
    display: block;
    height: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--green), var(--yellow), #ff5c5c);
    background-size: 300px 100%;
    transition: width 0.6s;
}

/* --- DIALOG --- */
.dialog {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-right: 2px;
}

.message {
    max-width: 88%;
    padding: 8px 10px;
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.45;
    background: rgba(255, 255, 255, 0.06);
    align-self: flex-start;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.message .from { display: block; font-size: 11px; font-weight: bold; margin-bottom: 2px; }
.message.user { align-self: flex-end; background: rgba(0, 255, 136, 0.12); }
.message.user .from { color: var(--user); }
.message.mind[data-channel="hajime"] .from { color: var(--hajime); }
.message.mind[data-channel="sage"] .from { color: var(--sage); }
.message.mind[data-channel="population"] .from { color: var(--people); }
.message.meta { align-self: center; background: none; color: var(--muted); font-style: italic; font-size: 12px; }
.message .auto-tag { color: var(--muted); font-weight: normal; }

.typing { color: var(--muted); font-size: 12px; font-style: italic; min-height: 16px; flex-shrink: 0; }

.composer {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.composer input {
    flex: 1;
    min-width: 0;
    background: #151525;
    border: 1px solid var(--violet);
    padding: 9px;
    color: #ffffff;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
}

.composer button, .user-actions button {
    background: var(--violet);
    border: none;
    color: white;
    padding: 0 14px;
    cursor: pointer;
    border-radius: 6px;
    font-size: 13px;
    font-weight: bold;
}

.observer-note {
    flex-shrink: 0;
    font-size: 12px;
    color: var(--muted);
    text-align: center;
    padding: 8px;
    border: 1px dashed var(--line);
    border-radius: 6px;
}

/* --- VERWALTUNG --- */
.user-list { overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }

.user-card {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    padding: 10px;
    font-size: 13px;
}

.user-card .user-meta { color: var(--muted); font-size: 12px; margin: 2px 0 8px; }
.user-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.user-actions button { padding: 6px 10px; font-size: 12px; }
.user-actions button.secondary { background: rgba(255, 255, 255, 0.1); }
.user-actions button.danger { background: #a3263b; }
.status-pending { color: var(--orange); font-weight: bold; }
.status-blocked { color: #ff5c5c; font-weight: bold; }

/* --- HINWEIS-TOAST --- */
#toast {
    position: absolute;
    z-index: 30;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    background: #2a1840;
    border: 1px solid var(--violet);
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 13px;
    max-width: calc(100vw - 48px);
}

/* --- HANDY / SCHMALE FENSTER --- */
@media (max-width: 900px) {
    .mobile-only { display: inline-block; }

    #world-panel {
        position: static;
        width: auto;
        max-height: none;
        overflow: visible;
        padding: 0;
        background: none;
        border: none;
        box-shadow: none;
    }

    #world-panel #panel-toggle, #world-panel .panel-summary { display: none !important; }
    #world-panel .panel-details { display: block !important; }

    #side-panel {
        top: auto;
        left: 8px;
        right: 8px;
        bottom: calc(8px + env(safe-area-inset-bottom));
        width: auto;
        height: 50vh;
        border-radius: 12px;
    }

    #side-panel.collapsed { height: auto; }
    #side-panel.collapsed .tab-pane { display: none; }
    #side-panel.collapsed #sheet-toggle { transform: rotate(180deg); }

    .tab-pane[data-pane="world"] { overflow-y: auto; }

    .tab { font-size: 12px; padding: 8px 2px 10px; }
    #sheet-toggle { width: 30px; height: 30px; }

    #top-bar { top: calc(10px + env(safe-area-inset-top)); }
    #world-clock, #portrait-btn { font-size: 12px; }

    /* 16px verhindert, dass iOS beim Tippen ins Feld hineinzoomt */
    .composer input { font-size: 16px; }
    .log-list, .need-list { max-height: 140px; }
}

/* --- ANMELDESEITE --- */
body.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    overflow: auto;
    background: radial-gradient(circle at 50% 30%, #14204a 0%, #050508 70%);
}

.login-box {
    width: min(360px, calc(100vw - 32px));
    margin: 16px 0;
    background: var(--panel);
    border: 1px solid var(--line);
    border-left: 4px solid var(--violet);
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.login-box h2 { margin-bottom: 0; }
.login-box label { font-size: 12px; color: var(--muted); margin-top: 8px; }
.login-hint { font-size: 12px; color: var(--muted); line-height: 1.5; margin: 6px 0 0; }

.login-box input {
    background: #151525;
    border: 1px solid var(--violet);
    padding: 10px;
    color: #ffffff;
    border-radius: 4px;
    font-size: 16px;
    outline: none;
}

.login-box button {
    margin-top: 14px;
    background: var(--violet);
    border: none;
    color: white;
    padding: 10px;
    cursor: pointer;
    border-radius: 4px;
    font-size: 14px;
    font-weight: bold;
}

.login-switch { margin-top: 10px; font-size: 13px; color: var(--muted); text-align: center; }

.login-error, .login-success {
    margin-top: 10px;
    padding: 8px 10px;
    border-radius: 4px;
    font-size: 13px;
}

.login-error { background: rgba(255, 60, 60, 0.15); color: #ff8080; }
.login-success { background: rgba(0, 255, 136, 0.12); color: var(--green); }
