:root {
    --bg-dark: #050814;
    --glass-bg: rgba(20, 25, 45, 0.7);
    --glass-border: rgba(245, 240, 230, 0.1);
    --gold: #d92b34;
    --gold-glow: 0 0 20px rgba(217, 43, 52, 0.3);
    --text-light: #f5f0e6;
    --text-muted: #a1abc2;
    --font-heading: 'Google Sans', sans-serif;
    --font-body: 'Google Sans Text', 'Google Sans', sans-serif;

    --card-w: 140px;
    --front-aspect: 0.58;
    --back-aspect: 0.6;
    --card-h: calc(var(--card-w) / var(--front-aspect));
}

[data-theme="light"] {
    --bg-dark: #f5f0e6;
    --glass-bg: rgba(255, 255, 255, 0.65);
    --glass-border: rgba(74, 92, 142, 0.2);
    --gold: #a91d22;
    --gold-glow: 0 0 15px rgba(169, 29, 34, 0.3);
    --text-light: #4a5c8e;
    --text-muted: #7886b0;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--font-body);
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-dark);
    color: var(--text-light);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
    transition: background-color 0.5s ease, color 0.5s ease;
}

/* Background effects */
.background-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, #131726 0%, #050814 100%);
    z-index: -2;
    transition: background 0.5s ease;
}

[data-theme="light"] .background-overlay {
    background: radial-gradient(circle at center, #fbf8f2 0%, #f5f0e6 100%);
}

/* Utilities */
.text-center {
    text-align: center;
}

.mt-4 {
    margin-top: 2rem;
}

.mb-4 {
    margin-bottom: 2rem;
}

.hidden {
    display: none !important;
}

/* Top Controls */
.top-controls {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    padding: 1.2rem 2rem;
    display: flex;
    justify-content: space-between;
    z-index: 100;
    pointer-events: none;
    align-items: center;
}

.icon-btn {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-light);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    pointer-events: auto;
    font-family: var(--font-body);
    font-weight: 600;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    white-space: nowrap;
}

.icon-btn:hover {
    border-color: var(--gold);
    box-shadow: var(--gold-glow);
}

/* Mobile: compact top bar to fit one line */
@media (max-width: 768px) {
    .top-controls {
        padding: 0.4rem 0.6rem;
    }

    .top-controls>div {
        gap: 0.3rem !important;
    }

    .icon-btn {
        padding: 0.3rem 0.55rem;
        font-size: 0.72rem;
        gap: 0.25rem;
    }

    .icon-btn svg {
        width: 14px;
        height: 14px;
    }
}

/* Layout */
.app-container {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 5.5rem 2rem 2rem 2rem;
}

@media (max-width: 768px) {
    .app-container {
        padding-top: 4rem;
    }
}

.screen {
    display: none;
    width: 100%;
    max-width: 1200px;
    animation: fadeIn 0.5s ease-out forwards;
}

.screen.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Glass Panel */
.glass-panel {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: 24px;
    padding: 3rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.3);
    position: relative;
}

/* Typography and Logo */
.app-logo {
    max-width: 280px;
    width: 100%;
    margin: 0 auto 0.5rem auto;
    display: none;
}

.app-logo.dark-logo {
    display: block;
}

[data-theme="light"] .app-logo.dark-logo {
    display: none;
}

[data-theme="light"] .app-logo.light-logo {
    display: block;
}

