* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    overflow: hidden;
    background: var(--bg-primary);
    height: 100vh;
    width: 100vw;
    transition: background-color 0.3s ease;
    /* Prevent pull-to-refresh and overscroll on mobile */
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
    /* Prevent text selection during touch interactions */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Use dynamic viewport height on supported mobile browsers */
@supports (height: 100dvh) {
    body {
        height: 100dvh;
    }
}

/* Mobile keyboard adjustments */
body.keyboard-open .modal-content {
    max-height: 50vh; /* Reduced when keyboard is open to prevent overlap */
    overflow-y: auto;
}

body.mobile-device .modal {
    /* Ensure modal works well on mobile */
    -webkit-overflow-scrolling: touch;
}

/* Performance optimization - pause grid animations when modal is open */
body.modal-open #grid-container {
    pointer-events: none;
}

body.modal-open #grid {
    will-change: auto; /* Stop GPU optimization when not needed */
}

/* Material Icons Base Styles */
.material-icons {
    font-family: 'Material Icons';
    font-weight: normal;
    font-style: normal;
    font-size: 18px;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    display: inline-block;
    white-space: nowrap;
    word-wrap: normal;
    direction: ltr;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: 'liga';
}

/* Button Icon Styles */
button .material-icons {
    vertical-align: middle;
}

button .material-icons + * {
    margin-left: 6px;
}

* + .material-icons {
    margin-left: 6px;
}

/* Specific Material Icons sizes for different buttons */
.welcome-btn .material-icons {
    font-size: 22px;
    margin: 0;
}

.floating-btn .material-icons {
    font-size: 24px;
}

.theme-toggle .material-icons {
    font-size: 20px;
}

.close-btn .material-icons {
    font-size: 20px;
}

.tab-button .material-icons {
    font-size: 18px;
    margin-right: 6px;
    margin-left: 0;
}

.save-btn .material-icons {
    font-size: 18px;
    margin-right: 6px;
    margin-left: 0;
}

.btn-primary .material-icons {
    font-size: 18px;
    margin-right: 6px;
    margin-left: 0;
}

/* Theme Variables */
:root {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #666;
    --border-color: #ddd;
    --shadow-color: rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --text-primary: #ffffff;
    --text-secondary: #ccc;
    --border-color: #444;
    --shadow-color: rgba(0, 0, 0, 0.3);
}

/* Dark mode grid item borders */
[data-theme="dark"] .grid-item {
    border-color: #000000;
    background: var(--bg-secondary);
}

[data-theme="dark"] .grid-item.empty {
    border-color: #000000;
    background: var(--bg-secondary);
}

[data-theme="dark"] .grid-item.empty:hover {
    border-color: #000000;
}

/* Page Loader */
.page-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.6s ease-out;
    animation: pageLoaderFadeIn 0.6s ease-out forwards;
}

.page-loader.fade-out {
    opacity: 0;
    pointer-events: none;
    animation: pageLoaderFadeOut 0.6s ease-out forwards;
}

@keyframes pageLoaderFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes pageLoaderFadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

.loader-content {
    text-align: center;
    transform: translateY(-20px);
}

.loader-animation {
    margin-bottom: 24px;
}

.loader-circles {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

.loader-circle {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-primary);
    opacity: 0.3;
    animation: loaderPulse 1.5s ease-in-out infinite;
}

.loader-circle:nth-child(1) {
    animation-delay: 0s;
}

.loader-circle:nth-child(2) {
    animation-delay: 0.3s;
}

.loader-circle:nth-child(3) {
    animation-delay: 0.6s;
}

@keyframes loaderPulse {
    0%, 100% {
        opacity: 0.3;
        transform: scale(1);
    }
    50% {
        opacity: 1;
        transform: scale(1.2);
    }
}

.loader-text {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.loader-title {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.loader-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 400;
}

/* Responsive loader */
@media (max-width: 768px) {
    .loader-title {
        font-size: 20px;
    }
    
    .loader-subtitle {
        font-size: 13px;
    }
    
    .loader-circle {
        width: 10px;
        height: 10px;
    }
}

/* Welcome Overlay */
.welcome-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 122, 204, 0.1);
    backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0.8s ease-out;
    padding: 2rem;
}

.welcome-content {
    text-align: center;
    color: #1a1a1a;
    max-width: 600px;
    width: 100%;
    padding: 4rem 3rem;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 32px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 
        0 20px 40px rgba(0, 0, 0, 0.1),
        0 0 0 1px rgba(255, 255, 255, 0.2) inset;
    animation: slideInUp 0.8s ease-out 0.2s both;
    position: relative;
    z-index: 10;
    overflow: hidden;
}

.welcome-content::before {
    content: '\e037';
    font-family: 'Material Icons';
    position: absolute;
    bottom: -40px;
    right: -30px;
    font-size: 220px;
    color: rgba(0, 122, 204, 0.06);
    line-height: 1;
    pointer-events: none;
    z-index: 0;
    user-select: none;
}

.welcome-content > * {
    position: relative;
    z-index: 1;
}

.welcome-title {
    font-family: 'Inter', sans-serif;
    font-size: 2.2rem;
    font-weight: 800;
    margin-bottom: 1rem;
    color: #007acc;
    line-height: 1.15;
}

.welcome-message {
    font-size: 1.1rem;
    line-height: 1.7;
    margin-bottom: 3rem;
    color: rgba(26, 26, 26, 0.8);
    font-weight: 400;
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
}

.welcome-message strong {
    font-weight: 600;
    color: #007acc;
}

.welcome-btn {
    background: #007acc;
    color: white;
    border: none;
    padding: 18px 40px;
    font-size: 16px;
    font-weight: 600;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-transform: capitalize;
    letter-spacing: 0.3px;
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: none;
}

.welcome-btn:hover {
    background: #0056b3;
    transform: translateY(-2px);
    box-shadow: none;
}

.welcome-btn:active {
    transform: none;
}

.welcome-overlay.fade-out {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease-out, visibility 0.5s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes cardFadeIn {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Modal animations */
@keyframes modalFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes modalFadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

@keyframes modalContentSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes modalContentSlideOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-20px);
    }
}

@keyframes confirmModalSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes confirmModalSlideOut {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
}

@keyframes slideUpFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.note-card.fade-in {
    animation: cardFadeIn 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* New card animations for background polling */
.note-card.new-card-animation {
    will-change: opacity, transform;
}

.note-card.highlight-new-card {
    animation: newCardHighlight 5s ease-in-out;
    z-index: 200 !important;
    position: relative !important;
}

@keyframes newCardHighlight {
    0% {
        transform: scale(1);
        filter: brightness(1.1);
    }
    10% {
        transform: scale(1.02);
        filter: brightness(1.2);
    }
    20% {
        transform: scale(1);
        filter: brightness(1.05);
    }
    30% {
        transform: scale(1.02);
        filter: brightness(1.2);
    }
    40% {
        transform: scale(1);
        filter: brightness(1.05);
    }
    50% {
        transform: scale(1.02);
        filter: brightness(1.2);
    }
    60% {
        transform: scale(1);
        filter: brightness(1.05);
    }
    70% {
        transform: scale(1.01);
        filter: brightness(1.15);
    }
    80% {
        transform: scale(1);
        filter: brightness(1.02);
    }
    90% {
        transform: scale(1);
        filter: brightness(1.01);
    }
    100% {
        transform: scale(1);
        filter: brightness(1);
    }
}

/* Baking Message Overlay */
.baking-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;

    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.baking-overlay.show {
    opacity: 1;
    visibility: visible;
}

.baking-overlay.fade-out {
    opacity: 0;
    transition: opacity 0.8s ease;
}

.baking-content {
     background: var(--bg-secondary);
    padding: 48px 40px;
    text-align: center;
    animation: bakingPulse 0.6s ease-out;
    min-width: 320px;
    max-width: 400px;
}

.baking-icon {
    font-size: 3.5rem;
    margin-bottom: 24px;
    animation: bakingRotate 2s linear infinite;
}

.baking-title {
    font-family: 'Inter', sans-serif;
    font-size: 24px;
    font-weight: 900;
    color: var(--text-primary);
    margin-bottom: 32px;
    line-height: 1.1;
}

.baking-loader {
    display: flex;
    justify-content: center;
    gap: 8px;
}

.loader-dot {
    width: 12px;
    height: 12px;
    background: rgba(0, 122, 204, 0.8);
    border-radius: 50%;
    animation: bakingBounce 1.4s ease-in-out infinite both;
}

.loader-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.loader-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bakingPulse {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes bakingRotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@keyframes bakingBounce {
    0%, 40%, 100% {
        transform: scale(0);
    }
    20% {
        transform: scale(1);
    }
}

#viewport {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

/* Use dynamic viewport height on supported mobile browsers */
@supports (height: 100dvh) {
    #viewport {
        height: 100dvh;
    }
}

#grid-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    cursor: grab;
    cursor: -webkit-grab;
    cursor: -moz-grab;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    /* Enhanced touch interactions for mobile */
    touch-action: none;
    -webkit-touch-callout: none;
    /* Improve scrolling performance on mobile */
    -webkit-overflow-scrolling: touch;
    /* Better touch response */
    -webkit-tap-highlight-color: transparent;
    /* Prevent text selection during gestures */
    -webkit-user-drag: none;
    -webkit-user-modify: read-only;
    /* Smooth cursor transition */
    transition: cursor 0.1s ease;
}

#grid-container.dragging {
    cursor: grabbing !important;
    cursor: -webkit-grabbing !important;
    cursor: -moz-grabbing !important;
}

/* Ensure dragging cursor is maintained during drag operations */
#grid-container.dragging * {
    cursor: inherit !important;
}

/* Prevent cursor changes on child elements during drag */
#grid-container.dragging .grid-item,
#grid-container.dragging .note-card {
    cursor: grabbing !important;
    cursor: -webkit-grabbing !important;
    cursor: -moz-grabbing !important;
}

#grid {
    position: absolute;
    /* Remove CSS Grid layout for virtual scrolling performance */
    /* display: grid; */
    /* grid-template-columns: repeat(100, 250px); */
    /* grid-template-rows: repeat(100, 250px); */
    /* gap: 0; */
    
    /* Virtual grid uses absolute positioning */
    width: 25000px; /* 100 * 250px */
    height: 25000px; /* 100 * 250px */
    
    transform-origin: 0 0;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.grid-item {
    width: 250px;
    height: 250px;
    border: 1px solid #ddd;
    background: #fff;
    position: absolute; /* Changed from relative for virtual scrolling */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    
    /* Performance optimizations for virtual scrolling */
    contain: layout style paint;
    transform: translateZ(0); /* Force hardware acceleration */
}

.grid-item:has(.note-card) {
    overflow: visible;
}

.grid-item:has(.highlight-new-card) {
    overflow: visible !important;
    z-index: 200;
    position: relative;
}

.grid-item.empty {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: var(--bg-secondary);
    border-color: var(--border-color);
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.grid-item.empty:hover {
    background: var(--bg-primary);
    border-color: var(--text-secondary);
    cursor: pointer;
}

.grid-item.empty::before {
    content: '+';
    font-size: 72px;
    color: var(--border-color);
    font-weight: 300;
    transition: color 0.15s ease;
}

.grid-item.empty:hover::before {
    color: var(--text-secondary);
}

/* Grid number styling for empty cells */
.grid-number {
    position: absolute;
    bottom: 4px;
    right: 6px;
    font-size: 10px;
    color: var(--border-color);
    font-weight: 400;
    opacity: 0.6;
    pointer-events: none;
    font-family: 'Inter', sans-serif;
    transition: opacity 0.15s ease, color 0.15s ease;
}

.grid-item.empty:hover .grid-number {
    opacity: 0.8;
    color: var(--text-secondary);
}

.note-card {
    width: 100%;
    height: 100%;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1.4;
    word-wrap: break-word;
    overflow: hidden;
    position: relative;
    cursor: pointer !important;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    transition: transform 0.15s ease;
    /* Sharp text and images at any scale */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

.note-card * {
    cursor: pointer !important;
}

.note-card:hover:not(.preview-card) {
    cursor: pointer; /* Make it clear note cards are clickable for zoom */
}

/* Grid item hover effect for cards */
.grid-item:hover .note-card:not(.preview-card) {
    transition: all 0.3s ease;
}

/* Disable hover effects for preview modal */
#note-preview .note-card {
    transition: none !important;
}

#note-preview .note-card:hover {
    transform: none !important;
    box-shadow: none !important;
}

/* Disable hover effects on touch devices */
@media (hover: none) and (pointer: coarse) {
    .note-card:hover:not(.preview-card) {
        cursor: pointer;
    }
    
    .grid-item:hover .note-card:not(.preview-card) {
        box-shadow: none !important;
        transform: none !important;
    }
    
    [data-theme="dark"] .grid-item:hover .note-card:not(.preview-card) {
        box-shadow: none !important;
    }
    
    #note-preview:hover,
    #note-preview .note-card:hover {
        transform: none !important;
        box-shadow: none !important;
    }
    
    /* Ensure proper touch targets on mobile */
    .note-card {
        cursor: pointer !important;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    
    .grid-item {
        touch-action: manipulation;
    }
    
    /* Active state for touch feedback */
    .note-card:active {
        opacity: 0.8;
        transition: opacity 0.1s ease;
    }
    
    /* Make note-preview clickable on mobile */
    #note-preview .note-card {
        cursor: pointer !important;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    
    #note-preview .note-text,
    #note-preview .note-author {
        pointer-events: auto !important;
        cursor: text !important;
        -webkit-tap-highlight-color: rgba(0, 122, 204, 0.2);
        touch-action: manipulation;
        min-height: 44px; /* iOS recommended touch target size */
        display: flex !important;
        align-items: center;
        justify-content: center;
    }
    
    /* Ensure text areas are easily tappable */
    #note-preview .note-text-container,
    #note-preview .note-author-container {
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        pointer-events: auto !important;
        touch-action: manipulation;
    }
}

/* Card Action Buttons */
.card-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 6px;
    z-index: 10;
    opacity: 0;
    transform: translateY(-5px);
    transition: all 0.2s ease;
    pointer-events: none;
}

