/* ==========================================================================
   FlashCards — design tokens
   A clean, modern study tool: soft neutral surface, one confident indigo
   accent, and clear semantic color for the two study actions (red = not
   yet, green = got it). Mobile-first: base rules target small screens,
   min-width queries add refinement as the viewport grows.
   ========================================================================== */

:root {
    --bg: #f5f6fb;
    --surface: #ffffff;
    --surface-muted: #eef0f9;
    --border: #e3e6f3;

    --ink: #14151f;
    --ink-soft: #6a6f85;
    --ink-faint: #9599ac;

    --primary: #5b5fef;
    --primary-dark: #4649c9;
    --primary-soft: #edeefe;

    --danger: #ff4d5e;
    --danger-dark: #e23648;
    --danger-soft: #ffe9eb;

    --success: #16b978;
    --success-dark: #0f9c64;
    --success-soft: #e4faf1;

    --font-display: "Space Grotesk", "Inter", sans-serif;
    --font-body: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: "JetBrains Mono", "SFMono-Regular", monospace;

    --radius-lg: 22px;
    --radius-md: 14px;
    --radius-sm: 10px;
    --radius-pill: 999px;

    --shadow-sm: 0 2px 8px rgba(20, 21, 31, 0.06);
    --shadow-md: 0 10px 30px rgba(20, 21, 31, 0.10);
    --shadow-lg: 0 20px 50px rgba(20, 21, 31, 0.16);

    --fab-safe-zone: 6.5rem;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-body);
    line-height: 1.55;
    font-size: 0.95rem;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

@media (min-width: 768px) {
    body {
        font-size: 1rem;
    }
}

a {
    color: var(--primary);
    text-decoration: none;
}

::selection {
    background: var(--primary);
    color: #fff;
}

.btn {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-pill);
    font-weight: 600;
    font-size: 0.88rem;
    padding-inline: 1.1rem;
    border: 1px solid transparent;
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

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

a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}

/* ---------------------------------------------------------------------- */
/* Buttons                                                                 */
/* ---------------------------------------------------------------------- */

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    color: #fff;
}

.btn-ghost {
    background: var(--surface);
    border-color: var(--border);
    color: var(--ink);
}

.btn-ghost:hover {
    background: var(--surface-muted);
    color: var(--ink);
    border-color: var(--border);
}

.btn-outline-danger {
    background: transparent;
    border-color: var(--danger-soft);
    color: var(--danger-dark);
}

.btn-outline-danger:hover {
    background: var(--danger-soft);
    color: var(--danger-dark);
    border-color: var(--danger-soft);
}

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    background: var(--danger-dark);
    border-color: var(--danger-dark);
    color: #fff;
}

/* ---------------------------------------------------------------------- */
/* Nav / brand                                                             */
/* ---------------------------------------------------------------------- */

.navbar-app {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding-top: 0.7rem;
    padding-bottom: 0.7rem;
}

.brand {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: -0.01em;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.brand .brand-mark {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.95rem;
}

.brand-tag {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    font-weight: 500;
    color: var(--primary);
    letter-spacing: 1.5px;
    text-transform: uppercase;
    background: var(--primary-soft);
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius-pill);
}

@media (min-width: 576px) {
    .brand {
        font-size: 1.3rem;
    }
}

.eyebrow {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--ink-faint);
    font-weight: 600;
}

.app-footer {
    color: var(--ink-faint);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    text-align: center;
    padding: 1.5rem 1rem 2rem;
}

#view-study {
    padding-bottom: var(--fab-safe-zone);
}

/* ---------------------------------------------------------------------- */
/* Hero / home                                                             */
/* ---------------------------------------------------------------------- */

.home-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.9rem;
    line-height: 1.15;
    letter-spacing: -0.01em;
    color: var(--ink);
}

@media (min-width: 576px) {
    .home-title {
        font-size: 2.5rem;
    }
}

@media (min-width: 768px) {
    .home-title {
        font-size: 3rem;
    }
}

/* Deck avatar — a small gradient badge with the deck's initial, giving
   every deck a distinct, memorable identity at a glance. */
.deck-avatar {
    width: 44px;
    height: 44px;
    border-radius: 13px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.deck-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.1rem;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.deck-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
}

@media (max-width: 767.98px) {
    .deck-card {
        flex-direction: row;
        align-items: center;
    }

    .deck-card-body {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 0.85rem;
    }

    .deck-card-footer {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        flex: 1;
    }
}

.deck-card .deck-name {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.05rem;
    color: var(--ink);
    line-height: 1.2;
}

.deck-card .deck-meta {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--ink-faint);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.deck-card-body {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    min-width: 0;
}

.deck-card-footer {
    color: var(--ink-soft);
    font-size: 0.82rem;
    line-height: 1.4;
}

.panel-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}

/* ---------------------------------------------------------------------- */
/* Progress bar                                                            */
/* ---------------------------------------------------------------------- */

