/**
 * Daily Card - Styles
 *
 * Design: the deck as printed matter. The 1909 Rider-Waite-Smith cards are flat
 * lithographic inks on cream card stock with black keylines and hand-lettered
 * title plates, so the app borrows from the booklet that came with them:
 * uncoated paper, warm black ink, small-caps labels, hairline and double rules.
 * Accent colours are sampled from the cards themselves and used sparingly.
 *
 * Palette (sampled from the scans):
 * - Paper:     #efe7d6 (a shade lighter than the card stock, so cards read as objects)
 * - Ink:       #231d15 (the cards' warm black keyline)
 * - Back blue: #2f5f86 (the card back's blue, deepened for text contrast)
 * - Vermilion: #b4502e (the Magician's robe; used for warnings/destructive actions)
 * - Ochre:     #d9b24a (the Star; used for small highlights)
 *
 * Type:
 * - Display: IM Fell English (18th-century press type; uneven, printed feel)
 * - Text:    EB Garamond (book face with true small caps and old-style figures)
 */

/* ==================== FONTS ==================== */
/* Served from this site (not Google Fonts) so visitors' browsers contact no one else.
   Latin subset only; see assets/fonts/README.txt for licences. */
@font-face {
    font-family: 'EB Garamond';
    font-style: normal;
    font-weight: 400 600;
    font-display: swap;
    src: url('../assets/fonts/eb-garamond-latin.woff2') format('woff2');
}

@font-face {
    font-family: 'EB Garamond';
    font-style: italic;
    font-weight: 400;
    font-display: swap;
    src: url('../assets/fonts/eb-garamond-italic-latin.woff2') format('woff2');
}

@font-face {
    font-family: 'IM Fell English';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('../assets/fonts/im-fell-english-latin.woff2') format('woff2');
}

/* ==================== TOKENS ==================== */
:root {
    color-scheme: light;

    --paper: #efe7d6;
    --paper-deep: #e5dbc5;        /* inputs, pressed states */
    --card-stock: #e0d6bf;        /* matches the scans' cream edge */
    --ink: #231d15;
    --ink-soft: #4d4234;
    --ink-muted: #6f624e;         /* 4.6:1 on paper */
    --rule: rgba(35, 29, 21, 0.5);
    --rule-faint: rgba(35, 29, 21, 0.18);
    --blue: #2f5f86;
    --blue-deep: #244a69;
    --vermilion: #b4502e;
    --ochre: #d9b24a;
    --on-blue: #f4eee1;
    --lightbox-backdrop: rgba(24, 19, 13, 0.94);

    --font-display: 'IM Fell English', 'Iowan Old Style', Georgia, serif;
    --font-text: 'EB Garamond', 'Iowan Old Style', Georgia, serif;

    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-7: 3rem;

    /* Card sizes follow the scans' proportions (~0.575 : 1). Height is capped by the
       window height too, so short windows (e.g. a scaled laptop screen) get smaller
       cards instead of clipped ones. */
    --card-height: min(202px, 30dvh);
    --card-width: calc(var(--card-height) * 0.575);
    --card-radius: 6px;
    --card-shadow: 0 1px 1px rgba(35, 29, 21, 0.18), 0 8px 18px -8px rgba(35, 29, 21, 0.45);
    --card-back-image: url('../assets/card-back.jpg');

    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --fast: 160ms;
    --normal: 380ms;
    --slow: 600ms;
}

/* Night: the card back's blue-black as the page, paper-coloured ink */
/* Used when the device is in dark mode (theme set to Auto)... */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;

        --paper: #161d25;
        --paper-deep: #1e2731;
        --ink: #e9e0cd;
        --ink-soft: #cfc4ad;
        --ink-muted: #a89c85;
        --rule: rgba(233, 224, 205, 0.45);
        --rule-faint: rgba(233, 224, 205, 0.15);
        --blue: #8db3d3;
        --blue-deep: #a9c7e0;
        --vermilion: #e08a68;
        --ochre: #e0bf62;
        --on-blue: #121820;
        --lightbox-backdrop: rgba(8, 11, 15, 0.95);
        --card-shadow: 0 1px 1px rgba(0, 0, 0, 0.4), 0 10px 22px -8px rgba(0, 0, 0, 0.7);
    }
}

