/* Components: Cards, Buttons, Controls */

/* ========================================
   TIER-BASED TEXT SIZING (Standard Mode)
   Dynamic font sizing based on text length
   ======================================== */

/* TIER-BASED TEXT SIZING (Standard Mode)
   Dynamic font sizing based on text length with clamp() for responsiveness
   ======================================== */

/* TIER 1: Short text (1-8 chars) - Standard size */
.flashcard[data-text-tier="short"] {
    --text-size-ja: clamp(3rem, 10vw + 1rem, 5em);
    --text-size-en: clamp(1.5rem, 4vw + 0.5rem, 2.8em);
    --text-size-roma: clamp(0.9rem, 1.1em, 1.2em);
}

/* TIER 2: Medium text (9-15 chars) - Reduced size */
.flashcard[data-text-tier="medium"] {
    --text-size-ja: clamp(2.2rem, 7vw + 0.5rem, 3.8em);
    --text-size-en: clamp(1.2rem, 3.5vw + 0.5rem, 2.3em);
    --text-size-roma: clamp(0.85rem, 1em, 1.1em);
}

/* TIER 3: Long text (16+ chars) - Smallest size */
.flashcard[data-text-tier="long"] {
    --text-size-ja: clamp(1.8rem, 5vw + 0.5rem, 3em);
    --text-size-en: clamp(1rem, 3vw + 0.5rem, 1.9em);
    --text-size-roma: clamp(0.8rem, 0.9em, 1em);
}

/* ========================================
   TABLET/IPAD TEXT SIZING (769px - 1024px)
   Intermediate sizes between mobile and desktop
   ======================================== */
@media (min-width: 769px) and (max-width: 1024px) {
    /* TIER 1: Short text - Tablet optimized */
    .flashcard[data-text-tier="short"] {
        --text-size-ja: clamp(2.8rem, 9vw + 0.8rem, 4.5em);
        --text-size-en: clamp(1.4rem, 3.8vw + 0.4rem, 2.5em);
        --text-size-roma: clamp(0.85rem, 1em, 1.15em);
    }

    /* TIER 2: Medium text - Tablet optimized */
    .flashcard[data-text-tier="medium"] {
        --text-size-ja: clamp(2rem, 6.5vw + 0.4rem, 3.5em);
        --text-size-en: clamp(1.1rem, 3.2vw + 0.4rem, 2.1em);
        --text-size-roma: clamp(0.8rem, 0.95em, 1.05em);
    }

    /* TIER 3: Long text - Tablet optimized */
    .flashcard[data-text-tier="long"] {
        --text-size-ja: clamp(1.7rem, 4.8vw + 0.4rem, 2.8em);
        --text-size-en: clamp(0.95rem, 2.8vw + 0.4rem, 1.8em);
        --text-size-roma: clamp(0.75rem, 0.85em, 0.95em);
    }

    /* Branding - scaled for 65px tablet top bar */
    .app-branding-topleft {
        height: 65px;
    }

    .branding-title-topleft {
        height: auto;
        font-size: 1rem;
        padding: 6px 14px 6px 6px;
        gap: 8px;
    }

    .branding-logo {
        width: 38px;
        height: 38px;
    }

    .branding-name {
        font-size: 13px;
    }

    .branding-subtitle-topleft {
        font-size: 1em;
    }
}

/* App Branding (Top Left) - Elegant text branding */
.app-branding-topleft {
    position: fixed;
    top: 0;
    left: 30px;
    height: 90px; /* Match standard mode top bar height */
    z-index: 100;
    display: flex;
    flex-direction: row;
    align-items: center; /* Vertically center 80px pill in 90px space */
    gap: 12px;
    transition: opacity 0.3s ease;
    opacity: 1;
    pointer-events: none;
}

.app-branding-topleft > * {
    pointer-events: auto;
}