.progress-track {
    height: 8px;
    background: var(--surface-muted);
    border-radius: var(--radius-pill);
    overflow: hidden;
}

.progress-track .bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #8b5cf6);
    border-radius: var(--radius-pill);
    transition: width 0.3s ease;
}

.progress-label {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--ink-faint);
    letter-spacing: 0.5px;
}

/* ---------------------------------------------------------------------- */
/* Flash card + flip animation                                            */
/* ---------------------------------------------------------------------- */

.card-stack {
    position: relative;
    max-width: 560px;
    margin: 0 auto;
}

.flip-scene {
    perspective: 1800px;
    -webkit-perspective: 1800px;
}

.flip-card {
    position: relative;
    width: 100%;
    display: grid;
    transition: transform 0.5s cubic-bezier(0.4, 0.2, 0.2, 1);
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
}

/* Used briefly by JS to reset the flip state without animating, so a
   lingering flip from the previous card never visibly "spins" when the
   next card's content is swapped in. */
.flip-card.no-anim {
    transition: none !important;
}

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

/* Both faces occupy the same grid cell (rather than being absolutely
   positioned to a fixed-height parent), so the card's height is always
   driven by whichever face's content is tallest — short Q&A stays compact,
   and a few paragraphs of text simply make the card taller instead of
   overflowing or getting clipped. */
.flip-face {
    grid-column: 1;
    grid-row: 1;
    min-height: 230px;
    max-height: 65vh;
    overflow-y: auto;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    /* Promotes each face to its own crisp GPU layer at native resolution
       instead of a scaled bitmap, which is what was making the text look
       blurry during and after the 3D flip. */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 1.5rem 1.35rem;
}

@media (min-width: 576px) {
    .flip-face {
        min-height: 280px;
        padding: 2.25rem 2rem;
    }
}

.flip-face-back {
    transform: rotateY(180deg) translateZ(0);
    -webkit-transform: rotateY(180deg) translateZ(0);
    background: var(--primary-soft);
    border-color: var(--primary-soft);
}

.flip-face .face-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: 100%;
    font-size: 1.15rem;
    font-weight: 500;
    color: var(--ink);
    overflow-wrap: break-word;
    white-space: pre-wrap;
}

/* Rich-text content from the editor (paragraphs, lists, bold/italic runs)
   needs its own baseline spacing — Quill's default HTML doesn't carry any
   styling of its own. Using column-direction flex above (rather than the
   row-direction flex this used to have) is what fixes long answers: a
   single list/paragraph as the lone item in a *row* flex container was
   sized by shrink-to-fit/min-content rules and could collapse into a
   garbled narrow column. Column direction stretches it to full width by
   default while still centering short content vertically. */
.face-body p,
.face-body ol,
.face-body ul,
.face-body blockquote {
    margin: 0 0 0.65em;
}

.face-body ol,
.face-body ul {
    padding-left: 1.4em;
}

.face-body li {
    margin-bottom: 0.3em;
}

.face-body > *:last-child {
    margin-bottom: 0;
}

.face-body a {
    color: var(--primary-dark);
    text-decoration: underline;
}

@media (min-width: 576px) {
    .flip-face .face-body {
        font-size: 1.3rem;
    }
}

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

/* ---------------------------------------------------------------------- */
/* Grade buttons — fixed red (bottom-left) / green (bottom-right)         */
/* Each corner is its own independently fixed element (not a shared       */
/* full-width flex bar) so positioning never depends on a parent's width. */
/* ---------------------------------------------------------------------- */

.grade-fab-slot {
    position: fixed;
    bottom: calc(1.1rem + env(safe-area-inset-bottom, 0px));
    z-index: 1040;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.grade-fab-slot--left {
    left: 1.1rem;
}

.grade-fab-slot--right {
    right: 1.1rem;
}

.grade-fab-slot.d-none {
    display: none;
}

.grade-fab {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

@media (min-width: 576px) {
    .grade-fab {
        width: 72px;
        height: 72px;
    }
}

.grade-fab svg {
    width: 28px;
    height: 28px;
}

@media (min-width: 576px) {
    .grade-fab svg {
        width: 32px;
        height: 32px;
    }
}

.grade-fab:active {
    transform: scale(0.9);
}

.grade-fab-fail {
    background: var(--danger);
    color: #fff;
}

.grade-fab-fail:hover {
    background: var(--danger-dark);
}

.grade-fab-success {
    background: var(--success);
    color: #fff;
}

.grade-fab-success:hover {
    background: var(--success-dark);
}

.grade-fab-label {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    font-weight: 600;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 0.2rem 0.55rem;
    border-radius: var(--radius-pill);
    white-space: nowrap;
    box-shadow: var(--shadow-sm);
}

/* ---------------------------------------------------------------------- */
/* Editor layout                                                          */
/* ---------------------------------------------------------------------- */

.deck-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.7rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--ink);
    min-height: 44px;
    border: 1px solid transparent;
}

