:root {
    --bg: #111;
    --bg2: #1b1b1b;
    --fg: #eee;
    --accent: #4caf50;
    --border: #333;
    --border2: #444;
    --danger: #e53935;
}
* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    height: calc(var(--vh, 1vh) * 100);
    overflow: hidden;
}
h2 {
    margin: 12px 0 6px;
    font-size: 18px;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
h3 {
    margin: 12px 0 6px;
    font-size: 15px;
    font-weight: 600;
}

/* TOP BAR: sits at the top of the scrollable panel list, scrolls away with the rest of the UI like every other panel */
#topBar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    margin-bottom: 10px;
    background: #181818;
    border: 1px solid var(--border2);
    border-radius: 4px;
}
#topBar label {
    font-size: 13px;
}
#topBar .topBarGroup {
    display: flex;
    align-items: center;
    gap: 6px;
}
#topBar #panelSizeInput {
    width: 80px;
}

#layoutRoot {
    display: flex;
    width: 100%;
    height: calc(var(--vh, 1vh) * 100);
    min-height: 0;
    overflow: hidden;
}
#uiRoot {
    padding: 12px 16px 40px;
    background: var(--bg2);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    flex: 0 0 420px;
    min-height: 0;
}
#viewportContainer {
    flex: 1 1 auto;
    position: relative;
    min-height: 0;
    background: #000;
}
#viewport {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: #000;
}

/* layout variants */
.layout-left #uiRoot {
    order: 2;
    border-left: 1px solid var(--border);
    border-right: none;
    flex: 0 0 var(--panel-width, 420px);
}
.layout-left #viewportContainer {
    order: 1;
}
.layout-right #uiRoot {
    order: 1;
    border-right: 1px solid var(--border);
    border-left: none;
    flex: 0 0 var(--panel-width, 420px);
}
.layout-right #viewportContainer {
    order: 2;
}
.layout-top {
    flex-direction: column;
}
.layout-top #uiRoot {
    order: 1;
    border-bottom: 1px solid var(--border);
    border-right: none;
    width: 100%;
    flex: 0 0 auto;
    height: var(--panel-height, 300px);
}
.layout-top #viewportContainer {
    order: 2;
}
.layout-bottom {
    flex-direction: column;
}
.layout-bottom #uiRoot {
    order: 2;
    border-top: 1px solid var(--border);
    border-right: none;
    width: 100%;
    flex: 0 0 auto;
    height: var(--panel-height, 300px);
    overflow-y: auto;
}
.layout-bottom #viewportContainer {
    order: 1;
}

.panel {
    border: 1px solid var(--border2);
    border-radius: 4px;
    padding: 8px 10px 10px;
    margin-bottom: 10px;
    background: #181818;
}
.panelBody {
    margin-top: 6px;
}
.panelRow {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-bottom: 6px;
}

/* make each label+input pair go to its own line */
.panelRowField {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    width: 100%;
    margin-bottom: 4px;
}
.panelRowField label {
    min-width: 90px;
    font-size: 13px;
}
.panelRowField input,
.panelRowField select {
    flex: 1 1 auto;
}

label {
    font-size: 13px;
    white-space: nowrap;
}
input[type="number"],
input[type="text"],
select {
    background: #101010;
    color: var(--fg);
    border: 1px solid var(--border2);
    border-radius: 3px;
    padding: 3px 5px;
    font-size: 13px;
    min-width: 60px;
}
input[type="color"] {
    border: 1px solid var(--border2);
    background: #101010;
    width: 40px;
    height: 22px;
    padding: 0;
}
button {
    background: #222;
    color: var(--fg);
    border: 1px solid var(--border2);
    border-radius: 3px;
    padding: 3px 8px;
    font-size: 13px;
    cursor: pointer;
}
button:hover {
    background: #333;
}
button.danger {
    border-color: var(--danger);
    color: #ffb3b3;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
th, td {
    border-bottom: 1px solid var(--border);
    padding: 3px 4px;
    text-align: left;
}
th {
    background: #202020;
    font-weight: 500;
}
td input[type="number"] {
    width: 70px;
}
td .angleVal {
    font-family: monospace;
    font-size: 12px;
}
.smallNote {
    font-size: 11px;
    opacity: 0.7;
}

/* ===========================================================
   DICTIONARY GAME (ported from a_copilot_dictionary_set_05.html)
   =========================================================== */
.dictGridContainer {
    display: grid;
    gap: 2px;
    margin-top: 8px;
    background-color: #111111;
    padding: 4px;
    border: 1px solid var(--border2);
}
.dictGridCell,
.dictChoiceCell,
.dictEmptyCell {
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px solid var(--border2);
    background-color: #000000;
    color: var(--fg);
    overflow: hidden;
}
.dictGridCell img,
.dictChoiceCell img {
    object-fit: contain;
}
.dictChoiceCell {
    cursor: pointer;
}
.dictChoiceCell:hover {
    border-color: var(--accent);
}
.dictEmptyCell {
    background-color: #111111;
}
.dictScoreRow {
    display: flex;
    gap: 20px;
    align-items: center;
    margin-top: 8px;
}
.dictScoreRow input {
    width: 80px;
}
#dictInfo {
    color: var(--accent);
    font-weight: bold;
}
#dictErrorInfo {
    color: var(--danger);
    font-weight: bold;
}
#dictGameActive {
    margin-top: 10px;
    border-top: 1px solid var(--border2);
    padding-top: 8px;
}

