/* ==========================================================================
   OnlyHighYield — chat answer panel + options bar
   Shared by the Step 1 and Step 2 chat pages (link AFTER nightmode.css).
   Mirrors the Anki add-on (minus the card and header): highlighter citations, reference
   cards with a yellow edge, and a sliding References switch.

   Uses the site tokens from styles.css / nightmode.css (--primary, --ink,
   --line, --paper, --white, --highlighter ...) so night mode follows for free.
   ========================================================================== */

:root {
    --ohy-hl-soft: #fff4c2;
    --ohy-hl-faint: rgba(255, 214, 77, 0.26);
    --ohy-cite-ink: #3b2f00;
    --ohy-on-primary: #ffffff;
    --ohy-track-off: #d9d4c3;
    --ohy-knob-off: #ffffff;
    --ohy-hero: linear-gradient(135deg, #0a5c5f 0%, #0d7378 100%);
}

html.dark-mode {
    --ohy-hl-soft: #3a3413;
    --ohy-hl-faint: rgba(255, 210, 63, 0.13);
    --ohy-on-primary: #0b2a2c;
    --ohy-track-off: #3a4849;
    --ohy-knob-off: #9fb0b1;
}

/* ---------------------------------------------------------------- panel -- */

.ohy-panel {
    /* a plain reply on the page background: no card, no header */
    color: var(--ink);
    font: 15px/1.65 var(--font-body);
    text-align: left;
}

.ohy-panel * {
    box-sizing: border-box;
}

/* Body */
.ohy-panel .ohy-body {
    padding: 0;
    color: var(--ink);
    overflow-wrap: break-word;
}

.ohy-panel .ohy-body p {
    margin: 0 0 13px;
    color: var(--ink);
    font-size: inherit;
    line-height: inherit;
}

.ohy-panel .ohy-body h3 {
    margin: 20px 0 4px;
    font: 600 11px/1.2 var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--primary);
}

.ohy-panel .ohy-body strong {
    font-weight: 700;
    color: inherit;
    background: linear-gradient(transparent 58%, var(--ohy-hl-soft) 58%);
}

/* ==key phrase== from the summary prompt: a faint highlighter stroke, lighter than bold */
.ohy-panel .ohy-body mark.ohy-hl {
    color: inherit;
    font-weight: inherit;
    background: linear-gradient(transparent 52%, var(--ohy-hl-faint) 52%, var(--ohy-hl-faint) 94%, transparent 94%);
    padding: 0 1px;
    border-radius: 2px;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
}

.ohy-panel .ohy-body ul {
    list-style: none;
    margin: 10px 0;
    padding: 0;
}

.ohy-panel .ohy-body li {
    position: relative;
    list-style: none;
    display: block;
    padding: 0 0 0 22px;
    margin: 8px 0;
    line-height: inherit;
}

.ohy-panel .ohy-body li::before {
    content: "";
    position: absolute;
    left: 4px;
    top: 0.62em;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--primary);
}

.ohy-panel .ohy-body li.l2 {
    margin-left: 22px;
    color: var(--ink-soft);
}

.ohy-panel .ohy-body li.l2::before {
    background: transparent;
    border: 2px solid var(--highlighter-dark);
    width: 5px;
    height: 5px;
}

/* numbered lists: the number replaces the dot */
.ohy-panel .ohy-body li.n {
    padding-left: 28px;
}

.ohy-panel .ohy-body li.n::before {
    display: none;
}

.ohy-n {
    position: absolute;
    left: 0;
    top: 0;
    font: 600 12.5px/1.9 var(--font-mono);
    color: var(--primary);
}

.ohy-arrow {
    color: var(--primary);
    font-weight: 600;
}

/* Citation badges */
.ohy-cite {
    all: unset;
    box-sizing: border-box;
    display: inline-block;
    cursor: pointer;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    margin: 0 1px 0 2px;
    border-radius: 9px;
    background: var(--highlighter);
    color: var(--ohy-cite-ink);
    font: 700 10.5px/17px var(--font-body);
    text-align: center;
    vertical-align: 2px;
    transition: background 0.15s ease;
}

.ohy-cite:hover {
    background: var(--highlighter-dark);
}

.ohy-cite:focus-visible {
    outline: 2px solid var(--highlighter-dark);
    outline-offset: 2px;
}

