#app,
#app *
{
    border: 0;
    border-radius: 0;
}

body
{
    overflow: hidden;
}

#app
{
    display: grid;
    height: 100vh;
    height: 100dvh;
    grid-template-columns: 310px minmax(0, 1fr) 368px;
    grid-template-rows: 52px minmax(0, 1fr) 28px;
    grid-template-areas:
        'top top top'
        'left stage right'
        'status status status';
}

#topbar
{
    grid-area: top;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 10px 0 14px;
    background: var(--chrome);
    color: var(--chrome-fg);
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
}

#topbar::-webkit-scrollbar
{
    display: none;
}

#brand
{
    display: flex;
    align-items: center;
    gap: 10px;
    margin-right: 14px;
    flex: none;
}

#brand svg
{
    width: 26px;
    height: 26px;
    display: block;
    color: transparent;
}

#brand-name
{
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.topbar-group
{
    display: flex;
    align-items: center;
    gap: 2px;
    flex: none;
}

.topbar-label
{
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--chrome-muted);
    margin-right: 8px;
}

.topbar-divider
{
    width: 1px;
    height: 22px;
    margin: 0 6px;
    background: var(--chrome-line);
    flex: none;
}

#topbar .icon-btn:hover:not(:disabled)
{
    background: var(--chrome-hover);
}

#topbar .icon-btn:focus-visible
{
    background: var(--chrome-fg);
    color: var(--chrome);
}

#topbar select
{
    width: 230px;
    background-color: var(--chrome-field);
    color: var(--chrome-fg);
}

#topbar select:hover,
#topbar select:focus
{
    background-color: var(--chrome-hover);
}

#topbar .btn
{
    background: var(--chrome-field);
    color: var(--chrome-fg);
    flex: none;
}

#topbar .btn:hover:not(:disabled)
{
    background: var(--chrome-hover);
}

#topbar .btn.primary
{
    background: var(--chrome-fg);
    color: var(--chrome);
}

#topbar .btn.primary:hover:not(:disabled)
{
    background: var(--chrome-primary-hover);
}

#topbar .btn.ghost
{
    background: transparent;
    padding: 0 10px;
}

#topbar .btn.ghost:hover:not(:disabled)
{
    background: var(--chrome-hover);
}

#topbar .btn:focus-visible
{
    background: var(--chrome-fg);
    color: var(--chrome);
}

#leftpanel,
#rightpanel
{
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--chrome);
    overflow: hidden;
}

#leftpanel
{
    grid-area: left;
}

#rightpanel
{
    grid-area: right;
    gap: 0;
}

.panel-section
{
    background: var(--bg);
    padding: 16px 18px 18px;
    flex: none;
}

