:root {
    --ink:#17332f;
    --soft:#45645b;
    --paper:#fffdf8;
    --card:#fff;
    --cream:#f7f0e2;
    --coral:#ec725d;
    --peach:#ffc078aa;
    --sage:#cfe2d0ff;
    --lav:#e6dcfa;
    --sky:#d9edf1;
    --line:#ded7c8;
    --muted:#68776f;
    --success:#2f8f6a;
    --shadow:0 16px 38px rgba(34, 62, 52, .09)
}

[data-theme=dark] {
    --ink:#eff6ef;
    --soft:#c5d8cc;
    --paper:#142b28;
    --card:#1c3935;
    --cream:#284740;
    --coral:#ff9c84;
    --peach:#7d553baa;
    --sage:#31554c;
    --lav:#403a5a;
    --sky:#294c55;
    --line:#416159;
    --muted:#adc3b8;
    --success:#6fd9ab;
    --shadow:0 16px 38px rgba(0, 0, 0, .25)
}

*, *::before, *::after {
    box-sizing: border-box;
    min-width: 0;
}

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: "DM Sans", Arial, sans-serif;
    transition: .25s;
    overflow-x: hidden;
}

.shell, .site-header {
    width: min(1120px, calc(100% - 32px));
    margin-left: auto !important;
    margin-right: auto !important;
}

.site-header {
    height: 76px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.brand {
    color: var(--ink);
    text-decoration: none;
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -.04em;
}

.brand span, .brand em {
    color: var(--coral);
}

.brand em, h1, h2, h3 {
    font-family: "Playfair Display", serif;
}

.site-header nav {
    display: flex;
    gap: 26px;
}

.site-header nav a, .text-link {
    color: var(--soft);
    text-decoration: none;
    font-size: .85rem;
    font-weight: 600;
}

.theme-toggle {
    width: 38px;
    height: 38px;
    border: 1px solid var(--line);
    background: transparent;
    border-radius: 50%;
    color: var(--ink);
    cursor: pointer;
    font-size: 1.1rem;
}

.eyebrow {
    margin: 0 0 12px;
    color: var(--muted);
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .14em;
}

.hero {
    min-height: 520px;
    padding: 48px 0 66px;
    display: grid;
    grid-template-columns: 1.12fr .88fr;
    align-items: center;
    gap: 34px;
}

.hero h1, .features h2, .how h2, .study-space h2, .dashboard h2 {
    margin: 0;
    letter-spacing: -.065em;
    line-height: .98;
}

.hero h1 {
    font-size: clamp(3.5rem, 7vw, 6rem);
}

.hero h1 i {
    color: var(--coral);
    font-style: normal;
    font-weight: 600;
}

.lead {
    max-width: 540px;
    color: var(--soft);
    line-height: 1.7;
    margin: 25px 0;
    font-size: 1.03rem;
}

.primary {
    border: 0;
    border-radius: 10px;
    background: var(--ink);
    color: var(--paper);
    font: 700 .9rem "DM Sans", sans-serif;
    padding: 13px 18px;
    cursor: pointer;
    box-shadow: 0 5px 0 rgba(23, 51, 47, .3);
    transition: .15s;
}

.primary:hover, .action:hover {
    transform: translateY(-2px);
}

.hero-actions {
    display: flex;
    align-items: center;
    gap: 21px;
}

.promise-list {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
    padding: 0;
    margin: 30px 0 0;
    color: var(--soft);
    font-size: .79rem;
    font-weight: 600;
}

.promise-list li:before {
    content: "✓";
    color: var(--coral);
    margin-right: 5px;
}

.hero-art {
    height: 300px;
    position: relative;
}

.note {
    position: absolute;
    color: var(--ink);
    border-radius: 15px;
    box-shadow: var(--shadow);
}

.note-back {
    right: 17%;
    top: 22px;
    width: 200px;
    height: 245px;
    padding: 39px 24px;
    background: var(--sage);
    font: 600 1.35rem/1.2 "Playfair Display", serif;
    transform: rotate(7deg);
}

.note-front {
    right: 30%;
    top: 31px;
    width: 210px;
    height: 240px;
    padding: 28px;
    background: var(--peach);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transform: rotate(-6deg);
}

.note-front span {
    color: var(--coral);
    font-size: 2rem;
}

.note-front strong {
    font-size: 2.2rem;
    line-height: .9;
    letter-spacing: -.07em;
}

.note-front small {
    font-size: .7rem;
}

.dashboard {
    padding: 30px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 30px;
    border-block: 1px solid var(--line);
}

.dashboard h2 {
    font-size: 2rem;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    flex: 1;
    max-width: 700px;
}

.metric-grid article {
    border-left: 1px solid var(--line);
    padding-left: 14px;
}

.metric-grid strong {
    display: block;
    color: var(--coral);
    font: 700 2rem/1 "Playfair Display", serif;
}

.metric-grid span {
    display: block;
    color: var(--muted);
    font-size: .7rem;
    line-height: 1.25;
    margin-top: 5px;
}

.features {
    padding: 100px 0;
}

.features h2, .how h2, .study-space h2 {
    font-size: clamp(2.4rem, 4vw, 3.8rem);
    max-width: 620px;
}

.feature-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-top: 42px;
}

