/* Display layout (#106): blocks placed by a saved layout
   (.display-layout-custom) and the layout editor around them
   (.display-layout-editing). Without either class nothing here applies, so a
   display without a saved layout keeps the default flow layout of layout.css. */

/* The light size on the whole lights block, for the cards frame below. Same
   formula as .display-orb-wrap (components.css). */
.display-lights {
    --orb-size: calc(clamp(38px, 19.2vmin, 224px) * var(--display-zoom, 1));
}

/* Default flow layout: extra room between the cards + reasons and the
   verdict, so in the editor the cards label (under the cards frame) and the
   verdict label (above the verdict) sit one above the other instead of on
   top of each other (#162). Fixed px like the labels, which do not scale:
   two labels of 27px minus the 12px flex gap, plus a few px
   (--layout-verdict-room; raise it with the label font or padding). The
   negative bottom margin keeps the height of the flow, so the timer and the
   lights stay where they were and only the verdict moves down. */
.display-full:not(.display-layout-custom) .display-verdict-inline {
    margin-top: var(--layout-verdict-room);
    margin-bottom: calc(-1 * var(--layout-verdict-room));
}

/* ===== SAVED LAYOUT ===== */
/* Each block sits at its own left/top (percent of the display, inline style)
   and scales with its own --display-zoom. */
.display-layout-custom .layout-block {
    position: absolute;
    width: max-content;
    right: auto;
    bottom: auto;
}

.display-layout-custom:not(.display-layout-editing) .layout-hidden {
    display: none;
}
.display-layout-custom:not(.display-layout-editing) .layout-hidden-lights .display-orb {
    visibility: hidden;
}
.display-layout-custom:not(.display-layout-editing) .layout-hidden-cards .display-orb-card,
.display-layout-custom:not(.display-layout-editing) .layout-hidden-cards .display-orb-reason {
    display: none;
}

/* ===== EDITOR ===== */
/* Frames are positioned inside their block; in the default flow layout this
   only happens while editing, so the display looks as before otherwise. */
.display-layout-editing:not(.display-layout-custom) .layout-block--timer,
.display-layout-editing:not(.display-layout-custom) .display-lights,
.display-layout-editing:not(.display-layout-custom) .display-verdict-inline {
    position: relative;
}

.display-layout-editing .layout-block {
    cursor: move;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: auto;   /* the VPortal corners are click-through otherwise */
}

/* Hidden blocks stay visible but faded while editing, to switch them on
   again; so does the sample text of the VPortal blocks without a lifter. */
.display-layout-editing .layout-sample > :not(.layout-frame),
.display-layout-editing .layout-hidden > :not(.layout-frame),
.display-layout-editing .layout-hidden-lights .display-orb,
.display-layout-editing .layout-hidden-cards .display-orb-card,
.display-layout-editing .layout-hidden-cards .display-orb-reason {
    opacity: 0.3;
}

/* Centre lines (#189): a dashed horizontal and vertical line through the
   middle of the display, to centre blocks by eye. First child of the display,
   so the blocks (positioned too while editing) paint over them; they catch no
   pointer, so a block on a line is grabbed as anywhere else. Fixed px like
   the frames. Shown only while editing (x-show). */
.layout-center-lines {
    position: absolute;
    inset: 0;
    pointer-events: none;
}
.layout-center-line--h {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(50% - 1px);
    border-top: 2px dashed var(--layout-center-line);
}
.layout-center-line--v {
    position: absolute;
    top: 0;
    bottom: 0;
    left: calc(50% - 1px);
    border-left: 2px dashed var(--layout-center-line);
}

/* Frame chrome has fixed sizes: it must not scale with the block. */
.layout-frame {
    position: absolute;
    inset: -6px;
    border: 2px dashed var(--layout-frame);
    pointer-events: none;
    font-family: 'Rajdhani', sans-serif;
    font-size: 13px;
    letter-spacing: .08em;
    line-height: 1;
    text-transform: uppercase;
    text-align: left;
    z-index: 6;   /* labels above the cards frame of the lights */
}

.layout-frame-label {
    position: absolute;
    left: -2px;
    bottom: 100%;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    background: var(--layout-frame);
    color: var(--layout-frame-text);
    font-weight: 700;
    white-space: nowrap;
    pointer-events: auto;
}

.layout-hide-toggle {
    background: var(--bg-void);
    color: var(--panel-text-bright);
    border: none;
    padding: 3px 8px;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    cursor: pointer;
}
.layout-hide-toggle[aria-pressed="true"] {
    background: var(--blood);
}

.layout-scale-handle {
    position: absolute;
    right: -12px;
    bottom: -12px;
    width: 24px;
    height: 24px;
    background: var(--layout-frame);
    border: 2px solid var(--bg-void);
    cursor: nwse-resize;
    touch-action: none;
    pointer-events: auto;
}