/* Show card actions on hover - both grid-item and note-card hover */
.grid-item:hover .card-actions,
.note-card:hover .card-actions {
    opacity: 1 !important;
    transform: translateY(0) !important;
    pointer-events: auto !important;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 500;
    font-family: 'Inter', sans-serif;
    backdrop-filter: blur(8px);
    transition: all 0.2s ease;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border: 1px solid;
}

.action-btn svg {
    flex-shrink: 0;
}

/* Light mode styling */
.action-btn {
    background: rgba(255, 255, 255, 0.95);
    color: #374151;
    border-color: rgba(0, 0, 0, 0.1);
}

.action-btn:hover {
    background: rgba(249, 250, 251, 0.95);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Dark mode styling */
[data-theme="dark"] .action-btn {
    background: rgba(45, 45, 45, 0.95);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.2);
}

[data-theme="dark"] .action-btn:hover {
    background: rgba(55, 65, 81, 0.95);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Toast Notification */
.toast-notification {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    font-family: 'Inter', sans-serif;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 10000;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(8px);
    max-width: 400px;
    text-align: center;
}

/* New Cards Notification */
.new-cards-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.95) 0%, rgba(37, 99, 235, 0.98) 100%);
    color: white;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    box-shadow: 
        0 6px 24px rgba(59, 130, 246, 0.4),
        0 0 0 1px rgba(255, 255, 255, 0.2) inset,
        0 1px 0 rgba(255, 255, 255, 0.3) inset;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-30px) translateX(20px) scale(0.8);
    transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    backdrop-filter: blur(20px);
    cursor: pointer;
    user-select: none;
    border: 1px solid rgba(255, 255, 255, 0.15);
    width: auto;
    max-width: 220px;
    white-space: nowrap;
    overflow: visible;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Animated ring effect on show */
.new-cards-notification::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    border: 2px solid rgba(59, 130, 246, 0.6);
    border-radius: 12px;
    transform: translate(-50%, -50%) scale(1);
    opacity: 0;
    pointer-events: none;
}

.new-cards-notification.show::after {
    animation: notificationRing 1s ease-out;
}

@keyframes notificationRing {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.8;
    }
    100% {
        transform: translate(-50%, -50%) scale(2.5);
        opacity: 0;
    }
}

.new-cards-notification::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.4), rgba(255, 255, 255, 0.1));
    border-radius: 14px;
    z-index: -1;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.new-cards-notification.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) translateX(0) scale(1);
    animation: notificationBounce 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.new-cards-notification:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 
        0 12px 40px rgba(59, 130, 246, 0.5),
        0 0 0 1px rgba(255, 255, 255, 0.3) inset,
        0 1px 0 rgba(255, 255, 255, 0.4) inset;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.98) 0%, rgba(29, 78, 216, 1) 100%);
}

.new-cards-notification:hover::before {
    opacity: 1;
}

.new-cards-notification:active {
    transform: translateY(-1px) scale(1.02);
    transition: all 0.1s ease;
}

.notification-content {
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    z-index: 2;
    white-space: nowrap;
}

.notification-icon {
    font-size: 16px;
    animation: notificationPulse 2s ease-in-out infinite;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
    flex-shrink: 0;
}

.notification-text {
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    letter-spacing: 0.2px;
    flex-shrink: 0;
}

@keyframes notificationBounce {
    0% {
        opacity: 0;
        transform: translateY(-30px) translateX(20px) scale(0.8);
    }
    40% {
        opacity: 1;
        transform: translateY(-8px) translateX(-2px) scale(1.15);
    }
    60% {
        transform: translateY(-5px) translateX(2px) scale(1.1);
    }
    70% {
        transform: translateY(-2px) translateX(-1px) scale(1.05);
    }
    80% {
        transform: translateY(2px) translateX(1px) scale(0.95);
    }
    90% {
        transform: translateY(-1px) translateX(0) scale(1.02);
    }
    100% {
        opacity: 1;
        transform: translateY(0) translateX(0) scale(1);
    }
}

@keyframes notificationPulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.15);
    }
}

/* Enhanced Explosive Confetti Animation */
.confetti-container {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 120px;
    height: 120px;
    transform: translate(-50%, -50%);
    overflow: visible;
    pointer-events: none;
    border-radius: 50%;
}

.confetti-piece {
    position: absolute;
    width: 8px;
    height: 8px;
    background: rgba(255, 255, 255, 0.9);
    opacity: 0;
    border-radius: 50%;
    transform-origin: center center;
}

.confetti-piece:nth-child(1) { animation: explodeConfetti1 3s ease-out forwards; }
.confetti-piece:nth-child(2) { animation: explodeConfetti2 3s ease-out forwards; }
.confetti-piece:nth-child(3) { animation: explodeConfetti3 3s ease-out forwards; }
.confetti-piece:nth-child(4) { animation: explodeConfetti4 3s ease-out forwards; }
.confetti-piece:nth-child(5) { animation: explodeConfetti5 3s ease-out forwards; }
.confetti-piece:nth-child(6) { animation: explodeConfetti6 3s ease-out forwards; }
.confetti-piece:nth-child(7) { animation: explodeConfetti7 3s ease-out forwards; }
.confetti-piece:nth-child(8) { animation: explodeConfetti8 3s ease-out forwards; }
.confetti-piece:nth-child(9) { animation: explodeConfetti9 3s ease-out forwards; }
.confetti-piece:nth-child(10) { animation: explodeConfetti10 3s ease-out forwards; }
.confetti-piece:nth-child(11) { animation: explodeConfetti11 3s ease-out forwards; }
.confetti-piece:nth-child(12) { animation: explodeConfetti12 3s ease-out forwards; }
.confetti-piece:nth-child(13) { animation: explodeConfetti13 3s ease-out forwards; }
.confetti-piece:nth-child(14) { animation: explodeConfetti14 3s ease-out forwards; }
.confetti-piece:nth-child(15) { animation: explodeConfetti15 3s ease-out forwards; }
.confetti-piece:nth-child(16) { animation: explodeConfetti16 3s ease-out forwards; }
.confetti-piece:nth-child(17) { animation: explodeConfetti17 3s ease-out forwards; }
.confetti-piece:nth-child(18) { animation: explodeConfetti18 3s ease-out forwards; }
.confetti-piece:nth-child(19) { animation: explodeConfetti19 3s ease-out forwards; }
.confetti-piece:nth-child(20) { animation: explodeConfetti20 3s ease-out forwards; }

.confetti-piece:nth-child(odd) {
    background: rgba(255, 215, 0, 0.9);
    width: 6px;
    height: 10px;
    border-radius: 3px;
}

.confetti-piece:nth-child(3n) {
    background: rgba(255, 105, 180, 0.9);
    width: 7px;
    height: 7px;
}

.confetti-piece:nth-child(4n) {
    background: rgba(0, 255, 127, 0.9);
    width: 4px;
    height: 12px;
    border-radius: 2px;
}

.confetti-piece:nth-child(5n) {
    background: rgba(255, 69, 0, 0.9);
    width: 10px;
    height: 4px;
    border-radius: 2px;
}

.confetti-piece:nth-child(6n) {
    background: rgba(138, 43, 226, 0.9);
    width: 5px;
    height: 5px;
    border-radius: 50%;
}

/* Explosive Confetti Keyframes - Each piece explodes in different directions */
@keyframes explodeConfetti1 {
    0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
    100% { opacity: 0; transform: translate(120px, -80px) rotate(720deg) scale(0.3); }
}

@keyframes explodeConfetti2 {
    0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
    100% { opacity: 0; transform: translate(-110px, -70px) rotate(-540deg) scale(0.2); }
}

@keyframes explodeConfetti3 {
    0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
    100% { opacity: 0; transform: translate(90px, 100px) rotate(900deg) scale(0.4); }
}

@keyframes explodeConfetti4 {
    0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
    100% { opacity: 0; transform: translate(-130px, 90px) rotate(-720deg) scale(0.3); }
}

@keyframes explodeConfetti5 {
    0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
    100% { opacity: 0; transform: translate(150px, 20px) rotate(1080deg) scale(0.2); }
}

@keyframes explodeConfetti6 {
    0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
    100% { opacity: 0; transform: translate(-100px, 10px) rotate(-630deg) scale(0.5); }
}

@keyframes explodeConfetti7 {
    0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
    100% { opacity: 0; transform: translate(80px, -120px) rotate(810deg) scale(0.3); }
}

@keyframes explodeConfetti8 {
    0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
    100% { opacity: 0; transform: translate(-90px, -110px) rotate(-900deg) scale(0.4); }
}

@keyframes explodeConfetti9 {
    0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
    100% { opacity: 0; transform: translate(140px, 70px) rotate(1260deg) scale(0.2); }
}

@keyframes explodeConfetti10 {
    0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
    100% { opacity: 0; transform: translate(-120px, 60px) rotate(-1080deg) scale(0.3); }
}

@keyframes explodeConfetti11 {
    0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
    100% { opacity: 0; transform: translate(60px, -100px) rotate(540deg) scale(0.4); }
}

@keyframes explodeConfetti12 {
    0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
    100% { opacity: 0; transform: translate(-80px, -90px) rotate(-720deg) scale(0.5); }
}

@keyframes explodeConfetti13 {
    0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
    100% { opacity: 0; transform: translate(110px, 110px) rotate(900deg) scale(0.3); }
}

@keyframes explodeConfetti14 {
    0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
    100% { opacity: 0; transform: translate(-140px, 80px) rotate(-810deg) scale(0.2); }
}

@keyframes explodeConfetti15 {
    0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
    100% { opacity: 0; transform: translate(130px, -50px) rotate(1170deg) scale(0.4); }
}

@keyframes explodeConfetti16 {
    0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
    100% { opacity: 0; transform: translate(-70px, 120px) rotate(-990deg) scale(0.3); }
}

@keyframes explodeConfetti17 {
    0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
    100% { opacity: 0; transform: translate(100px, -70px) rotate(630deg) scale(0.5); }
}

@keyframes explodeConfetti18 {
    0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
    100% { opacity: 0; transform: translate(-110px, -130px) rotate(-1170deg) scale(0.2); }
}

@keyframes explodeConfetti19 {
    0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
    100% { opacity: 0; transform: translate(70px, 130px) rotate(1350deg) scale(0.4); }
}

@keyframes explodeConfetti20 {
    0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
    100% { opacity: 0; transform: translate(-150px, -40px) rotate(-1260deg) scale(0.3); }
}

/* Dark theme support */
[data-theme="dark"] .new-cards-notification {
    background: linear-gradient(135deg, rgba(99, 179, 237, 0.95) 0%, rgba(59, 130, 246, 0.98) 100%);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 
        0 8px 32px rgba(99, 179, 237, 0.4),
        0 0 0 1px rgba(255, 255, 255, 0.1) inset,
        0 1px 0 rgba(255, 255, 255, 0.2) inset;
}

[data-theme="dark"] .new-cards-notification::before {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.05));
}

[data-theme="dark"] .new-cards-notification:hover {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.98) 0%, rgba(37, 99, 235, 1) 100%);
    box-shadow: 
        0 12px 40px rgba(99, 179, 237, 0.5),
        0 0 0 1px rgba(255, 255, 255, 0.2) inset,
        0 1px 0 rgba(255, 255, 255, 0.3) inset;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .new-cards-notification {
        top: 80px;
        right: 15px;
        font-size: 12px;
        padding: 10px 14px;
        max-width: 180px;
        border-radius: 10px;
    }
    
    .notification-icon {
        font-size: 14px;
    }
    
    .confetti-container {
        width: 100px;
        height: 100px;
    }
}

@media (max-width: 480px) {
    .new-cards-notification {
        top: 70px;
        right: 10px;
        font-size: 11px;
        padding: 8px 12px;
        max-width: 160px;
        border-radius: 8px;
    }
    
    .notification-icon {
        font-size: 13px;
    }
    
    .confetti-container {
        width: 80px;
        height: 80px;
    }
}

.note-text {
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
    background: transparent;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    resize: none;
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    /* Allow text selection in editable areas */
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

.note-content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    z-index: 2; /* Above shine effect */
}

/* Grid card text styles - centered in full available space */
.grid-item .note-text {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 14px;
    border: none;
    outline: none;
    background: transparent;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    resize: none;
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-line;
    padding: 10px;
    box-sizing: border-box;
}

/* Grid card author fixed at bottom center */
.grid-item .note-author {
    position: absolute;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 16px);
    height: 12px;
    border: none;
    outline: none;
    background: transparent;
    text-align: center;
    font-size: 7px;
    font-weight: 300;
    color: inherit;
    cursor: text;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Ensure consistent grid card proportions on mobile */
@media (max-width: 768px) {
    .grid-item .note-text {
        /* Maintain consistent padding relative to card size */
        padding: 10px;
        line-height: 1.4; /* Keep consistent line height */
    }
    
    .grid-item .note-author {
        /* Maintain proportional positioning on mobile */
        font-size: 7px; /* Keep same relative size */
        height: 12px;
        bottom: 6px;
    }
}

/* Modal text container */
#note-preview .note-text-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 14px;
    padding: 10px;
    box-sizing: border-box;
}

/* Modal placeholder - centered */
#note-preview .note-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: currentColor;
    opacity: .6;
    pointer-events: none; /* Not clickable */
    text-align: center;
    font-family: inherit;
    font-size: inherit;
    line-height: 1.4;
    white-space: pre-line;
    display: block; /* Visible by default */
    width: 100%; /* Match note text max-width */
    word-wrap: break-word;
    margin: 0 auto; /* Center the text within the container */
}

/* Modal text input - centered */
#note-preview .note-text {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: none;
    outline: none;
    background: transparent;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    resize: none;
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    line-height: 1.4;
    cursor: text;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-line;
    caret-color: transparent; /* Hide cursor initially */
    pointer-events: none; /* Make it non-interactive initially */
    max-width: 240px; /* Match preview card width */
    margin: 0 auto; /* Center the text within the container */
}

/* Show cursor and make interactive when active */
#note-preview .note-text.active {
    caret-color: currentColor;
    pointer-events: auto;
}

/* Modal author container */
#note-preview .note-author-container {
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 16px);
    height: 12px;
}

