@font-face {
    font-family: Medieval;
    src: url(../assets/fonts/Medieval.ttf);
}

* {
    box-sizing: border-box;
}

.top-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 15px 20px 0;
}

.top-bar h1 {
    margin: 0;
}

.top-bar-under {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 10px 20px 15px;
}

.top-bar-nav-links {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.top-drive-controls {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.top-drive-btn {
    border: none;
    cursor: pointer;
    padding: 10px 14px;
}

.top-drive-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.top-drive-status-wrap {
    display: flex;
    justify-content: center;
    margin: -6px 20px 12px;
}

#driveStatusText {
    color: #e2e8f0;
    background: rgba(0, 0, 0, 0.22);
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 12px;
}

/* Full-viewport load overlay when opening a card from Drive (indeterminate bar + dim) */
.cm-card-loading {
    position: fixed;
    inset: 0;
    z-index: 20000;
    pointer-events: none;
}

.cm-card-loading[hidden] {
    display: none !important;
}

.cm-card-loading-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.16);
    pointer-events: auto;
}

.cm-card-loading-top {
    position: relative;
    z-index: 1;
    padding: 12px 18px 14px;
    background: linear-gradient(180deg, rgba(8, 28, 26, 0.94) 0%, rgba(8, 28, 26, 0) 100%);
    pointer-events: none;
}

.cm-card-loading-track {
    height: 5px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.14);
    overflow: hidden;
    max-width: min(720px, calc(100vw - 36px));
    margin: 0 auto;
}

.cm-card-loading-bar {
    height: 100%;
    width: 38%;
    border-radius: 999px;
    background: linear-gradient(90deg, #3d9b86, #e6a23c, #9b7ad4);
    animation: cm-card-loading-slide 1.05s ease-in-out infinite;
}

@keyframes cm-card-loading-slide {
    0% {
        transform: translateX(-130%);
    }
    100% {
        transform: translateX(340%);
    }
}

.cm-card-loading-label {
    margin: 10px auto 0;
    max-width: min(720px, calc(100vw - 36px));
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 13px;
    font-weight: 600;
    color: #e2e8f0;
    text-align: center;
    text-shadow: 0 1px 10px rgba(0, 0, 0, 0.75);
}

h1{
    font-family: Medieval;
    text-align: center;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(240, 240, 255, 0.95) 100%);
    padding: 15px 20px;
    border-radius: 12px;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    font-size: 2.5em;
    letter-spacing: 2px;
}

body.cm-page h1 {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #f1f5f9;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

html {
    scroll-padding-top: max(56px, calc(env(safe-area-inset-top) + 48px));
}

body {
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    background:
        radial-gradient(ellipse 80% 50% at 50% -10%, rgba(155, 122, 212, 0.12), transparent 55%),
        radial-gradient(ellipse 60% 40% at 90% 20%, rgba(61, 155, 134, 0.1), transparent 50%),
        #050f14;
    background-attachment: fixed;
    min-height: 100vh;
    min-height: 100dvh;
    color: #dce8e1;
    font-family: 'Outfit', 'Segoe UI', system-ui, sans-serif;
}

/* Card Maker editor page — match Saved Projects dark workspace */
body.cm-page {
    background:
        radial-gradient(ellipse 80% 50% at 50% -10%, rgba(155, 122, 212, 0.12), transparent 55%),
        #050f14;
    background-attachment: scroll;
}

@media (max-width: 900px) {
    body {
        background-attachment: scroll;
    }
}

/* Saved Projects–style max width + two-column grid (preview | wide editor) */
.cm-wrap {
    max-width: min(1960px, calc(100vw - 24px));
    margin: 0 auto;
    padding: 0 max(12px, env(safe-area-inset-right)) 40px max(12px, env(safe-area-inset-left));
    box-sizing: border-box;
}

body.cm-page .top-bar {
    margin: 15px auto 0;
    padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
    max-width: min(1960px, calc(100vw - 24px));
    box-sizing: border-box;
}

body.cm-page .top-bar-under {
    margin: 10px auto 14px;
    padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
    max-width: min(1960px, calc(100vw - 24px));
    box-sizing: border-box;
}

body.cm-page .top-drive-status-wrap {
    margin: -6px auto 12px;
    padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
    max-width: min(1960px, calc(100vw - 24px));
    box-sizing: border-box;
}

.main-container {
    display: grid;
    grid-template-columns: minmax(240px, 1fr) minmax(380px, min(920px, 56vw));
    gap: 20px;
    padding: 10px 0 0;
    max-width: 100%;
    box-sizing: border-box;
    align-items: start;
}

/* Frosted panels (same language as saved-projects .spm-panel) */
.cm-panel {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
    color: #e2e8f0;
}

.card-preview {
    display: flex;
    justify-content: flex-end;
    align-items: flex-start;
    min-width: 0;
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
    position: sticky;
    top: calc(var(--cm-app-nav-offset, 64px) + 12px);
    height: fit-content;
    max-height: calc(100dvh - var(--cm-app-nav-offset, 64px) - 24px);
    overflow: hidden;
}

#cardCanvas {
    border: 1px solid rgba(148, 163, 184, 0.35);
    display: block;
    max-width: min(92%, 920px);
    max-height: calc(100vh - 140px);
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 12px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
    background: white;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

@media (hover: hover) and (pointer: fine) {
    #cardCanvas:hover {
        transform: scale(1.01);
        box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
    }
}