/* Hanko stamp logo (desktop) */
.branding-logo {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

/* Kanji mark in branding pill (mobile fallback, hidden on desktop) */
.branding-kanji {
    font-family: 'Klee One', serif;
    font-size: 20px;
    font-weight: 600;
    color: #2C2C2C;
    line-height: 1;
    flex-shrink: 0;
    display: none; /* Hidden on desktop, shown on mobile */
}

/* App name in branding pill */
.branding-name {
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 15px;
    font-weight: 500;
    color: #57534e;
    letter-spacing: 0.05em;
}

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

/* Hover handled by .branding-title-topleft pill */

/* All modes: Warm pill with logo/kanji + text */
.branding-title-topleft {
    display: flex;
    align-items: center;
    gap: 10px;
    height: auto;
    padding: 8px 18px 8px 8px;
    border-radius: 28px;
    line-height: 1;
    color: #2C2C2C;
    background: rgba(250, 250, 247, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(44, 44, 44, 0.04);
    box-shadow: 0 1px 4px rgba(44, 44, 44, 0.03);
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

.branding-title-topleft:hover {
    background: rgba(250, 250, 247, 0.95);
    box-shadow: 0 2px 8px rgba(44, 44, 44, 0.05);
}

@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

/* Hide emojis - text branding replaces them */
.branding-title-topleft .emoji-gradient {
    display: none;
}

@keyframes emojiShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.branding-subtitle-topleft {
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 1.05em;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: #57534e;
    text-shadow: none;
    line-height: 1.3;
}

/* Focus/Video/Revision: Align with header buttons (90px bar, centered) */
body.focus-mode .app-branding-topleft,
body.video-mode .app-branding-topleft,
body.revision-mode .app-branding-topleft {
    display: flex;
    position: fixed;
    top: 0;
    left: 30px;
    height: 90px; /* Match header height for vertical centering */
    z-index: 1000;
    /* No pill styling - inner .branding-title-topleft handles it */
    background: none;
    border: none;
    padding: 0;
    box-shadow: none;
}

/* Consistent sizes across all modes - no overrides needed */

/* Logo (Bottom-left inside card) - All modes */
.logo-watermark {
    position: absolute;
    bottom: 25px;
    left: 25px;
    z-index: 100;
    pointer-events: none;
    opacity: 0.85;
    transition: opacity 0.3s ease;
}

.logo-watermark img {
    width: 56px;
    height: 56px;
    object-fit: contain;
    border-radius: 50%;
    filter: drop-shadow(0 2px 8px rgba(44, 44, 44, 0.3));
}

/* Larger logo in focus/video/revision modes for YouTube */
body.focus-mode .logo-watermark img,
body.video-mode .logo-watermark img,
body.revision-mode .logo-watermark img {
    width: 80px;
    height: 80px;
}

/* Align stats to right when header is removed */
.top-bar {
    justify-content: flex-end;
}

/* Card Category Watermark - hidden, element exists in HTML */
.card-category-badge {
    display: none !important;
}

/* Loading screen - full page overlay */
.loading-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #F0EDE8;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.4s ease-out;
}

.loading-container.fade-out {
    opacity: 0;
    pointer-events: none;
}

.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
}

/* Elegant three-dot loader */
.loading-dots {
    display: flex;
    gap: 8px;
    align-items: center;
}

.loading-dots span {
    width: 10px;
    height: 10px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    animation: dotPulse 1.4s ease-in-out infinite;
}

.loading-dots span:nth-child(1) {
    animation-delay: 0s;
}

.loading-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.loading-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes dotPulse {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Legacy spinner (kept for compatibility) */
.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid #57534e;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

/* Controls */
.controls {
    background: rgba(255,255,255,0.10);
    backdrop-filter: blur(10px);
    border-radius: 18px;
    padding: 20px 24px;
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    position: relative;
    transition: border-color 0.6s ease;
    gap: 0;
    box-shadow: 0 4px 16px rgba(44, 44, 44, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.25);
}

/* Subtle category color tint on controls */
.controls::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--category-primary);
    opacity: 0.06;
    border-radius: 18px;
    pointer-events: none;
    transition: opacity 0.6s ease;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
    z-index: 1;
}

select, button {
    padding: 9px 18px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    font-size: 0.95em;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    background: rgba(255, 255, 255, 0.92);
    color: var(--text-primary);
}

/* Allow category dropdown to flex naturally */
#class-filter {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

button {
    background: white;
    box-shadow: 0 4px 15px rgba(44, 44, 44, 0.06);
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(44, 44, 44, 0.09);
}

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

/* Toggle switches */
.toggle-switch {
    position: relative;
    width: 60px;
    height: 30px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 15px;
    cursor: pointer;
    transition: var(--transition);
}

.toggle-switch input {
    display: none;
}

.toggle-slider {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 24px;
    height: 24px;
    background: white;
    border-radius: 50%;
    transition: var(--transition);
    box-shadow: 0 2px 5px rgba(44, 44, 44, 0.12);
}

.toggle-switch input:checked + .toggle-slider {
    transform: translateX(30px);
}

/* Turn accent when checked - pure CSS, no JavaScript needed */
.toggle-switch:has(input:checked) {
    background: #3D5A80;
}

/* Legacy support for JavaScript-added class */
.toggle-switch.active {
    background: #3D5A80;
}

/* Segmented Control */
.segmented-control {
    display: flex;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 3px;
    gap: 4px;
}