/* Modal author placeholder */
#note-preview .author-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: currentColor;
    opacity: 0.6;
    pointer-events: none; /* Not clickable */
    text-align: center;
    font-size: 7px;
    font-weight: 300;
    display: block; /* Visible by default */
    width: calc(100% - 16px); /* Match author container width */
    max-width: 240px; /* Match text max-width */
}

/* Modal author input */
#note-preview .note-author {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: none;
    outline: none;
    background: transparent;
    text-align: center;
    font-size: 7px;
    font-weight: 300;
    color: inherit;
    opacity: 0.5;
    cursor: text;
    display: flex;
    align-items: center;
    justify-content: center;
    caret-color: transparent;
    pointer-events: none;
    max-width: 240px; /* Match text max-width */
    margin: 0 auto; /* Center the text within the container */
}

/* Show cursor for author when active */
#note-preview .note-author.active {
    caret-color: currentColor;
    pointer-events: auto;
}

/* Modal content container adjustment */
#note-preview .note-content {
    padding: 15px;
}

.note-text:focus {
    outline: none;
}

.note-author:focus {
    outline: none;
}

/* Grid card placeholder - centered with correct color */
.grid-item .note-text:empty::before {
    content: attr(placeholder);
    color: currentColor;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.grid-item .note-author:empty::before {
    content: attr(placeholder);
    color: currentColor;
}

/* Color Presets */
.preset-1 { background: #1a1a1a; color: #ffffff; }
.preset-2 { background: #ffffff; color: #1a1a1a; }
.preset-3 { background: #ff6b6b; color: #ffffff; }
.preset-4 { background: #4ecdc4; color: #ffffff; }
.preset-5 { background: #45b7d1; color: #ffffff; }
.preset-6 { background: #96ceb4; color: #ffffff; }
.preset-7 { background: #feca57; color: #1a1a1a; }
.preset-8 { background: #ff9ff3; color: #1a1a1a; }
.preset-9 { background: #54a0ff; color: #ffffff; }
.preset-10 { background: #5f27cd; color: #ffffff; }
.preset-11 { background: #00d2d3; color: #ffffff; }
.preset-12 { background: #ff9f43; color: #ffffff; }
.preset-13 { background: #ee5a24; color: #ffffff; }
.preset-14 { background: #0abde3; color: #ffffff; }
.preset-15 { background: #006ba6; color: #ffffff; }
.preset-16 { background: #f8b500; color: #1a1a1a; }
.preset-17 { background: #2c2c54; color: #ffffff; }
.preset-18 { background: #40407a; color: #ffffff; }
.preset-19 { background: #706fd3; color: #ffffff; }
.preset-20 { background: #f7f1e3; color: #2c2c54; }

/* Font Families - 25 Diverse Options */
.font-inter { font-family: 'Inter', sans-serif; }
.font-jetbrains { font-family: 'JetBrains Mono', monospace; }
.font-playfair { font-family: 'Playfair Display', serif; }
.font-dancing { font-family: 'Dancing Script', cursive; }
.font-roboto { font-family: 'Roboto', sans-serif; }
.font-poppins { font-family: 'Poppins', sans-serif; }
.font-source-code-pro { font-family: 'Source Code Pro', monospace; }
.font-merriweather { font-family: 'Merriweather', serif; }
.font-lora { font-family: 'Lora', serif; }
.font-nunito-sans { font-family: 'Nunito Sans', sans-serif; }
.font-crimson-text { font-family: 'Crimson Text', serif; }
.font-oswald { font-family: 'Oswald', sans-serif; }
.font-montserrat { font-family: 'Montserrat', sans-serif; }
.font-open-sans { font-family: 'Open Sans', sans-serif; }
.font-raleway { font-family: 'Raleway', sans-serif; }
.font-ubuntu { font-family: 'Ubuntu', sans-serif; }
.font-quicksand { font-family: 'Quicksand', sans-serif; }
.font-work-sans { font-family: 'Work Sans', sans-serif; }
.font-space-grotesk { font-family: 'Space Grotesk', sans-serif; }
.font-dm-sans { font-family: 'DM Sans', sans-serif; }
.font-eb-garamond { font-family: 'EB Garamond', serif; }
.font-fira-code { font-family: 'Fira Code', monospace; }
.font-comfortaa { font-family: 'Comfortaa', sans-serif; }
.font-caveat { font-family: 'Caveat', cursive; }
.font-righteous { font-family: 'Righteous', sans-serif; }

/* Theme Toggle */
.theme-toggle {
    display: none; /* Hidden as requested */
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: all 0.3s ease;
    z-index: 1000;
    box-shadow: 0 2px 10px var(--shadow-color);
}

.theme-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 20px var(--shadow-color);
}

/* Demo Card Styling */
.note-card.demo-card {
    position: relative;
    overflow: visible;
}

.note-card.demo-card::before {
    content: '🎭';
    position: absolute;
    top: -5px;
    right: -5px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 10;
}

.note-card.demo-card::after {
    content: 'DEMO';
    position: absolute;
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(45deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 8px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 8px;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    z-index: 10;
}

/* Floating Button - Hidden */
.floating-btn {
    display: none;
}

/* Floating button styles removed for performance */

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 122, 204, 0.1);
    z-index: 2000;
    backdrop-filter: blur(60px);
    opacity: 0;
    transition: none;
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 1;
    animation: modalFadeIn 0.3s ease-out;
}

.modal.closing {
    animation: modalFadeOut 0.3s ease-in;
}

/* Confirmation Modal - Independent Overlay */
#confirm-modal {
    z-index: 3000; /* Above main modal */
    background: rgba(0, 122, 204, 0.15);
    backdrop-filter: blur(20px);
    opacity: 0;
    transition: none;
}

#confirm-modal.active {
    opacity: 1;
    animation: modalFadeIn 0.3s ease-out;
}

#confirm-modal.closing {
    animation: modalFadeOut 0.3s ease-in;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 20px;
    width: 100%;
    max-width: 800px;
    height: calc(100vh - 40px);
    max-height: 700px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 122, 204, 0.15);
    border: 1px solid rgba(0, 122, 204, 0.1);
    transform: translateY(20px);
    opacity: 0;
    animation: modalContentSlideIn 0.4s ease-out 0.1s forwards;
}

.modal.closing .modal-content {
    animation: modalContentSlideOut 0.3s ease-in forwards;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 28px 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.header-content h2 {
    font-family: 'Inter', sans-serif;
    font-size: 22px;
    font-weight: 900;
    color: var(--text-primary);
    margin: 0 0 4px 0;
    line-height: 1.1;
}

.subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 0;
    font-weight: 400;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.rate-limit-badge {
    background: var(--bg-primary);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid var(--border-color);
    display: none; /* Hidden on all breakpoints */
    align-items: center;
    gap: 4px;
}

.rate-limit-badge::before {
    content: "Limit today:";
}

#remaining-notes {
    color: var(--text-primary);
    font-weight: 600;
}

.close-btn {
    background: rgba(255, 255, 255, 0.9);
    border: none;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
    flex-shrink: 0;
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 1001;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.close-btn:hover {
    background: rgba(255, 255, 255, 1);
    color: var(--text-primary);
    transform: scale(1.05);
}

/* Dark theme support for close button */
[data-theme="dark"] .close-btn {
    background: rgba(30, 30, 30, 0.9);
    color: #f0f0f0;
}

[data-theme="dark"] .close-btn:hover {
    background: rgba(30, 30, 30, 1);
    color: #ffffff;
}

.modal-body {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 24px;
    padding: 16px 28px;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.preview-section {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 24px 0;
    overflow: visible;
    position: relative;
}

#note-preview {
    width: 240px;
    height: 240px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    transform: scale(1.4);
    transform-origin: center;
    box-shadow: 0 8px 32px var(--shadow-color);
}

.controls-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 8px 0 16px;
    overflow: visible;
    min-height: 0;
}

.modal-footer {
    padding: 20px 28px 24px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.save-btn {
    width: 100%;
    padding: 16px;
    font-size: 16px;
    font-weight: 600;
    border-radius: 12px;
    background: #007acc;
    color: white;
    border: none;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 16px rgba(0, 122, 204, 0.3);
}

.save-btn:hover:not(:disabled) {
    background: #0056b3;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 122, 204, 0.4);
}

.save-btn:disabled {
    cursor: not-allowed;
    transform: none;
}

/* Light mode specific disabled button styling */
[data-theme="light"] .save-btn:disabled {
    background: rgba(0, 0, 0, 0.05);
    color: rgba(26, 26, 26, 0.4);
}

/* Dark mode specific disabled button styling */
[data-theme="dark"] .save-btn:disabled {
    background: rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.4);
}

.settings-toggle-btn {
    display: none; /* Hidden by default, shown on mobile/tablet */
    padding: 12px;
    font-size: 0; /* Hide text content */
    font-weight: 600;
    border-radius: 10px;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    align-items: center;
    justify-content: center;
    width: 48px;
    min-width: 48px;
}

.settings-toggle-btn .material-icons {
    font-size: 18px; /* Restore icon size */
}

.settings-toggle-btn:hover {
    background: var(--bg-tertiary);
    border-color: #007acc;
}

.settings-toggle-btn.active {
    background: #007acc;
    color: white;
    border-color: #007acc;
}

/* Light mode: greyish background for inactive buttons */
[data-theme="light"] .settings-toggle-btn:not(.active) {
    background: #f5f5f5;
    color: #666;
    border-color: #e0e0e0;
}

[data-theme="light"] .settings-toggle-btn:not(.active):hover {
    background: #e8e8e8;
    border-color: #d0d0d0;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
}

.control-group label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Font controls header */
.font-controls-header {
    margin-bottom: 4px;
}

.font-controls-header label {
    margin: 0;
}

.backgrounds-group {
    flex: 1;
    min-height: 0;
    overflow: visible;
    display: flex;
    flex-direction: column;
}

.backgrounds-tabs {
    display: flex;
    background: var(--bg-primary);
    border-radius: 8px;
    padding: 4px;
    margin-bottom: 6px;
    gap: 2px;
}

.tab-button {
    flex: 1;
    padding: 8px 12px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tab-button.active {
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-shadow: 0 2px 4px var(--shadow-color);
}

/* Dark mode inactive tab button styles */
[data-theme="dark"] .tab-button:not(.active) {
    color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.06);
}

.tab-button:hover:not(.active) {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.5);
}

[data-theme="dark"] .tab-button:hover:not(.active) {
    color: rgba(255, 255, 255, 0.4);
    background: rgba(255, 255, 255, 0.1);
}

.tab-content {
    display: none;
    flex: 1;
    overflow: visible;
    flex-direction: column;
}

.tab-content.active {
    display: flex;
}



.images-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.images-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    display: none;
}

.randomize-icon {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 10;
}

.randomize-icon:hover {
    background: #007acc;
    color: white;
    border-color: #007acc;
    transform: translateX(-50%) translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 122, 204, 0.3);
}

.randomize-icon .material-icons {
    font-size: 16px;
    flex-shrink: 0;
}

.randomize-icon span:not(.material-icons) {
    white-space: nowrap;
}

.colors-scroll-container {
    flex: 1;
    overflow-y: auto;
    padding-right: 4px;
    margin-right: -4px;
    min-height: 0;
}

.colors-scroll-container::-webkit-scrollbar {
    width: 4px;
}

.colors-scroll-container::-webkit-scrollbar-track {
    background: var(--bg-primary);
    border-radius: 2px;
}

.colors-scroll-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.colors-scroll-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}



.images-scroll-container {
    flex: 1;
    overflow-y: auto;
    padding-right: 4px;
    margin-right: -4px;
    min-height: 0;
}

.images-scroll-container::-webkit-scrollbar {
    width: 4px;
}

.images-scroll-container::-webkit-scrollbar-track {
    background: var(--bg-primary);
    border-radius: 2px;
}

.images-scroll-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.images-scroll-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.image-presets {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding-bottom: 8px;
}

.image-preset {
    aspect-ratio: 1;
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    position: relative;
    overflow: hidden;
}

.image-preset::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.1);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.image-preset:hover::before {
    opacity: 1;
}

.image-preset.selected {
    border-color: #007acc;
    box-shadow: 0 0 0 3px rgba(0, 122, 204, 0.2);
}

.image-preset.selected::before {
    opacity: 0;
}

.image-preset.selected::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #007acc;
    font-size: 18px;
    font-weight: bold;
    text-shadow: 0 0 4px rgba(255, 255, 255, 0.8);
}

#font-select {
    padding: 12px 24px 12px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    font-weight: 500;
}

#font-select:focus {
    outline: none;
    border-color: #007acc;
    box-shadow: 0 0 0 3px rgba(0, 122, 204, 0.1);
}

.color-presets {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    padding-bottom: 8px;
}

.color-preset {
    aspect-ratio: 1;

    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.color-preset::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.1);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.color-preset:hover::before {
    opacity: 1;
}

.color-preset.selected {
    border-color: #007acc;
    box-shadow: 0 0 0 3px rgba(0, 122, 204, 0.2);
}

.color-preset.selected::before {
    opacity: 0;
}

.color-preset.selected::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #ffffff;
    font-size: 18px;
    font-weight: bold;
    text-shadow: 0 0 4px rgba(255, 255, 255, 0.8);
}

/* Legacy button styles removed - using specific modal button styles */

/* Clean Confirmation Modal */
.confirm-modal-content {
    width: 360px;
    height: auto;
    max-height: none;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    animation: confirmModalSlideIn 0.4s ease-out 0.1s forwards;
}

#confirm-modal.closing .confirm-modal-content {
    animation: confirmModalSlideOut 0.3s ease-in forwards;
}

.confirm-modal-content .modal-header {
    padding: 24px 48px 20px 28px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.confirm-modal-content .modal-header h2 {
    font-family: 'Inter', sans-serif;
    margin: 0;
    font-size: 18px;
    font-weight: 900;
    line-height: 1.1;
    color: var(--text-primary);
}

.confirm-modal-content .close-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 32px;
    height: 32px;
    font-size: 20px;
}

.confirm-modal-body {
    padding: 24px 28px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    flex: 1;
}

.confirm-modal-body p {
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-secondary);
    margin: 0;
    text-align: left;
}

.confirm-buttons {
    margin-top: 4px;
}

/* Clean Button Styles */
.confirm-buttons button {
    width: 100%;
    padding: 14px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}

.confirm-buttons .btn-primary {
    background: #007acc;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 122, 204, 0.3);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.confirm-buttons .btn-primary:hover {
    background: #0056b3;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 122, 204, 0.4);
}

/* Loading State for Save */
#confirm-modal.saving {
    pointer-events: none;
}

#confirm-modal.saving .confirm-modal-content {
    position: relative;
}

#confirm-modal.saving .confirm-modal-content::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 122, 204, 0.95);
    border-radius: 12px;
    pointer-events: none;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

#confirm-modal.saving .confirm-modal-content::before {
    content: '⏳ Saving your message...';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 16px;
    font-weight: 600;
    z-index: 11;
    text-align: center;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.8; }
    50% { opacity: 1; }
}