.controls-panel {
    min-width: 0;
    width: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: calc(100vh - 108px);
    padding: 22px 18px 24px 22px;
    scrollbar-width: thin;
    scrollbar-color: rgba(155, 122, 212, 0.5) rgba(8, 28, 26, 0.5);
}

.controls-panel::-webkit-scrollbar {
    width: 10px;
}

.controls-panel::-webkit-scrollbar-track {
    background: rgba(8, 28, 26, 0.45);
    border-radius: 5px;
}

.controls-panel::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(61, 155, 134, 0.75), rgba(155, 122, 212, 0.55));
    border-radius: 5px;
    border: 2px solid rgba(8, 28, 26, 0.35);
}

.controls-panel::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, rgba(155, 122, 212, 0.95), rgba(61, 155, 134, 0.85));
}

/* Dark form UI inside editor (saved-projects input/select vibe) */
.cm-page .controls-panel .control-section {
    background: rgba(8, 28, 26, 0.42);
    border: 1px solid rgba(148, 163, 184, 0.2);
    backdrop-filter: none;
}

.cm-page .controls-panel .control-section:hover {
    border-color: rgba(155, 122, 212, 0.35);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.cm-page .controls-panel .section-header {
    background: rgba(8, 28, 26, 0.55);
    border-bottom: 1px solid rgba(148, 163, 184, 0.22);
}

.cm-page .controls-panel .section-header:hover {
    background: rgba(8, 28, 26, 0.65);
}

.cm-page .controls-panel .section-header::after {
    color: #3d9b86;
}

.cm-page .controls-panel .control-section h2 {
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #3d9b86;
}

.cm-page .controls-panel .section-content {
    padding: 16px 16px 18px;
}

.cm-page .controls-panel .input-group label {
    color: #e2e8f0;
    font-size: 13px;
}

.cm-page .controls-panel .input-group input[type="text"],
.cm-page .controls-panel .input-group input[type="number"] {
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.06);
    color: #e2e8f0;
}

.cm-page .controls-panel .input-group input[type="text"]:focus,
.cm-page .controls-panel .input-group input[type="number"]:focus {
    border-color: rgba(155, 122, 212, 0.65);
    background: rgba(8, 28, 26, 0.65);
    box-shadow: 0 0 0 2px rgba(61, 155, 134, 0.25);
}

.cm-page .controls-panel .input-group textarea {
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.06);
    color: #e2e8f0;
}

.cm-page .controls-panel .input-group textarea:focus {
    border-color: rgba(155, 122, 212, 0.65);
    background: rgba(8, 28, 26, 0.65);
    box-shadow: 0 0 0 2px rgba(61, 155, 134, 0.25);
}

.cm-page .controls-panel .input-group select {
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(255, 255, 255, 0.06);
    color: #e2e8f0;
}

.cm-page .controls-panel .input-group select:focus {
    border-color: rgba(155, 122, 212, 0.65);
    background: rgba(8, 28, 26, 0.72);
}

.cm-page .controls-panel select option {
    background: #081c1a;
    color: #e2e8f0;
}

.cm-page .controls-panel .input-group input[type="file"] {
    border: 2px dashed rgba(148, 163, 184, 0.35);
    background: rgba(8, 28, 26, 0.35);
    color: #cbd5e1;
}

.cm-page .controls-panel .input-group input[type="file"]:hover {
    border-color: rgba(155, 122, 212, 0.55);
    background: rgba(8, 28, 26, 0.5);
}

.cm-page .controls-panel .input-group small,
.cm-page .controls-panel #exportBleedHint,
.cm-page .controls-panel #exportSizeHelp {
    color: #94a3b8 !important;
    font-style: normal !important;
}

.cm-page .controls-panel .cm-typography-hint {
    color: #94a3b8;
}

.cm-page .controls-panel .cm-quick-sub {
    color: #3d9b86;
    border-top-color: rgba(148, 163, 184, 0.2);
}

.cm-page .controls-panel .cm-value-pill {
    background: rgba(61, 155, 134, 0.22);
    color: #c7d2fe;
}

.cm-page .controls-panel .cm-check-row,
.cm-page .controls-panel .cm-label-stack {
    color: #e2e8f0;
}

.cm-page .controls-panel .cm-label-stack {
    color: #cbd5e1;
}

.cm-page .controls-panel .input-group span:not(.cm-value-pill) {
    color: #3d9b86;
    background: rgba(61, 155, 134, 0.15);
}

.cm-page .controls-panel .cm-hint-compact {
    color: #94a3b8 !important;
}

.cm-page .controls-panel .cm-essentials {
    border-color: rgba(155, 122, 212, 0.42);
    box-shadow: 0 4px 24px rgba(61, 155, 134, 0.14);
}

.cm-page .controls-panel .input-group input[type="range"] {
    background: rgba(148, 163, 184, 0.22);
}

.cm-page .controls-panel kbd {
    color: #9b7ad4;
    background: rgba(61, 155, 134, 0.18);
    border-color: rgba(165, 180, 252, 0.35);
}

