/* ==========================================
   ROOT VARIABLES & THEME
   ========================================== */
:root {
    --primary: #667eea;
    --primary-end: #764ba2;
    --secondary-start: #f093fb;
    --secondary-end: #f5576c;

    /* Solid backgrounds — no blur needed */
    --bg-primary: #f0f2ff;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-card-dark: #1e1e36;

    --text-primary: #1a1a2e;
    --text-secondary: #4a5568;
    --text-muted: #8492a6;

    --border: rgba(0, 0, 0, 0.08);
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.12);

    /* keep compat names */
    --primary-gradient-start: #667eea;
    --primary-gradient-end: #764ba2;
    --secondary-gradient-start: #f093fb;
    --secondary-gradient-end: #f5576c;
    --bg-card: #ffffff;
    --border-color: rgba(0,0,0,0.08);
    --shadow-color: rgba(0,0,0,0.08);
    --shadow-strong: rgba(0,0,0,0.18);
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 24px;
    --spacing-xs: 0.4rem;
    --spacing-sm: 0.75rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.4rem;
    --spacing-xl: 2rem;
    --transition-fast: 0.15s ease;
    --transition-normal: 0.2s ease;
    --transition-slow: 0.3s ease;
    --transition-bounce: 0.3s ease;
}

body.dark-theme {
    --bg-primary: #0d0d1a;
    --bg-secondary: #16162a;
    --bg-card: #1e1e36;
    --text-primary: #f0f0ff;
    --text-secondary: #c8c8e8;
    --text-muted: #8888aa;
    --border-color: rgba(255,255,255,0.08);
    --border: rgba(255,255,255,0.08);
    --shadow-color: rgba(0,0,0,0.4);
    --shadow-strong: rgba(0,0,0,0.6);
}

/* ==========================================
   RESET
   ========================================== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100dvh;
    overflow-x: hidden;
    /* no transition on body to avoid flicker */
}

/* ==========================================
   THEME TOGGLE
   ========================================== */
.theme-toggle {
    position: fixed;
    top: 0.75rem;
    right: 0.75rem;
    width: 44px;
    height: 44px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1000;
    box-shadow: var(--shadow-sm);
    animation: fadeIn 0.8s ease backwards;
    /* no animation */
}

.theme-toggle:active { transform: scale(0.9); }

.theme-toggle svg {
    width: 22px;
    height: 22px;
    color: var(--text-primary);
    position: absolute;
}

.theme-toggle .sun-icon  { 
    opacity: 1; 
    transform: scale(1);
    transition: opacity 0.2s, transform 0.2s;
}

.theme-toggle .moon-icon { 
    opacity: 0; 
    transform: scale(0.5);
    transition: opacity 0.2s, transform 0.2s;
}

body.dark-theme .theme-toggle .sun-icon  { 
    opacity: 0; 
    transform: scale(0.5);
}

body.dark-theme .theme-toggle .moon-icon { 
    opacity: 1; 
    transform: scale(1);
}

/* ==========================================
   BACKGROUND — static gradient, NO orbs on mobile
   ========================================== */
.orb { display: none; } /* kill all orbs on mobile */

/* ==========================================
   CONTAINER
   ========================================== */
.container {
    position: relative;
    z-index: 1;
    max-width: 560px;
    margin: 0 auto;
    padding: 0.75rem;
    padding-top: 3.8rem;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ==========================================
   HEADER
   ========================================== */
.header {
    text-align: center;
    margin-bottom: 0.75rem;
    width: 100%;
    animation: fadeInDown 0.8s ease backwards;
}

.logo {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: clamp(1.5rem, 7vw, 2.2rem);
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--primary-end));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.logo-icon { font-size: 1.8rem; }

.subtitle {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 400;
    letter-spacing: 1px;
    text-transform: uppercase;
}

/* ==========================================
   CARDS CONTAINER
   ========================================== */
.cards-container {
    position: relative;
    width: 100%;
    height: min(400px, 50vh);
    perspective: 800px;
    margin-bottom: 0.75rem;
}

.card {
    position: absolute;
    width: 100%;
    height: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 1.2rem;
    box-shadow: var(--shadow-md);
    cursor: grab;
    touch-action: pan-y;
    user-select: none;
    overflow: hidden;
    /* Only transition transform for swipe — nothing else */
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    will-change: transform;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.5s ease;
    transform-style: preserve-3d;
}

.card.flipped .card-inner { transform: rotateY(180deg); }

.card-front,
.card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

.card-back {
    transform: rotateY(180deg);
    background: var(--bg-card);
    border-radius: var(--radius-xl);
}

/* stacking */
.card:not(:nth-child(1)) .card-inner { opacity: 0; }
.card:nth-child(1) .card-inner       { opacity: 1; }
.card:nth-child(1) { z-index: 100; }
.card:nth-child(2) { transform: scale(0.96) translateY(8px); opacity: 0.7; z-index: 1; pointer-events: none; }
.card:nth-child(3) { transform: scale(0.92) translateY(16px); opacity: 0.4; z-index: 0; pointer-events: none; }
.card:active       { cursor: grabbing; }

/* Swipe Animations */
@keyframes swipe-left  { to { transform: translateX(-140%) rotate(-25deg); opacity: 0; } }
@keyframes swipe-right { to { transform: translateX(140%)  rotate(25deg);  opacity: 0; } }

