/* Small-screen refinements only. Desktop layout and printed card dimensions stay unchanged. */
@media screen and (max-width: 1279px) {
    body.index-page {
        --feedback-toolbar-clearance: 110px;
    }

    body.index-page .container {
        height: 100dvh;
    }

    body.index-page .left-panel {
        width: clamp(284px, 31vw, 340px);
        flex-shrink: 0;
        min-width: 0;
    }

    body.index-page .left-panel.collapsed {
        width: 0;
    }

    body.index-page .left-panel-content,
    body.index-page .cards-list,
    body.index-page .main-workspace,
    body.index-page .preview-area-wrapper,
    body.index-page .preview-area {
        min-width: 0;
        min-height: 0;
    }

    body.index-page .import-buttons {
        gap: 6px;
    }

    body.index-page .import-btn {
        padding: 6px 8px;
        font-size: 12px;
        letter-spacing: 0;
    }

    body.index-page .header,
    body.index-page .bottom-controls {
        flex-shrink: 0;
    }

    body.index-page .header-right {
        max-width: 228px;
        flex: 0 0 auto;
    }

    body.index-page .calibration-header-toolbar {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr);
        width: 100%;
        padding-right: 12px;
    }

    body.index-page .calibration-profile-picker {
        grid-column: 1 / -1;
        padding-right: 0;
    }

    body.index-page .calibration-toolbar-divider {
        display: none;
    }

    body.index-page .calibration-profile-picker label {
        font-size: 10.5px;
    }

    body.index-page .calibration-profile-picker .offset-select {
        min-height: 36px;
        font-size: 13px;
    }

    body.index-page .calibration-header-toolbar .calibration-btn {
        min-height: 36px;
        font-size: 11px;
        min-width: 0;
        white-space: normal;
        line-height: 1.2;
        padding: 7px 6px;
    }

    body.index-page .preview-headers {
        gap: 12px;
        padding: 12px 16px 8px;
    }

    body.index-page .preview-area {
        gap: 12px;
        padding: 0 16px 16px;
    }

    body.index-page .preview-sheet {
        /* Ease back to the original 72% sheet width as the viewport approaches 1280px. */
        width: clamp(72%, calc(96% + 1239px - 105vw), 96%);
        max-width: 96%;
    }

    body.index-page .bottom-controls {
        gap: 12px;
        padding: 10px 12px;
    }

    body.index-page .bottom-controls-cluster {
        grid-template-columns: repeat(3, max-content);
        justify-content: space-around;
        column-gap: 8px;
        row-gap: 4px;
    }

    body.index-page .bottom-controls .font-control,
    body.index-page .bottom-controls-cluster > .paper-size-control {
        gap: 4px;
        min-height: 36px;
        padding: 4px 8px;
        white-space: nowrap;
    }

    body.index-page .bottom-controls .font-control-label,
    body.index-page .paper-size-control label {
        font-size: 12px;
    }

    body.index-page .card-size-font-control .card-size-select {
        min-width: 3.8em;
        padding: 2px 16px 2px 2px;
        font-size: 13px;
    }

    body.index-page .paper-size-select,
    body.index-page .font-display-text {
        font-size: 13px;
    }

    body.index-page .shared-cut-lines-control {
        grid-column: 1 / -1;
        min-height: 36px;
        margin-top: 0;
    }

    body.index-page .print-btn {
        min-height: 44px;
        padding: 10px 18px;
        font-size: 14px;
    }

    body.index-page .feedback-btn {
        right: max(14px, env(safe-area-inset-right, 0px));
        min-height: 44px;
        padding: 10px 14px;
        font-size: 13px;
    }
}