/* hide buttons */
.hideBtn {
    background: #222;
    color: var(--fg);
    border: 1px solid var(--border2);
    border-radius: 3px;
    padding: 2px 6px;
    font-size: 12px;
    cursor: pointer;
}

/* INFO OVERLAY */
#infoOverlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}
#infoBox {
    background: #181818;
    border: 1px solid var(--border2);
    border-radius: 6px;
    width: 80%;
    max-width: 700px;
    max-height: 80%;
    display: flex;
    flex-direction: column;
}
#infoBoxHeader {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border2);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
#infoBoxBody {
    padding: 10px;
    overflow-y: auto;
    font-size: 14px;
    line-height: 1.4;
}

/* rotation control buttons panel */
#rotationButtonsContainer {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    --buttons-per-row: 6;
}
.rotationControlButton {
    flex: 0 0 calc(100% / var(--buttons-per-row));
    text-align: center;
    padding: 8px 4px;
    border: 1px solid var(--border2);
    border-radius: 4px;
    background: #222;
    font-size: 12px;
    line-height: 1.2;
}
.rotationControlButton.active {
    background: var(--accent);
    color: #000;
}
.rotationControlButtonLabelTop {
    display: block;
    font-weight: 600;
}
.rotationControlButtonLabelBottom {
    display: block;
}

/* ===========================================================
   MODE SWITCH (top of all settings)
   =========================================================== */
#modePanel {
    background: var(--bg2);
}
.modeSwitchRow {
    display: flex;
    gap: 6px;
}
.modeBtn {
    flex: 1;
    padding: 10px 6px;
    border: 1px solid var(--border2);
    border-radius: 4px;
    background: #222;
    color: var(--fg);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.modeBtn.active {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
}

/* ===========================================================
   LABYRINTH PANEL
   =========================================================== */
.smallNote {
    display: block;
    font-size: 12px;
    color: #999;
    margin: 4px 0;
}
.stepGrid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 8px 0;
}
.stepCol {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 0 0 auto;
}
.stepCol button {
    padding: 6px 8px;
    border: 1px solid var(--border2);
    border-radius: 4px;
    background: #222;
    color: var(--fg);
    font-size: 12px;
    cursor: pointer;
}
.stepCol button.plus { border-color: var(--accent); }
.stepCol button.minus { border-color: var(--danger); }

.moveGrid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
    max-width: 220px;
    margin: 8px 0;
}
.moveGrid button {
    padding: 10px 4px;
    border: 1px solid var(--border2);
    border-radius: 4px;
    background: #222;
    color: var(--fg);
    font-size: 12px;
    cursor: pointer;
}
.moveGridW {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
    max-width: 220px;
    margin: 8px 0;
}

/* ===========================================================
   In Labyrinth mode, hide the Rotation-mode-only controls that
   don't apply to the maze: Object parameters (dimension/object
   select + per-object params like parallelepiped 4D sizes),
   Scan settings, stereo controls, and the lines/points color +
   apply-colors controls.
   =========================================================== */
body.mode-labyrinth .hideInLabyrinth {
    display: none !important;
}

/* ===========================================================
   Floating bar pinned to the very top of the screen (currently
   just the Show/Hide Shortest Path button) - only relevant, and
   only shown, while in Labyrinth mode.
   =========================================================== */
#topFloatingBar {
    display: none;
    position: fixed;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
}
body.mode-labyrinth #topFloatingBar {
    display: block;
}
#topFloatingBar button {
    padding: 10px 20px;
    border: 1px solid var(--accent);
    border-radius: 6px;
    background: #1b1b1b;
    color: var(--fg);
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0,0,0,0.6);
}
#topFloatingBar button:hover {
    background: var(--accent);
    color: #000;
}

/* ===========================================================
   Shortest-path quick toggle: pinned near the top of the sidebar
   (right above Destination & style), only shown in Labyrinth mode.
   =========================================================== */
.onlyInLabyrinth {
    display: none;
}
body.mode-labyrinth .onlyInLabyrinth {
    display: block;
}
#shortestPathQuickPanel {
    padding: 8px 12px;
    background: var(--bg2);
}
#shortestPathQuickPanel button {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--accent);
    border-radius: 4px;
    background: #222;
    color: var(--fg);
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
}