/* ----------------------------------------------------------- references -- */

.ohy-refs {
    margin-top: 18px;
    padding: 12px 0 0;
    border-top: 1px solid var(--line);
}

.ohy-refs-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.ohy-panel .ohy-refs h4 {
    margin: 0;
    font: 600 11px/1.2 var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-soft);
}

.ohy-refs-fold {
    display: grid;
    grid-template-rows: 1fr;
    opacity: 1;
    visibility: visible;
    transition: grid-template-rows 0.3s ease, opacity 0.22s ease, visibility 0s linear 0s;
}

.ohy-refs-clip {
    min-height: 0;
    overflow: hidden;
}

.ohy-refs-in {
    padding: 10px 0 2px;
}

.ohy-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 9px;
}

.ohy-ref {
    display: flex;
    gap: 10px;
    align-items: center;
    background: var(--white);
    border: 1px solid var(--line);
    border-left: 4px solid var(--highlighter-dark);
    border-radius: 10px;
    padding: 9px 12px;
    transition: box-shadow 0.3s ease, background 0.3s ease;
}

.ohy-ref.flash {
    background: var(--ohy-hl-soft);
    box-shadow: 0 0 0 3px var(--highlighter);
}

.ohy-num {
    flex: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--highlighter);
    color: var(--ohy-cite-ink);
    font: 700 12px/24px var(--font-body);
    text-align: center;
}

.ohy-form {
    font-weight: 700;
    font-size: 13.5px;
    line-height: 1.25;
    color: var(--ink);
}

.ohy-where {
    font-size: 12px;
    line-height: 1.3;
    color: var(--ink-soft);
}

/* ---------------------------------------------------------- the switch --- */
/* One switch, one setting: the panel switches and the options-bar switch all
   read the `refs-off` class on <body>, so every answer stays in sync. */

.ohy-tog {
    cursor: pointer;
    user-select: none;
    padding: 6px 0 6px 14px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.ohy-sw {
    all: unset;
    box-sizing: border-box;
    position: relative;
    display: block;
    flex: none;
    width: 36px;
    height: 20px;
    border-radius: 999px;
    background: var(--primary);
    border: 1px solid var(--primary);
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.ohy-sw .ohy-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--highlighter);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.28);
    transform: translateX(16px);
    transition: transform 0.22s cubic-bezier(0.3, 0.7, 0.25, 1), background 0.2s ease;
}

.ohy-tog:hover .ohy-sw {
    box-shadow: 0 0 0 3px var(--ohy-hl-soft);
}

.ohy-sw:focus-visible {
    outline: 2px solid var(--highlighter-dark);
    outline-offset: 2px;
}

body.refs-off .ohy-sw {
    background: var(--ohy-track-off);
    border-color: var(--ohy-track-off);
}

body.refs-off .ohy-sw .ohy-knob {
    transform: translateX(0);
    background: var(--ohy-knob-off);
}

body.refs-off .ohy-tog:hover .ohy-sw {
    border-color: var(--primary);
}

/* References off: badges, the stats about them and the cards fold away */
body.refs-off .ohy-cites,
body.refs-off .ohy-refchips {
    display: none;
}

body.refs-off .ohy-refs-fold {
    grid-template-rows: 0fr;
    opacity: 0;
    visibility: hidden;
    transition: grid-template-rows 0.3s ease, opacity 0.18s ease, visibility 0s linear 0.3s;
}

/* ------------------------------------------------------------- actions --- */
/* The footer bar holding "Generate questions" and "Report error". The class
   names (.nbme-questions-*, .report-error-btn) are kept because the page JS
   finds the buttons by them. */

.ohy-actions {
    margin-top: 14px;
}

.ohy-panel .nbme-questions-section {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 16px;
    margin: 0;
}