.feature-grid article {
    min-height: 230px;
    padding: 21px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 15px;
}

.feature-icon {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    font-size: .75rem;
    font-weight: 700;
    margin-bottom: 34px;
}

.peach { background: var(--peach); }
.sage { background: var(--sage); }
.lavender { background: var(--lav); }
.sky { background: var(--sky); }

.feature-grid h3, .upload-panel h3 {
    margin: 0 0 8px;
    font-size: 1.1rem;
}

.feature-grid p, .how p {
    color: var(--soft);
    font-size: .87rem;
    line-height: 1.6;
    margin: 0;
}

.how {
    background: var(--cream);
    padding: 90px 0;
    width: 100%;
}

.how-inner {
    display: grid;
    grid-template-columns: .9fr 1.1fr;
    gap: 70px;
}

.how > p {
    margin-top: 22px;
}

.how ol {
    margin: 0;
    padding: 0;
    list-style: none;
}

.how li {
    display: flex;
    gap: 20px;
    padding: 20px 0;
    border-bottom: 1px solid var(--line);
}

.how li:first-child {
    padding-top: 0;
}

.how li span {
    width: 34px;
    height: 34px;
    border: 1px solid var(--coral);
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: var(--coral);
    font-size: .8rem;
    font-weight: 700;
    flex-shrink: 0;
}

.how h3 {
    font-family: "DM Sans", sans-serif;
    margin: 5px 0;
}

.benefit {
    margin-top: 70px;
    margin-bottom: 70px;
    padding: 34px 5%;
    border-radius: 18px;
    background: var(--ink);
    color: var(--paper);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
}

.benefit p {
    margin: 0;
    font: 700 clamp(1.4rem, 3vw, 2.4rem)/1 "Playfair Display", serif;
    letter-spacing: -.05em;
}

.benefit div {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.benefit span {
    font-size: .76rem;
    opacity: .78;
}

.benefit span:before {
    content: "●";
    color: var(--coral);
    font-size: .55rem;
    margin-right: 6px;
}

.study-space {
    padding: 40px 0 100px;
    scroll-margin-top: 15px;
}

.section-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 20px;
    margin-bottom: 27px;
}

.section-heading > p {
    margin: 0 0 7px;
    color: var(--muted);
    font-size: .84rem;
    text-align: right;
}

.workspace {
    display: grid;
    grid-template-columns: .75fr 1.6fr;
    gap: 15px;
    width: 100%;
}

.upload-panel, .workspace-panel, .result {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 17px;
    max-width: 100%;
}

.upload-panel {
    padding: 40px 20px;
    text-align: center;
    display: flex;
    align-items: center;
    flex-direction: column;
}

.upload-icon {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    background: var(--sage);
    border-radius: 50%;
    font-size: 1.5rem;
    margin-bottom: 16px;
}

.upload-panel > p {
    color: var(--muted);
    font-size: .83rem;
    line-height: 1.6;
    margin: 0 0 21px;
}

.file-status {
    margin: 20px 0 0 !important;
    overflow-wrap: anywhere;
}

.workspace-panel {
    padding: 27px;
    opacity: .48;
    pointer-events: none;
    transition: .25s;
}