.deck-list-item:hover {
    background: var(--surface-muted);
}

.deck-list-item.active {
    background: var(--primary-soft);
    border-color: var(--primary);
    color: var(--primary-dark);
    font-weight: 600;
}

.deck-list-item .deck-list-name {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    overflow: hidden;
}

.deck-list-item .deck-list-name span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.deck-list-item .deck-count {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    color: var(--ink-faint);
    flex-shrink: 0;
}

.deck-avatar-sm {
    width: 26px;
    height: 26px;
    border-radius: 8px;
    font-size: 0.75rem;
}

.form-label-app {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--ink-faint);
    font-weight: 600;
}

.form-control {
    border-radius: var(--radius-md) !important;
    border-color: var(--border) !important;
    font-family: var(--font-body);
}

.form-control:focus {
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 3px var(--primary-soft) !important;
}

/* Small preview card used in the editor's card list */
.card-chip {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    border-radius: var(--radius-md);
    padding: 0.6rem 0.85rem;
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.card-chip:hover {
    transform: translateX(2px);
    box-shadow: var(--shadow-sm);
}

.card-chip.active {
    border-left-color: var(--success);
    outline: 2px solid var(--primary-soft);
}

.card-chip .chip-question {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-chip .chip-id {
    font-family: var(--font-mono);
    font-size: 0.66rem;
    color: var(--ink-faint);
}

.dirty-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger);
    margin-left: 4px;
    vertical-align: middle;
}

/* Empty states */
.empty-state {
    text-align: center;
    color: var(--ink-faint);
    padding: 2rem 1rem;
    font-family: var(--font-mono);
    font-size: 0.8rem;
}

/* ---------------------------------------------------------------------- */
/* Bootstrap modal — restyle to match                                     */
/* ---------------------------------------------------------------------- */

.modal-content {
    border: none;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    font-family: var(--font-body);
}

.modal-header,
.modal-footer {
    border-color: var(--border);
}

.modal-title {
    font-family: var(--font-display);
    font-weight: 700;
}

kbd {
    background: var(--surface-muted);
    color: var(--ink-soft);
    border-radius: 6px;
    padding: 0.1rem 0.35rem;
    font-family: var(--font-mono);
}

/* ---------------------------------------------------------------------- */
/* Multi-page editor: breadcrumbs, deck-card actions, card rows           */
/* ---------------------------------------------------------------------- */

.min-w-0 {
    min-width: 0;
}

.breadcrumb-link {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--ink-soft);
    letter-spacing: 0.3px;
}

.breadcrumb-link:hover {
    color: var(--primary);
}

.deck-card-actions {
    display: flex;
    gap: 0.35rem;
    flex-shrink: 0;
}

.deck-card-actions .btn {
    min-height: 34px;
    padding-inline: 0.6rem;
}

/* Full-width card row on the Cards page */
.card-row {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    border-radius: var(--radius-md);
    padding: 0.75rem 0.9rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    transition: box-shadow 0.12s ease, transform 0.12s ease;
}

.card-row:hover {
    box-shadow: var(--shadow-sm);
    transform: translateX(2px);
}

.card-row-main {
    flex: 1 1 220px;
    min-width: 0;
    cursor: pointer;
}

.card-row-question {
    font-weight: 600;
    font-size: 0.94rem;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-row-id {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    color: var(--ink-faint);
}

.card-row-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* ---------------------------------------------------------------------- */
/* Rich text editor (Quill) — themed to match the app                    */
/* ---------------------------------------------------------------------- */

.rich-editor .ql-toolbar.ql-snow {
    border-color: var(--border);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    background: var(--surface-muted);
}

.rich-editor .ql-container.ql-snow {
    border-color: var(--border);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    font-family: var(--font-body);
    font-size: 0.95rem;
    background: var(--surface);
}

.rich-editor .ql-editor {
    min-height: 130px;
    color: var(--ink);
    line-height: 1.55;
}

.rich-editor .ql-editor.ql-blank::before {
    color: var(--ink-faint);
    font-style: normal;
    font-family: var(--font-body);
}

.rich-editor .ql-snow .ql-stroke {
    stroke: var(--ink-soft);
}

.rich-editor .ql-snow .ql-fill {
    fill: var(--ink-soft);
}

.rich-editor .ql-snow.ql-toolbar button:hover .ql-stroke,
.rich-editor .ql-snow.ql-toolbar button.ql-active .ql-stroke {
    stroke: var(--primary);
}

.rich-editor .ql-snow.ql-toolbar button:hover .ql-fill,
.rich-editor .ql-snow.ql-toolbar button.ql-active .ql-fill {
    fill: var(--primary);
}

/* Keep the editor's top-right button group on a single line even on very
   narrow screens; labels abbreviate via the markup, this just guards
   against any residual overflow. */
.nav-actions {
    flex-shrink: 0;
    overflow-x: auto;
}

.nav-actions .btn {
    white-space: nowrap;
}