/* Compact Card Maker sidebar — shorter fields, tighter gaps, more fits without scroll */
.cm-page .cm-editor-panel {
    padding: 10px 10px 12px;
    max-height: calc(100vh - 88px);
    background: rgba(8, 28, 26, 0.94);
    border-color: rgba(148, 163, 184, 0.26);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.cm-page .cm-editor-panel .control-section {
    margin-bottom: 10px;
}

.cm-page .cm-editor-panel .section-header {
    padding: 8px 12px;
}

.cm-page .cm-editor-panel .section-content {
    padding: 7px 9px 9px !important;
}

.cm-page .cm-editor-panel .input-group {
    margin-bottom: 7px;
    gap: 3px;
}

.cm-page .cm-editor-panel .input-group label {
    font-size: 11px;
    font-weight: 700;
}

.cm-page .cm-editor-panel .input-group input[type="text"],
.cm-page .cm-editor-panel .input-group input[type="number"],
.cm-page .cm-editor-panel .input-group select,
.cm-page .cm-editor-panel .input-group textarea {
    padding: 5px 8px;
    font-size: 13px;
    border-radius: 7px;
}

.cm-page .cm-editor-panel .input-group textarea {
    min-height: 2.4em;
    line-height: 1.3;
    resize: vertical;
}

.cm-page .cm-editor-panel .input-group input[type="range"] {
    height: 4px;
    margin: 2px 0 4px;
}

.cm-page .cm-editor-panel .input-group input[type="file"] {
    padding: 5px 8px;
    margin-bottom: 4px;
    font-size: 12px;
}

.cm-page .cm-editor-panel #CardRarity {
    padding: 5px 8px;
    font-size: 12px;
}

.cm-page .cm-editor-panel .cm-name-type-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(120px, 38%);
    gap: 6px 10px;
    align-items: start;
    margin-bottom: 6px;
}

.cm-page .cm-editor-panel .cm-name-type-row .cm-quick-name {
    margin-bottom: 0;
}

.cm-page .cm-editor-panel .cm-type-sub-col {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 4px 6px;
    align-items: start;
    min-width: 0;
}

.cm-page .cm-editor-panel .cm-type-sub-col .input-group {
    margin-bottom: 0;
}

.cm-page .cm-editor-panel .cm-field-options-manage-btn {
    grid-column: 1 / -1;
    justify-self: start;
    margin-top: 2px;
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid rgba(61, 155, 134, 0.35);
    background: rgba(255, 255, 255, 0.85);
    color: #5b6fd8;
    cursor: pointer;
}

.cm-page .cm-editor-panel .cm-field-options-manage-btn:hover {
    background: rgba(61, 155, 134, 0.08);
}

.cm-fonts-panel {
    max-width: 560px;
}

.cm-fonts-preview {
    margin: 10px 0 0;
    padding: 12px 14px;
    border-radius: 10px;
    background: rgba(8, 28, 26, 0.06);
    border: 1px solid rgba(148, 163, 184, 0.25);
    font-size: 22px;
    line-height: 1.35;
    color: #1e293b;
}

#cmFontsSelect {
    min-height: 160px;
}

.cm-field-options-panel {
    max-width: 720px;
}

.cm-field-options-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 16px;
    margin-top: 8px;
}

@media (max-width: 640px) {
    .cm-field-options-grid {
        grid-template-columns: 1fr;
    }
}

.cm-field-options-col-title {
    margin: 0 0 8px;
    font-size: 14px;
    font-weight: 700;
    color: #334155;
}

.cm-field-options-list {
    width: 100%;
    min-height: 160px;
    height: auto;
    margin-bottom: 8px;
}

.cm-field-options-row {
    margin-bottom: 8px;
}

.cm-field-options-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.cm-field-options-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
}

.cm-page .cm-editor-panel .cm-images-file-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 5px 7px;
    align-items: start;
    margin-bottom: 6px;
}

.cm-page .cm-editor-panel .cm-images-file-row .input-group {
    margin-bottom: 0;
}

.cm-cardbase-custom-wrap {
    margin-top: 6px;
}

.cm-cardbase-custom-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: #cbd5e1;
    margin-bottom: 4px;
}

.cm-page .cm-editor-panel .cm-cardbase-custom-label {
    font-size: 10px;
    margin-bottom: 3px;
}

.cm-page .cm-editor-panel .cm-quick-name {
    margin-bottom: 3px;
}

.cm-page .cm-editor-panel .cm-quick-toolbar {
    margin-bottom: 7px;
    padding: 5px 8px;
    gap: 5px 8px;
    border-radius: 9px;
}

.cm-page .cm-editor-panel .cm-quick-toolbar-label {
    font-size: 10px;
}

.cm-page .cm-editor-panel .cm-quick-presets button {
    padding: 4px 6px !important;
    font-size: 11px !important;
    min-height: 0 !important;
}

.cm-page .cm-editor-panel .cm-stat-strip {
    margin: 0 0 6px;
    border-radius: 8px;
}

.cm-page .cm-editor-panel .cm-stat-cell {
    padding: 5px 5px 6px;
}

.cm-page .cm-editor-panel .cm-stat-cell label {
    margin-bottom: 2px !important;
    font-size: 8px !important;
    letter-spacing: 0.06em !important;
}

.cm-page .cm-editor-panel .cm-stat-cell input[type="number"] {
    font-size: 14px !important;
    padding: 5px 4px !important;
}

.cm-page .cm-editor-panel .cm-show-stats-row {
    font-size: 11px;
}

.cm-page .cm-editor-panel .cm-check-inline {
    font-size: 12px;
}

.cm-page .cm-editor-panel .cm-quick-sub {
    margin: 8px 0 4px;
    padding-top: 8px;
    font-size: 10px;
    letter-spacing: 0.06em;
}

.cm-page .cm-editor-panel .cm-field-grid {
    gap: 5px 7px;
    margin-bottom: 6px;
}

.cm-page .cm-editor-panel .cm-typography-hint {
    font-size: 10px;
    margin: 0 0 6px;
    line-height: 1.35;
}