.workspace-panel.ready {
    opacity: 1;
    pointer-events: auto;
}

.controls {
    display: flex;
    justify-content: space-between;
    gap: 22px;
    padding-bottom: 23px;
    border-bottom: 1px solid var(--line);
}

.pills, .chips {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.mode, .difficulty, .chips button {
    border: 1px solid var(--line);
    background: transparent;
    color: var(--soft);
    padding: 7px 10px;
    border-radius: 99px;
    font: 600 .73rem "DM Sans", sans-serif;
    cursor: pointer;
    white-space: normal;
}

.mode.selected, .difficulty.selected {
    background: var(--ink);
    border-color: var(--ink);
    color: var(--paper);
}

.action-title {
    margin-top: 24px;
}

.action-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 9px;
}

.action {
    border: 1px solid transparent;
    background: var(--cream);
    border-radius: 12px;
    padding: 16px;
    text-align: left;
    color: var(--ink);
    cursor: pointer;
    transition: .15s;
}

.action:hover {
    border-color: var(--coral);
}

.action span {
    display: block;
    color: var(--coral);
    font: 1.4rem/1 "Playfair Display", serif;
    margin-bottom: 13px;
}

.action strong, .action small {
    display: block;
}

.action strong {
    font-size: .86rem;
}

.action small {
    color: var(--muted);
    font-size: .71rem;
    margin-top: 5px;
}

.question-form {
    margin-top: 25px;
}

.question-form label {
    font-size: .85rem;
    font-weight: 700;
    display: block;
    margin-bottom: 8px;
}

.question-entry {
    display: flex;
    border: 1px solid var(--line);
    background: var(--paper);
    border-radius: 10px;
    overflow: hidden;
}

.question-entry input {
    flex: 1;
    min-width: 0;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--ink);
    padding: 12px;
    font: inherit;
    font-size: .85rem;
}

.send {
    width: 46px;
    border: 0;
    background: var(--ink);
    color: var(--paper);
    font-size: 1.25rem;
    cursor: pointer;
    flex-shrink: 0;
}

.chips {
    margin-top: 9px;
}

.chips button {
    font-size: .67rem;
    padding: 5px 8px;
}

.result {
    margin-top: 15px;
    padding: 27px;
    min-height: 130px;
}

.result-heading {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--line);
}

.result-heading > div:last-child {
    display: flex;
    gap: 15px;
}

.result-heading button {
    border: 0;
    background: transparent;
    color: var(--soft);
    font: 600 .78rem "DM Sans", sans-serif;
    text-decoration: underline;
    cursor: pointer;
    white-space: nowrap;
}

.result-heading button:disabled {
    opacity: .5;
    cursor: default;
}

#resultMode {
    margin: 0;
    color: var(--muted);
    font-size: .76rem;
}

#resultText { 
    font-size: 1rem; 
    line-height: 1.8;
    overflow-wrap: break-word; 
    word-break: normal; 
}
#resultText > p,
.flashcard-answer > p {
    margin: 0 0 14px;
}
#resultText strong, .flashcard strong {
    color: var(--ink);
    font-weight: 700;
    letter-spacing: 0.02em;
}

#resultText h2, #resultText h3, #resultText h4 { 
    font-family: "Playfair Display", serif; 
    color: var(--ink); 
    line-height: 1.25; 
    font-weight: 700;
}
#resultText h2 { 
    margin: 32px 0 16px; 
    padding: 12px 16px; 
    font-size: 1.45rem; 
    border-left: 4px solid var(--coral); 
    border-radius: 0 12px 12px 0; 
    background: color-mix(in srgb, var(--cream) 80%, transparent); 
}
#resultText h3 { margin: 26px 0 10px; font-size: 1.25rem; }
#resultText h4 { margin: 20px 0 8px; font-size: 1.05rem; }
#resultText hr { margin: 24px 0; border: 0; border-top: 1px solid var(--line); }

.result-spacer { height: 8px; }

.structured-list-item {
    display: grid;
    grid-template-columns: 1.5rem minmax(0, 1fr);
    column-gap: 12px;
    align-items: start;
    margin: 8px 0;
}

