.battle-modal-box {
    width: min(880px, calc(100vw - 24px));
}

.battle-create-modal-box {
    width: min(440px, calc(100vw - 24px));
}

.battle-modal-body {
    display: grid;
    gap: 18px;
}

.battle-create-modal-body {
    display: grid;
    gap: 16px;
}

.battle-room-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.battle-room-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.battle-room-summary {
    margin: 0;
    color: var(--text-secondary);
}

.battle-connection-status {
    margin: 0;
    color: var(--danger);
}

.battle-connection-status.is-reconnecting {
    color: var(--text-secondary);
}

.battle-form-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.battle-form-grid[hidden] {
    display: none !important;
}

.battle-field {
    display: grid;
    gap: 6px;
}

.battle-field-wide {
    grid-column: 1 / -1;
}

.battle-field[hidden],
.battle-preview-panel[hidden] {
    display: none !important;
}

.battle-field-label {
    font-size: var(--text-sm);
    font-weight: 700;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
}

.battle-field input,
.battle-field select {
    width: 100%;
    min-height: 42px;
    border-radius: var(--radius-md);
    border: 1px solid var(--surface-border);
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 0 12px;
    font: inherit;
}

.battle-field select {
    cursor: pointer;
}

.battle-field input:focus,
.battle-field select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

.battle-room-toolbar .btn {
    flex: 0 0 auto;
    min-width: 152px;
    justify-content: center;
    padding: var(--space-sm);
    background: var(--bg-tertiary);
    border: 1px solid var(--surface-border);
    transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast), opacity var(--transition-fast);
}

.battle-room-toolbar .btn:hover {
    background: var(--surface-hover);
    border-color: var(--text-muted);
}

.battle-room-toolbar .btn:active {
    background: var(--surface-active);
}

.battle-room-toolbar .btn:disabled {
    opacity: 0.34;
    cursor: not-allowed;
    color: var(--text-tertiary);
    background: var(--surface-ghost-muted);
    border-color: var(--divider-subtle);
}

.battle-room-toolbar .battle-copy-link {
    min-width: 118px;
}

.battle-create-actions {
    display: flex;
    justify-content: flex-end;
}

.battle-create-actions .btn {
    min-width: 152px;
    justify-content: center;
    padding: var(--space-sm);
    background: var(--bg-tertiary);
    border: 1px solid var(--surface-border);
}

.battle-table-shell {
    --battle-visible-rows: 5;
    --battle-row-height: 46px;
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-lg);
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    background: var(--surface);
    max-height: calc(40px + (var(--battle-visible-rows) * var(--battle-row-height)));
    position: relative;
}

.battle-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.battle-table th,
.battle-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--divider-subtle);
}

.battle-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: var(--text-sm);
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.battle-table .battle-table-rank {
    width: 34px;
    overflow: hidden;
}

.battle-table .battle-table-player {
    width: auto;
}

.battle-table .battle-table-elo {
    white-space: nowrap;
    overflow: hidden;
    width: 58px;
}

.battle-table .battle-table-win,
.battle-table .battle-table-mean {
    display: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.battle-table .battle-table-win {
    width: 82px;
    text-align: center;
}

.battle-table .battle-table-mean {
    width: 84px;
    text-align: left;
}

.battle-table .battle-table-status {
    width: 110px;
    overflow: hidden;
    text-align: center;
}

.battle-table .battle-table-time {
    width: 104px;
}

.battle-table .battle-table-player,
.battle-table .battle-table-time {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.battle-table .battle-table-elo {
    text-align: center;
}

.battle-table td.battle-table-status {
    padding-left: 0px;
    padding-right: 0px;
}

.battle-table-shell.battle-table-show-win .battle-table .battle-table-win {
    display: table-cell;
}

.battle-table-shell.battle-table-show-mean .battle-table .battle-table-mean {
    display: table-cell;
}

.battle-table-compact .battle-table-elo,
.battle-table-compact .battle-table-win,
.battle-table-compact .battle-table-status {
    text-align: center;
}

.battle-table-compact .battle-table-mean,
.battle-table-compact .battle-table-time {
    text-align: left;
}

.battle-table tbody tr:last-child td {
    border-bottom: none;
}

.battle-table tr.is-local-player td {
    background: var(--accent-subtle);
    background-clip: padding-box;
}

.battle-table td.is-muted-time {
    color: var(--text-tertiary);
}

.battle-player-name {
    min-width: 0;
}

.battle-player-name-text {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.battle-player-name.is-disconnected .battle-player-name-text {
    color: var(--text-tertiary);
}

.battle-empty-cell {
    color: var(--text-secondary);
    text-align: center;
}

.battle-status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 0 10px;
    border-radius: 999px;
    border: 1px solid var(--floating-surface-border);
    background: var(--surface-ghost);
    color: var(--text-primary);
    font-size: var(--text-sm);
    font-weight: 700;
}

.battle-status-pill[data-battle-status="READY"] {
    border-color: color-mix(in srgb, var(--timer-ready) 45%, transparent);
}

.battle-status-pill[data-battle-status="INSPECTING"] {
    border-color: color-mix(in srgb, var(--accent) 45%, transparent);
}

.battle-status-pill[data-battle-status="SOLVING"] {
    border-color: color-mix(in srgb, var(--text-primary) 28%, transparent);
}

.battle-status-pill[data-battle-status="SOLVED"] {
    border-color: color-mix(in srgb, var(--stat-best) 45%, transparent);
}

.battle-preview-panel {
    width: 100%;
    display: grid;
    height: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    text-align: left;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.battle-preview-panel:hover {
    background: transparent;
}

.battle-preview-panel:focus-visible {
    outline: none;
}

.battle-table-shell-compact {
    border: 0;
    border-radius: 0;
    max-height: calc(40px + (var(--battle-visible-rows) * 42px));
}

.battle-table-compact th,
.battle-table-compact td {
    padding: 8px 9px;
    font-size: 0.8rem;
}

.battle-table-compact .battle-table-elo {
    width: 52px;
}

.battle-table-compact .battle-table-win {
    width: 56px;
}

.battle-table-compact .battle-table-mean {
    width: 64px;
}

.battle-table-compact .battle-table-status {
    width: 90px;
    padding: 8px 0;
}

.battle-table-compact .battle-table-time {
    width: 74px;
}

.battle-table-compact .battle-table-player {
    width: auto;
}

#graph-overlay {
    z-index: 999;
}

#graph-overlay .battle-graph-modal-box {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 1001;
    display: flex !important;
    flex-direction: column;
    width: 80vw;
    min-width: 80vw;
    max-width: 80vw;
    max-height: calc(100vh - 24px);
    transform: translate(-50%, -50%);
    margin: 0;
    pointer-events: none;
    visibility: hidden;
    transition: visibility 0s linear 200ms;
}

#graph-overlay.active .battle-graph-modal-box {
    pointer-events: auto;
    visibility: visible;
    transition: visibility 0s linear 0s;
}