.segmented-control .segment {
    padding: 6px 14px !important;
    border: none !important;
    background: transparent !important;
    color: rgba(255, 255, 255, 0.7) !important;
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.segmented-control .segment:hover:not(.active) {
    background: rgba(255, 255, 255, 0.1) !important;
    color: rgba(255, 255, 255, 0.9) !important;
}

.segmented-control .segment.active {
    background: #3D5A80 !important;
    color: white !important;
    font-weight: 600;
}

/* Mode buttons */
.mode-button {
    background: #3D5A80;
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.mode-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(44, 44, 44, 0.12);
}

/* Flashcard container */
.flashcard-container {
    perspective: 1000px;
    margin-bottom: 15px;
    flex: 1; /* Make flashcard container expand to fill available space */
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative; /* For logo watermark positioning */
}

/* Flashcard */
.flashcard {
    width: 100%;
    max-width: 900px;
    height: 740px;
    margin: 0 auto;
    position: relative;
    cursor: pointer;
    /* Prevent mobile tap highlight/flicker */
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    touch-action: manipulation;
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 25px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 35px; /* More vertical padding to account for fixed position elements */
    box-shadow: 0 8px 30px rgba(44, 44, 44, 0.10);
    border: 1px solid rgba(44, 44, 44, 0.04);
    background: #FAFAF7;
    transition: opacity 0.3s ease-out;
}

.card-back {
    /* Use visibility instead of display:none to prevent layout flicker on mobile */
    display: flex;
    visibility: hidden;
    pointer-events: none;
    opacity: 0;
}

.card-content {
    text-align: center;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 25px;
    position: relative;
}

/* Romanization styling */
.romanization {
    position: relative;
    display: inline-block;
    margin-top: 0;
    font-size: var(--text-size-roma, 1.1em);
    color: #4A4642;
    font-weight: 500;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-style: normal;
    letter-spacing: 0.05em;
    padding: 8px 20px;
    background: none;
    backdrop-filter: none;
    border: none;
    border-radius: 8px;
    box-shadow: none;
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease, opacity 0.3s ease;
    z-index: 10;
    text-transform: lowercase;
    white-space: nowrap;
    overflow: visible;
}

/* Hide romanization when empty - prevents flash of empty pill during load */
.romanization:empty {
    display: none !important;
}

/* Pitch-accent brackets — [ and ] glyphs injected around the HIGH region of
 * the romaji (e.g. o[mo]u, [a]ru). Rendered as quiet typographic annotation,
 * NOT decoration: a single warm tone in the same family as the romaji ink
 * (#4A4642) but recessed via alpha to ~50%. This keeps gold reserved for the
 * design system's "scarcity = meaning" moments (kintsugi error recovery,
 * sakura streaks) and lets the brackets read like parentheses — present when
 * you look for them, invisible when you don't. Applied across focus, video,
 * revise, and mobile Learn Mode wherever romaji is rendered.
 *
 * !important on .letter.pitch-bracket: mode-specific rules
 * (body.focus-mode .romanization .letter { color: #4A4642 }) outscore us on
 * specificity, and the bracket class is a leaf-level visual override with
 * no logical conflict to resolve via cascade.
 */
.pitch-bracket {
    color: rgba(74, 70, 66, 0.5);
    font-weight: inherit;
    margin: 0 1px;
    font-size: 0.92em;
    letter-spacing: -0.02em;
}
.letter.pitch-bracket {
    color: rgba(74, 70, 66, 0.5) !important;
    font-weight: inherit;
}

/*
 * Pitch-accent notation — renderOverlineHtml() in pitch.js tags each mora as
 * .pa-hi (HIGH) or .pa-lo (LOW); the *visual* encoding lives here, so the look
 * can change without touching JS. We use WEIGHT, not a drawn line: HIGH morae
 * are bold and LOW morae are normal + slightly dimmed, so the high run reads as
 * a calm bold cluster (the drop = where bold ends). This is far less cramped
 * than an overline at the 12px mobile romaji size, and fits the 和の感性
 * "subtraction" floor. Weight inherits the romaji's colour, so it works on both
 * light paper and dark photo cards. (.pa-step — the old downstep tick — is now
 * inert; the weight contrast already marks the drop.)
 */
.pa { white-space: nowrap; }
.pa-m { display: inline; }
.pa-hi { font-weight: 700; }
.pa-lo { font-weight: 400; opacity: 0.72; }


/* Content text styles */
.vocabulary-image {
    max-width: 520px;
    max-height: 520px;
    width: auto;
    height: auto;
    border-radius: 14px;
    box-shadow: 0 15px 35px rgba(44, 44, 44, 0.07);
    object-fit: contain;
    transition: transform 0.3s ease;
}

.vocabulary-image:hover {
    transform: scale(1.02);
}

.japanese-text {
    font-size: var(--text-size-ja, 4.5em);
    font-weight: 600;
    color: #332F2B; /* Warm sumi ink - unified across all modes */
    font-family: 'Klee One', 'Noto Sans JP', sans-serif;
    line-height: 1.4;
    white-space: nowrap;
    overflow: visible;
    /* Clean container - aligned with English face's light feel */
    display: inline-block;
    background: rgba(255, 255, 255, 0.97);
    padding: 12px 24px;
    border-radius: 12px;
    backdrop-filter: none;
    border: 1px solid rgba(44, 44, 44, 0.04);
    box-shadow: 0 1px 4px rgba(44, 44, 44, 0.03);
    text-shadow: none;
    /* Constrain width to prevent overflow */
    max-width: 90%;
    box-sizing: border-box;
}

/* ========================================
   Multi-form Verb Display (Two-Column)
   Dictionary form left, derived forms right
   ======================================== */

.verb-forms {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3em;
}

.verb-dictionary {
    font-size: 1em;
    font-weight: 600;
    color: inherit;
}

.verb-separator {
    display: none; /* Pill style doesn't need separator */
}

.verb-derived-stack {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.05em;
    line-height: 1.4;
}

.verb-polite,
.verb-te {
    font-size: 0.55em;
    font-weight: 400;
    color: #57534e;
    opacity: 1;
    white-space: nowrap;
}

/* Romanization version - single line */
.verb-romanization {
    gap: 0.4em;
}

.verb-romanization .verb-derived {
    font-size: 0.85em;
    font-weight: 400;
    opacity: 0.75;
    white-space: nowrap;
}

/* Mobile: Override dynamic scaling for verbs - use fixed sizes */
@media (max-width: 768px) {
    /* Japanese verb forms - smaller to fit long verbs like もってくる */
    .verb-forms:not(.verb-romanization) {
        font-size: 1.9rem !important;
    }

    .verb-dictionary {
        font-size: 1em; /* 2.2rem */
    }

    .verb-polite,
    .verb-te {
        font-size: 0.7em; /* ~1.5rem */
    }

    .verb-derived-stack {
        gap: 0.06em;
    }

    /* Romanization - smaller than Japanese */
    .verb-romanization {
        font-size: 1rem !important;
    }

    .verb-romanization .verb-dictionary {
        font-size: 1em;
        font-weight: 600;
    }

    .verb-romanization .verb-derived {
        font-size: 0.85em;
    }
}

.english-text {
    font-size: var(--text-size-en, 2.8em);
    font-weight: 600;
    color: #57534e; /* Warm stone - unified across all modes */
    line-height: 1.3;
    white-space: nowrap;
    overflow: visible;
}

/* Class badge (POS only - simple) */
.class-badge {
    position: absolute;
    top: 25px;
    right: 25px;
    background: rgba(61, 90, 128, 0.08);
    color: #3D5A80;
    padding: 8px 18px;
    border-radius: 50px;
    font-weight: 500;
    font-size: 0.9em;
    box-shadow: none;
    border: 1px solid rgba(61, 90, 128, 0.15);
    text-transform: lowercase;
    letter-spacing: 0.5px;
    backdrop-filter: blur(6px);
    transition: opacity 0.3s ease, transform 0.3s ease, box-shadow 0.3s ease;
}

/* Focus / video / revision POS badge — full styling in focus-mode.css
   (#class-badge cream chip rule). This stub is intentionally empty;
   the legacy right: 20px !important was beating the new right: 140px
   that pairs POS to the left of the freq chip. */

/* Video/Revision POS badge — unified with focus via the cream chip system
   (defined in focus-mode.css next to #class-badge). Legacy indigo override
   removed 2026-05-25; the chip surface now matches the freq chip. */

.card-number {
    position: absolute;
    top: 25px;
    left: 25px;
    transform: none;
    color: var(--text-secondary);
    font-size: 1em;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(6px);
    padding: 8px 18px;
    border-radius: 25px;
    font-weight: 500;
    box-shadow: 0 4px 15px rgba(44, 44, 44, 0.05);
    z-index: 100;
    border: 1px solid rgba(44, 44, 44, 0.05);
    transition: opacity 0.3s ease, transform 0.3s ease, box-shadow 0.3s ease;
    font-variant-numeric: tabular-nums;
}

/* 🔧 SPLIT: Focus mode gets minimal treatment, video/revision keep current styling */

/* Focus mode: Quiet frosted pill (matches focus-mode.css #card-number) */
body.focus-mode .card-number {
    padding: 8px 18px !important;
    font-size: 1rem !important;
    font-weight: 600 !important;
    top: 20px !important;
    left: 20px !important;
    background: rgba(44, 44, 44, 0.18) !important;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    color: rgba(255, 255, 255, 0.85) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    border-radius: 20px !important;
    box-shadow: none !important;
    text-shadow: 0 1px 2px rgba(44, 44, 44, 0.3);
    opacity: 0.6;
    transition: opacity 0.3s ease;
}

body.focus-mode .card-number:hover {
    opacity: 0.95;
}

/* Video/Revision modes: Aligned with focus mode sizing */
body.video-mode .card-number,
body.revision-mode .card-number {
    padding: 8px 18px !important;
    font-size: 1rem !important;
    font-weight: 600 !important;
    top: 30px !important;
    left: 30px !important;
    background: #3D5A80 !important;
    color: white !important; /* White text on colored background */
    box-shadow: 0 4px 20px rgba(61, 90, 128, 0.24) !important; /* Glowing shadow */
}

/* ========================================
   STATUS DOT - Quiz-Derived Mastery Status
   ======================================== */

/* Card number layout for status dot */
.card-number {
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-number-text {
    /* Inherits styling from parent */
}

/* Status dot - minimal indicator */
.status-dot {
    font-size: 0.8em;
    line-height: 1;
    cursor: help;
    transition: color 0.3s ease, opacity 0.3s ease, transform 0.3s ease;
    opacity: 0.9;
}

/* Status dot colors - Manual status (user-controlled) */
.status-dot.status-new,
.status-dot.dot-new {
    color: #9CA3AF; /* Gray - not marked */
}

.status-dot.status-learning,
.status-dot.dot-learning {
    color: rgba(194, 130, 114, 0.9); /* Terracotta - still learning */
}

.status-dot.status-known,
.status-dot.dot-known {
    color: rgba(163, 177, 138, 0.9); /* Moss - mastered */
}

/* Legacy quiz-derived classes (kept for compatibility) */
.status-dot.status-practicing {
    color: rgba(194, 130, 114, 0.9);
}

.status-dot.status-mastered {
    color: rgba(163, 177, 138, 0.9);
}

/* Hover effect on dot */
.status-dot:hover {
    opacity: 1;
    transform: scale(1.2);
}

/* ========================================
   CARD INFO TOOLTIP - Premium Status + Textbook
   Status-based accent colors throughout
   ======================================== */

.card-info-tooltip {
    /* Hidden by default */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px) scale(0.96);

    /* Positioning */
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 10px;
    z-index: 1000;

    /* Premium glass effect */
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(12px) saturate(120%);
    -webkit-backdrop-filter: blur(12px) saturate(120%);

    /* Sizing */
    min-width: 220px;
    max-width: 280px;
    padding: 14px 16px;
    padding-left: 20px; /* Room for accent bar */

    /* Visual styling */
    border-radius: 14px;
    border: 1px solid rgba(44, 44, 44, 0.06);
    box-shadow:
        0 12px 32px rgba(44, 44, 44, 0.07),
        0 4px 12px rgba(44, 44, 44, 0.05),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);

    /* Animation */
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s cubic-bezier(0.4, 0, 0.2, 1), border-color 0.25s cubic-bezier(0.4, 0, 0.2, 1);

    /* Status accent bar (left edge) - color set by status class */
    overflow: hidden;
}