.confirm-buttons .btn-primary:disabled {
    background: #007acc;
    cursor: not-allowed;
    position: relative;
    opacity: 0.8;
}

.confirm-buttons .btn-primary:disabled::before {
    content: '⌛';
    animation: spin 1s linear infinite;
    margin-right: 8px;
    display: inline-block;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive */
/* Mobile and Tablet Modal Fly-in Styles */
@media (max-width: 768px) {
    /* Modal transforms into bottom fly-in */
    .modal {
        align-items: flex-end;
        padding: 0;
    }
    
    .modal-content {
        width: 100vw;
        max-width: 100vw;
        height: 80vh;
        max-height: 80vh;
        border-radius: 20px 20px 0 0;
        margin: 0;
        bottom: 0;
        transform: translateY(100%);
        transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        animation: none;
        position: fixed;
    }
    
    .modal.show .modal-content {
        transform: translateY(0);
        opacity: 1;
    }

    /* Modal closing animation */
    .modal.closing .modal-content {
        transform: translateY(100%);
        opacity: 0;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    /* Expanded state when settings are visible */
    .modal-content.settings-expanded {
        height: 100vh !important;
        max-height: 100vh !important;
    }
    
    /* Hide subtitle on mobile/tablet */
    .subtitle {
        display: none !important;
    }
    
    /* Show settings toggle button */
    .modal-footer {
        display: flex;
        gap: 12px;
        padding: 16px 20px 20px;
        flex-direction: row-reverse;
    }
    
    .settings-toggle-btn {
        display: flex;
        flex: 0 0 auto;
        padding: 12px;
        width: 48px;
        min-width: 48px;
        justify-content: center;
        font-size: 0 !important;
    }
    
    .settings-toggle-btn .material-icons {
        font-size: 18px !important;
    }
    
    .save-btn {
        flex: 1;
    }
    
    /* Hide settings by default on mobile */
    .controls-section {
        display: none;
        padding: 20px;
        border-top: 1px solid var(--border-color);
        overflow-y: auto;
        overflow-x: hidden;
        background: var(--bg-secondary);
        animation: slideUpFadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        -webkit-overflow-scrolling: touch;
    }
    
    /* Show settings when expanded with parallax effect */
    .modal-content.settings-expanded .controls-section {
        display: flex !important;
        flex-direction: column;
        gap: 16px;
        overflow-y: scroll !important;
        overflow-x: hidden;
        flex: 1;
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        height: 50vh;
        max-height: 50vh;
        background: var(--bg-primary);
        border-radius: 20px 20px 0 0;
        z-index: 10;
        box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.15);
        backdrop-filter: blur(10px);
        animation: settingsFlyIn 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
        padding: 20px;
        padding-top: 50px; /* Make room for close button */
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
        scrollbar-width: thin; /* Firefox */
        scrollbar-color: rgba(0, 0, 0, 0.2) transparent; /* Firefox */
    }

    /* Webkit scrollbar styling for settings panel */
    .modal-content.settings-expanded .controls-section::-webkit-scrollbar {
        width: 6px;
    }

    .modal-content.settings-expanded .controls-section::-webkit-scrollbar-track {
        background: transparent;
    }

    .modal-content.settings-expanded .controls-section::-webkit-scrollbar-thumb {
        background: rgba(0, 0, 0, 0.2);
        border-radius: 3px;
    }

    .modal-content.settings-expanded .controls-section::-webkit-scrollbar-thumb:hover {
        background: rgba(0, 0, 0, 0.3);
    }

    /* Settings close button */
    .modal-content.settings-expanded .controls-section::before {
        content: "×";
        position: absolute;
        top: 15px;
        right: 20px;
        width: 32px;
        height: 32px;
        background: rgba(0, 0, 0, 0.1);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 20px;
        font-weight: bold;
        color: var(--text-secondary);
        cursor: pointer;
        transition: all 0.2s ease;
        z-index: 11;
    }

    .modal-content.settings-expanded .controls-section::before:hover {
        background: rgba(0, 0, 0, 0.2);
        transform: scale(1.1);
    }

    /* Scale card down when settings are expanded */
    .modal-content.settings-expanded #note-preview {
        transform: scale(1.2) translateY(-10vh);
        transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 5;
        position: relative;
    }

    /* Animation for settings fly-in */
    @keyframes settingsFlyIn {
        0% {
            transform: translateY(100%);
            opacity: 0.8;
        }
        100% {
            transform: translateY(0);
            opacity: 1;
        }
    }

    /* Animation for settings fly-out */
    @keyframes settingsFlyOut {
        0% {
            transform: translateY(0);
            opacity: 1;
        }
        100% {
            transform: translateY(100%);
            opacity: 0.8;
        }
    }

    /* Settings panel closing animation */
    .modal-content.settings-closing .controls-section {
        animation: settingsFlyOut 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    }

    /* Smooth transition back to normal size when settings close */
    #note-preview {
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* Dark theme support for settings panel */
    [data-theme="dark"] .modal-content.settings-expanded .controls-section {
        background: var(--bg-primary);
        box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.4);
    }

    [data-theme="dark"] .modal-content.settings-expanded .controls-section::before {
        background: rgba(255, 255, 255, 0.1);
        color: var(--text-secondary);
    }

    [data-theme="dark"] .modal-content.settings-expanded .controls-section::before:hover {
        background: rgba(255, 255, 255, 0.2);
    }

    /* Dark theme scrollbar */
    [data-theme="dark"] .modal-content.settings-expanded .controls-section {
        scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
    }

    [data-theme="dark"] .modal-content.settings-expanded .controls-section::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.3);
    }

    [data-theme="dark"] .modal-content.settings-expanded .controls-section::-webkit-scrollbar-thumb:hover {
        background: rgba(255, 255, 255, 0.4);
    }
    
    /* Remove individual scroll containers - make full panel scrollable */
    .modal-content.settings-expanded .colors-scroll-container,
    .modal-content.settings-expanded .images-scroll-container {
        max-height: none;
        overflow-y: visible;
        overflow-x: hidden;
    }

    .modal-content.settings-expanded .color-presets,
    .modal-content.settings-expanded .image-presets {
        display: grid;
    }

    /* Ensure all settings content is contained within the scrollable area */
    .modal-content.settings-expanded .tab-content {
        overflow: visible;
    }

    .modal-content.settings-expanded .tab-buttons {
        flex-shrink: 0; /* Keep tab buttons at top */
    }    /* Adjust modal body for single column on mobile */
    .modal-body {
        grid-template-columns: 1fr;
        padding: 16px 20px;
        overflow-y: visible; /* Remove scrolling from modal body */
        overflow-x: hidden;
        flex: 1;
    }
    
    /* Ensure modal body never scrolls, only settings panel should scroll */
    .modal-content .modal-body {
        overflow: visible;
    }
    
    /* Preview section takes full width */
    .preview-section {
        width: 100%;
        justify-content: center;
        padding: 20px 0 32px 0;
    }
    
    #note-preview {
        transform: scale(2.2); /* Good size for tablets */
        width: 240px;
        height: 240px;
    }
}

/* Specific styles for mobile phones (smaller screens) */
@media (max-width: 480px) {
    #note-preview {
        transform: scale(2.8); /* Much bigger for mobile phones */
        width: 240px;
        height: 240px;
    }
}

/* Continue with mobile styles for both tablet and phone */
@media (max-width: 768px) {
    /* Randomize button adjustments for mobile */
    .randomize-icon {
        padding: 4px 8px;
        font-size: 11px;
        bottom: -8px;
    }
    
    .randomize-icon .material-icons {
        font-size: 14px;
    }
    
    .color-presets {
        grid-template-columns: repeat(6, 1fr);
        gap: 10px;
    }
    
/* Enhanced touch targets for mobile */
    #note-preview .note-card {
        cursor: pointer !important;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    /* Make note text areas more touch-friendly */
    #note-preview .note-text,
    #note-preview .note-author {
        pointer-events: auto !important;
        cursor: text !important;
        -webkit-tap-highlight-color: rgba(0, 122, 204, 0.2);
        touch-action: manipulation;
        min-height: 40px; /* Better touch target */
    }
    
    /* Adjust text proportions for mobile scaling (1.8x scale) */
    #note-preview .note-text {
        /* Font size handled by JavaScript for adaptive scaling */
        line-height: 1.4; /* Maintain consistent line height */
    }
    
    #note-preview .note-author {
        font-size: 6.1px !important; /* Proportionally scaled for 1.8x: 11px / 1.8 ≈ 6.1px */
    }
    
    #note-preview .note-author-container {
        height: 6.7px; /* 12px / 1.8 ≈ 6.7px */
        bottom: 1.1px; /* 2px / 1.8 ≈ 1.1px */
    }    #note-preview .note-text.active,
    #note-preview .note-author.active {
        -webkit-tap-highlight-color: rgba(0, 122, 204, 0.3);
    }
    
    /* Better touch feedback */
    .note-card:active,
    .grid-item:active .note-card {
        opacity: 0.8;
        transition: opacity 0.1s ease;
    }
    
    /* Ensure text containers are clickable */
    #note-preview .note-text-container,
    #note-preview .note-author-container {
        pointer-events: auto !important;
        touch-action: manipulation;
    }
    
    /* Move randomize button down when settings are expanded */
    .modal-content.settings-expanded .randomize-icon {
        bottom: -28px;
    }
}

/* Landscape orientation - use same flyout styling as mobile/tablet */
@media (max-height: 768px) and (orientation: landscape) {
    /* Hide subtitle in landscape */
    .subtitle {
        display: none !important;
    }
    
    /* Modal transforms into bottom fly-in */
    .modal {
        align-items: flex-end;
        padding: 0;
    }
    
    .modal-content {
        width: 100vw;
        max-width: 100vw;
        height: 70vh;
        max-height: 70vh;
        border-radius: 20px 20px 0 0;
        margin: 0;
        bottom: 0;
        transform: translateY(100%);
        transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        animation: none;
        position: fixed;
    }
    
    .modal.show .modal-content {
        transform: translateY(0);
        opacity: 1;
    }
    
    /* Expanded state when settings are visible */
    .modal-content.settings-expanded {
        height: 100vh !important;
        max-height: 100vh !important;
    }
    
    /* Show settings toggle button */
    .modal-footer {
        display: flex;
        gap: 12px;
        padding: 16px 20px 20px;
        flex-direction: row-reverse;
    }
    
    .settings-toggle-btn {
        display: flex;
        flex: 0 0 auto;
        padding: 12px;
        width: 48px;
        min-width: 48px;
        justify-content: center;
        font-size: 0 !important;
    }
    
    .settings-toggle-btn .material-icons {
        font-size: 18px !important;
    }
    
    .save-btn {
        flex: 1;
    }
    
    /* Hide settings by default on landscape */
    .controls-section {
        display: none;
        padding: 20px;
        border-top: 1px solid var(--border-color);
        overflow-y: auto;
        overflow-x: hidden;
        background: var(--bg-secondary);
        animation: slideUpFadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        -webkit-overflow-scrolling: touch;
    }
    
    /* Show settings when expanded */
    .modal-content.settings-expanded .controls-section {
        display: flex;
        flex-direction: column;
        gap: 16px;
        overflow-y: auto;
        flex: 1;
        max-height: calc(100vh - 180px);
    }
    
    /* Remove individual scroll containers - make full panel scrollable */
    .colors-scroll-container,
    .images-scroll-container {
        max-height: none;
        overflow-y: visible;
    }
    
    /* Adjust modal body for single column on landscape */
    .modal-body {
        grid-template-columns: 1fr;
        padding: 16px 20px;
        overflow-y: auto;
        flex: 1;
    }
    
    /* Preview section takes full width */
    .preview-section {
        width: 100%;
        justify-content: center;
        padding: 16px 0 28px 0;
    }
    
    #note-preview {
        transform: scale(1.4);
        width: 240px;
        height: 240px;
    }
    
    /* Adjust text proportions for landscape scaling (1.4x scale) */
    #note-preview .note-author {
        font-size: 7.86px !important; /* 11px / 1.4 ≈ 7.86px */
    }
    
    #note-preview .note-author-container {
        height: 8.57px; /* 12px / 1.4 ≈ 8.57px */
        bottom: 1.43px; /* 2px / 1.4 ≈ 1.43px */
    }
    
    /* Randomize button adjustments for landscape */
    .randomize-icon {
        padding: 5px 10px;
        font-size: 11px;
        bottom: -8px;
    }
    
    .randomize-icon .material-icons {
        font-size: 14px;
    }
    
    .color-presets {
        grid-template-columns: repeat(6, 1fr);
        gap: 10px;
    }
    
    /* Move randomize button down when settings are expanded in landscape */
    .modal-content.settings-expanded .randomize-icon {
        bottom: -28px;
    }
}

/* Tablet-specific adjustments */
@media (max-width: 768px) and (min-width: 481px) {
    .floating-btn {
        bottom: 30px;
        right: 30px;
    }
    
    #note-preview {
        transform: scale(1.4);
    }
    
    /* Adjust text proportions for tablet scaling (1.4x scale) */
    #note-preview .note-author {
        font-size: 7.86px !important; /* 11px / 1.4 ≈ 7.86px */
    }
    
    #note-preview .note-author-container {
        height: 8.57px; /* 12px / 1.4 ≈ 8.57px */
        bottom: 1.43px; /* 2px / 1.4 ≈ 1.43px */
    }
}