/* ...or when the reader picks Night. Keep in step with the block above. */
:root[data-theme="dark"] {
    color-scheme: dark;

    --paper: #161d25;
    --paper-deep: #1e2731;
    --ink: #e9e0cd;
    --ink-soft: #cfc4ad;
    --ink-muted: #a89c85;
    --rule: rgba(233, 224, 205, 0.45);
    --rule-faint: rgba(233, 224, 205, 0.15);
    --blue: #8db3d3;
    --blue-deep: #a9c7e0;
    --vermilion: #e08a68;
    --ochre: #e0bf62;
    --on-blue: #121820;
    --lightbox-backdrop: rgba(8, 11, 15, 0.95);
    --card-shadow: 0 1px 1px rgba(0, 0, 0, 0.4), 0 10px 22px -8px rgba(0, 0, 0, 0.7);
}

/* ==================== RESET & BASE ==================== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 17px;
    -webkit-text-size-adjust: 100%;
}

html, body {
    /* Stop pull-to-refresh; manipulation keeps pinch-zoom but drops double-tap zoom */
    overscroll-behavior: none;
    touch-action: manipulation;
}

body {
    font-family: var(--font-text);
    font-size: 1.06rem;
    line-height: 1.55;
    font-variant-numeric: oldstyle-nums;
    color: var(--ink);
    background-color: var(--paper);
    /* Faint paper grain */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.5 0 0 0 0 0.42 0 0 0 0 0.3 0 0 0 0.07 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

button,
textarea {
    font: inherit;
    color: inherit;
}

:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 3px;
}

/* ==================== APP & SCREENS ==================== */
.app-container {
    position: relative;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.screen {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--slow) var(--ease), visibility var(--slow);
}

.screen.active {
    opacity: 1;
    visibility: visible;
    z-index: 1;
}

.screen-content {
    width: 100%;
    max-width: 26rem;
    padding: var(--space-5);
    padding-top: calc(var(--space-5) + env(safe-area-inset-top, 0px));
    padding-bottom: calc(var(--space-5) + env(safe-area-inset-bottom, 0px));
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-5);
}

/* Long screens scroll as a whole page, so the scrollbar sits at the window edge
   (not beside a narrow centred column on desktop) */
.screen.scroll-screen {
    display: block;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

/* Centred vertically when shorter than the window; grows and scrolls when longer */
.scroll-screen .screen-content {
    margin: 0 auto;
    min-height: 100%;
    justify-content: center;
}

.screen-content.scrollable {
    padding-top: calc(var(--space-7) + env(safe-area-inset-top, 0px));
    padding-bottom: calc(var(--space-7) + env(safe-area-inset-bottom, 0px));
}

/* Card + text screens (interpret, meaning). On phones the two parts merge into
   one column: title first, then the card, then the text. */
.split .reading-text {
    display: contents;
}

.split .reading-text > .kicker,
.split .reading-text > .section-title,
.split .reading-text > .pull-meta {
    order: -1;
}

.card-figure {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
}

.history-tools-row {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

/* ==================== TYPE ==================== */

/* Small-caps line above a title, like the numeral line on a card */
.kicker {
    font-variant-caps: all-small-caps;
    letter-spacing: 0.14em;
    font-size: 1rem;
    color: var(--ink-muted);
    margin-bottom: calc(-1 * var(--space-4));
}

.app-title {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 3.1rem;
    line-height: 1.05;
    letter-spacing: 0.01em;
}

.section-title {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 2.1rem;
    line-height: 1.1;
}

/* The card back's Tudor rose between rules */
.ornament {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 10rem;
    margin-top: calc(-1 * var(--space-3));
}

/* A mask, so the rose is printed in the current ink colour (light and dark themes) */
.rose-mark {
    width: 2.1rem;
    height: 2.1rem;
    background-color: var(--blue);
    -webkit-mask: url('../assets/rose.png') center / contain no-repeat;
    mask: url('../assets/rose.png') center / contain no-repeat;
}

.ornament::before,
.ornament::after {
    content: '';
    flex: 1;
    border-top: 1px solid var(--rule);
}

.guidance-text {
    font-style: italic;
    font-size: 1.15rem;
    line-height: 1.6;
    color: var(--ink-soft);
}

.instruction-text {
    font-variant-caps: all-small-caps;
    letter-spacing: 0.16em;
    font-size: 1rem;
    color: var(--ink-muted);
}

/* Card name shown under the reveal card once flipped, set like a card's title plate */
.instruction-text.revealed-name {
    font-family: var(--font-display);
    font-variant-caps: normal;
    font-size: 1.6rem;
    letter-spacing: 0.02em;
    color: var(--ink);
    animation: fadeIn var(--slow) var(--ease);
}

.welcome-text,
.guidance-text,
.quick-pull-hint {
    text-wrap: balance;
}

.welcome-text {
    font-style: italic;
    font-size: 1.15rem;
    color: var(--ink-soft);
    line-height: 1.7;
}

.welcome-text p {
    opacity: 0;
    animation: fadeIn 0.9s var(--ease) forwards;
}

.welcome-text p:nth-child(1) { animation-delay: 0.3s; }
.welcome-text p:nth-child(2) { animation-delay: 0.8s; }
.welcome-text p:nth-child(3) { animation-delay: 1.3s; }

/* ==================== TITLE PAGE (welcome) ==================== */

/* The welcome screen scrolls if the title page is taller than the window (tiny phones,
   or with today's card showing). margin: auto centres it without ever cutting off the
   top, which align-items: center would do once it overflows. */
#welcome-screen {
    overflow-y: auto;
    align-items: flex-start;
    padding: var(--space-4);
    padding-top: calc(var(--space-4) + env(safe-area-inset-top, 0px));
    padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
}

/* The screen's padding already provides the outer margin */
#welcome-screen .title-page {
    margin: auto;
    width: 100%;
}

