html, body {
    height: 100%;
    margin: 0;
}

body {
    display: flex;
    flex-direction: column;
}

.form-row-fixed-label .form-label {
    flex: 0 0 160px;
    width: 160px;
    margin-bottom: 0;
    padding-top: 0.375rem;
}

main {
    flex: 1 1 auto;
    min-height: 0;
    padding: 1em;
}

body.round-page main {
    padding: 0;
    display: flex;
    min-height: 0;
}

.round-layout {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
}

.mobile-view-toggle {
    flex: 0 0 auto;
    display: flex;
    gap: 0.5em;
    padding: 0.5em 1em 0;
}

.mobile-view-toggle .active {
    background-color: #0d6efd;
    color: #fff;
    border-color: #0d6efd;
}

/* Drei Ansichten (Chat/Praesentation/Charakterbogen), gesteuert ueber
   data-view auf #round-layout. Mobil (Standard) ist genau eine der drei
   Flaechen sichtbar; ab 1024px siehe Media Query unten (Chat immer da,
   Charakterbogen ersetzt dort die Praesentationsflaeche exklusiv). */
.presentation-pane {
    display: none;
}

#round-layout[data-view="presentation"] .presentation-pane {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    padding: 1em;
    box-sizing: border-box;
}

.character-sheet-pane {
    display: none;
}

#round-layout[data-view="charsheet"] .character-sheet-pane {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    padding: 1em;
    box-sizing: border-box;
    overflow-y: auto;
}

.chat-pane {
    display: none;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    padding: 1em;
    box-sizing: border-box;
    gap: 0.5em;
}

#round-layout[data-view="chat"] .chat-pane {
    display: flex;
}

.round-meta details {
    margin-bottom: 0.5em;
}

#dice-bar {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 0.5em;
}

.dice-bar-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5em;
    align-items: center;
}

#chat-toolbar {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    gap: 1em;
    align-items: center;
}

#chat-log {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    border: 1px solid #888;
    padding: 0.5em;
    background-color: #fdf6b2;
}

.chat-message {
    display: flex;
    align-items: baseline;
    gap: 0.5em;
}

.chat-message .msg-content {
    flex: 1 1 auto;
    min-width: 0;
}

.chat-message .text {
    white-space: pre-wrap;
}

.chat-message-whisper {
    font-style: italic;
    opacity: 0.85;
}

.chat-delete-btn {
    display: none;
    flex: 0 0 auto;
    margin-left: auto;
    padding: 0 0.4em;
    line-height: 1.2;
}

#chat-log.chat-edit-mode .chat-delete-btn {
    display: inline-block;
}

#chat-log.hide-timestamps .chat-message .time {
    display: none;
}

#chat-log.hide-rolls .chat-message-roll {
    display: none;
}

#chat-form {
    flex: 0 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 0.5em;
}

#chat-input {
    flex: 1 1 auto;
    resize: vertical;
}

@media (min-width: 1024px) {
    /* Chat ist ab 1024px immer sichtbar, daher ist der Chat-Button hier
       ueberfluessig - Praesentation/Charakterbogen bleiben aber als
       exklusives Umschalter-Paar sichtbar (siehe Regeln weiter unten). */
    #view-btn-chat {
        display: none;
    }

    /* Grid statt Row-Flex: die Umschalter-Buttons liegen als eigene,
       volle Breite einnehmende Zeile oben, darunter teilen sich
       Seitenflaeche (Praesentation/Charakterbogen) und Chat je zur
       Haelfte die restliche Breite - dadurch sind beide Flaechen breiter
       als vorher, wo die Buttons als schmale Seitenspalte Platz wegnahmen. */
    .round-layout {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto 1fr;
        grid-template-areas:
            "toggle toggle"
            "side chat";
        min-height: 0;
    }

    .mobile-view-toggle {
        grid-area: toggle;
    }

    /* Chat ist ab 1024px unabhaengig von data-view immer sichtbar. */
    .chat-pane {
        display: flex;
        grid-area: chat;
        min-width: 0;
    }

    /* Praesentationsflaeche ist die Standard-Seitenflaeche, wird aber vom
       Charakterbogen exklusiv verdraengt, wenn dieser aktiviert wurde. */
    .presentation-pane {
        display: flex;
        flex-direction: column;
        grid-area: side;
        min-width: 0;
        min-height: 0;
        border-right: 1px solid #ccc;
        padding: 1em;
        box-sizing: border-box;
        gap: 0.5em;
    }

    #round-layout[data-view="charsheet"] .presentation-pane {
        display: none;
    }

    .character-sheet-pane {
        display: none;
    }

    #round-layout[data-view="charsheet"] .character-sheet-pane {
        display: flex;
        flex-direction: column;
        grid-area: side;
        min-width: 0;
        min-height: 0;
        border-right: 1px solid #ccc;
        padding: 1em;
        box-sizing: border-box;
        overflow-y: auto;
    }
}

#media-toolbar {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 0.5em;
}

#media-toolbar.collapsed {
    display: none;
}