/* Desktop: Ensure settings are always visible and toggle button hidden */
@media (min-width: 769px) {
    .settings-toggle-btn {
        display: none !important;
    }
    
    .controls-section {
        display: flex !important;
        flex-direction: column;
    }
    
    .modal-content {
        animation: modalContentSlideIn 0.4s ease-out 0.1s forwards;
    }
}

@media (min-width: 1200px) {
    .modal-content {
        max-width: 900px;
    }
    
    #note-preview {
        transform: scale(2.0);
    }
    
    /* Text proportions are now handled by JavaScript for better scaling */
    
    #note-preview .note-author-container {
        height: 6px; /* 12px / 2.0 = 6px */
        bottom: 1px; /* 2px / 2.0 = 1px */
    }
    
    .preview-section {
        min-height: 400px;
        padding: 30px 0 50px 0;
    }
    
    /* Compact randomize button for desktop */
    .randomize-icon {
        padding: 6px 12px;
        font-size: 12px;
        bottom: 0px;
    }
    
    .randomize-icon .material-icons {
        font-size: 16px;
    }
}

/* Confirmation Modal Mobile & Tablet Responsive */
@media (max-width: 768px) {
    /* Make confirmation modal behave like main modal on mobile */
    #confirm-modal {
        align-items: flex-end;
        padding: 0;
    }
    
    .confirm-modal-content {
        width: 100vw;
        max-width: 100vw;
        height: auto;
        min-height: 300px;
        max-height: 60vh;
        border-radius: 20px 20px 0 0;
        margin: 0;
        bottom: 0;
        transform: translateY(100%);
        animation: none;
        transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        position: fixed;
    }
    
    #confirm-modal.active .confirm-modal-content {
        transform: translateY(0);
        opacity: 1;
    }
    
    .confirm-modal-content .modal-header {
        padding: 24px 28px 20px;
    }
    
    .confirm-modal-content .modal-header h2 {
        font-size: 20px;
    }
    
    .confirm-modal-body {
        padding: 20px 28px 28px;
    }
    
    .confirm-modal-body p {
        font-size: 16px;
        line-height: 1.5;
    }
    
    .confirm-buttons button {
        padding: 13px;
    }
}

/* Mobile zoom and touch optimizations */
@media (max-width: 768px) {
    #grid-container {
        /* Enhanced mobile touch performance */
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
        -webkit-perspective: 1000px;
        perspective: 1000px;
        /* Better touch gesture handling - prevent default zoom */
        touch-action: none;
        -webkit-user-select: none;
        user-select: none;
    }
    
    #grid {
        /* Improve mobile rendering performance */
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        will-change: transform;
        /* Ensure proper touch event handling */
        pointer-events: auto;
    }
    
    .note-card {
        /* Better mobile touch targets */
        min-height: 44px; /* iOS minimum touch target */
        min-width: 44px;
        /* Improve mobile performance */
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
        /* Prevent touch conflicts */
        touch-action: manipulation;
    }
    
    /* Improve mobile gesture recognition */
    .note-card:hover {
        /* Reduce hover effects on mobile for better performance */
        transform: none !important;
        box-shadow: none !important;
    }
    
    /* Enhanced touch feedback for action buttons on mobile */
    .action-btn {
        min-height: 44px;
        min-width: 44px;
        touch-action: manipulation;
    }
}

/* High DPI mobile displays optimization */
@media (max-width: 768px) and (-webkit-min-device-pixel-ratio: 2) {
    #grid {
        /* Optimize for high DPI mobile screens */
        image-rendering: -webkit-optimize-contrast;
        image-rendering: optimize-contrast;
    }
}
@media (max-width: 480px) {
    .welcome-content {
        padding: 1.5rem 1rem;
        border-radius: 15px;
    }
    
    .welcome-title {
        font-size: 1.8rem;
        margin-bottom: 0.8rem;
    }
    
    .welcome-message {
        font-size: 0.9rem;
        line-height: 1.5;
        margin-bottom: 1.5rem;
    }
    
    .welcome-btn {
        padding: 14px 24px;
        font-size: 14px;
    }
    
    /* Mobile modal adjustments - keep fly-in behavior from 768px */
    .modal {
        padding: 0; /* Remove padding for full-width fly-in */
    }
    
    .modal-content {
        max-height: 75vh; /* Increased initial height for better mobile experience */
        border-radius: 16px 16px 0 0; /* Rounded top corners only */
    }
    
    .modal-content.settings-expanded {
        max-height: 90vh !important;
    }
    
    .modal-header {
        padding: 16px 20px 12px;
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .header-right {
        width: 100%;
        justify-content: space-between;
    }
    
    .header-content h2 {
        font-size: 18px;
    }
    
    .subtitle {
        display: none !important; /* Keep hidden on smaller mobile too */
    }
    
    .modal-body {
        padding: 0 20px;
        gap: 16px;
    }
    
    .preview-section {
        padding: 12px 0 24px 0;
    }
    
    #note-preview {
        transform: scale(1.7); /* Increased from 1.0 to make card bigger on small mobile */
        width: 200px;
        height: 200px;
    }
    
    /* For 1.2x scale, adjust text proportions */
    #note-preview .note-author {
        font-size: 9.2px !important; /* Proportionally scaled for 1.2x: 11px / 1.2 ≈ 9.2px */
    }
    
    #note-preview .note-author-container {
        height: 10px; /* 12px / 1.2 = 10px */
        bottom: 1.67px; /* 2px / 1.2 ≈ 1.67px */
    }
    
    #note-preview .note-author-container {
        height: 12px; 
        bottom: 2px; 
    }
    
    /* Smaller randomize button for smaller screens */
    .randomize-icon {
        padding: 5px 10px;
        font-size: 11px;
        bottom: 0px;
    }
    
    .randomize-icon .material-icons {
        font-size: 14px;
    }
    
    .controls-section {
        gap: 14px;
    }
    
    .color-presets {
        grid-template-columns: repeat(4, 1fr);
        gap: 6px;
    }
    
    .modal-footer {
        padding: 14px 20px 16px;
        display: flex;
        gap: 10px;
    }
    
    .settings-toggle-btn {
        padding: 10px 12px;
        font-size: 13px;
    }
    
    .save-btn {
        padding: 12px;
        font-size: 15px;
        flex: 1;
    }
    
    .floating-btn {
        width: 50px;
        height: 50px;
        font-size: 20px;
        bottom: 80px; /* Above CRE8NOW branding */
        right: 15px;
    }
    
    .theme-toggle {
        width: 45px;
        height: 45px;
        top: 15px;
        right: 15px;
    }
    
    .zoom-info {
        bottom: 15px;
        left: 15px;
        padding: 8px 12px;
        font-size: 11px;
    }
    
    /* Confirmation Modal Mobile Styles - Override for smaller screens */
    .confirm-modal-content .modal-header h2 {
        font-size: 18px;
    }
    
    .confirm-modal-body p {
        font-size: 15px;
    }
    
    .confirm-buttons button {
        padding: 14px;
        font-size: 14px;
    }
    
    .cre8now-branding {
        bottom: 10px;
        padding: 6px 10px;
        font-size: 10px;
    }
    
    /* Ensure touch targets are large enough */
    .note-card {
        min-height: 44px; /* iOS minimum touch target */
    }
    
    .color-preset,
    .font-option {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Zoom Controls */
.zoom-info {
    position: fixed;
    bottom: 20px;
    left: 20px;
    background: var(--bg-secondary);
    padding: 10px 15px;
    border-radius: 8px;
    font-size: 12px;
    color: var(--text-secondary);
    backdrop-filter: blur(10px);
    z-index: 1000;
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 10px var(--shadow-color);
}

/* Floating Bottom Controls */
.floating-bottom-controls {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 1000;
}

/* Sound Toggle (top bar) */
.sound-toggle {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px var(--shadow-color);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
}
.sound-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-color);
    background: var(--bg-primary);
    color: var(--text-primary);
}
.sound-toggle .material-icons { font-size: 18px; }

/* Floating Theme Toggle */
.floating-theme-toggle {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px var(--shadow-color);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
}

.floating-theme-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-color);
    background: var(--bg-primary);
    color: var(--text-primary);
}

.floating-theme-toggle .material-icons {
    font-size: 18px;
}

/* Sound button active (playing) state */
.floating-theme-toggle.sound-active {
    background: #007acc;
    color: #ffffff;
    border-color: #007acc;
}

.floating-theme-toggle.sound-active:hover {
    background: #005a9e;
    border-color: #005a9e;
    color: #ffffff;
    transform: translateY(-2px);
}

/* Animated equalizer: shown only while the music is actually playing */
.sound-eq {
    display: none;
    align-items: flex-end;
    justify-content: center;
    gap: 2px;
    width: 18px;
    height: 14px;
}
.sound-eq i {
    display: block;
    width: 3px;
    height: 100%;
    border-radius: 1.5px;
    background: currentColor;
    transform-origin: bottom;
    animation: sound-eq 1s ease-in-out infinite;
}
.sound-eq i:nth-child(1) { animation-duration: .9s;  animation-delay: -.2s; }
.sound-eq i:nth-child(2) { animation-duration: .7s;  animation-delay: -.5s; }
.sound-eq i:nth-child(3) { animation-duration: 1.1s; animation-delay: -.1s; }
.sound-eq i:nth-child(4) { animation-duration: .8s;  animation-delay: -.35s; }
@keyframes sound-eq {
    0%, 100% { transform: scaleY(.25); }
    50%      { transform: scaleY(1); }
}
.floating-theme-toggle .sound-eq { margin-left: 0; }
.floating-theme-toggle.is-playing .sound-eq { display: flex; }
.floating-theme-toggle.is-playing .floating-sound-icon { display: none; }
@media (prefers-reduced-motion: reduce) {
    .sound-eq i { animation: none; transform: scaleY(.6); }
    .sound-eq i:nth-child(even) { transform: scaleY(1); }
}

/* Card Counter */
.card-counter {
    background: var(--bg-secondary);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 8px var(--shadow-color);
    transition: all 0.3s ease;
    font-weight: 500;
}

.card-counter:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-color);
}

#card-count {
    font-weight: 600;
    color: var(--text-primary);
}

/* Mobile responsiveness for floating controls */
@media (max-width: 768px) {
    /* Create a mobile bottom bar container */
    body::after {
        content: '';
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 50px;
        background: transparent;
        pointer-events: none;
        z-index: 999;
    }
    
    /* Zoom info on the left */
    .zoom-info {
        position: fixed;
        bottom: 15px;
        left: 15px;
        transform: none;
        padding: 6px 8px;
        font-size: 11px;
        min-width: auto;
    }
    
    /* CRE8NOW branding in the center */
    .cre8now-branding {
        position: fixed;

        left: 50%;
        transform: translateX(-50%);
        padding: 6px 8px;
        font-size: 10px;
        white-space: nowrap;
    }
    
    /* Floating controls on the right */
    .floating-bottom-controls {
        position: fixed;
        bottom: 15px;
        right: 15px;
        display: flex;
        align-items: center;
        gap: 6px;
        flex-direction: row-reverse; /* Put card counter closer to center */
    }
    
    .floating-theme-toggle {
        width: 30px;
        height: 30px;
        padding: 6px;
        flex-shrink: 0;
    }
    
    .floating-theme-toggle .material-icons {
        font-size: 16px;
    }
    
    .card-counter {
        padding: 6px 8px;
        font-size: 11px;
        white-space: nowrap;
        min-width: auto;
    }
    
    /* Show/hide branding text based on screen size - Higher specificity */
    .cre8now-branding .branding-text-desktop {
        display: none !important;
    }
    
    .cre8now-branding .branding-text-mobile {
        display: inline !important;
        margin-right: 4px;
    }
    
    /* Ensure proper spacing and alignment */
    .zoom-info,
    .cre8now-branding,
    .card-counter {
        height: 30px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Smaller screens adjustments */
    @media (max-width: 480px) {
        .zoom-info {
            left: 8px;
            bottom: 10px;
            padding: 4px 6px;
            font-size: 10px;
        }
        
        .cre8now-branding {

            padding: 4px 6px;
            font-size: 9px;
        }
        
        .floating-bottom-controls {
            right: 8px;
            bottom: 10px;
            gap: 4px;
        }
        
        .card-counter {
            padding: 4px 6px;
            font-size: 10px;
        }
        
        .floating-theme-toggle {
            width: 28px;
            height: 28px;
            padding: 4px;
        }
        
        .floating-theme-toggle .material-icons {
            font-size: 14px;
        }
        
        /* Ensure all bottom elements have consistent height */
        .zoom-info,
        .cre8now-branding,
        .card-counter {
            height: 28px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        /* Ensure branding text is correct on smaller screens too */
        .cre8now-branding .branding-text-desktop {
            display: none !important;
        }
        
        .cre8now-branding .branding-text-mobile {
            display: inline !important;
        }
    }
}

/* CRE8NOW Branding */
.cre8now-branding {
    position: fixed;
bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-secondary);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 11px;
    color: var(--text-secondary);
    backdrop-filter: blur(10px);
    z-index: 1000;
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 8px var(--shadow-color);
    transition: all 0.3s ease;
}

/* Branding text responsive display - Desktop first */
.branding-text-desktop {
    display: inline;
}

.branding-text-mobile {
    display: none;
}

.cre8now-branding:hover {
    transform: translateX(-50%) translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-color);
}

.cre8now-branding a {
    color: #007acc;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

.cre8now-branding a:hover {
    color: #005a9e;
    text-decoration: underline;
}

[data-theme="dark"] .cre8now-branding a {
    color: #4fb3f4;
}

[data-theme="dark"] .cre8now-branding a:hover {
    color: #6bc1f7;
}

/* Slideshow Indicator */
#slideshow-indicator {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 0;
    border-radius: 50%;
    z-index: 10000;
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(0, 0, 0, 0.1);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#slideshow-indicator.slideshow-toggle {
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

#slideshow-indicator.slideshow-toggle:active {
    transform: translateX(-50%) translateY(0) scale(0.95);
}

#slideshow-indicator.active {
    transform: translateX(-50%) translateY(0);
}

.slideshow-content {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #1a1a1a;
    font-size: 13px;
    font-weight: 500;
    width: 100%;
    height: 100%;
}

.slideshow-icon {
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse 2s infinite;
    transition: transform 0.2s ease;
    line-height: 1;
    margin: 0;
    padding: 0;
}