/* The timer's label sits under its frame (#188): above it, the editor
   toolbar covers it on screens up to 768px high. In the default layout it
   lies in the room between timer and lights (--display-timer-room). It ends
   left of the scale handle (bottom right corner), so the handle never covers
   its hide button: the handle reaches 12px into the frame (right: -12px,
   24px wide), the label ends 14px from its edge, 2px clear (change both
   together). Under a narrow timer it grows to the left.
   While editing the timer lies one layer above the other blocks: each block
   paints as a whole in DOM order (in a saved layout its transform makes it a
   stacking context), the timer comes first, so a timer scaled up or moved
   close to the lights would have its label under them. Gear, panel and
   toolbar stay above it. */
.layout-block--timer .layout-frame-label {
    top: 100%;
    bottom: auto;
    left: auto;
    right: 14px;
}
.display-layout-editing .layout-block--timer {
    z-index: 1;
}

/* The attempt block is anchored at its right edge: scale it from the left,
   and its label grows to the left, so it stays on screen (#162). */
.vportal-corner-right .layout-frame-label {
    left: auto;
    right: -2px;
}
.vportal-corner-right .layout-scale-handle {
    right: auto;
    left: -12px;
    cursor: nesw-resize;
}

/* Lights: the handle on the right side, half-way down the lights, sets the
   gap between them (#154). Dragged sideways only. */
.layout-gap-handle {
    position: absolute;
    right: -12px;
    top: calc(6px + var(--orb-size) / 2 - 18px);
    width: 16px;
    height: 36px;
    background: var(--layout-frame);
    border: 2px solid var(--bg-void);
    cursor: ew-resize;
    touch-action: none;
    pointer-events: auto;
}

/* Cards block: the row of cards and reasons under the lights. It only moves
   up and down (its gap to the lights). */
.layout-cards-frame {
    position: absolute;
    left: -2px;
    right: -2px;
    top: calc(var(--orb-size) * (1 + var(--orb-card-gap, 0)) + 0.25rem);
    bottom: 0;
    border: 2px dashed var(--layout-frame-cards);
    cursor: ns-resize;
    touch-action: none;
    pointer-events: auto;
    font-family: 'Rajdhani', sans-serif;
    font-size: 13px;
    letter-spacing: .08em;
    line-height: 1;
    text-transform: uppercase;
    z-index: 5;
}
.layout-cards-frame .layout-frame-label {
    top: 100%;
    bottom: auto;
    background: var(--layout-frame-cards);
}

/* Pause preview (#190): the pause instead of the other blocks. They are only
   transparent, not removed, so they can still be measured when the first
   change leaves the default layout; opacity, not visibility, which the cards
   and reasons set back to visible. Their frames and handles catch no pointer. */
.layout-pause-preview .layout-block:not(.display-pause),
.layout-pause-preview .layout-block:not(.display-pause) * {
    opacity: 0;
    pointer-events: none;
}

/* ===== EDITOR TOOLBAR ===== */
/* Centred by auto margins between left and right, not by left: 50% plus a
   transform: that would give it only half the screen width and wrap the
   German buttons into three rows. Kept flat, so it covers as little as
   possible of the blocks below it (#162; the timer label sits under the
   timer since #188). */
.layout-toolbar {
    position: absolute;
    top: 6px;
    left: 12px;
    right: 12px;
    width: fit-content;
    margin: 0 auto;
    z-index: 20;
    background: var(--bg-surface);
    border: 1px solid var(--panel-border);
    border-top: 2px solid var(--layout-frame);
    padding: 6px 12px;
    color: var(--panel-text);
    font-family: 'Rajdhani', sans-serif;
    box-shadow: 0 12px 32px rgba(0,0,0,0.5);
}

.layout-toolbar-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.layout-toolbar-title {
    font-size: 14px;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--panel-text-bright);
    margin-right: 8px;
}

.layout-toolbar-btn {
    background: transparent;
    border: 1px solid var(--panel-border);
    color: var(--panel-text);
    padding: 8px 14px;
    min-height: 36px;
    font-family: 'Rajdhani', sans-serif;
    font-size: 12px;
    letter-spacing: .12em;
    text-transform: uppercase;
    cursor: pointer;
}
.layout-toolbar-btn:hover { border-color: var(--panel-border-hover); color: var(--panel-text-bright); }
.layout-toolbar-btn[aria-pressed="true"] {
    border-color: var(--layout-frame);
    color: var(--panel-text-bright);
}
.layout-toolbar-btn--primary {
    background: var(--blood);
    border-color: var(--blood-bright);
    color: var(--contrast-text);
}

.layout-toolbar-hint {
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-dim);
}

.layout-code {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 10px;
    width: min(480px, 100%);
}

.layout-code-label {
    font-size: 11px;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--text-dim);
}

.layout-code-field {
    width: 100%;
    background: var(--bg-void);
    border: 1px solid var(--panel-border);
    color: var(--panel-text-bright);
    padding: 6px 8px;
    font-family: monospace;
    font-size: 12px;
    resize: vertical;
    word-break: break-all;
}

.layout-code-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.layout-code-error {
    color: var(--blood-bright);
    font-size: 13px;
    font-weight: 600;
}