.structured-list-item.depth-1 { margin-left: 2.5rem; }
.structured-list-item.depth-2 { margin-left: 5rem; }
.structured-list-item.depth-3 { margin-left: 7.5rem; }

.list-marker {
    color: var(--coral);
    font-weight: 700;
    text-align: right;
    white-space: nowrap;
    font-size: 1.1rem;
    margin-top: -1px;
}
.list-content { min-width: 0; }
.formula-indent { margin-top: 12px; margin-bottom: 12px; }
.structured-list-item.number .list-marker, 
.structured-list-item.letter .list-marker { color: var(--ink); font-size: 1rem; }
.structured-list-item.arrow .list-marker { font-size: 1.2rem; }

#resultText pre {
    margin: 12px 0;
    padding: 14px;
    overflow: visible;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--cream);
    white-space: pre-wrap;
}

#resultText pre code {
    display: block;
    padding: 0;
    background: transparent;
    overflow-wrap: normal;
    line-height: 1.6;
}

.flashcard-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 18px;
}

.flashcard {
    min-height: 120px;
    padding: 16px;
    background: var(--cream);
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow-wrap: break-word;
}

.flashcard .formula-block {
    margin: 12px 0;
    padding: 10px 12px;
}

.flashcard strong {
    display: block;
    color: var(--ink);
    margin-bottom: 14px;
    overflow-wrap: break-word;
}

.flashcard-label {
    display: block;
    color: var(--coral);
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
}
.flashcard-answer { margin-top: 8px; line-height: 1.65; }

#resultText code,
.flashcard code {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: .86em;
    background: var(--line);
    color: var(--ink);
    padding: 1px 6px;
    border-radius: 5px;
    overflow-wrap: break-word;
    word-break: normal;
}

.formula-block {
    margin: 16px 0;
    padding: 14px 16px;
    border: 1px solid color-mix(in srgb, var(--success) 34%, var(--line));
    border-left: 4px solid var(--success);
    border-radius: 0 12px 12px 0;
    background: color-mix(in srgb, var(--sage) 46%, var(--card));
    overflow-x: auto;
    text-align: center;
    line-height: 1.45;
}
#resultText .katex {
    color: inherit;
    white-space: normal;
    overflow-wrap: normal;
    word-break: normal;
    font-size: clamp(.68rem, 2.65vw, 1.05em);
}

#resultText .katex:not(.katex-display .katex) {
    display: inline-block;
    overflow-x: auto;
    overflow-y: hidden;
    vertical-align: -0.05em;
    scrollbar-width: none;      /* Firefox */
    -ms-overflow-style: none;   /* old Edge/IE */
}
#resultText .katex:not(.katex-display .katex)::-webkit-scrollbar {
    display: none;              /* Chrome, Safari */
    height: 0;
}

#resultText .katex-display {
    display: block;
    max-width: 100%;
    margin: 0;
    padding: 0;
    overflow: visible;
    text-align: center;
}

#resultText .katex-display > .katex {
    display: inline-block;
    min-width: 0;
    max-width: 100%;
}

.quiz-score {
    margin: 0 0 18px;
    color: var(--muted);
    font-size: .76rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
}

.quiz-card {
    padding: 18px 0;
    border-bottom: 1px solid var(--line);
}

.quiz-card:first-of-type {
    padding-top: 0;
}

.quiz-card:last-of-type {
    border-bottom: 0;
    padding-bottom: 0;
}

.quiz-question {
    margin: 0 0 12px;
    color: var(--ink);
    font-weight: 700;
    font-size: .95rem;
    line-height: 1.5;
}

.quiz-options {
    display: grid;
    gap: 8px;
}

.quiz-option {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    border: 1px solid var(--line);
    background: var(--cream);
    border-radius: 12px;
    padding: 12px 14px;
    text-align: left;
    color: var(--ink);
    font: 600 .83rem "DM Sans", sans-serif;
    cursor: pointer;
    transition: .15s;
}

.quiz-option:hover:not(:disabled) {
    border-color: var(--coral);
    transform: translateY(-1px);
}

.quiz-option:disabled {
    cursor: default;
}

.quiz-option-letter {
    display: grid;
    place-items: center;
    flex: none;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--card);
    border: 1px solid var(--line);
    font-size: .72rem;
    font-weight: 700;
}