/* Accent bar on left edge */
.card-info-tooltip::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: #9CA3AF; /* Default gray, overridden by status */
    border-radius: 14px 0 0 14px;
}

/* Status-based accent bar colors - Manual status (user-controlled) */
.card-info-tooltip.status-new::before {
    background: #9CA3AF;
}

.card-info-tooltip.status-learning::before {
    background: rgba(194, 130, 114, 0.85);
}

.card-info-tooltip.status-known::before {
    background: rgba(163, 177, 138, 0.85);
}

/* Legacy quiz-derived classes (kept for compatibility) */
.card-info-tooltip.status-practicing::before {
    background: rgba(194, 130, 114, 0.85);
}

.card-info-tooltip.status-mastered::before {
    background: rgba(163, 177, 138, 0.85);
}

/* Show tooltip on hover */
.card-number:hover .card-info-tooltip,
.status-dot:hover + .card-info-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ---- Status Section ---- */
.tooltip-status {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tooltip-status-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 4px 10px;
    border-radius: 6px;
    width: fit-content;
}

/* Status label pill backgrounds - Manual status (user-controlled) */
.tooltip-status-label.status-new {
    color: #4B5563;
    background: rgba(156, 163, 175, 0.15);
    border: 1px solid rgba(107, 114, 128, 0.2);
}

