/* ═══════════════════════════════════════════════
   MOBILE GRID VIEW — Browse layer between landing and Learn Mode
   Scoped under body.mobile-grid-active + #mobile-grid-container
   Class prefix: mg- (mobile grid)
   ═══════════════════════════════════════════════ */

/* ── Body-level rules ── */
body.mobile-grid-active {
    overflow: hidden;
    position: fixed;
    inset: 0;
    color-scheme: light;
}

body.mobile-grid-active .grid-container,
body.mobile-grid-active .flashcard-container,
body.mobile-grid-active .bottom-action-bar,
body.mobile-grid-active #mobileLandingContainer,
body.mobile-grid-active .container,
body.mobile-grid-active .hero-top-bar,
body.mobile-grid-active .ink-wash-nav,
body.mobile-grid-active .app-branding-topleft,
body.mobile-grid-active .mf-bottom-bar,
body.mobile-grid-active .mf-floating-audio,
body.mobile-grid-active .mf-scroll-track,
body.mobile-grid-active .mf-page-indicator,
body.mobile-grid-active .mf-status-bar {
    display: none !important;
}

body.mobile-grid-active #app {
    visibility: hidden;
    height: 0;
    overflow: hidden;
}

body:not(.mobile-grid-active) #mobile-grid-container {
    display: none !important;
}

/* ── Container ── */
#mobile-grid-container {
    position: fixed;
    inset: 0;
    z-index: 90;
    background:
        radial-gradient(ellipse 90% 70% at 50% 15%, var(--seasonal-tint, rgba(201, 169, 110, 0.04)) 0%, transparent 70%),
        var(--color-paper, #F0EDE8);
    display: flex;
    flex-direction: column;
    -webkit-overflow-scrolling: touch;
}

/* ── Washi paper grain (matches landing + Learn Mode) ── */
#mobile-grid-container::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    opacity: 0.025;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
    background-size: 300px 300px;
}

#mobile-grid-container.mg-entering {
    animation: mgEntrance 300ms ease-out both;
}

#mobile-grid-container.mg-exiting {
    opacity: 0;
    transform: scale(0.985);
    transition: opacity 280ms ease-out, transform 280ms ease-out;
    pointer-events: none;
}

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

/* ═══════════════════════════════════════════════
   HEADER — Fixed top bar
   ═══════════════════════════════════════════════ */

.mg-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 12px;
    height: 52px;
    padding: 0 16px;
    padding-top: env(safe-area-inset-top, 0);
    background: var(--color-paper, #F0EDE8);
    border-bottom: none;
    transition: background 0.3s ease, box-shadow 0.3s ease, backdrop-filter 0.3s ease;
}

.mg-header--solid {
    background: rgba(240, 237, 232, 0.88);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 1px 0 rgba(216, 210, 200, 0.4);
}

.mg-back {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(168, 162, 158, 0.18);
    padding: 0;
    cursor: pointer;
    border-radius: 50%;
    color: var(--color-stone, #57534e);
    -webkit-tap-highlight-color: transparent;
    transition: none;
}

.mg-back:hover {
    transform: none;
    box-shadow: none;
}

.mg-back:active {
    background: rgba(168, 162, 158, 0.35);
    transform: none;
}

.mg-back svg {
    width: 18px;
    height: 18px;
}

.mg-title {
    flex: 1;
    font-family: var(--font-ui, 'Inter', sans-serif);
    font-size: 16px;
    font-weight: 500;
    color: var(--color-stone, #57534e);
    letter-spacing: 0.01em;
}

.mg-count {
    font-family: var(--font-jp, 'Klee One', serif);
    font-size: 13px;
    font-weight: 400;
    color: var(--color-stone, #57534e);
    padding: 0;
    background: none;
    border-radius: 0;
    letter-spacing: 0.02em;
}

/* ═══════════════════════════════════════════════
   LIST — Scrollable word rows
   ═══════════════════════════════════════════════ */

.mg-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 20px 0;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0));
    position: relative;
}