.title {
    font-family: var(--font-heading);
    font-size: 3rem;
    font-style: italic;
    color: var(--gold);
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.subtitle {
    font-size: 1.1rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

/* Forms */
.querent-form {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.input-field {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    color: var(--text-light);
    padding: 0.8rem 1.2rem;
    border-radius: 12px;
    font-family: var(--font-body);
    font-size: 1rem;
    width: 100%;
    max-width: 300px;
    outline: none;
    transition: border-color 0.3s;
}

.input-field:focus {
    outline: none;
    border-color: var(--gold);
    background: rgba(255, 255, 255, 0.1);
}

select.input-field {
    text-align: center;
    text-align-last: center;
}
select.input-field option {
    text-align: left;
}

.deck-selector-wrapper select.input-field {
    max-width: none;
}

.input-field::placeholder {
    color: var(--text-muted);
}

select.input-field option {
    background-color: #1a1a1b;
    color: var(--text-light);
}

[data-theme="light"] select.input-field option {
    background-color: #ffffff;
    color: var(--text-dark);
}

/* Toggle Switch */
.toggle-switch-wrapper {
    display: inline-flex;
    align-items: center;
    gap: 0.8rem;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.03);
    padding: 0.5rem 1.2rem;
    border-radius: 50px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    transition: all 0.3s ease;
}

.toggle-switch-wrapper:hover {
    background: rgba(255, 255, 255, 0.08);
}

.toggle-label {
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 500;
    transition: color 0.3s;
}

.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.2);
    transition: .4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: #fff;
    transition: .4s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked+.slider {
    background-color: var(--gold);
}

.toggle-switch input:checked+.slider:before {
    transform: translateX(20px);
}

.toggle-switch-wrapper:has(input:checked) {
    border-color: rgba(212, 175, 55, 0.3);
    background: rgba(212, 175, 55, 0.05);
}

.toggle-switch-wrapper:has(input:checked) .toggle-label {
    color: var(--gold);
}

/* Buttons */
.btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-family: var(--font-body);
    transition: all 0.3s ease;
}

.spread-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
}

.spread-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(212, 175, 55, 0.3);
    border-radius: 15px;
    padding: 1.5rem 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
    width: 100%;
}

[data-theme="light"] .spread-btn {
    background: rgba(255, 255, 255, 0.2);
}

.spread-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--gold);
    transform: translateY(-5px);
    box-shadow: var(--gold-glow);
}

.btn-title {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    color: var(--text-light);
    margin-bottom: 0.5rem;
    text-align: center;
}

.btn-desc {
    font-size: 0.9rem;
    color: var(--text-muted);
    text-align: center;
}

.primary-btn {
    background: var(--gold);
    color: #ffffff;
    font-weight: 600;
    font-size: 1.1rem;
    padding: 1rem 2.5rem;
    border-radius: 30px;
    box-shadow: var(--gold-glow);
}

.primary-btn:hover {
    transform: scale(1.05);
    filter: brightness(1.2);
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--gold);
    color: var(--gold);
    font-weight: 400;
    font-size: 1rem;
    padding: 0.6rem 1.5rem;
    border-radius: 30px;
}

.secondary-btn:hover {
    background: rgba(212, 175, 55, 0.1);
    box-shadow: var(--gold-glow);
}

.btn-back {
    position: absolute;
    top: 1.5rem;
    left: 1.5rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: color 0.3s ease;
    z-index: 20;
}

.btn-back:hover {
    color: var(--gold);
}

/* History Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.modal-content {
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    padding-top: 4rem;
}

.close-btn {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
}

.close-btn:hover {
    color: var(--gold);
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1rem;
}

.history-item {
    border: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    padding: 1.5rem;
    text-align: left;
}

[data-theme="light"] .history-item {
    background: rgba(255, 255, 255, 0.3);
}

.history-date {
    font-size: 0.8rem;
    color: var(--gold);
    margin-bottom: 0.5rem;
}

.history-cards-mini {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 1rem;
}

.history-cards-mini img {
    width: 30px;
    height: 50px;
    border-radius: 2px;
}

.mini-reversed {
    transform: rotate(180deg);
}

/* Card Viewer Modal */
#card-viewer-modal {
    z-index: 2000;
}

#viewer-modal-content {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    max-width: 90vw;
    margin: auto;
    overflow: visible;
}

#enlarged-card-wrapper {
    animation: zoomIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    justify-content: center;
    align-items: center;
}

#enlarged-card-img {
    max-width: 100%;
    max-height: 85vh;
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), var(--gold-glow);
    transition: transform 0.3s ease;
}

#enlarged-card-img.reversed-img {
    transform: rotate(180deg);
}

#card-viewer-modal .close-btn {
    top: -40px;
    right: 0;
    color: #fff;
    font-size: 2.5rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
    z-index: 10;
}

@keyframes zoomIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}


/* Deck Container (Drawing Screen) */
.draw-panel {
    min-height: 80vh;
    display: flex;
    flex-direction: column;
    padding-left: 1rem;
    padding-right: 1rem;
    position: relative;
}

.deck-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 14px;
    margin-top: 2rem;
    padding: 10px;
    max-width: 1200px;
    margin-inline: auto;
    flex-grow: 1;
}

.deck-container::-webkit-scrollbar {
    height: 8px;
}