.tooltip-status-label.status-learning {
    color: #A3604E;
    background: rgba(194, 130, 114, 0.12);
    border: 1px solid rgba(194, 130, 114, 0.25);
}

.tooltip-status-label.status-known {
    color: #6B8F5B;
    background: rgba(163, 177, 138, 0.12);
    border: 1px solid rgba(163, 177, 138, 0.25);
}

/* Legacy quiz-derived classes (kept for compatibility) */
.tooltip-status-label.status-practicing {
    color: #A3604E;
    background: rgba(194, 130, 114, 0.12);
    border: 1px solid rgba(194, 130, 114, 0.25);
}

.tooltip-status-label.status-mastered {
    color: #6B8F5B;
    background: rgba(163, 177, 138, 0.12);
    border: 1px solid rgba(163, 177, 138, 0.25);
}

/* Quiz stats - larger, more prominent */
.tooltip-status-detail {
    font-size: 0.85rem;
    color: #374151;
    line-height: 1.4;
    font-weight: 500;
}

/* Style the percentage within the detail */
.tooltip-status-detail strong {
    font-weight: 700;
}

/* Last tested line - subtle with icon */
.tooltip-last-tested {
    font-size: 0.75rem;
    color: #6B7280;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
}

.tooltip-last-tested::before {
    content: '🕐';
    font-size: 0.7rem;
}