#slideshow-indicator.slideshow-toggle .slideshow-icon {
    animation: none; /* Disable pulse animation for cleaner toggle */
    transition: all 0.2s ease; /* Smooth transition for icon changes */
}

/* Accent color for stop icon when slideshow is active */
#slideshow-indicator.slideshow-toggle .slideshow-icon.stop {
    color: #ffffff;
}

#slideshow-indicator.slideshow-toggle:hover .slideshow-icon.stop {
    color: #ffffff;
}

[data-theme="dark"] #slideshow-indicator.slideshow-toggle .slideshow-icon.stop {
    color: #ffffff;
}

[data-theme="dark"] #slideshow-indicator.slideshow-toggle:hover .slideshow-icon.stop {
    color: #ffffff;
}

/* Active (playing) state: accent background */
#slideshow-indicator.slideshow-toggle.playing {
    background: #007acc;
    border-color: #007acc;
}

#slideshow-indicator.slideshow-toggle.playing:hover {
    background: #005a9e;
    border-color: #005a9e;
}

.slideshow-instruction {
    display: none;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

/* Dark theme adjustments for slideshow indicator */
[data-theme="dark"] #slideshow-indicator {
    background: rgba(30, 30, 30, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .slideshow-content {
    color: #f0f0f0;
}

[data-theme="dark"] .slideshow-instruction {
    opacity: 0.7;
}
/* ==========================================================================
   UI REFRESH — gallery-style grid, softer chrome, readable image cards.
   Self-contained layer: delete this block to revert to the previous look.
   ========================================================================== */
:root {
    --canvas: #eef0f3;
    --tile: rgba(15, 23, 42, 0.035);
    --tile-hover: rgba(15, 23, 42, 0.07);
    --tile-ink: rgba(15, 23, 42, 0.28);
    --card-radius: 14px;
    --card-inset: 6px;
    --card-shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 6px 16px -6px rgba(15, 23, 42, 0.18);
    --card-shadow-hover: 0 2px 4px rgba(15, 23, 42, 0.08), 0 14px 28px -10px rgba(15, 23, 42, 0.28);
    --glass-bg: rgba(255, 255, 255, 0.72);
    --glass-border: rgba(15, 23, 42, 0.08);
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

[data-theme="dark"] {
    --canvas: #111214;
    --tile: rgba(255, 255, 255, 0.035);
    --tile-hover: rgba(255, 255, 255, 0.07);
    --tile-ink: rgba(255, 255, 255, 0.3);
    --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 20px -8px rgba(0, 0, 0, 0.6);
    --card-shadow-hover: 0 2px 4px rgba(0, 0, 0, 0.5), 0 16px 32px -10px rgba(0, 0, 0, 0.75);
    --glass-bg: rgba(28, 29, 32, 0.72);
    --glass-border: rgba(255, 255, 255, 0.08);
}

/* Canvas behind the grid */
body,
#grid-container {
    background: var(--canvas);
}

/* Cells become invisible slots — no more spreadsheet lines */
#grid .grid-item,
#grid .grid-item.empty,
#grid .grid-item.empty:hover {
    border: none;
    background: transparent;
}

/* Empty slot: a quiet rounded tile, details revealed on hover */
#grid .grid-item.empty::after {
    content: '';
    position: absolute;
    inset: var(--card-inset);
    border-radius: var(--card-radius);
    background: var(--tile);
    transition: background-color 0.2s ease;
}

#grid .grid-item.empty:hover::after {
    background: var(--tile-hover);
}

#grid .grid-item.empty::before {
    position: relative;
    z-index: 1;
    font-size: 56px;
    color: var(--tile-ink);
    opacity: 0;
    transform: scale(0.85);
    transition: opacity 0.2s ease, transform 0.25s var(--ease-out);
}

#grid .grid-item.empty:hover::before {
    color: var(--tile-ink);
    opacity: 1;
    transform: scale(1);
}

#grid .grid-item.empty .grid-number {
    z-index: 1;
    bottom: calc(var(--card-inset) + 6px);
    right: calc(var(--card-inset) + 10px);
    color: var(--tile-ink);
    opacity: 0;
}

#grid .grid-item.empty:hover .grid-number {
    color: var(--tile-ink);
    opacity: 1;
}

/* Cards: inset, rounded, softly lifted */
#grid .grid-item > .note-card {
    width: calc(100% - 2 * var(--card-inset));
    height: calc(100% - 2 * var(--card-inset));
    margin: var(--card-inset);
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow);
    transition: transform 0.25s var(--ease-out), box-shadow 0.25s var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
    #grid .grid-item:hover > .note-card:not(.preview-card) {
        transform: translateY(-2px);
        box-shadow: var(--card-shadow-hover);
    }
}

/* Image cards: text shadow keeps text readable on busy art (no radial scrim) */

.note-card.has-image .note-text {
    text-shadow: 0 1px 12px rgba(255, 255, 255, 0.6);
}

.note-card.has-image.ink-light .note-text {
    text-shadow: 0 1px 10px rgba(0, 0, 0, 0.45);
}

/* Card actions: small frosted circles */
#grid .card-actions {
    top: 10px;
    right: 10px;
    gap: 6px;
    z-index: 3;
}

/* !important: these buttons receive inline styles from createActionButton() */
#grid .action-btn {
    width: 32px !important;
    height: 32px !important;
    padding: 0 !important;
    justify-content: center !important;
    border-radius: 999px !important;
    background: var(--glass-bg) !important;
    border: 1px solid var(--glass-border) !important;
    color: var(--text-primary) !important;
    -webkit-backdrop-filter: blur(12px) saturate(1.4) !important;
    backdrop-filter: blur(12px) saturate(1.4) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12) !important;
    transition: transform 0.15s var(--ease-out), background-color 0.15s ease !important;
}

#grid .action-btn:hover {
    background: var(--bg-secondary) !important;
    transform: scale(1.06) !important;
}

#grid .action-btn:active {
    transform: scale(0.94) !important;
}

/* Floating chrome: matching glass treatment */
.floating-theme-toggle,
.card-counter,
.cre8now-branding {
    background: var(--glass-bg) !important;
    border: 1px solid var(--glass-border) !important;
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    backdrop-filter: blur(16px) saturate(1.4);
    box-shadow: 0 4px 16px -4px rgba(0, 0, 0, 0.15) !important;
}

.cre8now-branding {
    border-radius: 999px;
}

/* Desktop: zoom pill + branding sit side by side in the bottom-left corner */
@media (min-width: 769px) {
    .zoom-info {
        min-width: 112px;
        height: 32px;
        padding: 0 12px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 999px;
        background: var(--glass-bg);
        border: 1px solid var(--glass-border);
        -webkit-backdrop-filter: blur(16px) saturate(1.4);
        backdrop-filter: blur(16px) saturate(1.4);
        box-shadow: 0 4px 16px -4px rgba(0, 0, 0, 0.15);
        font-variant-numeric: tabular-nums;
    }

    .cre8now-branding {
        left: 140px; /* 20px gutter + 112px zoom pill + 8px gap */
        bottom: 20px;
        height: 32px;
        display: flex;
        align-items: center;
        transform: none;
        padding: 0 12px;
    }

    .cre8now-branding:hover {
        transform: translateY(-1px);
    }
}

/* Modal header: keep the title clear of the absolutely positioned close button */
.modal-header {
    padding-right: 76px;
}

@media (max-width: 768px) {
    .modal-header {
        padding-right: 68px;
    }
}

/* Respect the OS "reduce motion" setting */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ---------- UI REFRESH: editor ---------- */
.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Font picker: two-row horizontal scroller of chips rendered in their own font */
.font-chips {
    display: grid;
    grid-auto-flow: column;
    grid-template-rows: repeat(2, auto);
    gap: 6px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    padding: 2px 2px 8px;
    margin: 0 -2px;
    scrollbar-width: thin;
    -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent);
    mask-image: linear-gradient(90deg, #000 85%, transparent);
}

.font-chip {
    scroll-snap-align: start;
    white-space: nowrap;
    padding: 7px 12px;
    font-size: 14px;
    line-height: 1.2;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s var(--ease-out);
}

.font-chip:hover {
    border-color: var(--text-secondary);
}

.font-chip:active {
    transform: scale(0.96);
}

.font-chip.active {
    background: var(--text-primary);
    border-color: var(--text-primary);
    color: var(--bg-secondary);
}

.font-chip:focus-visible {
    outline: 2px solid #007acc;
    outline-offset: 2px;
}

/* Editor preview: rounded like the grid cards */
#note-preview {
    border-radius: 10px;
    border-color: transparent;
}

/* Desktop: give the scaled preview real room so Randomize sits below it, not on it */
@media (min-width: 769px) {
    .modal-content { --preview-scale: 1.4; }

    .preview-section {
        flex-direction: column;
        gap: 14px;
        padding: 0;
    }

    /* transform: scale() doesn't affect layout, so reserve the overflow as margin */
    #note-preview {
        transform: scale(var(--preview-scale));
        margin: calc(120px * (var(--preview-scale) - 1)) 0;
    }

    .randomize-icon {
        position: static;
        transform: none;
        border-radius: 999px;
        padding: 7px 14px;
    }

    .randomize-icon:hover {
        transform: translateY(-1px);
    }
}

/* Save button: calm empty state, confident ready state */
.save-btn {
    border-radius: 14px;
    transition: background-color 0.25s ease, color 0.25s ease, box-shadow 0.25s ease, transform 0.15s var(--ease-out);
}

.save-btn:not(:disabled) {
    background: var(--brand, #007acc);
    box-shadow: 0 6px 18px -8px rgba(0, 122, 204, 0.6);
}

.save-btn:not(:disabled):active {
    transform: scale(0.98);
}

[data-theme] .save-btn:disabled {
    background: var(--tile-hover);
    color: var(--text-secondary);
    box-shadow: none;
}

/* Editor entrance: rise in with a soft spring */
@keyframes refreshModalIn {
    from { opacity: 0; transform: translateY(16px) scale(0.97); }
    to   { opacity: 1; transform: none; }
}

#modal.active:not(.closing) .modal-content {
    animation: refreshModalIn 0.45s var(--ease-out) forwards;
}

/* ---------- Desktop font menu (mobile keeps the chip row) ---------- */
.font-menu { display: none; position: relative; }

@media (min-width: 769px) {
    .font-chips { display: none; }
    .font-menu { display: block; }
}

.font-menu-trigger {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.font-menu-trigger:hover { border-color: var(--text-secondary); }

.font-menu.open .font-menu-trigger,
.font-menu-trigger:focus-visible {
    outline: none;
    border-color: #007acc;
    box-shadow: 0 0 0 3px rgba(0, 122, 204, 0.15);
}

.font-menu-label {
    font: 500 11px/1 'Inter', sans-serif;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.font-menu-current {
    flex: 1;
    font-size: 17px;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: right;
}

.font-menu-chevron {
    font-size: 20px !important;
    color: var(--text-secondary);
    transition: transform 0.2s var(--ease-out);
}

.font-menu.open .font-menu-chevron { transform: rotate(180deg); }

.font-menu-popover {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    max-height: min(360px, 52vh);
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    background: var(--bg-secondary);
    box-shadow: 0 18px 40px -12px rgba(15, 23, 42, 0.35), 0 2px 6px rgba(15, 23, 42, 0.08);
    overflow: hidden;
    transform-origin: top center;
    animation: fontMenuIn 0.18s var(--ease-out);
}

.font-menu-popover[hidden] { display: none; }

@keyframes fontMenuIn {
    from { opacity: 0; transform: translateY(-4px) scale(0.98); }
    to   { opacity: 1; transform: none; }
}

.font-menu-search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.font-menu-search .material-icons { font-size: 18px; }

.font-menu-search input {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-primary);
    font: 400 14px 'Inter', sans-serif;
    user-select: text;
    -webkit-user-select: text;
}

.font-menu-list {
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 4px 6px 8px;
}

.font-menu-group[hidden],
.font-menu-item[hidden] { display: none; }

.font-menu-group-title {
    position: sticky;
    top: -4px;
    padding: 10px 8px 4px;
    font: 600 10px/1 'Inter', sans-serif;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-secondary);
    background: var(--bg-secondary);
}

.font-menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 8px 10px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-primary);
    font-size: 17px;
    line-height: 1.25;
    text-align: left;
    cursor: pointer;
}

.font-menu-item:hover,
.font-menu-item:focus-visible {
    outline: none;
    background: var(--tile-hover);
}

.font-menu-item.active::after {
    content: 'check';
    font-family: 'Material Icons';
    font-size: 18px;
    color: #007acc;
}

/* ---------- Short desktop/laptop screens (e.g. 1366×768) ----------
   The landscape bottom-sheet editor is meant for touch devices. With a mouse and
   enough width, keep the regular centered two-column editor instead. */
@media (min-width: 769px) and (max-height: 768px) and (orientation: landscape) and (hover: hover) and (pointer: fine) {
    .modal {
        align-items: center;
        padding: 16px;
    }

    .modal-content {
        position: relative;
        width: 100%;
        max-width: 860px;
        height: calc(100vh - 32px);
        max-height: 700px;
        border-radius: 20px;
        transform: none;
        transition: none;
    }

    .modal-body {
        grid-template-columns: 1fr 280px;
        overflow: hidden;
        padding: 12px 28px;
    }

    .preview-section { padding: 0; }

    .controls-section {
        border-top: none;
        padding: 8px 0 16px;
        background: transparent;
        animation: none;
    }

    .modal-footer {
        display: block;
        padding: 16px 28px 20px;
    }

    .colors-scroll-container,
    .images-scroll-container {
        max-height: none;
        overflow-y: auto;
    }
}

/* Two-column editor: keep the row as tall as the body so the preview centers in view */
@media (min-width: 769px) and (min-height: 769px),
       (min-width: 769px) and (hover: hover) and (pointer: fine) {
    .modal-body { grid-template-rows: minmax(0, 1fr); }
}

/* ==========================================================================
   UI REFRESH: INTRO — loader, card ripple, welcome card
   ========================================================================== */
:root {
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --brand: #007acc;
    --brand-2: #6d5dfc;
    --brand-3: #ff5c8a;
}