/* Framed in a double rule, like the keyline around each card */
.title-page {
    border: 3px double var(--rule);
    padding: var(--space-6) var(--space-5);
    margin: var(--space-5);
    width: calc(100% - 2 * var(--space-5));
    max-width: 24rem;
    gap: var(--space-5);
}

.title-page .kicker {
    margin-bottom: calc(-1 * var(--space-4));
}

/* ==================== BUTTONS ==================== */
.primary-btn,
.secondary-btn {
    min-height: 44px;
    min-width: 11rem;
    padding: 0.55rem 1.6rem;
    font-variant-caps: all-small-caps;
    font-size: 1.2rem;
    letter-spacing: 0.14em;
    border-radius: 2px;
    cursor: pointer;
    transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease), border-color var(--fast) var(--ease);
}

.primary-btn {
    color: var(--on-blue);
    background: var(--blue);
    border: 1px solid var(--blue);
}

.primary-btn:hover {
    background: var(--blue-deep);
    border-color: var(--blue-deep);
}

.secondary-btn {
    color: var(--ink);
    background: transparent;
    border: 1px solid var(--ink);
}

.secondary-btn:hover {
    background: var(--paper-deep);
}

.primary-btn:active,
.secondary-btn:active {
    transform: translateY(1px);
}

.text-btn {
    min-height: 44px;
    padding: 0 var(--space-2);
    font-variant-caps: all-small-caps;
    font-size: 1.1rem;
    letter-spacing: 0.12em;
    color: var(--ink-soft);
    background: none;
    border: none;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.25em;
    cursor: pointer;
}

.text-btn:hover {
    color: var(--ink);
}

.text-btn.danger {
    color: var(--vermilion);
}

/* "‹ Back" link at the top-left of long screens */
.top-back {
    align-self: flex-start;
    padding-left: 0;
    margin-bottom: calc(-1 * var(--space-3));
    text-decoration: none;
}

.top-back::before {
    content: '‹';
    margin-right: 0.35em;
    font-size: 1.3em;
    line-height: 0;
}

.top-back:hover {
    text-decoration: underline;
}

/* On phones the meaning screen's text and card merge into one column: keep this first */
.split .reading-text > .top-back {
    order: -2;
}

.secondary-btn:disabled,
.text-btn:disabled {
    opacity: 0.4;
    cursor: default;
    pointer-events: none;
}

.quick-pull {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    margin-top: calc(-1 * var(--space-2));
}

.quick-pull-hint {
    font-style: italic;
    font-size: 0.95rem;
    color: var(--ink-muted);
}

/* ==================== CARDS ==================== */

/* Shared card back (1909 Rider-Waite-Smith back) */
.deck-card,
.spread-card,
.card-front {
    background: var(--card-stock) var(--card-back-image) center / cover no-repeat;
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow);
}

.deck-container {
    width: 100%;
    height: calc(var(--card-height) + 50px);
    display: flex;
    align-items: center;
    justify-content: center;
    perspective: 1000px;
}