.cm-page .cm-editor-panel .cm-checkbox-tight {
    margin-bottom: 0;
    justify-content: center;
}

.cm-page .cm-editor-panel .cm-check-row {
    font-size: 12px;
    gap: 6px;
}

.cm-page .cm-editor-panel .cm-hint-compact,
.cm-page .cm-editor-panel .cm-quick-hint {
    font-size: 9px !important;
    margin-top: 1px !important;
    line-height: 1.3 !important;
}

.cm-page .cm-editor-panel .cm-export-actions {
    gap: 6px !important;
    margin-top: 6px !important;
}

.cm-page .cm-editor-panel .cm-export-actions button {
    padding: 8px 12px !important;
    margin: 0 !important;
    font-size: 11px !important;
    min-height: 36px;
}

.cm-page .cm-editor-panel .cm-export-shortcuts {
    margin-top: 6px !important;
    padding-top: 8px !important;
    font-size: 10px !important;
    line-height: 1.45;
}

/* —— Card Maker “essentials” grid (faster card authoring) —— */
.cm-essentials {
    border-color: rgba(61, 155, 134, 0.4);
    box-shadow: 0 4px 20px rgba(61, 155, 134, 0.1);
}

.cm-essentials .section-content {
    padding: 14px 16px 16px;
}

/* Quick card: minimal primary fields + single stat row */
.cm-name-type-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(130px, 40%);
    gap: 10px 14px;
    align-items: start;
    margin-bottom: 10px;
}

.cm-name-type-row .cm-quick-name {
    margin-bottom: 0;
}

.cm-type-sub-col {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 6px 10px;
    align-items: start;
    min-width: 0;
}

.cm-field-options-manage-btn {
    grid-column: 1 / -1;
    justify-self: start;
}

.cm-type-sub-col .input-group {
    margin-bottom: 0;
}

.cm-images-file-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px 14px;
    align-items: start;
    margin-bottom: 12px;
}

.cm-images-file-row .input-group {
    margin-bottom: 0;
}

@media (max-width: 520px) {
    .cm-name-type-row,
    .cm-images-file-row {
        grid-template-columns: 1fr;
    }
}

.cm-quick-name {
    margin-bottom: 10px;
}

.cm-quick-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
    margin-bottom: 16px;
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(8, 28, 26, 0.55);
    border: 1px solid rgba(148, 163, 184, 0.16);
}

.cm-quick-toolbar-label {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: #94a3b8;
    margin-right: auto;
    flex: 1 1 100%;
}

@media (min-width: 420px) {
    .cm-quick-toolbar-label {
        flex: 0 0 auto;
        margin-right: 0;
    }
}

.cm-quick-presets {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0 !important;
}

.cm-quick-presets button {
    flex: 1;
    min-width: 0;
    padding: 8px 10px !important;
    font-size: 12px !important;
    text-transform: none !important;
    letter-spacing: 0 !important;
}

.cm-check-inline {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #e2e8f0;
    cursor: pointer;
    white-space: nowrap;
    margin: 0;
}

.cm-check-inline input[type="checkbox"] {
    margin: 0;
}

.cm-stat-strip {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0;
    margin: 4px 0 12px;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid rgba(148, 163, 184, 0.22);
    background: rgba(8, 28, 26, 0.45);
}

.cm-stat-cell {
    padding: 12px 10px;
    text-align: center;
    border-right: 1px solid rgba(148, 163, 184, 0.14);
}

.cm-stat-cell:last-child {
    border-right: none;
}

.cm-stat-cell label {
    display: block;
    font-size: 10px !important;
    font-weight: 800 !important;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #3d9b86 !important;
    margin-bottom: 6px;
    justify-content: center !important;
}

.cm-stat-cell input[type="number"] {
    width: 100%;
    max-width: 5.5rem;
    margin: 0 auto;
    display: block;
    text-align: center;
    font-size: 18px !important;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    padding: 10px 8px !important;
}

.cm-show-stats-row {
    margin: 0;
    font-size: 13px;
}

.cm-typography-hint {
    font-size: 12px;
    color: #94a3b8;
    line-height: 1.4;
    margin: 0 0 14px;
}

.cm-quick-sub {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #3d9b86;
    margin: 18px 0 10px;
    padding-top: 16px;
    border-top: 1px dashed rgba(148, 163, 184, 0.22);
}

.cm-quick-hint {
    display: block;
    margin-top: 2px !important;
}

.cm-field-grid {
    display: grid;
    gap: 10px 12px;
    margin-bottom: 12px;
}

.cm-field-grid .input-group {
    margin-bottom: 0;
}

.cm-field-grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.cm-field-grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media (max-width: 900px) {
    .cm-field-grid-2,
    .cm-field-grid-3 {
        grid-template-columns: 1fr;
    }
}

