.toolbar {
    position: absolute;
    width: 200px;
    top: 10px;
    right: 10px;
    /* bottom: 10px; */
    padding: 16px;
    background: #ffffff;
    border: 2px solid #2266aa;
    z-index: 100;
}

.tab {
    display: none;
    overflow: hidden;
    background: #ffffff;
    z-index: 101;
}

/* The sheet grip/Close row exists only in the phone layout below. */
.menu-sheet-handle {
    display: none;
}

/* Phone layout: the toolbar is a bottom sheet instead of a panel pinned
   top-right, so the world stays visible above it while editing. The tab
   strip scrolls sideways in one row; the sheet scrolls vertically and can
   be pulled up (expanded) for the tall tabs. */
@media (max-width: 640px) {
    .toolbar {
        position: fixed;
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        width: auto;
        max-height: 42vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        /* env() keeps the last row clear of Firefox Android's bottom address
           bar; the css linter does not know the function. */
        /* eslint-disable-next-line css/no-invalid-properties */
        padding: 4px 10px calc(10px + env(safe-area-inset-bottom, 0px));
        border: 0;
        border-top: 2px solid #2266aa;
        border-radius: 12px 12px 0 0;
        box-sizing: border-box;
    }
    .toolbar.expanded {
        max-height: 88vh;
    }
    .menu-sheet-handle {
        display: flex;
        align-items: center;
        position: sticky;
        top: 0;
        background: #ffffff;
        z-index: 102;
    }
    /* A 30 px-tall drag target drawing a 6 px bar down its middle. */
    .menu-sheet-handle .grip {
        flex: 1;
        height: 30px;
        min-width: 40px;
        margin: 0 12px;
        background: linear-gradient(#bbbbbb, #bbbbbb) center / 100% 6px no-repeat;
        touch-action: none;
        cursor: grab;
    }
    .menu-sheet-close {
        flex: 0 0 auto;
        font-size: 15px;
        padding: 8px 12px;
    }
    /* The energy badge lives in this row while the sheet is open
       (mmn-client.ts updateEnergyBadge), so it is never over the world. */
    .menu-sheet-handle .sheet-badge {
        flex: 0 1 auto;
        margin-left: auto;
    }
    .menu-tabs {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        white-space: nowrap;
        padding-bottom: 4px;
    }
    .menu-tabs .button {
        flex: 0 0 auto;
    }
}

.button {
    padding: 5px;
    border-radius: 10px;
    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
    margin: 5px;
}

.big-btn {
    height: 50px;
}

.button-label {
    padding: 10px;
}

.no-select {
    -moz-user-select: none;
    -webkit-user-select: none;
    -ms-user-select: none;
    -webkit-touch-callout: none;
    -khtml-user-select: none;
    -webkit-tap-highlight-color: transparent;
    -o-user-select: none;
    cursor: default;
}

.main-canvas {
    /* image-rendering: optimizeSpeed; */
    image-rendering: pixelated;
    z-index: 0;
}

.icon-canvas {
    pointer-events: none;
    z-index: 1;
}

.above-canvas {
    position: absolute;
    z-index: 1;
}

.use-full-view-area {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100vw;
    height: 100vh;
}

.use-full-view-percent {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 100%;
}

.menu-container {
    display: none;
    overflow: scroll;
}

.menu-child {
    flex: 1;
    border: 2px solid green;
    justify-content: center;
    margin: 12px;
    display: block;
}

.flex-child:first-child {
    margin-right: 20px;
}

button > * {
    pointer-events: none;
}

.toolbar input[type="radio"] {
    z-index: 100;
    display: none;
}

.toolbar input[type="radio"]:checked + label,
.Checked + label {
    background: green;
}

.toolbar .button {
    border: 1px solid #ccc;
    z-index: 90;
    display: inline-block;
}

.toolbar .button:hover {
    background: #ddd;
}

.tab input[type="radio"] {
    z-index: 100;
    display: none;
}

.tab input[type="radio"]:checked + label,
.Checked + label {
    background: green;
}

.tab .button {
    border: 1px solid #ccc;
    z-index: 90;
    display: inline-block;
}

.tab .button:hover {
    background: #ddd;
}

/* Target footer: "Select" while armed (next canvas press picks the Target),
   and the "locked" checkbox beside it. */
.tab .button.selecting-target {
    background: green;
    color: white;
}

.target-locked-label {
    display: inline-block;
    margin: 5px;
    vertical-align: middle;
}

.stats-div {
    margin-left: 5px;
}

/* Character selection window */
.char-select-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    z-index: 200;
    justify-content: center;
    align-items: center;
}

.char-select-window {
    width: 80%;
    height: 80%;
    background: #ffffff;
    border: 2px solid #2266aa;
    border-radius: 6px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.char-select-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #ccc;
}

.char-select-list {
    flex: 1;
    overflow-y: auto;
}

.char-select-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 6px;
    background: #f8f8f8;
}

.char-select-row.char-select-found {
    background: #e8f5e9;
    border-color: #4caf50;
}

.char-select-nickname {
    width: 120px;
    padding: 4px 6px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
}

.char-select-id {
    font-family: monospace;
    font-size: 12px;
    color: #666;
    min-width: 70px;
}

.char-select-status {
    font-size: 12px;
    color: #999;
    min-width: 80px;
}

.char-select-found .char-select-status {
    color: #2e7d32;
    font-weight: bold;
}

.char-select-select-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.char-select-footer {
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid #ccc;
}

.char-select-new-btn {
    font-size: 14px;
    padding: 8px 16px;
}

.char-select-empty {
    padding: 20px;
    text-align: center;
    color: #999;
    font-size: 14px;
}

.char-select-delete-btn {
    color: #c62828;
    font-size: 12px;
}

/* Servers tab: the per-server status table. Fixed layout + hidden x-overflow
   so it always fits the 200px toolbar without a horizontal scrollbar; only the
   row list scrolls, vertically, once it outgrows the viewport share. */
.servers-table-scroll {
    margin-top: 8px;
    max-height: 50vh;
    overflow-y: auto;
    overflow-x: hidden;
}

.servers-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-family: monospace;
    font-size: 12px;
}

.servers-table th,
.servers-table td {
    padding: 1px 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.servers-table th {
    position: sticky;
    top: 0;
    background: #ffffff;
    font-weight: normal;
    color: #666;
    border-bottom: 1px solid #ccc;
    text-align: left;
}

/* coords column gets the most room; the two numeric columns are right-aligned */
.servers-table th:nth-child(1) {
    width: 42%;
}
.servers-table th:nth-child(2) {
    width: 24%;
}
.servers-table th:nth-child(3) {
    width: 34%;
}

.servers-table th:nth-child(2),
.servers-table th:nth-child(3),
.servers-table td:nth-child(2),
.servers-table td:nth-child(3) {
    text-align: right;
}