.quiz-option.correct {
    border-color: var(--success);
    background: color-mix(in srgb, var(--success) 16%, var(--cream));
}

.quiz-option.correct .quiz-option-letter {
    background: var(--success);
    border-color: var(--success);
    color: var(--paper);
}

.quiz-option.incorrect {
    border-color: var(--coral);
    background: color-mix(in srgb, var(--coral) 14%, var(--cream));
}

.quiz-option.incorrect .quiz-option-letter {
    background: var(--coral);
    border-color: var(--coral);
    color: var(--paper);
}

.quiz-explanation {
    margin: 12px 2px 0;
    color: var(--soft);
    font-size: .84rem;
    line-height: 1.6;
}

.quiz-explanation:empty {
    display: none;
}

.history-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin: 15px 0 0;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--line);
}

.history-chip {
    border: 1px solid var(--line);
    background: var(--cream);
    color: var(--soft);
    padding: 6px 12px;
    border-radius: 99px;
    font: 600 .72rem "DM Sans", sans-serif;
    cursor: pointer;
    transition: .15s;
}

.history-chip:hover {
    border-color: var(--coral);
    color: var(--ink);
}

.history-chip.active {
    background: var(--ink);
    border-color: var(--ink);
    color: var(--paper);
}

.result-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
    overflow: visible;
}

.result-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font: 700 .95rem "DM Sans", sans-serif;
    padding: 12px 4px 14px;
    margin-bottom: -1px;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: .15s;
}

.result-tab:hover {
    color: var(--ink);
}

.result-tab.active {
    color: var(--ink);
    border-bottom-color: var(--coral);
}

.result-tab-close {
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    color: var(--muted);
    font-size: .95rem;
    line-height: 1;
}

.result-tab-close:hover {
    background: var(--line);
    color: var(--ink);
}

.qa-question {
    margin: 0 0 14px;
    padding: 0;
    background: transparent;
    border: 0;
    color: var(--ink);
    font-weight: 700;
    font-size: 1rem;
    line-height: 1.5;
}

.site-footer {
    padding: 33px 0 42px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 20px;
    border-top: 1px solid var(--line);
}

.site-footer p {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: .78rem;
}

.loading {
    position: fixed;
    z-index: 10;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(10, 30, 26, .3);
    backdrop-filter: blur(3px);
}

.loader-card {
    width: min(310px, calc(100% - 40px));
    padding: 28px;
    text-align: center;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow);
}

.spark-loader {
    width: 50px;
    height: 50px;
    display: grid;
    place-items: center;
    margin: 0 auto 17px;
    border-radius: 50%;
    background: var(--peach);
    color: var(--coral);
    font-size: 1.4rem;
    animation: pulse 1.1s infinite;
}

.loader-card strong {
    font: 1.2rem "Playfair Display", serif;
}

.loader-card p {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: .8rem;
    line-height: 1.5;
}

@keyframes pulse {
    50% {
        transform: scale(.82) rotate(12deg);
        opacity: .7;
    }
}

@media (min-width: 1201px) {
  .shell, .site-header {
    width: min(1200px, calc(100% - 40px));
  }
}

@media (max-width: 1200px) {
  .hero { gap: 24px; padding: 40px 0 50px; }
  .hero h1 { font-size: 3.8rem; }
  .lead { font-size: 0.98rem; }
  .metric-grid { max-width: 680px; gap: 6px; }
  .metric-grid article strong { font-size: 1.75rem; }
  .metric-grid article span { font-size: 0.65rem; }
  .feature-grid article { padding: 16px; }
  .how-inner { gap: 40px; }
}