@media (min-width: 901px) and (max-width: 1180px) {
    .cm-field-grid-3 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* Main + sub description side by side in Quick card */
.cm-desc-pair {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: 12px;
    row-gap: 0;
    align-items: start;
    margin: 8px 0 4px;
    padding-top: 8px;
    border-top: 1px dashed rgba(148, 163, 184, 0.22);
}

.cm-desc-pair-col {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.cm-desc-pair .cm-quick-sub {
    margin: 0 0 4px;
    padding-top: 0;
    border-top: none;
}

.cm-desc-pair .cm-field-grid:last-child {
    margin-bottom: 0;
}

.cm-page .cm-editor-panel .cm-desc-pair {
    margin: 6px 0 4px;
    padding-top: 8px;
    column-gap: 10px;
}

@media (max-width: 720px) {
    .cm-desc-pair {
        grid-template-columns: 1fr;
        row-gap: 10px;
    }
}

.cm-value-pill {
    display: inline-block;
    min-width: 2.25ch;
    text-align: center;
    font-weight: 700;
    font-size: 12px;
    color: #5b21b6;
    background: rgba(61, 155, 134, 0.14);
    padding: 2px 8px;
    border-radius: 6px;
    vertical-align: middle;
}

.cm-checkbox-tight {
    margin-bottom: 8px;
}

.cm-label-stack {
    display: block;
    font-weight: 600;
    font-size: 13px;
    color: #2d3748;
    margin-bottom: 4px;
}

.cm-check-row {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    color: #2d3748;
    margin: 0;
}

.cm-check-row input[type="checkbox"] {
    flex-shrink: 0;
}

.cm-setnum-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.cm-setnum-row input[type="number"] {
    width: 4.25rem;
}

.cm-setnum-slash {
    font-weight: 800;
    color: #94a3b8;
    font-size: 15px;
    user-select: none;
}

.cm-hint-compact {
    font-size: 10px !important;
    line-height: 1.35 !important;
    margin-top: 4px !important;
    color: #718096 !important;
    font-style: normal !important;
}

.cm-hint-inline {
    font-weight: 500;
    color: #94a3b8;
    font-size: 11px;
    text-transform: none;
    letter-spacing: 0;
}

.cm-essentials .quick-buttons button {
    min-height: 34px;
    font-size: 13px;
    font-weight: 700;
}

.controls {
    text-align: center;
    margin-bottom: 25px;
    padding: 20px;
    border-bottom: 2px solid rgba(200, 200, 220, 0.3);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.9) 0%, rgba(245, 245, 255, 0.9) 100%);
    border-radius: 12px;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.controls input[type="file"],
.input-group input[type="file"] {
    margin-bottom: 10px;
    width: 100%;
    padding: 10px;
    border: 2px dashed rgba(61, 155, 134, 0.3);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 13px;
}

.controls input[type="file"]:hover,
.input-group input[type="file"]:hover {
    border-color: #3d9b86;
    background: rgba(255, 255, 255, 0.9);
}

.controls select,
.input-group select {
    padding: 10px 12px;
    border: 2px solid rgba(200, 200, 220, 0.5);
    border-radius: 8px;
    font-size: 14px;
    background: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
    width: 100%;
}

.controls select:focus,
.input-group select:focus {
    outline: none;
    border-color: #3d9b86;
    box-shadow: 0 0 0 3px rgba(61, 155, 134, 0.1);
    background: white;
}

.controls button {
    margin: 6px;
    padding: 12px 24px;
    cursor: pointer;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    background: linear-gradient(135deg, #3d9b86 0%, #9b7ad4 100%);
    color: white;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.controls button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(61, 155, 134, 0.4);
}

.controls button:active {
    transform: translateY(0);
}

.controls button[style*="background-color: #ff6b6b"] {
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 100%) !important;
}

.controls button[style*="background-color: #ff6b6b"]:hover {
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.4);
}

.control-section {
    margin-bottom: 20px;
    padding: 0;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 12px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(200, 200, 220, 0.2);
    overflow: hidden;
    transition: all 0.3s ease;
}

.control-section:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    border-color: rgba(61, 155, 134, 0.3);
}

.control-section.collapsed .section-content {
    display: none;
}

.control-section.collapsed .section-header::after {
    transform: rotate(0deg);
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 18px;
    cursor: pointer;
    background: linear-gradient(135deg, rgba(61, 155, 134, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    border-bottom: 1px solid rgba(200, 200, 220, 0.3);
    transition: all 0.3s ease;
    user-select: none;
}

.section-header:hover {
    background: linear-gradient(135deg, rgba(61, 155, 134, 0.15) 0%, rgba(118, 75, 162, 0.15) 100%);
}

.section-header::after {
    content: '▼';
    font-size: 12px;
    color: #3d9b86;
    transition: transform 0.3s ease;
    transform: rotate(180deg);
}

/* Rarity tier colors (Card Maker sidebar) — Uncommon white on dark field for contrast */
#CardRarity {
    border-width: 2px;
    border-style: solid;
    font-weight: 800;
    padding: 10px 12px;
    border-radius: 10px;
    background: #fff;
    cursor: pointer;
}
#CardRarity[data-rarity-tier="Common"] {
    color: #78716c;
    border-color: rgba(120, 113, 108, 0.5);
}
#CardRarity[data-rarity-tier="Uncommon"] {
    color: #ffffff;
    background: #0a2422;
    border-color: rgba(255, 255, 255, 0.35);
}
#CardRarity[data-rarity-tier="Rare"] {
    color: #3b82f6;
    border-color: rgba(59, 130, 246, 0.55);
}
#CardRarity[data-rarity-tier="Epic"] {
    color: #9b7ad4;
    border-color: rgba(139, 92, 246, 0.55);
}
#CardRarity[data-rarity-tier="Legendary"] {
    color: #d1bc43;
    border-color: rgba(209, 188, 67, 0.65);
}
#CardRarity[data-rarity-tier="Mythic"] {
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.55);
}
#CardRarity[data-rarity-tier="Fantastical"] {
    color: #10b981;
    border-color: rgba(16, 185, 129, 0.55);
}

.control-section h2 {
    margin: 0;
    font-size: 18px;
    font-family: Medieval;
    text-align: left;
    color: #2d3748;
    font-weight: 600;
}