.ohy-panel .nbme-questions-btn {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    background: var(--ohy-hero);
    color: #fff;
    border: 0;
    border-bottom: 3px solid #ecb400;
    border-radius: 12px;
    padding: 11px 18px 9px;
    font: 600 13.5px/1.2 var(--font-body);
    letter-spacing: 0.01em;
    box-shadow: 0 4px 14px rgba(10, 92, 95, 0.28);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.ohy-panel .nbme-questions-btn > * {
    /* generateNBMEQuestions() reads event.target as the button, so keep clicks on the icon landing on it */
    pointer-events: none;
}

.ohy-panel .nbme-questions-btn svg {
    color: #ffd23f;
    margin-right: 8px !important;
    flex: none;
}

.ohy-panel .nbme-questions-btn:hover {
    background: var(--ohy-hero);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(10, 92, 95, 0.34);
    filter: none;
}

.ohy-panel .nbme-questions-btn:active {
    transform: translateY(0);
}

.ohy-panel .nbme-questions-btn:disabled {
    background: var(--line);
    color: var(--ink-soft);
    border-bottom-color: transparent;
    box-shadow: none;
    transform: none;
    cursor: not-allowed;
}

.ohy-panel .nbme-loading {
    margin: 0;
    color: var(--ink-soft);
    font-size: 12.5px;
}

.ohy-panel .nbme-loading span {
    color: var(--ink-soft) !important;
}

.ohy-panel .report-error-btn {
    margin-left: auto;
    background: transparent;
    color: var(--ink-soft);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 4px 12px;
    font: 600 11.5px/1.5 var(--font-body);
}

.ohy-panel .report-error-btn:hover {
    border-color: #d9534f;
    color: #d9534f;
}

/* -------------------------------------------------- notice / loading ----- */

.ohy-note {
    padding: 2px 0;
}

.ohy-note-icon {
    font-size: 20px;
    line-height: 1.2;
}

.ohy-panel .ohy-note h2 {
    margin: 4px 0 4px;
    font: 600 16px/1.3 var(--font-display);
    color: var(--ink);
}

.ohy-panel .ohy-note p {
    margin: 4px 0 0;
    color: var(--ink-soft);
}

/* ------------------------------------------------------------ thinking --- */
/* The loading state. Three phrases swap on a fixed schedule, then the last one
   stays until the answer replaces this element:

     0s  - 2s   Understanding your question...
     2s  - 4s   Finding matching NBME questions...
     4s  - ...  Synthesizing your answer...   (until the answer arrives)

   It is CSS-only (animation-delay), so nothing has to be started or cleaned up.
   --ohy-step is the one timing knob: how long each of the first two phrases stays. */

.ohy-think {
    --ohy-step: 2s;
    padding: 4px 0 2px;
}

/* every phrase sits in the same grid cell, so the box never jumps between phrases */
.ohy-think-lines {
    display: grid;
}

.ohy-think-line {
    grid-area: 1 / 1;
    opacity: 0;
    font: 500 15px/1.5 var(--font-body);
    letter-spacing: 0.005em;
    animation: ohyPhaseSwap var(--ohy-step) cubic-bezier(0.4, 0, 0.2, 1) both;
}

.ohy-think-line[data-phase="2"] {
    animation-delay: var(--ohy-step);
}

/* the last phrase only fades in, and stays */
.ohy-think-line[data-phase="3"] {
    animation-name: ohyPhaseIn;
    animation-duration: 0.45s;
    animation-delay: calc(var(--ohy-step) * 2);
}

/* a soft light sweeping across the text, the way the big chat apps do it */
.ohy-think-text {
    color: var(--ink-soft);
}

@supports ((-webkit-background-clip: text) or (background-clip: text)) {
    .ohy-think-text {
        background-image: linear-gradient(100deg, var(--ink-soft) 40%, var(--primary) 50%, var(--ink-soft) 60%);
        background-size: 250% 100%;
        background-repeat: no-repeat;
        -webkit-background-clip: text;
        background-clip: text;
        -webkit-text-fill-color: transparent;
        color: transparent;
        animation: ohyShimmer 2.4s linear infinite;
    }
}

/* three little progress marks in the highlighter yellow, one per phrase */
.ohy-think-pips {
    display: flex;
    gap: 5px;
    margin-top: 12px;
}

.ohy-think-pips i {
    position: relative;
    display: block;
    width: 22px;
    height: 3px;
    border-radius: 3px;
    background: var(--line);
    overflow: hidden;
}

.ohy-think-pips i::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    border-radius: inherit;
    background: var(--highlighter-dark);
    transform: scaleX(0);
    transform-origin: left center;
    animation: ohyPipFill var(--ohy-step) linear both;
}

.ohy-think-pips i:nth-child(2)::after {
    animation-delay: var(--ohy-step);
}

