/* Base Styles and CSS Variables */

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

/* Form elements don't inherit font by default — fix globally */
button, input, select, textarea {
    font-family: inherit;
}


/* Screen-reader only utility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

:root {
    /* Category theme colors (dynamically set by theming.js) */
    --category-primary: #3D5A80;
    --category-secondary: #2C4A6E;
    --category-light: #8FA3B8;
    --category-dark: #2C3E50;
    --category-background: url('../media/backgrounds/fuji_cherry_blossom.png'); /* Default fallback */

    --text-primary: #332F2B;  /* Warm sumi ink - not neutral gray */
    --text-secondary: #57534e;
    --card-shadow: 0 20px 40px rgba(44, 44, 44, 0.15);

    /* Status colors — vivid, for badges and indicators */
    --status-mastered-vivid: #16a34a;     /* green-600 */
    --status-mastered-vivid-rgb: 22, 163, 74;
    --status-learning-vivid: #ea580c;     /* orange-600 */
    --status-learning-vivid-rgb: 234, 88, 12;
    --status-online: #10b981;             /* emerald-500 — connection dot */
    --status-online-text: #059669;        /* emerald-600 — connection label */
    --status-online-rgb: 16, 185, 129;
    --transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    /* Shared motion tokens (promoted from grid-base.css for cross-mode consistency) */
    --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-out-back: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-spring: cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

body {
    font-family: 'Inter', 'Noto Sans JP', sans-serif;
    min-height: 100vh;  /* Fallback for older browsers */
    min-height: 100dvh; /* Dynamic viewport - excludes Safari address bar */
    background: var(--body-bg, #F0EDE8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    overflow-x: hidden;
    position: relative;
    transition: background 0.6s ease;
    padding-top: 2vh;
    padding-bottom: 2vh;
    box-sizing: border-box;
}

/* Seasonal color overlay (四季の色) - subtle warmth from traditional Japanese palette
   Opacity shifts with time of day (渋い depth) via --seasonal-opacity */
body::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: -1;
    opacity: var(--seasonal-opacity, 0.08);
    background: var(--seasonal-primary, transparent);
    transition: background 2s ease, opacity 2s ease;
}

/* Image Fade-in Transition */
.img-fade-in {
    opacity: 0;
    transition: opacity 0.3s ease-in;
}

.img-fade-in.loaded {
    opacity: 1;
}

/* Container */
.container {
    width: 95%;
    max-width: 1300px;
    margin: 0 auto;
    padding: 15px;
    padding-bottom: 5px; /* Reduce bottom padding */
    z-index: 10;
    display: none;
    flex: 1; /* Make container expand to fill available height */
    flex-direction: column;
}

.container.active {
    display: flex;
    /* Removed slideIn animation - was causing 0.5s delay on first load */
}

/* Top Bar Container */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding: 0 10px;
}

/* Motivational message - toast style */
.motivation {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    color: white;
    font-size: 1.1em;
    font-weight: 500;
    padding: 12px 24px;
    background: rgba(30, 30, 40, 0.85);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border-radius: 12px;
    text-shadow: 1px 1px 2px rgba(44, 44, 44, 0.18);
    box-shadow: 0 4px 20px rgba(44, 44, 44, 0.18);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    pointer-events: none;
    max-width: 90vw;
}

.motivation.show {
    opacity: 1;
    visibility: visible;
}

/* Base Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn:active {
    transform: scale(0.95);
}

.loader {
    width: 48px;
    height: 48px;
    border: 5px solid #FFF;
    border-bottom-color: transparent;
    border-radius: 50%;
    display: inline-block;
    box-sizing: border-box;
    animation: rotation 1s linear infinite;
    margin-bottom: 20px;
}

.loading-text {
    color: white;
    font-size: 1.2rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-shadow: 0 2px 4px rgba(44,44,44,0.3);
    animation: pulse 1.5s ease-in-out infinite;
}

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

/* Scrollbar Styling — warm stone background (#F0EDE8) */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(44, 44, 44, 0.04);
}

