:root {
    color-scheme: dark light;

    --bg: #13110d;
    --text: #f4ecd8;
    --text-muted: #b8ad99;
    --accent: #bb2828;
    --line: #f4ecd8;
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: #f4ecd8;
        --text: #2a2520;
        --text-muted: #6b5f50;
        --accent: #a02222;
        --line: #2a2520;
    }
}

:root.theme-dark {
    color-scheme: dark;
    --bg: #13110d;
    --text: #f4ecd8;
    --text-muted: #b8ad99;
    --accent: #bb2828;
    --line: #f4ecd8;
}

:root.theme-light {
    color-scheme: light;
    --bg: #fefefe;
    --text: #222;
    --text-muted: #555;
    --accent: #a02222;
    --line: #222;
}

@font-face {
    font-family: 'Lora';
    src: url('https://fonts.noisefactor.io/fonts/lora/Lora%5Bwght%5D.woff2') format('woff2');
    font-weight: 400 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Lora';
    src: url('https://fonts.noisefactor.io/fonts/lora/Lora-Italic%5Bwght%5D.woff2') format('woff2');
    font-weight: 400 700;
    font-style: italic;
    font-display: swap;
}

/* Metric-matched invisible placeholders: reserve space at first paint, zero CLS
   when Lora swaps in. */
@font-face {
    font-family: 'Lora Blank';
    src: url('https://fonts.noisefactor.io/fonts/lora/Lora-Blank.woff2') format('woff2');
    font-weight: 400 700;
    font-style: normal;
    font-display: block;
}

@font-face {
    font-family: 'Lora Blank';
    src: url('https://fonts.noisefactor.io/fonts/lora/Lora-Italic-Blank.woff2') format('woff2');
    font-weight: 400 700;
    font-style: italic;
    font-display: block;
}

* { box-sizing: border-box; }

body {
    background-color: var(--bg);
    color: var(--text);
    font-family: 'Lora', 'Lora Blank', 'Noto Serif TC', 'Noto Sans Symbols 2', 'Songti TC', 'STSong', 'PMingLiU', 'Microsoft JhengHei', 'Apple Symbols', 'Segoe UI Symbol', Georgia, 'Times New Roman', serif;
    letter-spacing: 0.03em;
    margin: 0 auto;
    padding: 0 10% 2rem 10%;
    line-height: 1.6;
}

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

h1 {
    margin: 0.85em 0 0 0;
    font-size: 1.5em;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.3em;
}

.om-mark {
    color: var(--accent);
    /* optical centering: the Devanagari glyph box rides high next to Lora */
    transform: translateY(0.12em);
}

h2 {
    margin: 1.5em 0 0.5em 0;
    font-weight: 600;
    font-size: 1.15em;
}

h3 {
    margin: 0.75em 0 0.25em 0;
    font-weight: 600;
    font-size: 1em;
}

.subtitle {
    color: var(--text-muted);
    font-style: italic;
    margin: 0.25em 0 1.5em 0;
}

.comment, .text-muted {
    color: var(--text-muted);
}

.pre {
    white-space: normal;
}

.pre > :first-child {
    margin-top: 0;
}

.pre > :last-child {
    margin-bottom: 0;
}

.pre p,
.pre ul,
.pre ol,
.pre blockquote,
.pre pre {
    margin: 0 0 0.8em 0;
}

.pre ul,
.pre ol {
    padding-left: 1.5em;
}

.pre ul {
    list-style-type: disc;
}

.pre ol {
    list-style-type: decimal;
}

.pre blockquote {
    border-left: 2px solid var(--accent);
    color: var(--text-muted);
    padding-left: 1em;
}

.pre code {
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 0.9em;
}

.pre :not(pre) > code {
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    border-radius: 0.2em;
    padding: 0.08em 0.25em;
}

.pre pre {
    overflow-x: auto;
    white-space: pre;
}

.hidden {
    display: none;
}

ul, ol {
    list-style-type: none;
    padding-left: 0;
}

header nav {
    position: absolute;
    top: 0.9em;
    right: 0.9em;
}

.theme-toggle {
    background: none;
    border: none;
    color: inherit;
    font: inherit;
    font-weight: bold;
    cursor: pointer;
    padding: 0;
    display: inline-block;
    min-width: 1.5em;
    text-align: center;
    line-height: 1;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
    color: var(--accent);
}

form {
    margin: 0.5em 0 1.5em 0;
}

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 0.5em;
}

.input-row button[type="submit"] {
    /* match the single-line textarea: 1.5em line + 2 × 0.5em padding + borders */
    height: calc(2.5em + 2px);
    padding-top: 0;
    padding-bottom: 0;
}

textarea {
    flex: 1;
    width: 100%;
    background: transparent;
    border: 1px solid var(--text-muted);
    color: var(--text);
    font-family: inherit;
    font-size: 1em;
    letter-spacing: inherit;
    line-height: 1.5;
    padding: 0.5em 0.75em;
    resize: none;
    overflow-y: hidden;
}

textarea:focus {
    outline: 1px solid var(--accent);
    border-color: var(--accent);
}

.ask-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 0.5em;
    margin-top: 0.75em;
}

.canned {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--text);
    font: inherit;
    font-size: 0.85em;
    font-weight: 600;
    padding: 0.35em 1em;
    cursor: pointer;
}

.canned:hover,
.canned:focus-visible {
    background: var(--text);
    color: var(--bg);
}

.query-header {
    font-size: 1.4em;
    font-weight: 400;
    font-style: italic;
    margin: 0.75em 0 0.25em 0;
    outline: none;
}

/* Cooldown landing: the seal, and an invitation to return */

.cooldown {
    text-align: center;
}