.card.swiping-left  { animation: swipe-left  0.4s ease forwards; }
.card.swiping-right { animation: swipe-right 0.4s ease forwards; }
.card.removing      { animation: swipe-right 0.3s ease forwards; }

/* ==========================================
   CARD CONTENT
   ========================================== */
.proverb-container {
    position: relative;
    text-align: center;
    margin-bottom: 0.75rem;
}

.quote-mark {
    font-family: 'Playfair Display', serif;
    font-size: 3rem;
    line-height: 0;
    color: var(--primary);
    opacity: 0.2;
    position: absolute;
    top: -6px;
    left: -4px;
}

.quote-mark.closing {
    top: auto;
    bottom: -20px;
    left: auto;
    right: -4px;
    transform: rotate(180deg);
}

.proverb {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: clamp(1.1rem, 4.5vw, 1.8rem);
    font-weight: 700;
    line-height: 1.4;
    color: var(--text-primary);
    margin: 0.5rem 0;
    padding: 0 0.5rem;
    opacity: 1 !important;
}

.meaning-container {
    background: rgba(102, 126, 234, 0.07);
    border-left: 3px solid var(--primary);
    padding: 0.7rem 0.9rem;
    border-radius: var(--radius-sm);
    margin-bottom: 0.75rem;
}

.meaning-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.meaning {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.55;
}

.flip-hint, .flip-hint-back {
    margin-top: 0.6rem;
    font-size: 0.78rem;
    color: var(--text-muted);
    opacity: 0.7;
}

.proverb-small {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    font-style: italic;
    opacity: 0.5;
}

/* ==========================================
   SWIPE BUTTONS
   ========================================== */
.swipe-buttons {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 0.6rem;
    animation: fadeInUp 0.8s ease backwards 0.2s;
}

.swipe-button {
    width: 54px;
    height: 54px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.swipe-button:active { transform: scale(0.88); box-shadow: none; }

.swipe-button svg {
    width: 24px;
    height: 24px;
    position: relative;
    z-index: 1;
}

.dislike-button  { background: #fff0f2; border: 1.5px solid rgba(245,87,108,0.3); }
.dislike-button svg { color: #f5576c; }

.refresh-button  {
    width: 62px;
    height: 62px;
    background: var(--bg-card);
    border: 1.5px solid var(--border);
}
.refresh-button svg { color: var(--primary); }

.like-button     { background: #f0f3ff; border: 1.5px solid rgba(102,126,234,0.3); }
.like-button svg { color: #667eea; }

/* ==========================================
   LOADING STATE
   ========================================== */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    min-height: 200px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-state p { color: var(--text-muted); font-size: 0.9rem; }

/* ==========================================
   FOOTER
   ========================================== */
.footer {
    text-align: center;
    margin-top: auto;
    padding: 0.75rem 0;
    color: var(--text-muted);
    font-size: 0.82rem;
}

.footer-count span { font-weight: 600; color: var(--primary); }

/* ==========================================
   UTILITY
   ========================================== */
.hidden { display: none !important; }

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

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

@keyframes slideInUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

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

/* ==========================================
   ACCESSIBILITY
   ========================================== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ==========================================
   DARK THEME TEXT FIX
   ========================================== */
body.dark-theme .proverb,
body.dark-theme .meaning,
body.dark-theme .meaning-title {
    color: #ffffff !important;
}

body.dark-theme .card:nth-child(1) .proverb {
    color: #ffffff !important;
}

.card:nth-child(1) { opacity: 1 !important; filter: none !important; }
.card:nth-child(1) .proverb,
.card:nth-child(1) .meaning-container { opacity: 1 !important; }

/* ==========================================
   DESKTOP ENHANCEMENTS
   ========================================== */
@media (min-width: 640px) {
    .container { padding: 1rem; padding-top: 4.5rem; }
    .cards-container { height: min(480px, 58vh); }
}

@media (min-width: 768px) {
    :root {
        --spacing-md: 1.5rem;
        --spacing-lg: 2rem;
        --spacing-xl: 3rem;
    }

    .theme-toggle { top: 1.5rem; right: 1.5rem; width: 50px; height: 50px; }

    /* Orbs only on desktop where GPU handles it fine */
    .orb {
        display: block;
        position: fixed;
        border-radius: 50%;
        filter: blur(60px);
        opacity: 0.25;
        pointer-events: none;
        z-index: 0;
        animation: float 25s ease-in-out infinite;
    }
    .orb-1 { width: 300px; height: 300px; background: var(--orb-1, linear-gradient(135deg,#667eea,#764ba2)); top: -5%; left: -5%; }
    .orb-2 { width: 250px; height: 250px; background: var(--orb-2, linear-gradient(135deg,#f093fb,#f5576c)); bottom: -3%; right: -3%; animation-delay: 8s; }
    .orb-3 { display: none; }

    @keyframes float {
        0%, 100% { transform: translate(0,0); }
        50%       { transform: translate(30px, -20px); }
    }

    .card { padding: var(--spacing-lg); }
    .proverb { font-size: clamp(1.4rem, 3vw, 2rem); }
    .meaning { font-size: 1rem; }
    .swipe-button { width: 60px; height: 60px; }
    .swipe-button:hover { transform: scale(1.08) translateY(-3px); }
    .refresh-button { width: 68px; height: 68px; }
    .logo { font-size: clamp(1.8rem, 4vw, 2.6rem); }
    .subtitle { font-size: 0.9rem; }
}