.card-deck {
    position: relative;
    width: var(--card-width);
    height: var(--card-height);
    cursor: pointer;
}

/* Stacked deck: only the top card casts the full shadow */
.deck-card {
    position: absolute;
    width: var(--card-width);
    height: var(--card-height);
    box-shadow: 0 1px 0 rgba(35, 29, 21, 0.25);
    transition: transform var(--normal) var(--ease);
}

.deck-card:first-child {
    box-shadow: var(--card-shadow);
}

.card-deck.shuffling .deck-card {
    animation: shuffle 0.32s ease-in-out infinite;
}

.card-deck.shuffling .deck-card:nth-child(odd) {
    animation-direction: reverse;
}

.spread-container {
    width: 100%;
    height: calc(var(--card-height) + 80px);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.spread-card {
    position: absolute;
    width: var(--card-width);
    height: var(--card-height);
    cursor: pointer;
    transform-origin: bottom center;
    transition: transform var(--normal) var(--ease), box-shadow var(--normal) var(--ease);
}

@media (hover: hover) {
    .spread-card:hover {
        box-shadow: 0 1px 1px rgba(35, 29, 21, 0.2), 0 16px 28px -10px rgba(35, 29, 21, 0.55);
        z-index: 50;
    }
}

/* Reveal */
.reveal-card-container {
    perspective: 1200px;
    height: min(366px, 62dvh);
    aspect-ratio: 380 / 655;
}

.tarot-card {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 1s var(--ease);
    cursor: pointer;
}

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

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
}

.card-front,
.card-back {
    position: absolute;
    inset: 0;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    border-radius: var(--card-radius);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-back {
    background: var(--card-stock);
    box-shadow: var(--card-shadow);
    transform: rotateY(180deg);
}

.card-visual {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
}

.card-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Thumbnails (interpret + meaning) */
.card-thumb {
    flex-shrink: 0;
    width: 150px;
    aspect-ratio: 380 / 655;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    border-radius: var(--card-radius);
    overflow: hidden;
    background: var(--card-stock);
    box-shadow: var(--card-shadow);
    cursor: zoom-in;
    transition: transform var(--fast) var(--ease);
}

.card-thumb:hover {
    transform: translateY(-2px);
}

.card-thumb:disabled {
    cursor: default;
}

.card-thumb-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.card-thumb-symbol {
    font-size: 3.5rem;
}

.thumb-hint {
    font-style: italic;
    font-size: 0.95rem;
    color: var(--ink-muted);
}

/* ==================== TODAY'S CARD (welcome) ==================== */
.today-panel {
    display: flex;
    align-items: center;
    gap: var(--space-5);
    animation: fadeIn var(--slow) var(--ease);
}

.today-thumb {
    flex-shrink: 0;
    width: 88px;
    aspect-ratio: 380 / 655;
    padding: 0;
    border: none;
    border-radius: 4px;
    overflow: hidden;
    background: var(--card-stock);
    box-shadow: var(--card-shadow);
    cursor: pointer;
}

.today-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.today-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-1);
    text-align: left;
}

.today-label {
    font-variant-caps: all-small-caps;
    letter-spacing: 0.14em;
    color: var(--ink-muted);
}

.today-card-name {
    font-family: var(--font-display);
    font-size: 1.45rem;
    line-height: 1.15;
    margin-bottom: var(--space-2);
}

.today-info .primary-btn {
    min-width: 0;
    padding: 0.4rem 1.2rem;
}

/* ==================== INTERPRETATION & NOTES ==================== */
.interpretation-input {
    width: 100%;
}

.interpretation-input textarea,
.notes-section textarea {
    display: block;
    width: 100%;
    min-height: 7rem;
    padding: var(--space-3) var(--space-4);
    font-size: 1.1rem; /* 16px+ stops iOS zooming in on focus */
    line-height: 1.5;
    background: var(--paper-deep);
    border: none;
    border-bottom: 1px solid var(--ink);
    border-radius: 2px 2px 0 0;
    resize: vertical;
}

.interpretation-input textarea:focus,
.notes-section textarea:focus {
    outline: none;
    border-bottom: 2px solid var(--blue);
    padding-bottom: calc(var(--space-3) - 1px);
}

textarea::placeholder {
    font-style: italic;
    color: var(--ink-muted);
}