.deck-container::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
}

.deck-container::-webkit-scrollbar-thumb {
    background: var(--gold);
    border-radius: 4px;
}

.deck-card {
    flex: 0 0 auto;
    width: calc((100% / 13) - 14px);
    max-width: 130px;
    min-width: 45px;
    aspect-ratio: var(--back-aspect);
    background-image: var(--deck-back, url('Cards/Tarot/Back of the card.webp'));
    background-size: cover;
    background-position: center;
    border-radius: 4px;
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    position: relative;
}

.deck-container.grid-12 .deck-card {
    width: calc((100% / 12) - 14px);
    max-width: 140px;
}

.deck-container.grid-11 .deck-card {
    width: calc((100% / 11) - 14px);
    max-width: 150px;
}

.deck-container.grid-10 .deck-card {
    width: calc((100% / 10) - 14px);
    max-width: 160px;
}

.deck-container.grid-5 .deck-card {
    width: calc((100% / 5) - 14px);
    max-width: 220px;
}

.deck-container.grid-3 .deck-card {
    width: calc((100% / 3) - 20px);
    max-width: 300px;
}

.deck-card:hover {
    transform: translateY(-10px) scale(1.15);
    box-shadow: var(--gold-glow);
    z-index: 10;
}

.deck-card.selected {
    transform: translateY(-15px) scale(1.1) !important;
    box-shadow: 0 0 15px var(--gold) !important;
    border: 2px solid var(--gold);
    opacity: 1;
    z-index: 20;
}

.deck-card.shuffling-pile {
    animation: shufflePileAnim 1.5s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes shufflePileAnim {
    0% {
        transform: translate(0, 0) rotate(0deg);
        z-index: 1;
    }

    15% {
        transform: translate(var(--pile-x), var(--pile-y)) rotate(var(--pile-rot));
        z-index: 100;
    }

    30% {
        transform: translate(calc(var(--pile-x) + 10px), calc(var(--pile-y) - 10px)) rotate(calc(var(--pile-rot) + 15deg));
        z-index: 100;
    }

    45% {
        transform: translate(calc(var(--pile-x) - 10px), calc(var(--pile-y) + 10px)) rotate(calc(var(--pile-rot) - 15deg));
        z-index: 100;
    }

    60% {
        transform: translate(calc(var(--pile-x) + 5px), calc(var(--pile-y) + 5px)) rotate(calc(var(--pile-rot) + 5deg));
        z-index: 100;
    }

    75% {
        transform: translate(var(--pile-x), var(--pile-y)) rotate(var(--pile-rot));
        z-index: 100;
    }

    100% {
        transform: translate(0, 0) rotate(0deg);
        z-index: 1;
    }
}

/* Tarot Card Element */
.tarot-card {
    width: var(--card-w);
    height: calc(var(--card-w) / var(--front-aspect));
    perspective: 1000px;
    cursor: pointer;
    position: relative;
}

.tarot-card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transition: transform 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform-style: preserve-3d;
}

.tarot-card.flipped .tarot-card-inner {
    transform: rotateY(180deg);
}

.tarot-card-front,
.tarot-card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    border-radius: 8px;
    box-shadow: none;
    border: 1px solid rgba(255, 255, 255, 0.2);
    overflow: hidden;
}

.tarot-card-back {
    background-image: var(--deck-back, url('Cards/Tarot/Back of the card.webp'));
    background-size: 100% 100%;
    background-position: center;
    background-repeat: no-repeat;
    transform: translateZ(1px);
    transition: visibility 0s linear 0.4s;
}

/* Hide back card completely when flipped so it never bleeds or overlaps */
.tarot-card.flipped .tarot-card-back {
    visibility: hidden;
    transition: visibility 0s linear 0.4s;
}

.tarot-card-front {
    transform: rotateY(180deg) translateZ(1px);
    background-size: 100% 100%;
    background-position: center;
    background-repeat: no-repeat;
}

.tarot-card.reversed .tarot-card-front {
    transform: rotateY(180deg) rotateZ(180deg) translateZ(1px);
}

.tarot-card.flipped {
    box-shadow: none;
    border-radius: 8px;
}

/* Fix html2canvas 3D transforms */
.reading-panel.exporting .tarot-card.flipped .tarot-card-back {
    display: none !important;
}