.cooldown-om {
    color: var(--accent);
    font-size: 3em;
    line-height: 1;
    margin: 0.5em 0 0.25em 0;
}

/* Pre-ask hero: logotype, tagline, and form centered in the viewport */

body.asking main {
    min-height: calc(100vh - 2rem);
    min-height: calc(100svh - 2rem);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

body.asking h1 {
    margin: 0;
    font-size: 2.6em;
}

body.asking .subtitle {
    text-align: center;
    max-width: 36em;
    margin: 0.75em 0 2em 0;
}

body.asking form#ask {
    width: min(640px, 100%);
    margin: 0;
}

body.asking #status {
    display: none;
}

button[type="submit"] {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
    font: inherit;
    font-weight: 600;
    padding: 0.4em 1.5em;
    cursor: pointer;
}

button[type="submit"]:hover,
button[type="submit"]:focus-visible {
    background: var(--accent);
    color: var(--bg);
}

/* Side-by-side readings */

.readings-pair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 3rem;
    align-items: start;
}

@media screen and (max-width: 1000px) {
    .readings-pair {
        grid-template-columns: 1fr;
    }
}

/* I Ching block */

.hexagram-heading {
    display: flex;
    align-items: baseline;
    gap: 0.4em;
    margin: 0.5em 0 0.25em 0;
}

.hex-glyph {
    font-family: 'Noto Sans Symbols 2', 'Apple Symbols', 'Segoe UI Symbol', sans-serif;
    color: var(--accent);
    font-size: 1.5em;
    line-height: 1;
}

.hex-num {
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.hex-name {
    font-weight: 600;
}

.hex-cname {
    color: var(--text-muted);
    margin-left: 0.25em;
}

.judgment, .image {
    margin: 0.5em 0;
}

.judgment-label, .image-label {
    color: var(--text-muted);
    font-style: italic;
}

.changing-lines {
    margin: 0.75em 0;
}

.changing-lines li {
    margin: 0.25em 0;
}

.changing-lines .line-num {
    color: var(--accent);
    font-weight: 600;
}

.transformed {
    color: var(--text-muted);
    margin: 0.5em 0;
}

.transformed .hex-name,
.transformed .hex-glyph {
    color: var(--text);
}

/* Tarot block */

.card-grid {
    display: grid;
    grid-template-columns: max-content 1fr max-content;
    gap: 0.25em 0.75em;
    align-items: baseline;
    padding: 0;
    margin: 0;
}

.card-grid > li {
    display: grid;
    grid-template-columns: subgrid;
    grid-column: 1 / -1;
}

.card-position {
    color: var(--text-muted);
    font-style: italic;
}

.card-name {
    font-weight: 600;
}

.card-suit {
    color: var(--text-muted);
    font-size: 0.9em;
}

/* Oracle synthesis */

#oracle-body {
    margin-top: 0.5em;
}

.om {
    color: var(--accent);
    text-align: center;
    font-size: 1.4em;
    margin: 1.25em 0 0 0;
}

#status {
    margin: 1em 0;
    min-height: 1.4em;
    font-style: italic;
}

/* Copy controls: quiet enough to sit beneath the seal without competing */

.copy-row {
    display: flex;
    justify-content: center;
    margin: 0.75em 0 0 0;
}

.copy-row-inline {
    justify-content: flex-start;
    margin: 0.5em 0 0 0;
}

.copy {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--text-muted);
    font: inherit;
    font-size: 0.8em;
    letter-spacing: 0.08em;
    padding: 0.3em 1em;
    /* holds its width while the label reports the outcome */
    min-width: 9em;
    text-align: center;
    cursor: pointer;
}

.copy:hover,
.copy:focus-visible {
    background: var(--text-muted);
    color: var(--bg);
}

.copy.copied {
    background: transparent;
    color: var(--accent);
    border-color: var(--accent);
}

/* The reading's own control is a bare glyph sitting under the last line of
   text — available, but not a second invitation beside the follow-up field. */

#reading-actions {
    margin: 0.35em 0 0 0;
}

.copy-icon {
    border: 0;
    min-width: 0;
    /* keeps the tap target honest while the glyph stays small */
    padding: 0.35em;
    font-size: 1em;
    line-height: 0;
    opacity: 0.5;
}

.copy-icon:hover,
.copy-icon:focus-visible {
    background: transparent;
    color: var(--text-muted);
    opacity: 1;
}

.copy-icon.copied,
.copy-icon.failed {
    color: var(--accent);
    opacity: 1;
}

.copy-icon .glyph {
    width: 1em;
    height: 1em;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.3;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.copy-icon .glyph-done,
.copy-icon.copied .glyph-copy {
    display: none;
}

.copy-icon.copied .glyph-done {
    display: inline;
}

.copy-label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* Reveal choreography */

.seq {
    /* duration matches PACE.fade in app.js */
    animation: rise-in 0.55s ease both;
}

@keyframes rise-in {
    from {
        opacity: 0;
        transform: translateY(0.3em);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

.pre.streaming::after {
    content: '▌';
    color: var(--accent);
    animation: cursor-blink 1s step-end infinite;
}

@keyframes cursor-blink {
    50% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .seq {
        animation: none;
    }

    .pre.streaming::after {
        animation: none;
    }
}

/* Follow-up conversation */

.followup-q {
    font-size: 1.15em;
    font-weight: 400;
    font-style: italic;
    margin: 1.5em 0 0.5em 0;
}

#followup {
    margin: 1.5em 0;
}

.session-ended {
    text-align: center;
    font-style: italic;
    color: var(--text-muted);
    margin: 1.5em 0;
}

@media screen and (max-width: 800px) {
    body {
        padding: 0 5%;
    }
}