/* ==================== MEANING ==================== */
.pull-meta {
    font-variant-caps: all-small-caps;
    letter-spacing: 0.12em;
    color: var(--ink-muted);
    margin-top: calc(-1 * var(--space-4));
}

.interpretation-section,
.meaning-section,
.keywords-section,
.symbolism-section,
.reflection-section,
.upright-section,
.notes-section {
    width: 100%;
    text-align: left;
}

/* Section heads: small caps with a rule running to the margin */
.interpretation-section h3,
.meaning-section h3,
.keywords-section h3,
.symbolism-section h3,
.reflection-section h3,
.upright-section h3,
.notes-section h3,
.history-tools h3 {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-weight: 500;
    font-size: 1.05rem;
    font-variant-caps: all-small-caps;
    letter-spacing: 0.16em;
    color: var(--ink-soft);
    margin-bottom: var(--space-2);
}

.interpretation-section h3::after,
.meaning-section h3::after,
.keywords-section h3::after,
.symbolism-section h3::after,
.reflection-section h3::after,
.upright-section h3::after,
.notes-section h3::after,
.history-tools h3::after {
    content: '';
    flex: 1;
    border-top: 1px solid var(--rule-faint);
}

.interpretation-section p,
.meaning-section p,
.symbolism-section p,
.reflection-section p,
.upright-section p {
    font-size: 1.1rem;
    line-height: 1.6;
    hyphens: auto;
}

/* The reader's own words, set apart like a quotation */
.interpretation-section p {
    font-style: italic;
    padding-left: var(--space-4);
    border-left: 2px solid var(--blue);
}

/* Drop cap opening the traditional meaning */
.meaning-section p::first-letter {
    float: left;
    font-family: var(--font-display);
    font-size: 3.4em;
    line-height: 0.8;
    padding: 0.08em 0.08em 0 0;
    color: var(--blue);
}

.reflection-section p {
    font-style: italic;
}

/* The upright meaning under a reversed reading: context, so a quieter tone */
.upright-section p {
    color: var(--ink-soft);
}

/* ==================== REVERSALS (Major Arcana only) ==================== */

/* A reversed card is shown upside down everywhere it appears */
.card-visual.is-reversed img,
.card-thumb.is-reversed img,
.today-thumb.is-reversed img,
.history-thumb.is-reversed,
.lightbox-image.is-reversed {
    transform: rotate(180deg);
}

/* Small-caps "Reversed" beside or under a card name */
.reversed-label {
    font-family: var(--font-text);
    font-variant-caps: all-small-caps;
    font-size: 0.95rem;
    letter-spacing: 0.14em;
    color: var(--vermilion);
    margin-left: var(--space-1);
}

/* Under the revealed card, the label sits on its own line */
.instruction-text.revealed-name .reversed-label {
    display: block;
    margin-left: 0;
    font-size: 1.05rem;
}

/* Keywords as a line of text separated by interpuncts */
.keywords-container {
    font-size: 1.1rem;
    line-height: 1.6;
}

/* Non-breaking space before the dot, ordinary space after, so lines wrap after a dot.
   (Written as a literal '·' - a CSS escape would swallow the space after it.) */
.keyword ~ .keyword::before {
    content: '\00a0· ';
    color: var(--ink-muted);
}

.notes-status,
.backup-status {
    min-height: 1.4em;
    font-style: italic;
    font-size: 0.95rem;
    color: var(--ink-muted);
}

/* ==================== HISTORY ==================== */
.storage-warning {
    width: 100%;
    text-align: left;
    font-size: 1rem;
    padding: var(--space-3) var(--space-4);
    border-left: 2px solid var(--vermilion);
    background: var(--paper-deep);
}

/* A ledger: rows divided by hairlines, no boxes */
.history-list {
    list-style: none;
    width: 100%;
    border-top: 1px solid var(--rule);
}

.history-list li {
    border-bottom: 1px solid var(--rule-faint);
}

.history-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-1);
    text-align: left;
    background: none;
    border: none;
    cursor: pointer;
    transition: background-color var(--fast) var(--ease);
}

.history-item:hover {
    background: var(--paper-deep);
}

.history-thumb {
    flex-shrink: 0;
    width: 40px;
    aspect-ratio: 380 / 655;
    object-fit: cover;
    border-radius: 3px;
    box-shadow: 0 1px 2px rgba(35, 29, 21, 0.3);
}

.history-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.history-card-name {
    font-family: var(--font-display);
    font-size: 1.25rem;
    line-height: 1.2;
}