.section-content {
    padding: 18px;
}

.input-group {
    margin-bottom: 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-group:last-child {
    margin-bottom: 0;
}

.input-group label {
    font-weight: 600;
    font-size: 14px;
    color: #2d3748;
    display: flex;
    align-items: center;
    gap: 8px;
}

.input-group input[type="text"],
.input-group input[type="number"] {
    padding: 10px 12px;
    border: 2px solid rgba(200, 200, 220, 0.5);
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.3s ease;
    background: rgba(255, 255, 255, 0.8);
    font-family: inherit;
}

.input-group input[type="text"]:focus,
.input-group input[type="number"]:focus {
    outline: none;
    border-color: #3d9b86;
    box-shadow: 0 0 0 3px rgba(61, 155, 134, 0.1);
    background: white;
}

.input-group textarea {
    padding: 10px 12px;
    border: 2px solid rgba(200, 200, 220, 0.5);
    border-radius: 8px;
    font-size: 14px;
    resize: vertical;
    font-family: inherit;
    width: 100%;
    box-sizing: border-box;
    transition: all 0.3s ease;
    background: rgba(255, 255, 255, 0.8);
}

.input-group textarea:focus {
    outline: none;
    border-color: #3d9b86;
    box-shadow: 0 0 0 3px rgba(61, 155, 134, 0.1);
    background: white;
}

.input-group input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: rgba(200, 200, 220, 0.3);
    outline: none;
    -webkit-appearance: none;
}

.input-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3d9b86 0%, #9b7ad4 100%);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(61, 155, 134, 0.4);
    transition: all 0.2s ease;
}

.input-group input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 3px 8px rgba(61, 155, 134, 0.6);
}

.input-group input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3d9b86 0%, #9b7ad4 100%);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 6px rgba(61, 155, 134, 0.4);
}

.input-group input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: #3d9b86;
}

.input-group span {
    display: inline-block;
    min-width: 50px;
    text-align: center;
    font-weight: 600;
    color: #3d9b86;
    background: rgba(61, 155, 134, 0.1);
    padding: 4px 8px;
    border-radius: 6px;
}

.input-group small {
    font-size: 11px;
    color: #718096;
    font-style: italic;
    margin-top: -2px;
    line-height: 1.4;
}

.quick-buttons {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.quick-buttons button {
    flex: 1;
    /* appearance → cardmaker-buttons.css */
}

canvas{
    background-color: white;
}

/* Google Drive saves modal — button appearance in cardmaker-buttons.css */

.drive-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9400;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.drive-modal.is-open {
    display: flex;
}

.drive-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(8, 28, 26, 0.72);
    backdrop-filter: blur(6px);
}

.drive-modal-panel {
    position: relative;
    width: 100%;
    max-width: min(96vw, 880px);
    max-height: min(90vh, 720px);
    display: flex;
    flex-direction: column;
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.98) 0%, rgba(248, 250, 252, 0.97) 100%);
    border-radius: 16px;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.6) inset;
    padding: 22px 22px 16px;
    z-index: 1;
    overflow: hidden;
}

.drive-modal-close {
    position: absolute;
    top: 10px;
    right: 12px;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: rgba(226, 232, 240, 0.8);
    color: #475569;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.drive-modal-close:hover {
    background: #e2e8f0;
    color: #1e293b;
}

.drive-modal-title {
    font-family: 'Cinzel', Medieval, Georgia, serif;
    margin: 0 32px 8px 0;
    font-size: 1.45rem;
    color: #0b3d38;
    letter-spacing: 0.04em;
}

.drive-modal-hint {
    margin: 0 0 18px;
    font-size: 13px;
    line-height: 1.45;
    color: #64748b;
}

.drive-modal-hint strong {
    color: #475569;
}

.drive-modal-section {
    margin-bottom: 16px;
}

.drive-modal-section-grow {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    margin-bottom: 8px;
}

.drive-modal-label {
    display: block;
    font-family: 'Cinzel', Georgia, serif;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #0b3d38;
    margin-bottom: 8px;
}

.drive-save-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: stretch;
}