#media-thumbnails {
    display: flex;
    gap: 0.5em;
    overflow-x: auto;
    padding-bottom: 0.25em;
}

.media-thumb {
    position: relative;
    flex: 0 0 auto;
}

.media-thumb-select {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25em;
    width: 90px;
    border: 2px solid transparent;
    background: none;
    padding: 0.25em;
    cursor: pointer;
}

.media-thumb-select img {
    width: 80px;
    height: 60px;
    object-fit: cover;
    border: 1px solid #ccc;
}

.media-thumb-empty-icon {
    width: 80px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: #888;
    border: 1px dashed #ccc;
    box-sizing: border-box;
}

.media-thumb-select.active {
    border-color: #0d6efd;
}

.media-thumb-delete {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 1.4em;
    height: 1.4em;
    line-height: 1;
    padding: 0;
    border: 1px solid #dc3545;
    border-radius: 50%;
    background-color: #fff;
    color: #dc3545;
    font-size: 0.8rem;
}

.media-thumb-label {
    font-size: 0.75rem;
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#media-viewer {
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
    overflow: hidden;
    background-color: #1a1a1a;
    display: flex;
    align-items: center;
    justify-content: center;
}

#media-stage {
    display: none;
    position: absolute;
    inset: 0;
    overflow: hidden;
    cursor: grab;
}

#media-stage.grabbing {
    cursor: grabbing;
}

#media-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: auto;
    transform-origin: 0 0;
    user-select: none;
    -webkit-user-drag: none;
}

/* Touch-Steuerung (+/-, Pfeile): auf dem Smartphone gibt es keine
   Tastatur und kein Mausrad, daher eigene Buttons fuer Zoom/Verschieben. */
#media-touch-controls {
    display: none;
    position: absolute;
    right: 0.5em;
    bottom: 0.5em;
    z-index: 2;
    flex-direction: column;
    align-items: center;
    gap: 0.4em;
}

.media-ctrl-btn {
    width: 2.4em;
    height: 2.4em;
    line-height: 1;
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 0.3em;
    background-color: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 1.1rem;
}

.media-dpad {
    display: grid;
    grid-template-columns: repeat(3, 2.4em);
    grid-template-rows: repeat(3, 2.4em);
    gap: 0.3em;
}

.media-ctrl-up { grid-area: 1 / 2 / 2 / 3; }
.media-ctrl-left { grid-area: 2 / 1 / 3 / 2; }
.media-ctrl-right { grid-area: 2 / 3 / 3 / 4; }
.media-ctrl-down { grid-area: 3 / 2 / 4 / 3; }

@media (max-width: 1023.98px) {
    #media-touch-controls {
        display: flex;
    }
}

/* Charakterbogen */
.char-sheet-scroll {
    overflow-y: auto;
    overflow-x: auto;
    height: 100%;
}

.char-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5em;
    margin-bottom: 0.5em;
}

/* Ansicht/Bearbeiten-Modus: je nach Modus sind unterschiedliche Spalten/
   Felder sichtbar (siehe Spec: Bearbeiten zeigt Basis/Punkte-Eingaben ohne
   Halb/Fuenftel, Ansicht zeigt nur Wert+Halb+Fuenftel ohne Eingabefelder). */
.char-edit-only {
    display: none;
}

.char-sheet-scroll.mode-edit .char-edit-only {
    display: revert;
}

.char-view-only {
    display: none;
}

.char-sheet-scroll.mode-view .char-view-only {
    display: revert;
}

.char-multiline {
    white-space: pre-wrap;
}

.char-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4em;
    margin: 0.75em 0;
}

.char-tab-btn.active {
    background-color: #0d6efd;
    color: #fff;
    border-color: #0d6efd;
}

.char-tab-panel {
    display: none;
}

.char-tab-panel.active {
    display: block;
}

.char-switch-bar {
    display: flex;
    align-items: center;
    gap: 0.5em;
    margin-bottom: 0.75em;
}

.char-header-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1em;
}

.char-header-grid label,
.char-background-grid label {
    display: flex;
    flex-direction: column;
    font-size: 0.85rem;
    gap: 0.2em;
}

.char-background-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.75em;
}

.char-attr-table td,
.char-derived-table td,
.char-skill-table td {
    vertical-align: middle;
}

.char-skill-table input[type="number"],
.char-skill-table input[type="text"] {
    padding: 0.15rem 0.35rem;
}

/* Wert-Spalte (Attribute/Fertigkeiten): in der Ansicht hervorgehoben. */
.char-value-view {
    font-weight: 700;
}

.char-sheet-scroll.mode-view .char-skill-current {
    font-weight: 700;
}

/* Fertigkeiten ohne Beruf-/Interessepunkte werden zurueckhaltender
   dargestellt, damit investierte Fertigkeiten sofort auffallen. Bootstraps
   Tabellen-CSS setzt color direkt auf td (nicht nur vererbt von tr), daher
   hier gezielt td statt tr einfaerben. */
.char-skill-row.char-skill-unused > td {
    color: #888;
}

.char-history ul {
    max-height: 200px;
    overflow-y: auto;
    padding-left: 1.2em;
}