.history-meta {
    font-variant-caps: all-small-caps;
    letter-spacing: 0.1em;
    font-size: 0.95rem;
    color: var(--ink-muted);
}

.history-item.is-daily .history-meta {
    color: var(--blue);
}

.history-snippet {
    font-style: italic;
    font-size: 0.98rem;
    color: var(--ink-soft);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.history-tools {
    width: 100%;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.history-tools-text {
    font-size: 1rem;
    color: var(--ink-soft);
}

.history-tools-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
}

/* Keep labels on one line; the buttons stack instead if there isn't room */
.history-tools-buttons .secondary-btn {
    min-width: 0;
    flex: 1 1 auto;
    padding-left: var(--space-4);
    padding-right: var(--space-4);
    font-size: 1.1rem;
    letter-spacing: 0.1em;
    white-space: nowrap;
}

.history-tools .text-btn {
    align-self: flex-start;
    padding-left: 0;
}

/* ==================== INTRO (first visit, and "About") ==================== */

/* Before the app starts on a first visit, show the intro instead of the home page so
   the home page never flashes up first. app.js takes over and removes the class. */
.first-visit #welcome-screen {
    opacity: 0;
    visibility: hidden;
}

.first-visit #intro-screen {
    opacity: 1;
    visibility: visible;
    z-index: 1;
}

/* A readable column on every screen size (more specific than the wide desktop
   layout used by the other long screens) */
.scroll-screen .screen-content.intro {
    max-width: 36rem;
}

.intro .ornament {
    margin-top: calc(-1 * var(--space-2));
}

.intro-lede {
    font-size: 1.2rem;
    font-style: italic;
    line-height: 1.6;
    color: var(--ink-soft);
    text-wrap: balance;
}

.intro-section {
    width: 100%;
    text-align: left;
}

.intro-section h3 {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-weight: 500;
    font-size: 1.05rem;
    font-variant-caps: all-small-caps;
    letter-spacing: 0.16em;
    color: var(--ink-soft);
    margin-bottom: var(--space-2);
}

.intro-section h3::after {
    content: '';
    flex: 1;
    border-top: 1px solid var(--rule-faint);
}

.intro-section p {
    font-size: 1.1rem;
    line-height: 1.6;
    hyphens: auto;
}

/* ==================== WELCOME LINKS ==================== */
.welcome-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0 var(--space-4);
    margin-top: calc(-1 * var(--space-3));
}

/* ==================== LIBRARY (browse the deck) ==================== */
.library-search {
    width: 100%;
    max-width: 28rem;
}

.library-search input {
    display: block;
    width: 100%;
    min-height: 44px;
    padding: var(--space-2) var(--space-3);
    font: inherit;
    font-size: 1.1rem; /* 16px+ stops iOS zooming in on focus */
    color: var(--ink);
    background: var(--paper-deep);
    border: none;
    border-bottom: 1px solid var(--ink);
    border-radius: 2px 2px 0 0;
    -webkit-appearance: none;
    appearance: none;
}

.library-search input:focus {
    outline: none;
    border-bottom: 2px solid var(--blue);
}

.library-search input::placeholder {
    font-style: italic;
    color: var(--ink-muted);
}

/* Group links, set like the theme switch */
.library-jump {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: calc(-1 * var(--space-3));
}

.library-jump button {
    min-height: 44px;
    padding: 0 0.25rem;
    font-variant-caps: all-small-caps;
    font-size: 1rem;
    letter-spacing: 0.08em;
    color: var(--ink-soft);
    background: none;
    border: none;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-decoration-color: var(--rule-faint);
    text-underline-offset: 0.3em;
    cursor: pointer;
}

.library-jump button:hover {
    color: var(--ink);
    text-decoration-color: currentColor;
}