.reading-panel.exporting .tarot-card.flipped .tarot-card-inner {
    transform: none !important;
}

.reading-panel.exporting .tarot-card.flipped .tarot-card-front {
    transform: none !important;
}

.reading-panel.exporting .tarot-card.flipped.reversed .tarot-card-front {
    transform: rotateZ(180deg) !important;
}

.card-title-label {
    position: absolute;
    top: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%);
    width: 140px;
    text-align: center;
    word-break: break-word;
    font-size: 0.85rem;
    color: #fbf4ee;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    font-weight: 500;
    line-height: 1.2;
}

[data-theme="light"] .card-title-label {
    color: var(--gold);
}

.tarot-card.flipped .card-title-label {
    opacity: 1;
}

/* Celtic Overlay */
.card-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 10;
}

.tarot-card.flipped .card-overlay {
    opacity: 1;
}

.overlay-month,
.overlay-age {
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    font-size: 0.75rem;
    padding: 4px 0;
    text-align: center;
    width: 100%;
    font-weight: 600;
    font-family: var(--font-body);
}

.overlay-month {
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
}

.overlay-age {
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
    color: var(--gold);
}

[data-theme="light"] .overlay-month,
[data-theme="light"] .overlay-age {
    background: rgba(255, 255, 255, 0.85);
    color: #000;
}

/* Clarification Container */
.clarification-container {
    --card-w: 110px;
    padding-bottom: 4rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4.5rem;
    margin-top: 1rem;
    max-width: 100%;
}

.clarification-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1.5rem;
    row-gap: 4.5rem;
    width: 100%;
}

/* SPREADS LAYOUTS */
.reading-meta {
    font-size: 1.2rem;
    color: var(--gold);
    margin-bottom: 1rem;
    font-family: var(--font-heading);
    font-style: italic;
}

.spread-container {
    display: block;
    text-align: center;
    white-space: nowrap;
    margin-top: 1rem;
    min-height: 200px;
    padding-top: 1rem;
    padding-bottom: 4rem;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding-inline: 1rem;
}

.layout-1,
.layout-3,
.layout-5,
.layout-9-custom,
.layout-celtic {
    display: inline-flex;
    white-space: normal;
    text-align: left;
    vertical-align: middle;
    margin: 0 auto;
}

.layout-1 {
    justify-content: center;
    width: 100%;
}

.layout-1 .tarot-card {
    width: 160px;
    height: calc(160px / var(--front-aspect));
}

.layout-1 .card-title-label {
    width: 160px;
    font-size: 1rem;
}

.layout-3 {
    gap: 2rem;
    justify-content: center;
    flex-wrap: nowrap;
    width: max-content;
}

.layout-5 {
    display: inline-flex;
    justify-content: center;
    width: max-content;
}

/* Custom 9-Card Spread */
.layout-9-custom {
    flex-direction: column;
    align-items: center;
    gap: 3.5rem;
    width: max-content;
}

.layout-9-row {
    display: flex;
    justify-content: center;
    width: 100%;
}

.layout-9-custom .row-1 {
    gap: 3rem;
}

.layout-9-custom .group {
    display: flex;
    gap: 1rem;
}

.layout-9-custom .row-2 {
    gap: 3rem;
}

.layout-9-custom .group-center {
    display: flex;
    justify-content: center;
    width: calc(var(--card-w) * 2 + 1rem);
}

.layout-9-custom .row-3 {
    gap: 3rem;
}

.layout-9-custom .row-4 {
    justify-content: center;
}

/* Celtic Cross Layout */
.layout-celtic {
    flex-direction: row;
    gap: 4rem;
    justify-content: center;
    align-items: center;
    width: max-content;
}

.celtic-left {
    display: grid;
    grid-template-columns: repeat(3, var(--card-w));
    grid-template-rows: repeat(3, var(--card-h));
    gap: 4.5rem 1.5rem;
    position: relative;
}

.celtic-left .card-pos-6 {
    grid-column: 1;
    grid-row: 1;
}

.celtic-left .card-pos-3 {
    grid-column: 2;
    grid-row: 1;
}

.celtic-left .card-pos-2 {
    grid-column: 1;
    grid-row: 2;
}

.celtic-left .card-pos-1 {
    grid-column: 2;
    grid-row: 2;
    position: relative;
    z-index: 2;
}

