/* ---------- GRID ---------- */

.card{
    position:relative;
    min-height:0;
    perspective:1000px;
    cursor:pointer;
    box-sizing:border-box;
    border:1px solid var(--paper-line);
    border-radius:var(--radius);
    transition:border-color .25s ease, box-shadow .25s ease;
}

.inner{
    width:100%;
    height:100%;
    min-height:0;
    position:relative;
    display:grid;
    flex:1 1 auto;
    align-self:stretch;
    transition:transform .5s cubic-bezier(.4,.1,.2,1);
    transform-style:preserve-3d;
}

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

@media (prefers-reduced-motion:reduce){
    .inner{ transition:none; }
    .card{ transition:none; }
}

.front,
.back{
    position:relative;
    inset:auto;
    grid-area:1 / 1;
    width:100%;
    box-sizing:border-box;
    display:flex;
    flex-direction:column;
    justify-content:center;
    align-items:center;
    gap:4px;
    text-align:center;
    padding:15px;
    line-height:1.4;
    word-break:break-word;
    backface-visibility:hidden;
    border:1px solid transparent;
    box-shadow:var(--shadow);
    overflow-y:auto;
}

.front{
    background:var(--paper-cell);
    color:var(--ink);
    font-family:'Zen Kaku Gothic New', sans-serif;
    font-size:15px;
    font-weight:600;
}