.library-groups {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

.library-group {
    /* Leave room above the heading when jumped to */
    scroll-margin-top: var(--space-5);
}

.library-group h3 {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 1.5rem;
    margin-bottom: var(--space-4);
}

.library-group h3::after {
    content: '';
    flex: 1;
    border-top: 1px solid var(--rule);
}

.library-grid {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
    gap: var(--space-5) var(--space-4);
}

.library-card {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    padding: 0;
    background: none;
    border: none;
    cursor: pointer;
}

.library-thumb {
    width: 100%;
    aspect-ratio: 380 / 655;
    object-fit: cover;
    border-radius: 4px;
    background: var(--card-stock);
    box-shadow: var(--card-shadow);
    transition: transform var(--fast) var(--ease);
}

.library-card:hover .library-thumb,
.library-card:focus-visible .library-thumb {
    transform: translateY(-3px);
}

.library-name {
    font-size: 0.98rem;
    line-height: 1.25;
    text-align: center;
}

@media (min-width: 900px) {
    .library-grid {
        grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
        gap: var(--space-6) var(--space-5);
    }
}

/* ==================== WELCOME FOOTER (theme + privacy) ==================== */
.page-footer {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: var(--space-1) var(--space-4);
    padding-top: var(--space-3);
    border-top: 1px solid var(--rule-faint);
    margin-top: calc(-1 * var(--space-2));
}

/* Auto · Day · Night, set like a line of small caps; the chosen one is underlined */
.theme-switch {
    display: flex;
    align-items: center;
}

.theme-switch button {
    min-height: 44px;
    padding: 0 var(--space-2);
    font-variant-caps: all-small-caps;
    font-size: 1.05rem;
    letter-spacing: 0.12em;
    color: var(--ink-muted);
    background: none;
    border: none;
    cursor: pointer;
}

.theme-switch button + button::before {
    content: '·';
    margin-right: var(--space-3);
    color: var(--ink-muted);
}

/* Name of a setting before its choices, e.g. "Reversals:" */
.switch-label {
    font-variant-caps: all-small-caps;
    font-size: 1.05rem;
    letter-spacing: 0.12em;
    color: var(--ink-muted);
    margin-right: var(--space-1);
}

.switch-label::after {
    content: ':';
}

/* "Reversals" opens the explanation: a label with a dotted underline */
.switch-label-link {
    min-height: 44px;
    padding: 0;
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: underline dotted;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.3em;
}

.switch-label-link:hover {
    color: var(--ink);
}

/* The dot separators are inline-blocks so a selected option's underline doesn't run
   under the dot in front of it */
.theme-switch button + button::before {
    display: inline-block;
}

/* The visit-count opt-out sits under its paragraph in the privacy sheet */
.opt-out-switch {
    margin-top: var(--space-2);
    margin-left: calc(-1 * var(--space-2));
}

/* No dot between a setting's name and its first choice */
.theme-switch .switch-label + button::before {
    content: none;
}

/* Choice buttons at the foot of a sheet */
.sheet-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-3);
}

.theme-switch button:hover {
    color: var(--ink);
}

.theme-switch button[aria-pressed="true"] {
    color: var(--ink);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.3em;
}

.footer-link {
    font-size: 1.05rem;
    color: var(--ink-muted);
}

.footer-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0 var(--space-4);
}

/* ==================== PRIVACY SHEET ==================== */
.sheet {
    width: calc(100% - 2 * var(--space-4));
    max-width: 36rem;
    max-height: calc(100dvh - 2 * var(--space-5));
    margin: auto;
    padding: 0;
    color: var(--ink);
    background-color: var(--paper);
    border: 3px double var(--rule);
    border-radius: 2px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.sheet::backdrop {
    background: rgba(24, 19, 13, 0.55);
}

.sheet[open] {
    animation: fadeIn var(--normal) var(--ease);
}

.sheet-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-6) var(--space-5);
    text-align: center;
}

.sheet-content .kicker {
    margin-bottom: calc(-1 * var(--space-3));
}

.sheet-content .section-title {
    font-size: 1.8rem;
}

/* Focused only so the sheet opens at the top; no ring needed */
.sheet-content .section-title:focus {
    outline: none;
}

.sheet-section {
    width: 100%;
    text-align: left;
}

.sheet-section h3 {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-weight: 500;
    font-size: 1.05rem;
    font-variant-caps: all-small-caps;
    letter-spacing: 0.16em;
    color: var(--ink-soft);
    margin-bottom: var(--space-2);
}

.sheet-section h3::after {
    content: '';
    flex: 1;
    border-top: 1px solid var(--rule-faint);
}

.sheet-section p,
.sheet-section li {
    font-size: 1.05rem;
    line-height: 1.55;
}

.sheet-section p + p {
    margin-top: var(--space-2);
}

.sheet-section ul {
    list-style: none;
    margin-bottom: var(--space-2);
}

.sheet-section li {
    padding-left: var(--space-4);
    position: relative;
}