/* ── Section hairline between header and content ── */
.mg-list::before {
    content: '';
    display: block;
    width: 40px;
    height: 0.5px;
    margin: 0 auto 8px;
    background: linear-gradient(90deg, transparent, var(--color-divider, #D8D2C8) 20%, var(--color-divider, #D8D2C8) 80%, transparent);
}

/* ═══════════════════════════════════════════════
   ROW — Individual word entry
   ═══════════════════════════════════════════════ */

.mg-row {
    position: relative;
    padding: 0;
    border-bottom: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    cursor: pointer;
    overflow: hidden;
    animation: mgRowEnter 220ms var(--ease-out, cubic-bezier(0.16, 1, 0.3, 1)) both;
}

/* Gradient fade divider — starts after thumbnail, fades at edges */
.mg-row::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 76px;
    right: 24px;
    height: 0.5px;
    background: linear-gradient(90deg, transparent, var(--color-divider, #D8D2C8) 10%, var(--color-divider, #D8D2C8) 90%, transparent);
    pointer-events: none;
}

.mg-row:last-child::after {
    display: none;
}

.mg-row-inner:active {
    background: rgba(201, 169, 110, 0.06);
}

/* Staggered entry — delays set via inline style */
@keyframes mgRowEnter {
    from { opacity: 0; transform: translateY(6px) scale(0.995); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Thumbnail ── */
.mg-thumb {
    position: relative;
    width: 58px;
    height: 58px;
    border-radius: var(--radius-lg, 14px);
    background: var(--color-card, #FAFAF7);
    overflow: hidden;
    box-shadow: 0 2px 6px rgba(44, 28, 10, 0.06), 0 0 0 0.5px rgba(216, 210, 200, 0.6);
    flex-shrink: 0;
}

.mg-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.mg-thumb img.loaded {
    opacity: 1;
}

/* No-image placeholder */
.mg-thumb.no-image::before {
    content: "\8A00";
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    font-family: var(--font-jp, 'Klee One', serif);
    font-size: 22px;
    color: var(--color-divider, #D8D2C8);
}

/* ── Status dot (thumbnail corner) ── */
.mg-status-dot {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: 1.5px solid var(--color-paper, #F0EDE8);
    opacity: 0;
    animation: mgDotAppear 250ms ease-out 200ms forwards;
}

.mg-status-dot--known {
    background: var(--color-moss);
}

.mg-status-dot--learning {
    background: var(--color-amber);
}

@keyframes mgDotAppear {
    from { opacity: 0; transform: scale(0.4); }
    to   { opacity: 1; transform: scale(1); }
}

/* ── Right-edge status dot ── */
.mg-right-dot {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    height: 8px;
    border-radius: 50%;
    opacity: 0;
    animation: mgDotAppear 250ms ease-out 200ms forwards;
}

.mg-right-dot--known {
    background: var(--color-moss);
}

.mg-right-dot--learning {
    background: var(--color-amber);
}

/* ── Text area ── */
.mg-text {
    min-width: 0;
    padding-right: 20px;
}

.mg-japanese {
    font-family: var(--font-jp, 'Klee One', serif);
    font-size: 22px;
    font-weight: 400;
    color: var(--color-jp-text, #523E1E);
    line-height: 1.4;
    letter-spacing: 0.03em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mg-details {
    display: flex;
    align-items: baseline;
    gap: 0;
    margin-top: 2px;
    font-family: var(--font-ui, 'Inter', sans-serif);
    font-size: 13px;
    line-height: 1.45;
    color: var(--color-stone, #57534e);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mg-roma {
    color: var(--color-romaji, #78716c);
    font-style: italic;
    font-size: 12px;
}

.mg-sep {
    margin: 0 5px;
    color: var(--color-divider, #D8D2C8);
}

.mg-english {
    color: var(--color-stone, #57534e);
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ═══════════════════════════════════════════════
   VISITED STATE — targeted ink-fade, not blanket opacity
   ═══════════════════════════════════════════════ */

.mg-row-visited .mg-japanese {
    color: var(--color-stone, #57534e);
    opacity: 0.85;
    transition: color 0.4s ease, opacity 0.4s ease;
}

.mg-row-visited .mg-thumb {
    filter: saturate(0.7);
    transition: filter 0.4s ease;
}

.mg-row-visited .mg-details {
    color: var(--color-faint, #8C8578);
    transition: color 0.4s ease;
}

/* ═══════════════════════════════════════════════
   SWIPE GESTURE
   ═══════════════════════════════════════════════ */

.mg-row-inner {
    position: relative;
    display: grid;
    grid-template-columns: 58px 1fr;
    gap: 18px;
    align-items: center;
    padding: 18px 0;
    background: var(--color-paper, #F0EDE8);
    z-index: 1;
    will-change: transform;
}

/* When swiping, the row itself becomes the swipe container */
.mg-row.mg-swiping {
    overflow: visible;
}

/* Background reveal behind the sliding row */
.mg-swipe-bg {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    opacity: 0;
    transition: opacity 100ms ease;
    z-index: 0;
}

.mg-swipe-bg.mg-swipe-bg--right {
    justify-content: flex-start;
    padding-left: 20px;
    background: rgba(107, 127, 92, 0.1);
}

.mg-swipe-bg.mg-swipe-bg--left {
    justify-content: flex-end;
    padding-right: 20px;
    background: rgba(160, 120, 80, 0.1);
}

.mg-swipe-bg.mg-swipe-visible {
    opacity: 1;
}

.mg-swipe-icon {
    font-size: 16px;
    font-weight: 500;
    font-family: var(--font-ui, 'Inter', sans-serif);
    color: var(--color-stone, #57534e);
}

.mg-swipe-bg--right .mg-swipe-icon { color: var(--color-moss); }
.mg-swipe-bg--left .mg-swipe-icon  { color: var(--color-amber); }

/* Graded state (after swipe completes) */
.mg-row-graded {
    opacity: 0.6;
    transition: opacity 300ms ease;
}

/* Kintsugi gold sweep on grade */
.mg-row-graded-sweep::before {
    content: "";
    position: absolute;
    left: 76px;
    right: 0;
    bottom: 0;
    height: 1.5px;
    opacity: 0.7;
    transform-origin: left center;
    animation: mgAudioSweep 0.8s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    z-index: 2;
    pointer-events: none;
}

.mg-row-graded-sweep--known::before {
    background: var(--color-gold, #C9A96E);
}

.mg-row-graded-sweep--learning::before {
    background: var(--color-moss, #6B7F5C);
}

/* Row exit animation — card no longer belongs in current deck after grading.
   Two-phase: fade+slide then height collapse (mirrors desktop cardExit). */
@keyframes mgRowExit {
    0%   { opacity: 0.6; transform: translateX(0); height: var(--mg-row-exit-height); }
    40%  { opacity: 0; transform: translateX(-30px); height: var(--mg-row-exit-height); }
    100% { opacity: 0; transform: translateX(-30px); height: 0; padding: 0; margin: 0; border-width: 0; }
}

.mg-row.mg-row-exiting {
    animation: mgRowExit 0.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    pointer-events: none;
    overflow: hidden;
    min-height: 0 !important;
}

/* Snap-back animation */
.mg-snap-back {
    transition: transform 200ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ═══════════════════════════════════════════════
   LONG-PRESS AUDIO
   ═══════════════════════════════════════════════ */

.mg-row.audio-playing::after {
    content: "";
    position: absolute;
    left: 76px;
    right: 0;
    bottom: 0;
    height: 1.5px;
    background: var(--color-gold);
    opacity: 0.6;
    transform-origin: left center;
    animation: mgAudioSweep 1.1s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    z-index: 2;
}

@keyframes mgAudioSweep {
    0%   { transform: scaleX(0); opacity: 0.8; }
    60%  { transform: scaleX(1); opacity: 0.6; }
    100% { transform: scaleX(1); opacity: 0; }
}

.mg-row.audio-playing .mg-thumb {
    animation: mgThumbPulse 0.6s ease-in-out 2;
}

@keyframes mgThumbPulse {
    0%, 100% { box-shadow: 0 1px 2px rgba(44, 44, 44, 0.04), inset 0 0 0 1px rgba(44, 44, 44, 0.04); }
    50%      { box-shadow: 0 1px 2px rgba(44, 44, 44, 0.04), inset 0 0 0 3px rgba(201, 169, 110, 0.35); }
}

/* ═══════════════════════════════════════════════
   PAGINATION
   ═══════════════════════════════════════════════ */

.mg-pagination {
    padding: 20px 0 8px;
    text-align: center;
    position: relative;
}

/* Hairline above pagination */
.mg-pagination::before {
    content: '';
    display: block;
    width: 40px;
    height: 0.5px;
    margin: 0 auto 16px;
    background: linear-gradient(90deg, transparent, var(--color-divider, #D8D2C8) 20%, var(--color-divider, #D8D2C8) 80%, transparent);
}

.mg-load-more {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 28px;
    border: 1px solid rgba(44, 44, 44, 0.08);
    border-radius: var(--radius-xl, 22px);
    background: rgba(250, 250, 247, 0.6);
    font-family: var(--font-ui, 'Inter', sans-serif);
    font-size: 13px;
    font-weight: 500;
    color: var(--color-stone, #57534e);
    letter-spacing: 0.01em;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background 150ms ease, border-color 150ms ease;
}

.mg-load-more:active {
    background: rgba(44, 44, 44, 0.04);
    border-color: rgba(44, 44, 44, 0.12);
}

.mg-load-more-count {
    font-size: 12px;
    color: var(--color-faint, #8C8578);
}

/* ═══════════════════════════════════════════════
   EMPTY STATE
   ═══════════════════════════════════════════════ */

.mg-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 60px 40px;
    text-align: center;
}

.mg-empty-text {
    font-family: var(--font-ui, 'Inter', sans-serif);
    font-size: 15px;
    color: var(--color-stone, #57534e);
    line-height: 1.5;
    margin-bottom: 16px;
}

.mg-empty-back {
    font-family: var(--font-ui, 'Inter', sans-serif);
    font-size: 14px;
    color: var(--color-accent, #3D5A80);
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px 16px;
    -webkit-tap-highlight-color: transparent;
}

/* ═══════════════════════════════════════════════
   STATUS ACCENT LINE (replaces corner/right dots)
   ═══════════════════════════════════════════════ */

.mg-accent-line {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 2.5px;
    height: 55%;
    border-radius: 0 2px 2px 0;
    opacity: 0;
    animation: mgDotAppear 250ms ease-out 200ms forwards;
}

.mg-accent-line--known {
    background: var(--color-moss, #6B7F5C);
}

.mg-accent-line--learning {
    background: var(--color-amber);
}

/* ═══════════════════════════════════════════════
   WARM RETURN — highlight row after Learn Mode
   ═══════════════════════════════════════════════ */

.mg-row-returning {
    animation: mgWarmReturn 800ms ease-out forwards;
}

@keyframes mgWarmReturn {
    0%   { background: rgba(201, 169, 110, 0.10); }
    100% { background: transparent; }
}

/* ═══════════════════════════════════════════════
   HEADER PROGRESS BAR
   ═══════════════════════════════════════════════ */

.mg-progress-bar {
    position: absolute;
    bottom: 0;
    left: 16px;
    right: 16px;
    height: 3px;
    border-radius: 1.5px;
    background: rgba(44, 44, 44, 0.04);
    overflow: hidden;
    display: flex;
}

.mg-progress-segment {
    height: 100%;
    transition: width 0.4s var(--ease-out, cubic-bezier(0.16, 1, 0.3, 1));
}

.mg-progress-segment--known {
    background: var(--color-moss, #6B7F5C);
    border-radius: 1.5px 0 0 1.5px;
}

.mg-progress-segment--learning {
    background: var(--color-amber);
}

/* ═══════════════════════════════════════════════
   GESTURE HINT — quiet one-time primer under header
   ═══════════════════════════════════════════════ */

.mg-hint {
    position: relative;
    margin: 4px 16px 10px;
    padding: 10px 14px;
    border-radius: 10px;
    background: rgba(247, 244, 238, 0.6);
    border: 1px solid rgba(168, 162, 158, 0.14);
    animation: mgHintFadeIn 420ms cubic-bezier(0.16, 1, 0.3, 1) both;
    animation-delay: 120ms;
    z-index: 2;
}

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

.mg-hint-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    align-items: center;
    text-align: center;
}
.mg-hint-line {
    font-family: var(--font-ui, 'Inter', sans-serif);
    font-size: 12.5px;
    line-height: 1.55;
    color: var(--color-stone, #57534e);
    letter-spacing: 0.01em;
}
.mg-hint-line--faint {
    font-size: 11.5px;
    color: var(--color-faint, #8b857a);
}
.mg-hint-arrow {
    color: var(--color-gold, #C9A96E);
    font-weight: 600;
    padding: 0 2px;
}
.mg-hint-sep {
    display: inline-block;
    padding: 0 7px;
    color: rgba(168, 162, 158, 0.55);
}
.mg-hint-dim { color: rgba(168, 162, 158, 0.7); }

.mg-hint-badge {
    position: absolute;
    top: 8px;
    right: 10px;
    width: 20px;
    height: 20px;
    padding: 0;
    border: 1px solid rgba(168, 162, 158, 0.3);
    border-radius: 50%;
    background: rgba(250, 250, 247, 0.7);
    font-family: var(--font-ui, 'Inter', sans-serif);
    font-size: 11px;
    line-height: 1;
    color: var(--color-faint, #8b857a);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, background 0.15s ease;
}

.mg-hint--minimized {
    padding: 0;
    background: transparent;
    border: none;
    min-height: 0;
    margin: 0 16px 6px;
    display: flex;
    justify-content: flex-end;
}
.mg-hint--minimized .mg-hint-body { display: none; }
.mg-hint--minimized .mg-hint-badge {
    position: static;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    pointer-events: auto;
}
.mg-hint--minimized.mg-hint--expanded {
    display: block;
    padding: 10px 14px;
    background: rgba(247, 244, 238, 0.6);
    border: 1px solid rgba(168, 162, 158, 0.14);
    border-radius: 10px;
    margin: 4px 16px 10px;
}
.mg-hint--minimized.mg-hint--expanded .mg-hint-body { display: flex; }
.mg-hint--minimized.mg-hint--expanded .mg-hint-badge {
    position: absolute;
    top: 8px;
    right: 10px;
}

/* ═══════════════════════════════════════════════
   REDUCED MOTION
   ═══════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
    #mobile-grid-container.mg-entering { animation: none; opacity: 1; }
    .mg-row { animation: none; opacity: 1; }
    .mg-status-dot,
    .mg-right-dot,
    .mg-accent-line { animation: none; opacity: 1; }
    .mg-row.audio-playing::after { animation: none; }
    .mg-row.audio-playing .mg-thumb { animation: none; }
    .mg-row-graded-sweep::before { animation: none; }
    .mg-row-returning { animation: none; }
    .mg-hint { animation: none; }
}