.drive-modal-input {
    flex: 1;
    min-width: 160px;
    padding: 10px 12px;
    border: 2px solid rgba(61, 155, 134, 0.28);
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.drive-modal-input:focus {
    outline: none;
    border-color: #3d9b86;
    box-shadow: 0 0 0 3px rgba(61, 155, 134, 0.15);
}

.drive-modal-suffix {
    display: block;
    margin-top: 8px;
    font-size: 11px;
    color: #94a3b8;
}

.drive-code {
    font-family: ui-monospace, 'Cascadia Code', monospace;
    font-size: 10px;
    padding: 2px 6px;
    background: #f1f5f9;
    border-radius: 4px;
    color: #475569;
}

.drive-list-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.drive-modal-search-label {
    display: block;
    margin: 0 0 6px;
    font-size: 12px;
}

.drive-modal-search-input {
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 10px;
}

.drive-modal-saves-split {
    flex: 1;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 14px;
    min-height: 0;
}

.drive-modal-preview-aside {
    flex-shrink: 0;
    width: min(220px, 32vw);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.drive-modal-preview-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #3d9b86;
    margin-bottom: 8px;
}

.drive-modal-preview-body {
    flex: 1;
    min-height: 160px;
    max-height: min(42vh, 360px);
    overflow: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px;
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 12px;
    background: rgba(241, 245, 249, 0.65);
    scrollbar-width: thin;
}

.drive-modal-preview-placeholder {
    margin: 0;
    font-size: 12px;
    line-height: 1.45;
    color: #64748b;
    text-align: center;
}

.drive-modal-preview-loading {
    font-size: 13px;
    font-weight: 600;
    color: #475569;
}

.drive-modal-preview-error {
    margin: 0;
    font-size: 12px;
    line-height: 1.4;
    color: #b91c1c;
    font-weight: 600;
    text-align: center;
}

.drive-modal-preview-img {
    max-width: 100%;
    width: auto;
    height: auto;
    display: block;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(8, 28, 26, 0.18);
    background: #fff;
}

.drive-modal-item-preview-hit {
    cursor: pointer;
    border-radius: 8px;
    padding: 2px 4px 2px 2px;
    margin: -2px 0 -2px -2px;
    outline: none;
    transition: background 0.12s ease;
}

.drive-modal-item-preview-hit:hover {
    background: rgba(61, 155, 134, 0.08);
}

.drive-modal-item-preview-hit:focus-visible {
    box-shadow: 0 0 0 2px #3d9b86;
}

.drive-modal-item.is-preview-selected {
    background: rgba(61, 155, 134, 0.12);
}

.drive-modal-item.is-preview-selected .drive-modal-item-preview-hit {
    background: rgba(61, 155, 134, 0.06);
}

.drive-modal-list {
    flex: 1;
    min-width: 0;
    min-height: 140px;
    max-height: min(42vh, 360px);
    overflow-y: auto;
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.7);
    scrollbar-width: thin;
    scrollbar-color: rgba(61, 155, 134, 0.45) rgba(241, 245, 249, 0.8);
}

.drive-modal-list::-webkit-scrollbar {
    width: 8px;
}

.drive-modal-list::-webkit-scrollbar-thumb {
    background: rgba(61, 155, 134, 0.4);
    border-radius: 6px;
}

.drive-modal-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(226, 232, 240, 0.9);
    transition: background 0.12s ease;
}

.drive-modal-item:last-child {
    border-bottom: none;
}

.drive-modal-item:hover {
    background: rgba(61, 155, 134, 0.06);
}