.sheet-section li::before {
    content: '·';
    position: absolute;
    left: var(--space-1);
    color: var(--blue);
    font-weight: 600;
}

.sheet-section strong {
    font-weight: 600;
}

/* ==================== CLOSE-UP VIEWER ==================== */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-5);
    padding-top: calc(var(--space-7) + env(safe-area-inset-top, 0px));
    padding-bottom: calc(var(--space-5) + env(safe-area-inset-bottom, 0px));
    background: var(--lightbox-backdrop);
    cursor: zoom-out;
    animation: fadeIn var(--normal) var(--ease);
}

.lightbox-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: var(--card-radius);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.lightbox-close {
    position: absolute;
    top: calc(var(--space-3) + env(safe-area-inset-top, 0px));
    right: var(--space-3);
    width: 44px;
    height: 44px;
    font-size: 2rem;
    line-height: 1;
    color: #efe7d6;
    background: none;
    border: 1px solid rgba(239, 231, 214, 0.4);
    border-radius: 50%;
    cursor: pointer;
}

/* ==================== UTILITIES ==================== */
.hidden,
[hidden] {
    display: none !important;
}

/* Visually hidden but still read by screen readers */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ==================== ANIMATIONS ==================== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes shuffle {
    0%, 100% { transform: translateX(0) rotate(0deg); }
    25% { transform: translateX(-9px) rotate(-2deg); }
    75% { transform: translateX(9px) rotate(2deg); }
}

/* ==================== LARGER SCREENS ==================== */
@media (min-width: 480px) {
    :root {
        --card-height: min(236px, 30dvh);
    }

    .app-title {
        font-size: 3.6rem;
    }

    .reveal-card-container {
        height: min(394px, 62dvh);
    }

    .card-thumb {
        width: 170px;
    }
}

@media (min-width: 768px) {
    :root {
        --card-height: min(270px, 32dvh);
    }

    .screen-content {
        max-width: 32rem;
    }

    .title-page {
        max-width: 28rem;
    }

    .reveal-card-container {
        height: min(422px, 62dvh);
    }

    .card-thumb {
        width: 190px;
    }
}

/* Desktop and landscape tablets: use the width */
@media (min-width: 900px) {
    .scroll-screen .screen-content {
        max-width: 62rem;
        padding-left: var(--space-6);
        padding-right: var(--space-6);
    }

    /* Card on the left, staying in view while the text scrolls beside it */
    .split {
        display: grid;
        grid-template-columns: minmax(220px, 21rem) minmax(0, 36rem);
        justify-content: center;
        align-content: center;
        align-items: start;
        column-gap: 4rem;
        text-align: left;
    }

    .split .card-figure {
        grid-column: 1;
        position: sticky;
        top: var(--space-7);
    }

    .split .card-thumb {
        width: 100%;
    }

    .split .reading-text {
        grid-column: 2;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-5);
    }

    /* History: two columns of entries; install and backup side by side */
    .history-list {
        display: grid;
        grid-template-columns: 1fr 1fr;
        column-gap: var(--space-6);
    }

    .history-tools-row {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
        gap: var(--space-6);
        align-items: start;
    }
}

/* Large monitors: bigger cards and title */
@media (min-width: 1200px) and (min-height: 800px) {
    :root {
        --card-height: min(340px, 34dvh);
    }

    .reveal-card-container {
        height: min(520px, 62dvh);
    }

    .app-title {
        font-size: 4.2rem;
    }

    .title-page {
        max-width: 32rem;
    }
}

/* Short phones (e.g. iPhone SE): tighten the title page so it fits without scrolling */
@media (max-height: 700px) {
    .title-page {
        padding: var(--space-5) var(--space-4);
        gap: var(--space-4);
    }

    .app-title {
        font-size: 2.6rem;
    }

    .welcome-text {
        line-height: 1.5;
    }
}

/* Very short screens (e.g. iPhone SE 1st gen, 568px) */
@media (max-height: 620px) {
    #welcome-screen {
        padding: var(--space-2);
    }

    .title-page {
        padding: var(--space-3) var(--space-4);
        gap: var(--space-3);
    }

    .app-title {
        font-size: 2.3rem;
    }

    .welcome-text {
        font-size: 1.05rem;
        line-height: 1.4;
    }

    .page-footer {
        padding-top: var(--space-1);
        margin-top: 0;
    }

    .theme-switch button,
    .footer-link {
        min-height: 36px;
    }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