/* ---------- Page loader ---------- */
.page-loader {
    background: var(--canvas);
    transition: none;
    animation: pageLoaderFadeIn 0.4s ease-out forwards;
}

.page-loader.fade-out {
    animation: loaderExit 0.7s cubic-bezier(0.65, 0, 0.35, 1) forwards;
}

@keyframes loaderExit {
    0%   { opacity: 1; transform: scale(1); filter: blur(0); }
    100% { opacity: 0; transform: scale(1.08); filter: blur(12px); }
}

.page-loader .loader-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 22px;
    transform: none;
}

.loader-grid {
    display: grid;
    grid-template-columns: repeat(3, 22px);
    gap: 6px;
}

.loader-grid span {
    width: 22px;
    height: 22px;
    border-radius: 7px;
    background: var(--tile-hover);
    opacity: 0;
    transform: scale(0.4);
    animation:
        loaderTileIn 0.5s var(--ease-spring) forwards,
        loaderTileWave 1.8s ease-in-out 0.9s infinite;
}

/* Diagonal assemble: delay by (row + column) */
.loader-grid span:nth-child(1) { animation-delay: 0s, 0.9s; background: #3b82f6; }
.loader-grid span:nth-child(2) { animation-delay: 0.07s, 0.97s; background: #ec4899; }
.loader-grid span:nth-child(4) { animation-delay: 0.07s, 0.97s; background: #06b6d4; }
.loader-grid span:nth-child(3) { animation-delay: 0.14s, 1.04s; background: #10b981; }
.loader-grid span:nth-child(5) { animation-delay: 0.14s, 1.04s; }
.loader-grid span:nth-child(7) { animation-delay: 0.14s, 1.04s; background: #f59e0b; }
.loader-grid span:nth-child(6) { animation-delay: 0.21s, 1.11s; background: #8b5cf6; }
.loader-grid span:nth-child(8) { animation-delay: 0.21s, 1.11s; background: #ef4444; }
.loader-grid span:nth-child(9) { animation-delay: 0.28s, 1.18s; background: #f97316; }

/* The center tile is "yours": an empty slot that keeps inviting */
.loader-grid .loader-you {
    background: transparent;
    box-shadow: inset 0 0 0 2px var(--brand);
    animation:
        loaderTileIn 0.5s var(--ease-spring) 0.14s forwards,
        loaderYou 1.4s ease-in-out 0.8s infinite;
}

@keyframes loaderTileIn {
    to { opacity: 1; transform: scale(1); }
}

@keyframes loaderTileWave {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(0.82); }
}

@keyframes loaderYou {
    0%, 100% { transform: scale(1); box-shadow: inset 0 0 0 2px var(--brand), 0 0 0 0 rgba(0, 122, 204, 0.35); }
    50%      { transform: scale(1.08); box-shadow: inset 0 0 0 2px var(--brand), 0 0 0 8px rgba(0, 122, 204, 0); }
}

.page-loader .loader-text {
    align-items: center;
    gap: 6px;
    opacity: 0;
    animation: introRise 0.6s var(--ease-out) 0.35s forwards;
}

.page-loader .loader-title {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.03em;
}

.page-loader .loader-subtitle {
    font-size: 14px;
}

.loader-progress {
    width: 120px;
    height: 3px;
    border-radius: 999px;
    background: var(--tile-hover);
    overflow: hidden;
    opacity: 0;
    animation: introRise 0.6s var(--ease-out) 0.5s forwards;
}

.loader-progress span {
    display: block;
    width: 40%;
    height: 100%;
    border-radius: inherit;
    background: var(--text-primary);
    opacity: 0.7;
    animation: loaderBar 1.2s ease-in-out infinite;
}

@keyframes loaderBar {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(250%); }
}

@keyframes introRise {
    from { opacity: 0; transform: translateY(10px); filter: blur(4px); }
    to   { opacity: 1; transform: none; filter: blur(0); }
}

/* ---------- Card ripple ("dealt" from the center) ---------- */
body.intro-pending #grid .grid-item > .note-card,
body.intro-pending #grid .grid-item.empty::after {
    opacity: 0;
}

#grid .grid-item.intro-in > .note-card {
    animation: introCardIn 0.75s var(--ease-spring) var(--intro-delay, 0ms) both;
}

#grid .grid-item.intro-in.empty::after {
    animation: introTileIn 0.6s var(--ease-out) var(--intro-delay, 0ms) both;
}

@keyframes introCardIn {
    0%   { opacity: 0; transform: translateY(26px) scale(0.82) rotate(var(--intro-tilt, 0deg)); }
    55%  { opacity: 1; }
    100% { opacity: 1; transform: none; }
}

@keyframes introTileIn {
    from { opacity: 0; transform: scale(0.7); }
    to   { opacity: 1; transform: none; }
}

/* ---------- Welcome overlay ---------- */
.welcome-overlay {
    background: rgba(238, 240, 243, 0.4);
    -webkit-backdrop-filter: blur(14px) saturate(1.2);
    backdrop-filter: blur(14px) saturate(1.2);
    padding: 24px 16px;
    animation: welcomeBackdropIn 0.9s ease-out both;
}

[data-theme="dark"] .welcome-overlay {
    background: rgba(10, 11, 13, 0.5);
}

@keyframes welcomeBackdropIn {
    from { opacity: 0; -webkit-backdrop-filter: blur(0); backdrop-filter: blur(0); }
}

.welcome-content {
    max-width: 600px;
    padding: 40px 48px 28px;
    border-radius: 28px;
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.82);
    border: 1px solid rgba(255, 255, 255, 0.7);
    -webkit-backdrop-filter: blur(24px) saturate(1.5);
    backdrop-filter: blur(24px) saturate(1.5);
    box-shadow:
        0 1px 0 rgba(255, 255, 255, 0.8) inset,
        0 30px 80px -20px rgba(15, 23, 42, 0.35),
        0 8px 24px -8px rgba(15, 23, 42, 0.15);
    overflow: visible;
    animation: welcomeCardIn 0.9s var(--ease-spring) 0.15s both;
}

[data-theme="dark"] .welcome-content {
    background: rgba(28, 29, 33, 0.82);
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow:
        0 1px 0 rgba(255, 255, 255, 0.06) inset,
        0 30px 80px -20px rgba(0, 0, 0, 0.7);
}

/* Drop the old decorative play icon */
.welcome-content::before { content: none; }

@keyframes welcomeCardIn {
    from { opacity: 0; transform: translateY(28px) scale(0.94); }
    to   { opacity: 1; transform: none; }
}

/* Staggered entrance of everything inside */
.welcome-content > * {
    animation: introRise 0.7s var(--ease-out) both;
}
.welcome-content > :nth-child(1) { animation-delay: 0.30s; }
.welcome-content > :nth-child(2) { animation-delay: 0.42s; }
.welcome-content > :nth-child(3) { animation-delay: 0.50s; }
.welcome-content > :nth-child(4) { animation-delay: 0.58s; }
.welcome-content > :nth-child(5) { animation-delay: 0.66s; }
.welcome-content > :nth-child(6) { animation-delay: 0.74s; }
.welcome-content > :nth-child(7) { animation-delay: 0.82s; }

/* Fanned postcards floating above the title */
.welcome-cards {
    position: relative;
    height: 92px;
    margin: -78px auto 14px;
    width: 220px;
}

.welcome-card {
    position: absolute;
    top: 0;
    left: 50%;
    width: 82px;
    height: 82px;
    margin-left: -41px;
    border-radius: 14px;
    box-shadow: 0 14px 30px -10px rgba(15, 23, 42, 0.45);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    animation: welcomeCardFloat 5s ease-in-out infinite;
}

.welcome-card i {
    display: block;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.85);
}
.welcome-card i:nth-child(1) { width: 52%; }
.welcome-card i:nth-child(2) { width: 38%; }
.welcome-card i:nth-child(3) { width: 22%; margin-top: 8px; opacity: 0.6; }

.wc-1 { background: #ec4899; --r: -14deg; --x: -62px; animation-delay: -1.2s; }
.wc-2 { background: #3b82f6; --r: 0deg;   --x: 0px;   animation-delay: 0s; z-index: 1; top: -8px; }
.wc-3 { background: #f59e0b; --r: 14deg;  --x: 62px;  animation-delay: -2.4s; }

@keyframes welcomeCardFloat {
    0%, 100% { transform: translateX(var(--x)) rotate(var(--r)) translateY(0); }
    50%      { transform: translateX(var(--x)) rotate(var(--r)) translateY(-6px); }
}

.welcome-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    margin-bottom: 14px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text-secondary);
    background: var(--tile-hover);
    font-variant-numeric: tabular-nums;
}

.welcome-live-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5);
    animation: liveDot 2s ease-out infinite;
}

@keyframes liveDot {
    0%   { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
    80%, 100% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
}

.welcome-content .welcome-title {
    font-size: clamp(30px, 6vw, 40px);
    font-weight: 800;
    letter-spacing: -0.035em;
    line-height: 1.05;
    margin-bottom: 14px;
    color: var(--text-primary);
}

.welcome-title-accent {
    color: var(--brand);
}

.welcome-content .welcome-message {
    font-size: 15.5px;
    line-height: 1.6;
    color: var(--text-secondary);
    margin: 0 0 22px;
    max-width: none;
}

.welcome-steps {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 0 0 24px;
    padding: 0;
    counter-reset: step;
}

.welcome-steps li {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 6px;
    border-radius: 14px;
    background: var(--tile);
    font-size: 14px;
    font-weight: 600;
    line-height: 1.25;
    color: var(--text-primary);
}

.welcome-steps .material-icons {
    font-size: 20px;
    margin: 0;
    color: var(--brand);
}

.welcome-content .welcome-btn {
    position: relative;
    overflow: hidden;
    padding: 17px 24px;
    border-radius: 16px;
    font-size: 16px;
    text-transform: none;
    letter-spacing: 0;
    background: var(--brand);
    box-shadow: 0 10px 24px -12px rgba(0, 122, 204, 0.6);
    transition: transform 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out);
}

.welcome-content .welcome-btn .material-icons {
    transition: transform 0.25s var(--ease-out);
}

.welcome-content .welcome-btn:hover {
    background: #006bb3;
    transform: translateY(-2px);
    box-shadow: 0 14px 28px -12px rgba(0, 122, 204, 0.7);
}

.welcome-content .welcome-btn:hover .material-icons {
    transform: translateX(4px);
}

.welcome-content .welcome-btn:active {
    transform: scale(0.98);
}

.welcome-note {
    margin: 14px 0 0;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-secondary);
}

/* Exit: the card steps back while the blur dissolves into the grid */
.welcome-overlay.fade-out {
    opacity: 1;
    visibility: visible;
    pointer-events: none;
    transition: none;
    animation: welcomeBackdropOut 0.7s ease-in forwards;
}

.welcome-overlay.fade-out .welcome-content {
    animation: welcomeCardOut 0.4s cubic-bezier(0.4, 0, 1, 1) forwards;
}

@keyframes welcomeBackdropOut {
    to { opacity: 0; -webkit-backdrop-filter: blur(0); backdrop-filter: blur(0); }
}

@keyframes welcomeCardOut {
    to { opacity: 0; transform: translateY(-10px) scale(0.95); filter: blur(4px); }
}

@media (max-width: 520px) {
    .welcome-content {
        padding: 34px 22px 22px;
        border-radius: 24px;
    }

    .welcome-cards {
        transform: scale(0.85);
        margin-top: -70px;
        margin-bottom: 8px;
    }

    .welcome-steps li {
        font-size: 11.5px;
        padding: 10px 4px;
    }
}

/* Loader backdrop: a field of the same little squares, drifting slowly,
   faded toward the edges so the assembling 3×3 stays the focus */
.page-loader::before {
    content: '';
    position: absolute;
    inset: -64px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32'%3E%3Crect x='4' y='4' width='24' height='24' rx='7' fill='%230f172a' fill-opacity='0.06'/%3E%3C/svg%3E");
    background-size: 32px 32px;
    -webkit-mask-image: radial-gradient(closest-side, transparent 18%, #000 55%, transparent 100%);
    mask-image: radial-gradient(closest-side, transparent 18%, #000 55%, transparent 100%);
    animation: loaderFieldDrift 14s linear infinite;
    pointer-events: none;
}

[data-theme="dark"] .page-loader::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32'%3E%3Crect x='4' y='4' width='24' height='24' rx='7' fill='%23ffffff' fill-opacity='0.06'/%3E%3C/svg%3E");
}

@keyframes loaderFieldDrift {
    to { transform: translate(32px, 32px); }
}

.page-loader .loader-content {
    position: relative;
    z-index: 1;
}

/* ---------- Intro v2: the loader floats over the real, empty grid ---------- */
.page-loader {
    z-index: 10001; /* above the welcome overlay, which waits underneath */
    background: color-mix(in srgb, var(--canvas) 78%, transparent);
}

/* The real grid replaces the decorative pattern */
.page-loader::before { content: none; }

/* While loading only the cards wait; empty tiles are already there */
body.intro-pending #grid .grid-item.empty::after { opacity: 1; }

/* Empty tiles get a soft wave as the cards are dealt in */
#grid .grid-item.intro-in.empty::after {
    animation: introTileWave 0.9s ease-in-out var(--intro-delay, 0ms) both;
}

@keyframes introTileWave {
    0%, 100% { transform: none; background: var(--tile); }
    40%      { transform: scale(0.88); background: var(--tile-hover); }
}

/* The welcome card waits for the reveal, then plays its entrance */
body.intro-pending .welcome-overlay {
    opacity: 0;
    animation: none;
}

body.intro-pending .welcome-content,
body.intro-pending .welcome-content > * {
    animation: none;
}

/* Slideshow play button: above the grid chrome, but below every overlay/modal blur */
#slideshow-indicator { z-index: 1100; }

/* ==========================================================================
   UI REFRESH: COMPOSER — the editor focused on the card
   ========================================================================== */

/* Shared pill buttons under the card */
.composer-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
}

#modal .randomize-icon,
.composer-chip {
    position: static;
    transform: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 38px;
    padding: 0 16px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font: 600 13px/1 'Inter', sans-serif;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
    transition: transform 0.15s var(--ease-out), background-color 0.15s ease, border-color 0.15s ease;
}