.celtic-left .card-pos-4 {
    grid-column: 2;
    grid-row: 3;
}

.celtic-left .card-pos-5 {
    grid-column: 3;
    grid-row: 2;
}

.celtic-right {
    display: flex;
    flex-direction: column-reverse;
    gap: 3rem;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    :root {
        --card-w: 85px;
    }

    .app-container {
        padding: 4.5rem 1rem 2rem 1rem;
        align-items: flex-start;
    }

    .deck-selector-wrapper {
        flex-direction: column !important;
        gap: 0.5rem !important;
        width: 100% !important;
        max-width: 600px !important;
        margin: 0 auto !important;
        align-items: center !important;
    }

    .deck-selector-wrapper select {
        flex: none !important;
        width: 100% !important;
        max-width: 300px !important;
    }


    .glass-panel {
        padding: 1.5rem;
    }

    .draw-panel,
    .reading-panel {
        padding-top: 3.5rem;
    }

    .title {
        font-size: 2.2rem;
    }

    .subtitle {
        font-size: 0.95rem;
    }

    .btn-back {
        top: 1rem;
        left: 1rem;
        font-size: 0.85rem;
    }

    .clarification-container {
        --card-w: 70px;
    }

    .spread-options {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 1rem;
    }

    .spread-btn {
        flex: 1 1 auto;
        max-width: none;
        min-width: 0;
        min-height: 100px;
        padding: 1rem;
    }

    .btn-title {
        font-size: 1.2rem;
        word-break: break-word;
    }

    .layout-3 {
        gap: 1rem;
        flex-wrap: nowrap;
    }

    .layout-5 {
        justify-content: center;
        width: max-content;
    }

    .card-title-label {
        width: 90px;
        font-size: 0.7rem;
        top: calc(100% + 5px);
        line-height: 1.1;
    }

    .layout-celtic {
        gap: 2rem;
        flex-direction: row;
        justify-content: flex-start;
        --card-w: 65px;
        padding-right: 2rem;
    }

    .layout-celtic .tarot-card {
        width: var(--card-w);
        height: calc(var(--card-w) / var(--front-aspect));
    }

    .celtic-left {
        gap: 2.5rem 1rem;
        flex-shrink: 0;
    }

    .celtic-right {
        gap: 2.5rem;
        flex-shrink: 0;
    }

    .layout-9-custom {
        gap: 2.5rem;
    }

    .layout-9-custom .row-1,
    .layout-9-custom .row-2,
    .layout-9-custom .row-3 {
        gap: 2rem;
    }

    .layout-9-custom .group {
        gap: 0.5rem;
    }

    .layout-9-custom .group-center {
        width: calc(var(--card-w) * 2 + 0.5rem);
    }

    .top-controls {
        padding: 1rem;
    }

    .deck-container,
    .deck-container.grid-10,
    .deck-container.grid-9 {
        gap: 5px;
        padding: 5px;
        grid-template-columns: repeat(10, 1fr) !important;
        overflow-x: hidden;
    }

    .database-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 10px;
    }

    .history-meta-edit {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.8rem;
    }

    .history-meta-edit .input-field {
        max-width: 100%;
        width: 100%;
    }
}

.reading-panel.exporting {
    background: radial-gradient(circle at top, #1c2336 0%, #050814 100%) !important;
    padding: 4rem 2rem !important;
    border-radius: 0 !important;
    border: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    box-shadow: none !important;
    margin: 0 !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: max-content !important;
    height: max-content !important;
    min-height: 0 !important;
    z-index: 1000;
}

.reading-panel.exporting::before {
    content: '';
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    bottom: 10px;
    border: 2px solid rgba(217, 43, 52, 0.3);
    border-radius: 16px;
    pointer-events: none;
}

[data-theme="light"] .reading-panel.exporting {
    background: linear-gradient(135deg, #ffffff 0%, #f0e6d2 100%) !important;
}

[data-theme="light"] .reading-panel.exporting::before {
    border: 2px solid rgba(169, 29, 34, 0.3);
}

/* Manual History Form Selects */
#manual-card-selectors select {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-light);
    border-radius: 4px;
    padding: 0.5rem;
    outline: none;
    font-family: var(--font-body);
}

#manual-card-selectors select:focus {
    border-color: var(--gold);
}

#manual-card-selectors select option {
    background: #1a1a1a;
    color: white;
}