@media (max-width: 992px) {
  .site-header { height: 70px; }
  .site-header nav { gap: 16px; }
  .hero { grid-template-columns: 1fr 1fr; gap: 20px; }
  .hero h1 { font-size: clamp(2.8rem, 5vw, 3.8rem); }
  .dashboard { flex-direction: column; align-items: flex-start; gap: 20px; }
  .metric-grid { width: 100%; max-width: 100%; grid-template-columns: repeat(5, 1fr); }
  .features { padding: 60px 0; }
  .feature-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .how { padding: 50px 0; }
  .how-inner { grid-template-columns: 1fr; gap: 32px; }
  .study-space { padding: 30px 0 60px; }
  .workspace { grid-template-columns: 1fr; gap: 20px; }
  .controls { flex-direction: column; gap: 16px; }
  .action-grid { grid-template-columns: repeat(3, 1fr); }
  .flashcard-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 767px) {
  .site-header nav { display: none; }
  .hero { grid-template-columns: 1fr; text-align: center; }
  .hero-art { display: none; }
  .hero-actions { justify-content: center; }
  .lead { margin: 18px auto; }
  .promise-list { justify-content: center; }
  .metric-grid { grid-template-columns: repeat(3, 1fr); gap: 16px 10px; max-width: 100%; }
  .action-grid { grid-template-columns: 1fr; }
  .action { padding: 14px; }
  .benefit { flex-direction: column; align-items: flex-start; padding: 24px 20px; margin: 30px 0; }
  .benefit div { margin-top: 14px; }
  .result { padding: 20px; }
  .result-heading { flex-direction: column; align-items: flex-start; gap: 12px; }
  .result-heading > div:last-child { justify-content: flex-start; gap: 12px; }
  .flashcard-grid { grid-template-columns: 1fr; }
  .site-footer { flex-direction: column; align-items: flex-start; padding: 24px 0 32px; }
}

@media (max-width: 576px) {
  .shell, .site-header { width: min(100% - 24px, 1120px); }
  .site-header { height: 60px; }
  .brand { font-size: 1.1rem; }
  .theme-toggle { width: 34px; height: 34px; font-size: 1rem; }
  .eyebrow { font-size: 0.62rem; letter-spacing: 0.1em; }
  .hero h1 { font-size: 2.5rem; line-height: 1.05; }
  .lead { font-size: 0.88rem; line-height: 1.5; }
  .hero-actions { flex-direction: column; width: 100%; gap: 10px; }
  .hero-actions .primary, .hero-actions .text-link { width: 100%; text-align: center; }
  .promise-list { font-size: 0.72rem; gap: 6px 12px; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); gap: 14px 10px; }
  .metric-grid article { padding-left: 10px; border-left: 1px solid var(--line); }
  .features h2, .how h2, .study-space h2, .dashboard h2 { font-size: 2rem; }
  .feature-grid { grid-template-columns: 1fr; }
  .workspace-panel { padding: 16px; }
  .upload-panel { padding: 24px 14px; }
  .upload-icon { width: 44px; height: 44px; font-size: 1.25rem; }
  .pills { gap: 5px; }
  .mode, .difficulty { padding: 6px 9px; font-size: 0.68rem; }
  .question-entry input { padding: 10px; font-size: 0.8rem; }
  .send { width: 40px; }
  .chips button { font-size: 0.63rem; padding: 4px 7px; }
  .quiz-card { padding: 14px 0; }
  .quiz-question { font-size: 0.88rem; }
  .quiz-option { padding: 10px 12px; font-size: 0.78rem; }
  .quiz-option-letter { width: 22px; height: 22px; font-size: 0.65rem; }
  .history-chip { padding: 5px 10px; font-size: 0.68rem; }
  .result-tab { font-size: 0.86rem; padding: 10px 3px 12px; }
  .result-tab-close { width: 20px; height: 20px; font-size: 0.86rem; }
  .loader-card { width: min(270px, calc(100% - 30px)); padding: 22px; }
  .spark-loader { width: 42px; height: 42px; font-size: 1.2rem; }
  #resultText h2 { padding: 10px 12px; font-size: 1.25rem; }
  .structured-list-item.depth-1 { margin-left: 1.4rem; }
  .structured-list-item.depth-2 { margin-left: 2.6rem; }
  .structured-list-item.depth-3 { margin-left: 3.8rem; }
}

@media (max-width: 380px) {
  .hero h1 { font-size: 2.1rem; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric-grid article { border-left: none; border-bottom: 1px solid var(--line); padding: 8px 0; }
  .metric-grid article:last-child { border-bottom: none; }
  .benefit p { font-size: 1.2rem; width: 100%; }
  .study-space { width: 100%; }
}