.panel-section.grow
{
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.section-head
{
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 26px;
    margin-bottom: 10px;
}

.section-head h2
{
    flex: 1;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.section-head .hint
{
    font-size: 11px;
}

.section-actions
{
    display: flex;
    gap: 2px;
}

#layer-list
{
    list-style: none;
    max-height: 132px;
    overflow-y: auto;
}

.layer
{
    display: flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 4px 0 10px;
    cursor: pointer;
    background: var(--panel);
    user-select: none;
}

.layer + .layer
{
    margin-top: 2px;
}

.layer:hover
{
    background: var(--field);
}

.layer.active
{
    background: var(--fg);
    color: var(--bg);
}

.layer:focus-visible
{
    background: var(--field-hover);
}

.layer.active:focus-visible
{
    background: var(--primary-hover);
}

.layer-name
{
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.layer-font
{
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
    opacity: 0.65;
}

.layer .icon-btn:hover
{
    background: transparent;
    opacity: 0.6;
}

.layer.hidden-layer .layer-name
{
    opacity: 0.45;
}

#text-input
{
    min-height: 92px;
    max-height: 260px;
    font-size: 14px;
}

#missing-glyphs
{
    margin-top: 8px;
}

.search
{
    position: relative;
}

.search .icon
{
    position: absolute;
    left: 8px;
    top: 6px;
    width: 18px;
    height: 18px;
    color: var(--muted);
}

.search input
{
    padding-left: 32px;
}

.chips
{
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 8px 0 10px;
}

#font-list
{
    flex: 1;
    min-height: 120px;
    overflow-y: auto;
    margin: 0 -18px;
    padding: 0 18px;
}

.font-group-title
{
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 8px 0 6px;
    background: var(--bg);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
}

.font-item
{
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    width: 100%;
    min-height: 58px;
    padding: 6px 4px 6px 10px;
    background: var(--panel);
    text-align: left;
    cursor: pointer;
}

.font-item + .font-item
{
    margin-top: 2px;
}

.font-item
{
    scroll-margin-top: 34px;
    scroll-margin-bottom: 8px;
}

.font-item:hover
{
    background: var(--field);
}

.font-item.active
{
    background: var(--fg);
    color: var(--bg);
}

.font-item:focus-visible
{
    background: var(--field-hover);
}

.font-item.active:focus-visible
{
    background: var(--primary-hover);
}

.font-preview
{
    display: block;
    height: 28px;
    width: 100%;
    overflow: visible;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.font-preview path
{
    vector-effect: non-scaling-stroke;
}

.font-preview.outline
{
    stroke-width: 1;
}

.font-preview-text
{
    display: block;
    height: 28px;
    font-size: 20px;
    line-height: 28px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.font-meta
{
    display: block;
    margin-top: 3px;
    font-size: 11px;
    opacity: 0.6;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.font-actions
{
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.font-item .icon-btn:hover
{
    background: transparent;
    opacity: 0.6;
}

.font-empty
{
    padding: 18px 4px;
    color: var(--muted);
    line-height: 1.5;
}

#btn-open-studio
{
    margin-top: 10px;
    flex: none;
}

#stage
{
    grid-area: stage;
    position: relative;
    min-width: 0;
    min-height: 0;
    background: var(--stage);
    overflow: hidden;
}

#bed-canvas
{
    position: absolute;
    inset: 0 0 48px 0;
    width: 100%;
    height: calc(100% - 48px);
    display: block;
    touch-action: none;
    cursor: default;
}

#bed-canvas.can-move
{
    cursor: move;
}

#bed-canvas.can-pan
{
    cursor: grab;
}

#bed-canvas.panning
{
    cursor: grabbing;
}

#bed-canvas.can-scale
{
    cursor: nwse-resize;
}

#bed-canvas.can-scale-alt
{
    cursor: nesw-resize;
}

#bed-canvas.can-rotate
{
    cursor: alias;
}

#stage-tools
{
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

#stage-tools .icon-btn
{
    background: var(--bg);
}

#stage-tools .icon-btn:hover
{
    background: var(--field);
}

#stage-info
{
    position: absolute;
    top: 12px;
    left: 12px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    pointer-events: none;
}

#stage-printer
{
    background: var(--fg);
    color: var(--bg);
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 600;
}

#welcome
{
    position: absolute;
    left: 12px;
    bottom: 60px;
    width: min(340px, calc(100% - 24px));
    padding: 16px 18px 18px;
    background: var(--fg);
    color: var(--bg);
    line-height: 1.5;
}

#welcome .btn
{
    background: var(--bg);
    color: var(--fg);
}

#welcome .btn:hover
{
    background: var(--field-hover);
}

#welcome strong
{
    display: block;
    font-size: 15px;
    margin-bottom: 8px;
}

#welcome ol
{
    padding-left: 20px;
    margin-bottom: 14px;
    opacity: 0.8;
}

#welcome li + li
{
    margin-top: 4px;
}

#stage-badge
{
    background: var(--bg);
    color: var(--fg);
    padding: 5px 10px;
    font-size: 12px;
    max-width: 420px;
}

#simbar
{
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 48px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    background: var(--bg);
}

#sim-scrub
{
    flex: 1;
    min-width: 80px;
}

#sim-time
{
    width: 104px;
    flex: none;
    font-family: var(--font-mono);
    font-size: 11.5px;
    text-align: center;
    color: var(--muted);
}

#sim-speed
{
    width: 74px;
    flex: none;
}

.toggle-inline
{
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--muted);
    cursor: pointer;
    user-select: none;
    flex: none;
}

.simbar-divider
{
    width: 1px;
    height: 20px;
    background: var(--band);
    flex: none;
}

#statusbar
{
    grid-area: status;
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 0 14px;
    background: var(--chrome);
    color: var(--chrome-muted);
    font-family: var(--font-mono);
    font-size: 11.5px;
    white-space: nowrap;
    overflow: hidden;
}

#statusbar b
{
    color: var(--chrome-fg);
    font-weight: 600;
}

#st-warning
{
    background: var(--chrome-fg);
    color: var(--chrome);
    padding: 2px 8px;
    font-family: var(--font-ui);
    cursor: pointer;
}

#right-tabs
{
    flex: none;
    background: var(--chrome);
}

.tab-page
{
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--chrome);
}

.tab-page .panel-section:last-child
{
    flex: 1;
}

.row-buttons
{
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 10px;
}

.row-buttons .btn
{
    flex: 1;
}

.sub
{
    margin-top: 14px;
    padding-top: 12px;
    background: linear-gradient(var(--band), var(--band)) no-repeat top / 100% 2px;
}

.sub-title
{
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 8px;
}

.font-chip
{
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
    color: var(--muted);
}

.empty-state
{
    padding: 28px 16px;
    text-align: center;
    color: var(--muted);
    line-height: 1.6;
}

.empty-state .btn
{
    margin-top: 12px;
}

#usb-status
{
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 3px 8px;
    background: var(--field);
    color: var(--muted);
}

#usb-status.on
{
    background: var(--fg);
    color: var(--bg);
}

#usb-firmware
{
    margin-top: 8px;
    word-break: break-word;
}

#job-status
{
    margin: 8px 0 2px;
    font-size: 12px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.jog
{
    display: grid;
    grid-template-columns: repeat(3, 40px) 14px 40px;
    grid-template-rows: repeat(3, 40px);
    gap: 2px;
    justify-content: center;
    margin: 10px 0;
}

.jog button
{
    background: var(--field);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
}

.jog button:hover:not(:disabled)
{
    background: var(--field-hover);
}

.jog button:active:not(:disabled)
{
    background: var(--fg);
    color: var(--bg);
}

.jog .jog-home
{
    background: var(--fg);
    color: var(--bg);
}

.jog .jog-home:hover:not(:disabled)
{
    background: var(--primary-hover);
}

.jog .gap
{
    background: transparent;
    pointer-events: none;
}

.step-row
{
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
}

.step-row .label
{
    width: 64px;
    font-size: 11px;
    color: var(--muted);
}

.step-row .seg
{
    flex: 1;
}

.step-row .seg button
{
    height: 26px;
}

#console-log
{
    height: 180px;
    overflow-y: auto;
    padding: 8px;
    background: var(--panel);
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
}

#console-log .out
{
    color: var(--muted);
}

#console-log .err
{
    background: var(--fg);
    color: var(--bg);
}

#console-form
{
    display: flex;
    gap: 2px;
    margin-top: 2px;
}

#console-form input
{
    font-family: var(--font-mono);
    font-size: 12px;
}

#gcode-peek
{
    height: 150px;
    overflow: auto;
    padding: 8px;
    background: var(--panel);
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.5;
    white-space: pre;
    color: var(--muted);
}

#custom-start,
#custom-end
{
    font-family: var(--font-mono);
    font-size: 12px;
    min-height: 64px;
}

@media (max-width: 1480px)
{
    .file-label
    {
        display: none;
    }
}

@media (max-width: 1180px)
{
    #app
    {
        grid-template-columns: 280px minmax(0, 1fr) 330px;
    }

    #topbar select
    {
        width: 170px;
    }

    .btn-label
    {
        display: none;
    }
}

@media (max-width: 880px)
{
    body
    {
        overflow: auto;
    }

    #app
    {
        height: auto;
        min-height: 100vh;
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: 52px 62vh auto auto 28px;
        grid-template-areas:
            'top'
            'stage'
            'left'
            'right'
            'status';
    }

    #leftpanel,
    #rightpanel
    {
        overflow: visible;
    }

    #font-list
    {
        max-height: 60vh;
    }

    .tab-page
    {
        overflow: visible;
    }

    #statusbar
    {
        position: sticky;
        bottom: 0;
        overflow-x: auto;
    }

    .toggle-inline span
    {
        display: none;
    }

    #simbar
    {
        overflow-x: auto;
        scrollbar-width: none;
    }
}

@media (max-width: 520px)
{
    #sim-time
    {
        display: none;
    }

    #brand-name,
    .topbar-label
    {
        display: none;
    }
}