/* the last mark has no end point (the answer arrives when it arrives), so it keeps sliding */
.ohy-think-pips i:nth-child(3)::after {
    width: 40%;
    transform: translateX(-100%);
    animation: ohyPipSlide 1.3s ease-in-out calc(var(--ohy-step) * 2) infinite both;
}

@keyframes ohyPhaseSwap {
    0%   { opacity: 0; transform: translateY(7px);  filter: blur(4px); }
    18%  { opacity: 1; transform: translateY(0);    filter: blur(0); }
    82%  { opacity: 1; transform: translateY(0);    filter: blur(0); }
    100% { opacity: 0; transform: translateY(-7px); filter: blur(4px); }
}

@keyframes ohyPhaseIn {
    from { opacity: 0; transform: translateY(7px); filter: blur(4px); }
    to   { opacity: 1; transform: translateY(0);   filter: blur(0); }
}

@keyframes ohyShimmer {
    from { background-position: 100% 0; }
    to   { background-position: 0% 0; }
}

@keyframes ohyPipFill {
    to { transform: scaleX(1); }
}

@keyframes ohyPipSlide {
    from { transform: translateX(-100%); }
    to   { transform: translateX(250%); }
}

/* reduced-motion versions: opacity only, no slide, blur or sweep */
@keyframes ohyFadeSwap {
    0%   { opacity: 0; }
    18%  { opacity: 1; }
    82%  { opacity: 1; }
    100% { opacity: 0; }
}

@keyframes ohyFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* --------------------------------------------------------- options bar --- */
/* Length / Style / References, above the message box. Same segmented pills
   and switch as the add-on. */

.ohy-opts {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 22px;
    padding: 0 0.5rem 0.7rem;
}

.ohy-grp {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ohy-lbl {
    font: 600 10px/1 var(--font-mono);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink-soft);
}

.ohy-seg {
    display: inline-flex;
    gap: 4px;
}

.ohy-seg button {
    cursor: pointer;
    user-select: none;
    border: 1px solid var(--line);
    background: var(--white);
    color: var(--ink-soft);
    border-radius: 999px;
    padding: 3px 11px;
    font: 600 11.5px/1.4 var(--font-body);
    transition: all 0.15s ease;
}

.ohy-seg button:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.ohy-seg button.on {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--ohy-on-primary);
}

.ohy-seg button:focus-visible {
    outline: 2px solid var(--highlighter-dark);
    outline-offset: 2px;
}

.ohy-grp .ohy-tog {
    padding: 4px 0;
}

/* -------------------------------------------- small adjustments elsewhere -- */

.header-btn,
.step-tag {
    white-space: nowrap;
}

/* the message box picks up the add-on's highlighter focus ring */
.input-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--ohy-hl-soft), 0 8px 28px rgba(10, 92, 95, 0.12);
}

.typing-indicator .ohy-panel {
    animation: none;
}

@media (max-width: 768px) {
    .ohy-opts { gap: 6px 14px; padding: 0 0.25rem 0.6rem; }
    .ohy-panel .nbme-questions-btn { width: 100%; justify-content: center; }
    .ohy-panel .report-error-btn { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .ohy-sw,
    .ohy-sw .ohy-knob,
    .ohy-refs-fold,
    body.refs-off .ohy-refs-fold {
        transition: none;
        animation: none;
    }

    /* styles.css squashes every animation to ~0s (!important) under reduced motion, which
       would skip straight past the phrases. These !important durations (higher specificity)
       bring the schedule back: the phrases and marks still change on time, they just fade
       instead of sliding, blurring or sweeping. */
    .ohy-think-line {
        animation-name: ohyFadeSwap;
        animation-duration: var(--ohy-step) !important;
    }

    .ohy-think-line[data-phase="3"] {
        animation-name: ohyFadeIn;
        animation-duration: 0.3s !important;
    }

    .ohy-think-text {
        animation: none;
    }

    .ohy-think-pips i::after,
    .ohy-think-pips i:nth-child(3)::after {
        width: 100%;
        transform: none;
        animation-name: ohyFadeIn;
        animation-duration: 0.3s !important;
        animation-iteration-count: 1;
    }

    .ohy-think-pips i:nth-child(3)::after {
        animation-delay: calc(var(--ohy-step) * 2);
    }
}