::-webkit-scrollbar-thumb {
    background: rgba(44, 44, 44, 0.15);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(44, 44, 44, 0.25);
}

/* ========================================
   REDUCED MOTION - Global accessibility
   Disables animations/transitions for users
   who prefer reduced motion (OS-level 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;
    }

    /* Card entrance: remove initial offset so cards appear in place */
    .grid-card {
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
    }

    .grid-card.in-view {
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
    }

    /* Ken Burns & image breathing: disable zoom/scale */
    body.video-mode .vocabulary-image {
        animation: none !important;
        transform: none !important;
    }

    /* Sakura petals: hide entirely */
    .japanese-flag .cherry-petal {
        display: none !important;
    }

    /* Shimmer loading: remove */
    .grid-card-image-placeholder::before {
        animation: none !important;
    }

    /* Seasonal overlay: make instant */
    body::after {
        transition: none !important;
    }
}

/* ========================================
   BATTERY SAVER - Background tab freeze
   Pauses all animations when tab is hidden
   (class toggled by app.js pauseApp/resumeApp)
   ======================================== */
html.app-backgrounded *, html.app-backgrounded *::before, html.app-backgrounded *::after {
    animation-play-state: paused !important;
}

/* Touch optimization for mobile */
button, a, [role="button"], input, select, textarea, .action-btn, .icon-btn, .filter-chip, .grid-card {
    touch-action: manipulation;
}

/* Keyboard focus indicators (visible only for keyboard nav, not mouse/touch) */
.action-btn:focus-visible,
.icon-btn:focus-visible,
.filter-chip:focus-visible,
.grid-card:focus-visible,
.flashcard:focus-visible,
[role="button"]:focus-visible {
    outline: 2px solid #3D5A80;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(61, 90, 128, 0.15);
}

/* Suppress focus ring on flashcard in video/focus mode (keyboard handled globally) */
body.video-mode .flashcard:focus-visible,
body.focus-mode .flashcard:focus-visible {
    outline: none;
    box-shadow: none;
}

/* ========================================
   FURIGANA (Ruby) Global Styles
   Small kana readings above kanji
   ======================================== */

/* Ruby text container - proper positioning */
ruby {
    ruby-position: over;
    ruby-align: space-around;
}

/* Furigana reading (kana above kanji)
   - 45% ratio ideal for flashcard displays (per W3C guidance)
   - Muted opacity creates visual hierarchy (kanji primary, furigana secondary)
   - Tight line-height prevents layout shifts */
ruby rt {
    font-family: 'Klee One', 'Noto Sans JP', sans-serif;
    font-size: 0.4em;
    font-weight: 400;
    line-height: 1;
    letter-spacing: 0.06em;
    color: inherit;
    opacity: 0.55;         /* WCAG AA for large text (≥3:1 at this size) */
    padding-bottom: 0.05em;
}

/* Grid mode front-face furigana — smaller than base (text is larger on front) */
.grid-card-japanese ruby rt {
    font-size: 0.35em;
}

/* Focus mode furigana - larger, more prominent */
.focus-mode .japanese-text ruby rt {
    font-size: 0.45em;
    opacity: 0.55;
}

/* Verb forms with furigana - slightly smaller for stacked conjugations */
.verb-forms ruby rt {
    font-size: 0.4em;
}

/* ========================================
   TABLET/IPAD ADJUSTMENTS (769px - 1024px)
   Optimized for iPad Mini, iPad Air, iPad Pro
   ======================================== */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        max-width: 900px;
        padding: 12px;
    }

    /* Slightly smaller buttons for tablet */
    .btn {
        padding: 9px 18px;
        font-size: 0.95em;
    }
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    .container {
        width: 100%;
        padding: 10px;
        padding-bottom: 5px; /* Reduce bottom padding on mobile too */
    }
}