.drive-modal-item-info {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.drive-modal-item-name {
    font-weight: 600;
    font-size: 14px;
    color: #0f172a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.drive-modal-item-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.35rem 0.65rem;
}

.drive-modal-item-date {
    font-size: 12px;
    color: #64748b;
}

.drive-modal-item-size {
    font-size: 12px;
    color: #64748b;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.drive-modal-item-size::before {
    content: '·';
    margin-right: 0.5rem;
    color: #cbd5e1;
    font-weight: 600;
}

.drive-modal-item-actions {
    display: flex;
    flex-shrink: 0;
    gap: 8px;
}

/* .drive-modal-btn* appearance → cardmaker-buttons.css */

.drive-modal-empty,
.drive-modal-loading {
    padding: 28px 16px;
    text-align: center;
    font-size: 14px;
    color: #64748b;
    line-height: 1.5;
}

.drive-modal-empty.is-error {
    color: #b91c1c;
}

.drive-modal-message {
    margin: 10px 0 0;
    min-height: 1.25em;
    font-size: 13px;
    color: #475569;
}

.drive-modal-message.is-error {
    color: #b91c1c;
    font-weight: 600;
}

/* Indeterminate save progress (Drive modal + Saved Projects edit) */
.cm-save-progress {
    margin-top: 10px;
    height: 6px;
    border-radius: 999px;
    background: rgba(8, 28, 26, 0.1);
    overflow: hidden;
}

.cm-save-progress[hidden] {
    display: none !important;
}

.cm-save-progress-fill {
    height: 100%;
    width: 42%;
    max-width: 200px;
    border-radius: inherit;
    background: linear-gradient(90deg, #3d9b86, #e6a23c, #9b7ad4);
    animation: cm-save-progress-slide 1.2s ease-in-out infinite;
}

@keyframes cm-save-progress-slide {
    0% {
        transform: translateX(-100%);
    }

    100% {
        transform: translateX(380%);
    }
}

@media (prefers-reduced-motion: reduce) {
    .cm-save-progress-fill {
        animation: none;
        width: 100%;
        opacity: 0.55;
    }
}

.spm-modal-panel .cm-save-progress {
    background: rgba(255, 255, 255, 0.1);
}

.spm-modal-panel .cm-save-progress-fill {
    background: linear-gradient(90deg, #3d9b86, #e6a23c, #9b7ad4);
}

@media (max-width: 640px) {
    .drive-modal-saves-split {
        flex-direction: column;
    }

    .drive-modal-preview-aside {
        width: 100%;
        max-height: 280px;
    }

    .drive-modal-preview-body {
        max-height: 240px;
    }
}

@media (max-width: 520px) {
    .drive-modal {
        padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
            max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
        align-items: flex-end;
    }

    .drive-modal-panel {
        max-height: min(100dvh - 16px, 100vh);
        border-radius: 16px 16px 0 0;
        padding: 18px 16px 14px;
    }

    .drive-save-row {
        flex-direction: column;
    }

    .drive-modal-btn-primary {
        width: 100%;
    }

    .drive-modal-item {
        flex-direction: column;
        align-items: stretch;
    }

    .drive-modal-item-actions {
        justify-content: flex-end;
    }
}

/* Fullscreen Modal Styles */
.fullscreen-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    overflow: auto;
}

.fullscreen-content {
    position: relative;
    margin: auto;
    padding: 20px;
    width: 90%;
    max-width: 90%;
    height: 90%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#fullscreenCanvas {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    border: 2px solid white;
    box-shadow: 0 4px 20px rgba(255, 255, 255, 0.3);
}

.close-fullscreen {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1001;
}

.close-fullscreen:hover,
.close-fullscreen:focus {
    color: #fff;
    text-decoration: none;
}

/* Keyboard shortcut styling */
kbd {
    display: inline-block;
    padding: 3px 6px;
    font-size: 11px;
    line-height: 1.4;
    color: #3d9b86;
    background: rgba(61, 155, 134, 0.1);
    border: 1px solid rgba(61, 155, 134, 0.3);
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    margin: 0 2px;
}

/* Responsive improvements */
@media (max-width: 1200px) {
    .main-container {
        grid-template-columns: 1fr;
        gap: 18px;
    }

    .controls-panel {
        max-width: 100%;
        max-height: none;
    }

    /* Editor before preview on phones/tablets — fields are the primary task */
    .main-container .controls-panel {
        order: 1;
    }

    .main-container .card-preview {
        order: 2;
    }

    .card-preview {
        position: relative;
        top: 0;
        justify-content: center;
        padding: 0;
        max-height: min(52dvh, 440px);
    }

    #cardCanvas {
        max-width: 100%;
        max-height: min(48dvh, 400px);
    }
}

@media (max-width: 900px) {
    .cm-wrap {
        max-width: 100%;
        padding: 0 max(12px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    }

    .top-bar {
        margin: 12px max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
        max-width: 100%;
    }

    .top-bar-under {
        margin: 8px max(12px, env(safe-area-inset-right)) 12px max(12px, env(safe-area-inset-left));
        flex-direction: column;
        max-width: 100%;
    }

    .top-bar-nav-links,
    .top-drive-controls {
        justify-content: stretch;
        width: 100%;
        flex-wrap: wrap;
        gap: 8px;
    }

    .top-drive-status-wrap {
        margin: -4px max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left));
        max-width: 100%;
    }

    h1 {
        font-size: clamp(1.35rem, 5vw, 2rem);
        padding: 12px 16px;
        letter-spacing: 1px;
    }

    .main-container {
        padding: 8px 0 0;
        gap: 14px;
        width: 100%;
    }

    .controls-panel {
        max-height: none;
        padding: 14px;
        padding-bottom: max(20px, env(safe-area-inset-bottom));
        -webkit-overflow-scrolling: touch;
    }

    .cm-page .cm-editor-panel {
        padding: 10px 12px max(14px, env(safe-area-inset-bottom));
        max-height: none;
        overflow: visible;
    }

    .cm-page .cm-editor-panel .cm-quick-presets button {
        min-height: 36px !important;
        padding: 8px 10px !important;
        font-size: 12px !important;
    }

    .cm-page .cm-editor-panel .section-header {
        padding: 12px 14px;
        min-height: 44px;
        box-sizing: border-box;
    }

    .cm-name-type-row,
    .cm-page .cm-editor-panel .cm-name-type-row,
    .cm-images-file-row,
    .cm-page .cm-editor-panel .cm-images-file-row,
    .cm-type-sub-col,
    .cm-page .cm-editor-panel .cm-type-sub-col {
        grid-template-columns: 1fr;
    }

    .cm-page .cm-editor-panel .cm-stat-strip,
    .cm-stat-strip {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .cm-page .cm-editor-panel .cm-export-actions,
    .cm-export-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .cm-page .cm-editor-panel .cm-export-actions button,
    .cm-export-actions button {
        width: 100%;
        justify-content: center;
    }

    .drive-modal-input,
    .drive-modal-search-input {
        font-size: 16px;
        min-height: 44px;
    }

    .drive-modal-close,
    .spm-modal-close {
        width: 44px;
        height: 44px;
        top: max(8px, env(safe-area-inset-top));
        right: max(8px, env(safe-area-inset-right));
    }

    .card-preview {
        position: relative;
        top: auto;
        max-height: none;
        justify-content: center;
        width: 100%;
    }

    #cardCanvas {
        max-width: min(100%, 420px);
        max-height: min(48dvh, 380px);
        margin-inline: auto;
    }

    .top-bar-btn,
    .top-drive-btn {
        min-height: 44px;
        padding: 12px 16px;
        font-size: 0.9rem;
        flex: 1 1 calc(50% - 6px);
        justify-content: center;
    }

    .controls-panel button,
    .controls-panel .quick-buttons button {
        min-height: 42px;
        padding: 10px 14px;
    }

    .controls-panel input[type="text"],
    .controls-panel input[type="number"],
    .controls-panel select,
    .controls-panel textarea {
        max-width: 100%;
        width: 100%;
        box-sizing: border-box;
    }

    .controls-panel input[type="file"] {
        max-width: 100%;
    }

    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
    select,
    textarea {
        font-size: 16px;
    }
}

@media (max-width: 520px) {
    .top-bar-btn,
    .top-drive-btn {
        flex: 1 1 100%;
        justify-content: center;
        text-align: center;
    }

    .cm-page .cm-editor-panel .cm-stat-strip,
    .cm-stat-strip {
        grid-template-columns: 1fr;
    }

    #cardCanvas {
        max-height: min(42dvh, 320px);
    }
}

/* Smooth transitions for all interactive elements */
button, input, textarea, select {
    transition: all 0.2s ease;
}

/* Focus visible for accessibility */
*:focus-visible {
    outline: 2px solid #3d9b86;
    outline-offset: 2px;
}