.back{
    background:var(--indigo);
    color:#F7F2E7;
    font-family:'Zen Kaku Gothic New', sans-serif;
    font-size:13.5px;
    font-weight:400;
    transform:rotateY(180deg);
    border-color:transparent;
}
.back .bangla{ color:#59cb75; }
.card:hover{ border-color:var(--vermilion); }
.card.grammar .front{ color:var(--vermilion); }
body.dark .card.grammar .front{ color:var(--vermilion); }

.speaker-btn{
    top:6px;
    right:6px;
    width:26px;
    height:26px;
    font-size:13px;
}

.lesson-tag{
    display:inline-block;
    font-family:'JetBrains Mono', monospace;
    font-size:9.5px;
    text-transform:uppercase;
    letter-spacing:.06em;
    color:var(--ink-soft);
}
.back .lesson-tag{ color:rgba(247,242,231,.65); }

.field{
    display:flex;
    flex-direction:column;
    gap:4px;
    position:relative;
    width:auto;
    flex:1 0 auto;
}

.vocabulary-back{
    align-items:center;
    justify-content:center;
    text-align:center;
    gap:6px;
}
.vocabulary-back .romaji{
    font-family:'JetBrains Mono', monospace;
    font-size:14px;
    font-weight:700;
    letter-spacing:.03em;
}
.vocabulary-back .english{ font-size:14px; font-weight:500; }
.vocabulary-back .bangla{
    font-family:'Noto Sans Bengali','Noto Sans',sans-serif;
    font-size:14px;
    font-weight:500;
    line-height:1.5;
}

.lesson-reset-btn{
    width:100%;
    min-height:38px;
    display:flex;
    align-items:center;
    justify-content:center;
    padding:6px 12px;
    border:1px solid var(--paper-line);
    border-radius:6px;
    background:var(--paper-cell);
    color:var(--ink);
    line-height:1;
    cursor:pointer;
    transition:transform .2s ease, border-color .25s ease, background-color .25s ease;
}
.lesson-reset-btn:hover,
.lesson-reset-btn:focus-visible{
    border-color:var(--vermilion);
    transform:translateY(-1px);
    outline:none;
}

.mobile-bottom-controls{ display:none; }

#backRomajiToggle,
#direction,
#shuffleBtn,
#lessonResetBtn,
.mobile-bottom-controls > button{ color:var(--vermilion) !important; }

.lesson-control-svg{
    width:20px !important;
    height:20px !important;
    flex:0 0 20px;
    display:inline-block;
    vertical-align:middle;
    fill:none !important;
    stroke:currentColor !important;
    stroke-width:1.8;
    stroke-linecap:round;
    stroke-linejoin:round;
}
.lesson-control-label{ color:inherit; }
html, body{ overscroll-behavior-y:none; }

@media only screen and (max-width:520px) {
    .toolbar .teacher-mode-btn, .toolbar .teacher-stop-btn{ display:none; }
    html, body{ overscroll-behavior-y:none; }
    .front{ font-size:18px; text-align:center; }
    .back{ font-size:16px; }
    .vocabulary-back .romaji,
    .vocabulary-back .english,
    .vocabulary-back .bangla{ font-size:13px; }

    .mobile-bottom-controls{
        position:fixed;
        left:0;
        right:0;
        bottom:0;
        z-index:9999;
        display:flex;
        align-items:stretch;
        width:100%;
        padding:5px 5px calc(5px + env(safe-area-inset-bottom));
        background:var(--paper-cell);
        border-top:1px solid var(--paper-line);
        box-shadow:0 -4px 14px rgba(36,31,24,.12);
        gap:5px;
    }

    .mobile-bottom-controls > button,
    .mobile-bottom-controls > .abacus,
    .mobile-bottom-controls > .screen-wake-field{
        flex:1 1 0;
        width:auto;
        min-width:0;
        min-height:44px;
        margin:0;
        border-radius:6px;
    }

    .mobile-bottom-controls > .screen-wake-field{
        display:flex !important;
        flex-direction:column;
        align-items:stretch;
        justify-content:stretch;
    }

    .mobile-bottom-controls .screen-wake-field > button{
        width:100%;
        min-width:0;
        height:100%;
        min-height:44px;
        padding:6px;
        background:transparent;
        box-shadow:none;
        white-space:nowrap;
        color:var(--vermilion) !important;
    }

    .mobile-bottom-controls .screen-wake-field .lesson-control-text{
        display:none !important;
    }

    .mobile-bottom-controls .lesson-reset-btn{ font-size:22px; padding:6px; }
    .mobile-bottom-controls .romaji-toggle{ font-size:20px; }
    .mobile-bottom-controls #shuffleBtn{ display:flex; align-items:center; justify-content:center; }
    .mobile-bottom-controls .rod{ width:42px; }
    .mobile-bottom-controls .abacus.right .bead{ transform:translate(22px,-50%); }
}

.recall-answer{ display:flex; flex-direction:column; padding-top:10px; }
.count-display{ max-width:var(--layout-width); margin:0 auto 20px; text-align:center !important; }

/* ---------- LESSON CARD NATURAL HEIGHT + EQUAL GRID ROWS ---------- */
.grid{ align-items:stretch; }
.grid > .card{ align-self:stretch; min-height:0 !important; height:auto !important; }
.card.lesson-card-structured{ min-height:0 !important; height:auto !important; }

.card.lesson-card-structured .lesson-card-inner{
    position:relative !important;
    inset:auto !important;
    width:100% !important;
    height:auto !important;
    min-height:0 !important;
    display:flex !important;
    flex-direction:column !important;
    flex:1 1 auto !important;
    overflow:visible !important;
    box-sizing:border-box !important;
    grid-template-rows: auto minmax(0, 1fr) auto !important;
}

/* ---------- EQUAL HEIGHT PER GRID ROW ---------- */
.grid{ align-items:stretch; }
.grid > .card{ align-self:stretch; height:auto !important; display:flex; flex-direction:column; }
.card.lesson-card-structured{ height:auto !important; }
.card.lesson-card-structured .lesson-card-inner{ height:100% !important; }
.card.lesson-card-structured .lesson-card-inner > .inner{
    width:100% !important;
    height:auto !important;
    min-height:100% !important;
    flex:1 1 auto !important;
    align-self:stretch !important;
}
.card.lesson-card-structured .lesson-card-content{ position:relative !important; width:100% !important; height:100% !important; min-height:0 !important; display:grid !important; flex:0 0 auto !important; overflow:visible !important; }
.card.lesson-card-structured .lesson-card-content > .front,
.card.lesson-card-structured .lesson-card-content > .back{ height:100% !important; }

/* ---------- GENERIC INNER ROW FILL ---------- */
/* The grid row determines the card height from the tallest card. The generic
   .inner then stretches inside that card without using a fixed pixel height. */
.grid > .card > .inner{
    flex:1 1 auto;
    width:100%;
    min-height:0;
    height:auto;
    align-self:stretch;
}

@media only screen and (max-width:520px){
    .card.lesson-card-structured .lesson-card-inner > .inner{
        min-height:100% !important;
    }
}

.lesson-card-topbar{
    border-radius: 5px 5px 0 0 !important;
}

.lesson-card-bottombar{
        background-color: #18212c !important;
}

.inner .lesson-tag{
    display: none !important;
}

.lesson-card-bottombar {
    border-radius: 0 0 5px 5px !important;
}