/* ---- Divider ---- */
.tooltip-divider {
    height: 1px;
    background: rgba(44, 44, 44, 0.06);
    margin: 12px 0;
}

/* ---- Textbook Section ---- */
.tooltip-textbook {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tooltip-textbook-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: #1E3A5F; /* Default indigo */
    display: flex;
    align-items: center;
    gap: 6px;
}

.tooltip-textbook-name::before {
    content: '📚';
    font-size: 0.85rem;
}

/* Textbook-specific icons and colors */
.tooltip-textbook-name[data-textbook*="Genki"]::before {
    content: '📘';
}
.tooltip-textbook-name[data-textbook*="Genki"] {
    color: #2563EB; /* Blue for Genki */
}

.tooltip-textbook-name[data-textbook*="Ippo"]::before {
    content: '🎌';
}
.tooltip-textbook-name[data-textbook*="Ippo"] {
    color: #DC2626; /* Red for Ippo (Japanese flag) */
}

.tooltip-textbook-name[data-textbook*="JapanesePod"]::before {
    content: '🎧';
}
.tooltip-textbook-name[data-textbook*="JapanesePod"] {
    color: #7C3AED; /* Purple for JapanesePod */
}

.tooltip-textbook-lesson {
    font-size: 0.72rem;
    font-weight: 500;
    color: #64748B; /* Muted slate gray */
    padding: 2px 0 0 22px; /* Align with text after icon */
    width: fit-content;
}

/* Textbook-specific lesson text colors (subtle) */
.tooltip-textbook-lesson[data-textbook*="Genki"] {
    color: #64748B;
}

.tooltip-textbook-lesson[data-textbook*="Ippo"] {
    color: #64748B;
}

.tooltip-textbook-lesson[data-textbook*="JapanesePod"] {
    color: #64748B;
}

/* Hide textbook section if empty */
.tooltip-textbook:empty {
    display: none;
}
.tooltip-textbook:empty + .tooltip-divider {
    display: none;
}

/* ========================================
   TEXTBOOK TOOLTIP - COMPACT PREMIUM
   ======================================== */

.textbook-indicator {
    margin-left: 6px;
    font-size: 0.85em;
    opacity: 0.75;
    cursor: help;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-block;
}

.textbook-indicator:hover {
    opacity: 1;
    transform: scale(1.1);
}

.textbook-tooltip {
    /* Hidden by default */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px) scale(0.96);

    /* Positioning */
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 10px;
    z-index: 1000;

    /* Premium glass effect */
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px) saturate(120%);
    -webkit-backdrop-filter: blur(12px) saturate(120%);

    /* Compact sizing - wider to prevent wrapping */
    min-width: 240px;
    max-width: 380px;
    padding: 8px 12px;

    /* Visual styling */
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.8);
    box-shadow:
        0 10px 28px rgba(44, 44, 44, 0.07),
        0 4px 10px rgba(44, 44, 44, 0.04),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);

    /* Category color accent */
    border-left: 3px solid var(--category-primary);

    /* Typography */
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 0.8em;
    line-height: 1.5;
    color: var(--text-primary);

    /* Smooth transitions */
    transition:
        opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        visibility 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transition-delay: 0.12s;

    pointer-events: none;
}