#manual-card-selectors::-webkit-scrollbar {
    width: 6px;
}

#manual-card-selectors::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

#manual-card-selectors::-webkit-scrollbar-thumb {
    background: var(--gold);
    border-radius: 4px;
}

/* Robust Modal Override */
#viewer-modal-content {
    width: 95% !important;
    max-width: 900px !important;
    padding: 1.5rem !important;
    gap: 1.5rem !important;
    flex-wrap: nowrap !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    max-height: 90vh !important;
}

#enlarged-card-wrapper {
    flex: 1 1 40% !important;
    min-width: 0 !important;
    display: flex;
    justify-content: center;
    align-items: center;
}

#enlarged-card-img {
    max-width: 100% !important;
    max-height: 60vh !important;
    object-fit: contain !important;
}

#card-notes-wrapper {
    flex: 1 1 60% !important;
    min-width: 0 !important;
    display: flex;
    flex-direction: column;
}

#viewer-card-notes {
    min-height: 120px !important;
    height: auto !important;
    flex: 1 !important;
}

@media (max-width: 768px) and (orientation: portrait),
(max-width: 600px) {
    #viewer-modal-content {
        flex-direction: column !important;
    }

    #enlarged-card-wrapper,
    #card-notes-wrapper {
        flex: none !important;
        width: 100% !important;
    }

    #enlarged-card-img {
        max-height: 40vh !important;
    }
}

/* Database Screen Specifics */
#screen-database,
#screen-database .glass-panel,
#database-grid {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
}

#database-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    column-gap: 15px;
    row-gap: 45px;
    /* Space for the title */
    margin-top: 2rem;
    width: 100%;
}

.database-group-header {
    grid-column: 1 / -1;
    color: var(--gold);
    font-size: 1.5rem;
    font-family: var(--font-heading);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.5rem;
    margin-top: 2rem;
    margin-bottom: 1rem;
    text-align: center;
    /* Center the group headers too! */
}

@media (max-width: 768px) {
    #database-grid {
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 15px !important;
        row-gap: 50px !important;
    }

    .database-card .card-title-label {
        font-size: 0.75rem;
        width: 100%;
        bottom: -35px;
    }
}

@media (max-width: 480px) {
    #database-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        column-gap: 20px !important;
        row-gap: 60px !important;
    }

    .database-card {
        max-width: 180px !important;
    }

    .database-card .card-title-label {
        font-size: 0.9rem;
        width: 100%;
        bottom: -45px;
    }
}

/* Landscape mobile: 4 columns */
@media (max-height: 500px) and (orientation: landscape) {
    #database-grid {
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 12px !important;
        row-gap: 45px !important;
    }

    .database-card {
        max-width: 150px !important;
    }

    .database-card .card-title-label {
        font-size: 0.75rem;
        width: 100%;
    }
}

.database-card {
    width: 100% !important;
    max-width: 130px;
    /* Desktop width limit */
    height: auto !important;
    aspect-ratio: var(--front-aspect);
    margin: 0 auto;
}

.database-card .card-title-label {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    line-height: 1.2;
    font-size: 0.8rem;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    margin-top: 8px;
}

/* Meaning Container Styles */
@media (max-width: 768px) {
    #screen-meaning {
        padding: 0 !important;
    }

    .meaning-container {
        padding: 1.5rem !important;
        gap: 2rem !important;
        flex-direction: column;
    }

    #meaning-card-title {
        font-size: 2rem !important;
    }

    #meaning-card-img {
        max-height: 50vh !important;
    }
}

@media (max-width: 768px) {
    .meaning-container {
        padding-top: 4.5rem !important;
    }
}

/* Deck Category Filters */
.deck-category-filters {
    display: flex;
    gap: 0.25rem;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0.25rem;
    border-radius: 20px;
    margin-bottom: 1rem;
    overflow-x: auto;
    width: fit-content;
    max-width: 100%;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    scrollbar-width: none; /* Firefox */
}
.deck-category-filters::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}
.btn-category {
    padding: 0.4rem 1rem;
    font-size: 0.85rem;
    border-radius: 16px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    position: relative;
    font-family: var(--font-body);
}
.btn-category:hover {
    color: var(--text-light);
    background: rgba(255, 255, 255, 0.05);
}
.btn-category.active {
    background: var(--gold);
    color: #000;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3);
}