#modal .randomize-icon .material-icons,
.composer-chip .material-icons {
    font-size: 17px;
    margin: 0;
}

#modal .randomize-icon span + span,
.composer-chip span + span {
    margin-left: 0;
}

#modal .randomize-icon:hover,
.composer-chip:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--text-secondary);
    transform: translateY(-1px);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

#modal .randomize-icon:active,
.composer-chip:active {
    transform: scale(0.96);
}

/* Randomize gives the shuffle icon a little spin */
#modal .randomize-icon:active .material-icons {
    transform: rotate(180deg);
    transition: transform 0.3s var(--ease-out);
}

.composer-chevron {
    font-size: 18px !important;
    color: var(--text-secondary);
    transition: transform 0.25s var(--ease-out);
}

.composer-chip[aria-expanded="true"] {
    border-color: var(--text-primary);
}

.composer-chip[aria-expanded="true"] .composer-chevron {
    transform: rotate(180deg);
}

/* Post button: its space is reserved, it slides in once the person has started */
#modal .modal-footer {
    position: relative;
}

.composer-hint {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    margin: 0;
    padding: 0 24px;
    text-align: center;
    font-size: 13.5px;
    color: var(--text-secondary);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.35s var(--ease-out);
}

#modal .modal-content.ready-to-post .composer-hint {
    opacity: 0;
    transform: translateY(calc(-50% - 8px));
}

#modal .save-btn {
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px) scale(0.98);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.3s var(--ease-out), visibility 0s linear 0.3s;
}

#modal .modal-content.ready-to-post .save-btn {
    opacity: 1;
    visibility: visible;
    transform: none;
    pointer-events: auto;
    transition: opacity 0.3s ease, transform 0.55s var(--ease-spring), visibility 0s;
}

/* The footer's old settings button is replaced by "Customize" */
#modal .settings-toggle-btn {
    display: none !important;
}

/* ---------- Desktop / tablet with room: one centered column ---------- */
@media (min-width: 769px) {
    #modal .modal-content {
        max-width: 640px;
        height: auto;
        max-height: min(calc(100vh - 32px), 820px);
        border-radius: 28px;
        border: 1px solid var(--glass-border);
        box-shadow: 0 40px 100px -30px rgba(15, 23, 42, 0.45), 0 10px 30px -12px rgba(15, 23, 42, 0.2);
    }

    #modal .modal-header {
        justify-content: center;
        text-align: center;
        padding: 30px 60px 4px;
        border-bottom: none;
        background: transparent;
    }

    #modal .header-content {
        width: 100%;
    }

    #modal .header-content h2 {
        font-size: 24px;
        font-weight: 800;
        letter-spacing: -0.025em;
        line-height: 1.15;
        margin-bottom: 6px;
    }

    #modal .subtitle {
        display: block !important;
        font-size: 14px;
    }

    #modal .close-btn {
        top: 18px;
        right: 18px;
        width: 36px;
        height: 36px;
        background: var(--tile-hover);
        color: var(--text-primary);
    }

    #modal .modal-body {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 18px;
        padding: 24px 32px;
        overflow-y: auto;
        overflow-x: hidden;
        overscroll-behavior: contain;
    }

    #modal .preview-section {
        flex-direction: column;
        gap: 18px;
        width: 100%;
        flex-shrink: 0;
        padding: 0;
    }

    /* Settings: optional, collapsed by default, opens below the card */
    #modal .controls-section {
        display: none !important;
        width: 100%;
        flex-shrink: 0;
        padding: 16px;
        gap: 14px;
        border-radius: 18px;
        background: var(--tile);
        border: 1px solid var(--glass-border);
    }

    #modal .modal-content.settings-expanded .controls-section {
        display: flex !important;
        animation: composerPanelIn 0.35s var(--ease-out);
    }

    #modal .font-controls-header {
        display: none;
    }

    #modal .colors-scroll-container,
    #modal .images-scroll-container {
        max-height: none;
        overflow: visible;
    }

    #modal .color-presets {
        grid-template-columns: repeat(8, 1fr);
    }

    #modal .image-presets {
        grid-template-columns: repeat(5, 1fr);
    }

    #modal .modal-footer {
        border-top: none;
        background: transparent;
        padding: 4px 32px 28px;
        min-height: 88px;
        display: flex;
        align-items: center;
    }
}

@keyframes composerPanelIn {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: none; }
}

/* ---------- Phones: actions sit under the card, Customize opens the sheet ---------- */
@media (max-width: 768px) {
    #modal .composer-actions {
        position: absolute;
        left: 50%;
        bottom: -8px;
        transform: translateX(-50%);
        z-index: 10;
        white-space: nowrap;
    }

    #modal .randomize-icon,
    .composer-chip {
        height: 36px;
        padding: 0 14px;
        font-size: 12.5px;
    }

    #modal .modal-footer {
        min-height: 84px;
    }
}

/* ==========================================================================
   UI REFRESH: MODAL MOTION — one consistent enter/exit for every modal
   ========================================================================== */
@keyframes refreshBackdropIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes refreshBackdropOut { from { opacity: 1; } to { opacity: 0; } }

@keyframes refreshContentOut {
    from { opacity: 1; transform: none; }
    to   { opacity: 0; transform: translateY(8px) scale(0.97); }
}

@keyframes refreshSheetIn {
    from { transform: translateY(40px); opacity: 0; }
    to   { transform: none; opacity: 1; }
}

.modal.active {
    animation: refreshBackdropIn 0.3s ease-out;
}

.modal.closing {
    animation: refreshBackdropOut 0.3s ease-in forwards;
}

#modal.active:not(.closing) .modal-content,
#confirm-modal.active:not(.closing) .modal-content {
    animation: refreshModalIn 0.5s var(--ease-spring) both;
}

#modal.closing .modal-content,
#confirm-modal.closing .modal-content {
    animation: refreshContentOut 0.22s cubic-bezier(0.4, 0, 1, 1) forwards;
}

@media (max-width: 768px) {
    #modal.active:not(.closing) .modal-content {
        animation: refreshSheetIn 0.45s var(--ease-out) both;
    }
}

/* Confirmation dialog: matching look */
#confirm-modal .modal-content {
    border-radius: 24px;
    border: 1px solid var(--glass-border);
    box-shadow: 0 40px 100px -30px rgba(15, 23, 42, 0.45);
}

#confirm-modal .modal-header {
    border-bottom: none;
    justify-content: center;
    text-align: center;
    padding: 28px 64px 4px;
}

#confirm-modal .modal-header h2 {
    font-size: 21px;
    font-weight: 800;
    letter-spacing: -0.02em;
}

#confirm-modal .confirm-modal-body {
    text-align: center;
}

#confirm-modal .btn-primary {
    border-radius: 14px;
    background: var(--brand);
    transition: transform 0.15s var(--ease-out), background-color 0.15s ease;
}

#confirm-modal .btn-primary:hover { background: #006bb3; }
#confirm-modal .btn-primary:active { transform: scale(0.98); }

/* "Baking" popup after posting: spring in too */
.baking-overlay.show .baking-content {
    animation: refreshModalIn 0.55s var(--ease-spring) both;
}

/* Phones: centered composer header too */
@media (max-width: 768px) {
    #modal .modal-header {
        align-items: center;
        text-align: center;
        padding-left: 60px;
        padding-right: 60px;
    }

    #modal .header-content {
        width: 100%;
    }

    #modal .header-content h2 {
        font-size: 19px;
        font-weight: 800;
        letter-spacing: -0.02em;
        line-height: 1.2;
    }
}

/* ---------- Composer header: one-per-day badge ---------- */
.composer-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    padding: 5px 11px 5px 9px;
    border-radius: 999px;
    background: var(--tile-hover);
    color: var(--text-primary);
    font: 600 12px/1 'Inter', sans-serif;
    letter-spacing: 0.01em;
}

.composer-badge .material-icons {
    font-size: 15px;
    margin: 0;
    color: var(--brand);
}

@media (max-width: 768px) {
    .composer-badge {
        margin-top: 8px;
        font-size: 11.5px;
    }
}

/* ---------- Desktop: Customize opens a sidebar, the modal widens ---------- */
@media (min-width: 769px) {
    #modal .modal-content {
        width: 100%;
        transition: max-width 0.45s var(--ease-out);
    }

    #modal .modal-content.settings-expanded {
        max-width: min(1000px, calc(100vw - 48px));
    }

    /* Body becomes a two-area grid: composer | sidebar */
    #modal .modal-body {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto;
        justify-items: center;
        align-items: start;
        column-gap: 28px;
    }

    #modal .modal-content.settings-expanded .modal-body {
        grid-template-columns: minmax(0, 1fr) 340px;
        overflow: hidden;
    }

    /* Sidebar: takes the row height set by the card column (height:0 + min-height:100%
       keeps it from growing the modal), and scrolls inside */
    #modal .modal-content.settings-expanded .controls-section {
        display: flex !important;
        grid-column: 2;
        grid-row: 1;
        width: 100%;
        height: 0;
        min-height: 100%;
        overflow-y: auto;
        overscroll-behavior: contain;
        animation: composerSidebarIn 0.4s var(--ease-out) both;
    }

    #modal .modal-content.settings-expanded .color-presets {
        grid-template-columns: repeat(5, 1fr);
    }

    #modal .modal-content.settings-expanded .image-presets {
        grid-template-columns: repeat(3, 1fr);
    }

    #modal .preview-section {
        grid-column: 1;
        grid-row: 1;
        align-self: center;
    }
}

@keyframes composerSidebarIn {
    from { opacity: 0; transform: translateX(18px); }
    to   { opacity: 1; transform: none; }
}

/* Phones: no divider lines cutting through the card area / action pills */
@media (max-width: 768px) {
    #modal .modal-header,
    #modal .modal-footer {
        border: none;
    }
}

/* =========================================================
   Mobile stability (iOS Safari was killing the tab)
   1. #grid needs no box of its own: cells are absolutely positioned, so the
      composited layer only covers rendered cells, not a 25,000px square.
   2. No permanent layer promotion (script.js promotes only during a gesture).
   3. No backdrop blur on touch devices: very GPU-hungry on iOS.
   ========================================================= */
#grid { width: 1px; height: 1px; overflow: visible; }
@media (max-width: 768px), (pointer: coarse) {
    #grid { will-change: auto; -webkit-transform: none; }
    *, *::before, *::after {
        -webkit-backdrop-filter: none !important;
        backdrop-filter: none !important;
    }
}

/* =========================================================
   Empty tiles: smooth hover with an animated blue "+"
   ========================================================= */
#grid .grid-item.empty::after {
    transition: background-color .35s ease, box-shadow .35s ease, transform .5s cubic-bezier(.34, 1.56, .64, 1);
}
#grid .grid-item.empty:hover::after {
    background: rgba(59, 155, 255, .08);
    box-shadow: inset 0 0 0 2px rgba(59, 155, 255, .85), inset 0 0 42px rgba(59, 155, 255, .16);
    transform: scale(1.025);
    animation: tg-tile-breathe 2.2s ease-in-out .5s infinite;
}
#grid .grid-item.empty::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 64px;
    height: 64px;
    margin: -32px 0 0 -32px;
    font-size: 0;
    border-radius: 3px;
    background:
        linear-gradient(#3b9bff, #3b9bff) center / 100% 6px no-repeat,
        linear-gradient(#3b9bff, #3b9bff) center / 6px 100% no-repeat;
    filter: drop-shadow(0 0 10px rgba(59, 155, 255, .55));
    opacity: 0;
    transform: scale(.35) rotate(-90deg);
    transition: opacity .25s ease, transform .6s cubic-bezier(.34, 1.56, .64, 1);
}
#grid .grid-item.empty:hover::before {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}
#grid .grid-item.empty:active::before { transform: scale(.88) rotate(0deg); transition-duration: .12s; }
#grid .grid-item.empty:hover .grid-number { color: #3b9bff; }
@keyframes tg-tile-breathe {
    0%, 100% { box-shadow: inset 0 0 0 2px rgba(59, 155, 255, .85), inset 0 0 42px rgba(59, 155, 255, .16); }
    50%      { box-shadow: inset 0 0 0 2px rgba(124, 192, 255, 1), inset 0 0 70px rgba(59, 155, 255, .28); }
}
@media (prefers-reduced-motion: reduce) {
    #grid .grid-item.empty::before, #grid .grid-item.empty:hover::before { transform: none; }
    #grid .grid-item.empty:hover::after { transform: none; animation: none; }
}

/* Mobile: no "by CRE8NOW" pill at the bottom */
@media (max-width: 768px), (pointer: coarse) {
    .cre8now-branding { display: none !important; }
}

/* Endless animations only while their element is actually shown
   (they kept the render loop busy in the background, also on phones) */
.baking-overlay:not(.show), .baking-overlay:not(.show) *,
.new-cards-notification:not(.show), .new-cards-notification:not(.show) * {
    animation: none !important;
}

/* =========================================================
   Tile trail: tiles light up instantly (hover or .lit from grid-fx.js)
   and fade out slowly, so a fast mouse leaves a wake of tiles.
   Leaving = slow transition on the base rule; entering = fast on the lit rule.
   ========================================================= */
#grid .grid-item.empty::after {
    transition: background-color 1.1s cubic-bezier(.2, .7, .2, 1), box-shadow 1.1s cubic-bezier(.2, .7, .2, 1), transform 1.1s cubic-bezier(.2, .7, .2, 1);
}
#grid .grid-item.empty.lit::after,
#grid .grid-item.empty:hover::after {
    background: rgba(59, 155, 255, .1);
    box-shadow: inset 0 0 0 2px rgba(59, 155, 255, .85), inset 0 0 42px rgba(59, 155, 255, .16);
    transform: scale(1.025);
    transition-duration: .08s, .08s, .25s;
    animation: none;
}
#grid .grid-item > .note-card {
    transition: transform .25s var(--ease-out), box-shadow 1.1s cubic-bezier(.2, .7, .2, 1);
}
#grid .grid-item.lit > .note-card {
    box-shadow: 0 0 0 2px rgba(59, 155, 255, .8), var(--card-shadow);
    transition: transform .25s var(--ease-out), box-shadow .08s ease;
}
@media (prefers-reduced-motion: reduce) {
    #grid .grid-item.empty::after { transition-duration: .2s; }
}