/* Washi paper texture */
.textbook-tooltip::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(255, 255, 255, 0.04) 2px, rgba(255, 255, 255, 0.04) 4px),
        repeating-linear-gradient(90deg, transparent, transparent 2px, rgba(255, 255, 255, 0.04) 2px, rgba(255, 255, 255, 0.04) 4px),
        repeating-linear-gradient(45deg, transparent, transparent 3px, rgba(44, 44, 44, 0.015) 3px, rgba(44, 44, 44, 0.015) 6px);
    opacity: 0.5;
    mix-blend-mode: overlay;
    pointer-events: none;
    border-radius: inherit;
    z-index: 1;
}

/* Category color tint */
.textbook-tooltip::after {
    content: '';
    position: absolute;
    inset: 0;
    background: color-mix(in srgb, var(--category-primary) 4%, transparent);
    opacity: 0.5;
    pointer-events: none;
    border-radius: inherit;
    z-index: 2;
}

.card-number:hover .textbook-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Arrow */
.textbook-tooltip-arrow {
    position: absolute;
    bottom: 100%;
    left: 18px;
    width: 0;
    height: 0;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-bottom: 7px solid var(--category-primary);
    filter: drop-shadow(0 -2px 3px rgba(44, 44, 44, 0.08));
    z-index: 3;
}

.textbook-tooltip > * {
    position: relative;
    z-index: 10;
}

/* Compact items */
.textbook-tooltip-item {
    margin-bottom: 6px;
    padding: 5px 8px;
    background: rgba(255, 255, 255, 0.35);
    border-radius: 8px;
    border: 1px solid rgba(44, 44, 44, 0.04);
}

.textbook-tooltip-item:last-child {
    margin-bottom: 0;
}

/* Source */
.textbook-tooltip-source {
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 0.92em;
    font-weight: 700;
    letter-spacing: 0.01em;
    color: var(--category-primary);
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.textbook-tooltip-source::before {
    content: '📖';
    font-size: 1.05em;
    filter: drop-shadow(0 1px 2px rgba(44, 44, 44, 0.1));
}

.textbook-tooltip-source[data-textbook*="Ippo"]::before {
    content: '🎌';
}

.textbook-tooltip-source[data-textbook*="Genki"]::before {
    content: '📘';
}

.textbook-tooltip-source[data-textbook*="JapanesePod"]::before {
    content: '🎧';
}

/* Lesson */
.textbook-tooltip-lesson {
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 0.88em;
    font-weight: 500;
    color: var(--text-secondary);
    padding: 3px 8px;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 6px;
    border: 1px solid rgba(44, 44, 44, 0.05);
    display: inline-block;
    white-space: nowrap; /* Prevent wrapping */
}

/* Hide textbook indicator in video/revision modes only (shown in focus mode for study) */
body.video-mode .textbook-indicator,
body.revision-mode .textbook-indicator {
    display: none !important;
}

/* Focus mode textbook tooltip - match standard mode light theme */
body.focus-mode .textbook-tooltip {
    /* Same light glass as standard mode for consistency */
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(12px) saturate(120%);
    -webkit-backdrop-filter: blur(12px) saturate(120%);
    border: 1px solid rgba(44, 44, 44, 0.08);
    box-shadow:
        0 10px 28px rgba(44, 44, 44, 0.09),
        0 4px 10px rgba(44, 44, 44, 0.05),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    color: var(--text-primary, #1d1d1f);
    /* Ensure proper text containment */
    max-width: 420px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

body.focus-mode .textbook-tooltip-source {
    color: var(--category-primary, #3D5A80);
}

body.focus-mode .textbook-tooltip-lesson {
    color: #1d1d1f;
    word-break: break-word;
    white-space: normal;
}

body.focus-mode .textbook-tooltip-item {
    background: rgba(255, 255, 255, 0.5);
    border-color: rgba(44, 44, 44, 0.04);
}

body.focus-mode .textbook-tooltip-arrow {
    border-bottom-color: rgba(255, 255, 255, 0.98);
}



/* 縦書き (Tategaki) — Vertical Japanese accent text */
.tategaki-accent {
    writing-mode: vertical-rl;
    font-family: 'Klee One', 'Noto Sans JP', sans-serif;
    font-size: 1.4rem;
    font-weight: 600;
    color: #C9A96E;
    letter-spacing: 0.15em;
    line-height: 1;
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.7;
}

body.video-mode .tategaki-accent {
    display: none;
}

/* Audio button (Updated for visibility) */
.audio-button {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08); /* Match nav-buttons */
    border: none;
    color: rgba(255, 255, 255, 0.9);
    font-size: 1.4rem; /* Match nav-buttons */
    cursor: pointer;
    transition: background-color 0.2s cubic-bezier(0.3, 1.5, 0.5, 1), transform 0.2s cubic-bezier(0.3, 1.5, 0.5, 1), opacity 0.2s cubic-bezier(0.3, 1.5, 0.5, 1), box-shadow 0.2s cubic-bezier(0.3, 1.5, 0.5, 1);
    box-shadow: none; /* Remove shadow to match nav-buttons style initially */
    display: flex;
    align-items: center;
    justify-content: center;
    /* Remove absolute positioning to fit in flex container */
    position: static; 
    bottom: auto;
    right: auto;
}

.audio-button:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.15);
    color: white;
}

.audio-button.playing {
    animation: pulse 1.5s infinite;
    background: #3D5A80;
    color: white;
}

.audio-button.hidden {
    display: none !important;
}

/* Navigation */
.navigation {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 25px;
    margin-bottom: 10px;
}

.nav-button {
    width: 56px;
    height: 56px;
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4em;
    background: #ffffff;
    box-shadow: 0 6px 20px rgba(44, 44, 44, 0.05);
    transition: background-color 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid rgba(44, 44, 44, 0.05);
}

.nav-button:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 10px 30px rgba(44, 44, 44, 0.07);
}