/* At phone and split-view widths, retain the editor and both previews in a vertical layout. */
@media screen and (max-width: 700px) {
    body.index-page {
        position: relative;
    }

    body.index-page .container {
        flex-direction: column;
        /* Short phones can scroll the page instead of losing the preview entirely. */
        min-height: 760px;
    }

    body.index-page .left-panel {
        width: 100%;
        height: clamp(320px, 40dvh, 350px);
        border-right: none;
        border-bottom: 2px solid #e0e0e0;
        transition: height 0.3s ease;
    }

    body.index-page .left-panel.collapsed {
        width: 100%;
        height: 0;
        border-bottom: none;
    }

    body.index-page .left-panel.collapsed .left-panel-header {
        display: none;
    }

    body.index-page .container:has(.left-panel.collapsed) {
        min-height: 0;
    }

    body.index-page .left-panel-header {
        padding: 8px 12px;
    }

    body.index-page .toggle-panel-btn .toggle-panel-icon {
        transform: rotate(90deg);
    }

    body.index-page .left-panel-content {
        padding: 10px 12px;
    }

    body.index-page .import-buttons {
        gap: 6px;
        margin-bottom: 10px;
    }

    body.index-page .import-btn {
        min-height: 30px;
        padding: 6px 8px;
        font-size: 12px;
        letter-spacing: 0;
    }

    body.index-page .clear-all-cards-btn {
        margin-bottom: 10px;
    }

    body.index-page .cards-list {
        margin-bottom: 10px;
    }

    body.index-page .add-card-btn {
        padding: 10px;
        font-size: 14px;
    }

    body.index-page .expand-panel-btn {
        position: static;
        transform: none;
        flex-direction: row;
        flex-shrink: 0;
        gap: 8px;
        min-height: 40px;
        padding: 6px 12px;
        border-radius: 0;
        box-shadow: none;
    }

    body.index-page .expand-text {
        writing-mode: horizontal-tb;
    }

    body.index-page .expand-chevron-icon {
        transform: rotate(90deg);
    }

    body.index-page .header {
        padding: 10px 0 10px 12px;
    }

    body.index-page .header-right {
        max-width: min(210px, 50vw);
    }

    body.index-page .header-title {
        font-size: 20px;
    }

    body.index-page .header-logo {
        height: 32px;
    }

    body.index-page .preview-headers {
        padding: 8px 10px 6px;
    }

    body.index-page .preview-header {
        font-size: 13px;
    }

    body.index-page .preview-area {
        padding: 0 10px 10px;
    }

    /* Follow the preview on short, scrollable pages rather than covering header buttons. */
    body.index-page .feedback-btn {
        position: absolute;
        top: calc(max(100dvh, 760px) - 160px);
        bottom: auto;
    }

    body.index-page:has(.left-panel.collapsed) .feedback-btn {
        top: calc(100dvh - 160px);
    }

    body.index-page .footer-content,
    body.index-page .footer.footer-split .footer-left {
        position: static;
        transform: none;
    }

    body.index-page .footer-content {
        gap: 12px;
    }

    body.index-page .style-menu {
        max-height: calc(100dvh - 40px);
        overflow-y: auto;
    }

    body.index-page .calibration-preview-container,
    body.index-page .calibration-offset-controls {
        flex-basis: 100%;
        min-width: 0;
    }

    body.index-page .calibration-preview-sheet {
        max-width: 330px;
        margin: 0 auto;
    }

    body.index-page .calibration-visual-area {
        gap: 16px;
        margin: 16px 0;
    }

    body.index-page .calibration-instructions-text {
        margin-bottom: 20px;
    }

    body.index-page .profile-name-section,
    body.index-page .input-row input[type="text"] {
        min-width: 0;
    }

    body.index-page .label-row {
        flex-wrap: wrap;
    }

    body.index-page .profile-name-warning {
        white-space: normal;
    }

    body.index-page .calibration-action-btn,
    body.index-page .calibration-next-btn {
        min-height: 44px;
        padding: 10px 12px;
    }
}

@media screen and (max-width: 360px) {
    body.index-page .header-brand {
        gap: 4px;
    }

    body.index-page .header-logo {
        height: 24px;
    }

    body.index-page .header-title {
        font-size: 17px;
    }

    body.index-page .header-right {
        width: 184px;
        max-width: 184px;
    }

    body.index-page .calibration-header-toolbar .calibration-btn {
        padding: 6px 3px;
        font-size: 10.5px;
    }
}