#graph-overlay .battle-graph-modal-header {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    pointer-events: none;
    cursor: default;
}

#graph-overlay .battle-graph-modal-legend {
    display: inline-flex;
    width: 100%;
}

#graph-overlay .battle-graph-modal-legend .graph-legend {
    display: inline-flex !important;
    margin-right: 0;
    flex-wrap: wrap;
}

#graph-overlay .battle-graph-modal-body {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
    max-height: calc(100vh - 24px);
    padding: 0;
    gap: 0;
}

#graph-overlay #graph-canvas-container {
    height: 70vh;
    min-height: 70vh;
    max-height: none;
    flex: 0 0 auto;
}

#graph-overlay #graph-controls {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 8px 10px;
}

#graph-overlay .graph-controls-primary,
#graph-overlay .graph-controls-secondary,
#graph-overlay .graph-controls-secondary.collapsed {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 6px;
    padding: 0;
    position: static;
    width: auto;
    max-height: none;
    opacity: 1;
    border: 0;
    background: transparent;
    overflow: visible;
}

#graph-overlay .graph-controls-primary>span,
#graph-overlay #btn-graph-tools {
    display: none;
}

#graph-overlay .graph-controls-sep {
    margin: 0;
}

body.camera-background-active #cube-panel.camera-background-hosting-timer.battle-preview-active .collapsible-body,
body.camera-background-active #cube-panel.camera-background-hosting-timer.battle-preview-active.collapsed .collapsible-body {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 10px;
    padding: 12px 0 0;
}

body.camera-background-active #cube-panel.camera-background-hosting-timer.battle-preview-active #battle-preview-panel {
    display: block;
    flex: 0 0 auto;
    height: auto;
    order: 1;
}

body.camera-background-active #cube-panel.camera-background-hosting-timer.battle-preview-active #cube-camera-timer-slot {
    margin-top: auto;
    order: 2;
    padding-top: 8px;
}

body.camera-background-active.battle-active #cube-panel {
    order: 1;
}

body.camera-background-active.battle-active #graph-panel {
    order: 2;
}

@media (max-width: 760px) {
    .battle-form-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .battle-room-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .battle-room-actions {
        width: 100%;
    }

    .battle-room-actions .btn {
        flex: 1 1 0;
    }

    .battle-room-toolbar .btn {
        width: 100%;
    }

    .battle-table-shell {
        --battle-visible-rows: 3;
    }

    .battle-table {
        font-size: var(--text-sm);
    }

    .battle-table th,
    .battle-table td {
        padding: 9px 8px;
    }

    .battle-table-compact th,
    .battle-table-compact td {
        padding: 8px 6px;
        font-size: 0.74rem;
    }

    .battle-table-compact {
        table-layout: auto;
    }

    .battle-table-compact .battle-table-player {
        width: auto;
        min-width: 0;
        padding-left: 12px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .battle-table-compact .battle-table-elo,
    .battle-table-compact .battle-table-win,
    .battle-table-compact .battle-table-mean,
    .battle-table-compact .battle-table-status,
    .battle-table-compact .battle-table-time {
        width: 1%;
        white-space: nowrap;
    }

    .battle-table-compact .battle-status-pill {
        min-height: 24px;
        padding: 0 7px;
        font-size: 0.7rem;
    }

    .battle-table .battle-table-rank {
        width: 28px;
    }

    .battle-table .battle-table-elo {
        width: 51px;
        max-width: 51px;
    }

    .battle-table .battle-table-status {
        width: 90px;
        padding: 9px 0;
    }

    .battle-table-compact .battle-table-time {
        width: 1%;
        padding: 9px 8px;
    }

    .battle-table .battle-table-time {
        width: 60px;
    }

    #graph-overlay .battle-graph-modal-box {
        width: 80vw;
        min-width: 80vw;
        max-width: 80vw;
        max-height: calc(100vh - 16px);
    }
}

@media (max-width: 1100px) and (orientation: landscape),
(pointer: coarse) and (orientation: landscape) {
    .battle-modal-box {
        width: 86vw;
    }
}