/* Progress bar */
.progress-container {
    width: 100%;
    max-width: 900px;
    margin: 15px auto 15px;
    background: rgba(255,255,255,0.12);
    border-radius: 10px;
    padding: 2px;
    box-shadow: inset 0 1px 3px rgba(44, 44, 44, 0.05);
}

.progress-bar {
    height: 8px;
    background: linear-gradient(90deg, var(--category-light) 0%, var(--category-primary) 100%);
    border-radius: 8px;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(61, 90, 128, 0.15);
}

/* Hide old focus button on card - now in action bar */
.focus-button-card {
    display: none !important;
}

/* ========================================
   PREMIUM FILTER SECTION
   ======================================== */

.filter-section {
    width: 100%;
    margin-bottom: 16px;
}

.filter-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.filter-icon {
    font-size: 1.4em;
    filter: drop-shadow(0 2px 4px rgba(44,44,44,0.2));
}

.filter-title {
    font-family: 'Inter', sans-serif;
    font-size: 1.1em;
    font-weight: 600;
    color: white;
    letter-spacing: -0.01em;
}

.word-count-badge {
    margin-left: auto;
    background: #3D5A80;
    color: white;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.9em;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(61, 90, 128, 0.18);
    transition: transform 0.3s ease, box-shadow 0.3s ease, opacity 0.3s ease;
}

.word-count-badge:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(61, 90, 128, 0.24);
}

#filteredWordCount {
    font-weight: 700;
    font-size: 1.1em;
}

.filter-controls {
    width: 100%;
}

.filter-row {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.filter-group {
    flex: 1 1 0;
    min-width: 220px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.filter-group label {
    font-size: 0.9em;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    gap: 6px;
}

.premium-select {
    width: 100%;
    padding: 12px 16px;
    border-radius: 12px;
    border: 2px solid rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.95);
    color: #2d3748;
    font-size: 0.95em;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease, color 0.3s ease;
    box-shadow: 0 4px 12px rgba(44, 44, 44, 0.05);
}

.premium-select:hover:not(:disabled) {
    border-color: rgba(255, 255, 255, 0.4);
    background: white;
    box-shadow: 0 6px 16px rgba(44, 44, 44, 0.07);
    transform: translateY(-1px);
}

.premium-select:focus:not(:focus-visible) {
    outline: none;
}

.premium-select:focus {
    border-color: #3D5A80;
    box-shadow: 0 0 0 4px rgba(61, 90, 128, 0.12);
}

.premium-select:focus-visible {
    outline: 2px solid #3D5A80;
    outline-offset: 2px;
}

.premium-select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: rgba(255, 255, 255, 0.6);
}

.control-divider {
    width: 100%;
    height: 1px;
    background: rgba(255, 255, 255, 0.2);
    margin: 16px 0;
}

.settings-section {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

/* Responsive adjustments for filters */
@media (max-width: 900px) {
    .filter-row {
        flex-direction: column;
    }
    
    .filter-group {
        min-width: 100%;
    }
}


/* ========================================
   SHORTCUTS PANEL (Premium Minimal Helper)
   ======================================== */

/* Hide on mobile */
@media (max-width: 768px) {
    /* Hide textbook references in status tooltip - show only mastery status */
    .card-info-tooltip .tooltip-divider,
    .card-info-tooltip .tooltip-textbook {
        display: none !important;
    }
}