/* Keep a short landscape phone from spending its whole height on the editor. */
@media screen and (min-width: 560px) and (max-width: 700px) and (max-height: 500px) {
    body.index-page .container {
        flex-direction: row;
        min-height: 0;
    }

    body.index-page .left-panel {
        width: 250px;
        height: 100%;
        border-bottom: none;
        border-right: 2px solid #e0e0e0;
    }

    body.index-page .left-panel.collapsed {
        width: 0;
        height: 100%;
        border-right: none;
    }

    body.index-page .toggle-panel-btn .toggle-panel-icon {
        transform: none;
    }

    body.index-page .expand-panel-btn {
        position: fixed;
        left: 0;
        top: 50%;
        transform: translateY(-50%);
        flex-direction: column;
        padding: 16px 8px;
        border-radius: 0 8px 8px 0;
    }

    body.index-page .expand-text {
        writing-mode: vertical-rl;
    }

    body.index-page .expand-chevron-icon {
        transform: none;
    }

    body.index-page .feedback-btn,
    body.index-page:has(.left-panel.collapsed) .feedback-btn {
        position: fixed;
        top: auto;
        bottom: calc(var(--feedback-toolbar-clearance) + env(safe-area-inset-bottom, 0px));
    }
}

/* Keep the layout controls from competing with PRINT in narrow tablet workspaces. */
@media screen and (max-width: 820px) {
    body.index-page {
        --feedback-toolbar-clearance: 120px;
    }

    body.index-page .bottom-controls {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px 8px;
        padding: 8px 10px;
    }

    body.index-page .bottom-controls-cluster {
        display: contents;
    }

    body.index-page .bottom-controls .font-control,
    body.index-page .bottom-controls-cluster > .paper-size-control {
        justify-self: stretch;
        justify-content: center;
        min-height: 40px;
        padding: 4px 6px;
    }

    body.index-page .bottom-controls .font-control-label,
    body.index-page .paper-size-control label {
        font-size: 11px;
    }

    body.index-page .shared-cut-lines-control {
        grid-column: 1 / 3;
        grid-row: 2;
        justify-self: start;
        min-height: 44px;
        font-size: 12px;
    }

    body.index-page .action-buttons {
        grid-column: 3;
        grid-row: 2;
        justify-self: stretch;
    }

    body.index-page .print-btn {
        width: 100%;
    }

}

/* Blend editor proportions into the unchanged desktop layout. */
@media screen and (min-width: 1181px) and (max-width: 1279px) {
    body.index-page .left-panel {
        width: calc(20vw + 104px);
    }

    body.index-page .left-panel.collapsed {
        width: 0;
    }
}

@media screen and (max-width: 360px) {
    body.index-page .bottom-controls .font-control,
    body.index-page .bottom-controls-cluster > .paper-size-control {
        flex-direction: column;
        gap: 1px;
        min-height: 50px;
    }

    body.index-page #font-control-bar {
        display: grid;
        grid-template-columns: auto auto;
        gap: 0 4px;
    }

    body.index-page #font-control-bar .font-control-label {
        grid-column: 1 / -1;
        justify-self: center;
    }

    body.index-page .feedback-btn {
        top: calc(max(100dvh, 760px) - 170px);
    }

    body.index-page:has(.left-panel.collapsed) .feedback-btn {
        top: calc(100dvh - 170px);
    }
}

@media screen and (max-width: 900px) {
    body.index-page .card-add-image-box {
        width: 56px;
        min-width: 56px;
    }
}

@media screen and (max-width: 1279px) and (max-height: 500px) {
    body.index-page .feedback-btn {
        width: 44px;
        padding: 10px;
    }

    body.index-page .feedback-text {
        display: none;
    }
}

@media screen and (max-width: 700px) {
    body.index-page.dark-mode .left-panel {
        border-color: #444444;
    }
}
