/* =========================================================================
   Vägvisare – "Vägen"
   Design language borrowed from the Swedish road: sign blue, huvudled yellow,
   asphalt, reflex white and the dashed centre line. Light theme is a day drive
   on a paper-white vägren; dark theme is a night drive with headlight yellow.
   ========================================================================= */

:root {
    color-scheme: light dark;

    /* Road palette */
    --sign-blue: #0a56a5;
    --sign-blue-deep: #063c75;
    --sign-yellow: #f6c700;
    --sign-red: #c8102e;
    --sign-green: #0b6d3f;

    /* Day */
    --app-bg: #f3f1ea;
    --app-bg-deep: #e9e6dc;
    --app-text: #14161a;
    --muted-text: #565b63;
    --subtle-text: #7b8089;
    --surface: #fbfaf6;
    --surface-soft: #f0ede4;
    --surface-raised: #ffffff;
    --border: #d9d5c9;
    --border-strong: #b9b4a6;
    --line: #14161a;               /* the painted road line */
    --primary: var(--sign-blue);
    --primary-text: #ffffff;
    --accent: var(--sign-yellow);
    --accent-text: #14161a;
    --secondary: #e5e9ee;
    --danger: var(--sign-red);
    --danger-soft: #fbe4e6;
    --danger-border: #e59aa5;
    --danger-text: #5a0f1a;
    --success: var(--sign-green);
    --success-soft: #e0f0e7;
    --success-border: #8fc2a6;
    --warning-soft: #fff3c4;
    --warning-border: #e2c25a;
    --conversation-user: #e5e9ee;
    --conversation-assistant: #f0ede4;
    --shadow: 0 1px 0 rgba(0, 0, 0, .06), 0 12px 30px -18px rgba(20, 22, 26, .35);

    --font-sans: "Archivo", "Arial Narrow", Arial, system-ui, sans-serif;
    --wdth-sign: 75;               /* condensed, like sign lettering */
    --wdth-body: 100;
    --radius: 6px;                 /* signs have small radii */
    --radius-lg: 12px;
    --gutter: clamp(16px, 4vw, 40px);
    --content-max: 1180px;
    --motion: 1;
}

@media (prefers-color-scheme: dark) {
    :root {
        --app-bg: #0d0f12;
        --app-bg-deep: #070809;
        --app-text: #eef0f2;
        --muted-text: #aab0b8;
        --subtle-text: #7f868f;
        --surface: #15181d;
        --surface-soft: #11141a;
        --surface-raised: #1c2027;
        --border: #2a2f37;
        --border-strong: #3d434d;
        --line: #f2f2f2;
        --primary: #3d8ee6;
        --primary-text: #ffffff;
        --accent: #ffd400;
        --accent-text: #14161a;
        --secondary: #1f2530;
        --danger: #ff5a6a;
        --danger-soft: #331418;
        --danger-border: #7a2c35;
        --danger-text: #ffd7dc;
        --success: #3dbf7c;
        --success-soft: #12261b;
        --success-border: #2f6b4a;
        --warning-soft: #2c2508;
        --warning-border: #7a6a1c;
        --conversation-user: #1c2a3c;
        --conversation-assistant: #1f2530;
        --shadow: 0 1px 0 rgba(255, 255, 255, .03), 0 14px 34px -18px rgba(0, 0, 0, .8);
    }
}

html[data-theme="light"] {
    color-scheme: light;
    --app-bg: #f3f1ea;
    --app-bg-deep: #e9e6dc;
    --app-text: #14161a;
    --muted-text: #565b63;
    --subtle-text: #7b8089;
    --surface: #fbfaf6;
    --surface-soft: #f0ede4;
    --surface-raised: #ffffff;
    --border: #d9d5c9;
    --border-strong: #b9b4a6;
    --line: #14161a;
    --primary: #0a56a5;
    --primary-text: #ffffff;
    --accent: #f6c700;
    --accent-text: #14161a;
    --secondary: #e5e9ee;
    --danger: #c8102e;
    --danger-soft: #fbe4e6;
    --danger-border: #e59aa5;
    --danger-text: #5a0f1a;
    --success: #0b6d3f;
    --success-soft: #e0f0e7;
    --success-border: #8fc2a6;
    --warning-soft: #fff3c4;
    --warning-border: #e2c25a;
    --conversation-user: #e5e9ee;
    --conversation-assistant: #f0ede4;
    --shadow: 0 1px 0 rgba(0, 0, 0, .06), 0 12px 30px -18px rgba(20, 22, 26, .35);
}

html[data-theme="dark"] {
    color-scheme: dark;
    --app-bg: #0d0f12;
    --app-bg-deep: #070809;
    --app-text: #eef0f2;
    --muted-text: #aab0b8;
    --subtle-text: #7f868f;
    --surface: #15181d;
    --surface-soft: #11141a;
    --surface-raised: #1c2027;
    --border: #2a2f37;
    --border-strong: #3d434d;
    --line: #f2f2f2;
    --primary: #3d8ee6;
    --primary-text: #ffffff;
    --accent: #ffd400;
    --accent-text: #14161a;
    --secondary: #1f2530;
    --danger: #ff5a6a;
    --danger-soft: #331418;
    --danger-border: #7a2c35;
    --danger-text: #ffd7dc;
    --success: #3dbf7c;
    --success-soft: #12261b;
    --success-border: #2f6b4a;
    --warning-soft: #2c2508;
    --warning-border: #7a6a1c;
    --conversation-user: #1c2a3c;
    --conversation-assistant: #1f2530;
    --shadow: 0 1px 0 rgba(255, 255, 255, .03), 0 14px 34px -18px rgba(0, 0, 0, .8);
}

@media (prefers-reduced-motion: reduce) {
    :root {
        --motion: 0;
    }

    *,
    *::before,
    *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
    }
}

/* ---------- Base ---------- */

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

html,
body {
    margin: 0;
    min-height: 100%;
    background: var(--app-bg);
    color: var(--app-text);
    font-family: var(--font-sans);
    font-variation-settings: "wdth" var(--wdth-body);
    font-size: 17px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
    text-rendering: optimizeLegibility;
}

/* Subtle asphalt grain – gives the page a surface without an image. */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: -1;
    background:
        radial-gradient(circle at 20% 0%, color-mix(in srgb, var(--primary) 8%, transparent), transparent 55%),
        radial-gradient(circle at 100% 100%, color-mix(in srgb, var(--accent) 7%, transparent), transparent 50%);
}

h1, h2, h3, h4 {
    font-family: var(--font-sans);
    font-variation-settings: "wdth" var(--wdth-sign);
    letter-spacing: -.01em;
    line-height: 1.05;
    font-weight: 800;
    margin: 0 0 .5rem;
    text-wrap: balance;
}

h1 {
    font-size: clamp(2rem, 4.5vw, 3.4rem);
}

h2 {
    font-size: clamp(1.4rem, 2.6vw, 2rem);
}

h3 {
    font-size: 1.15rem;
}

p {
    margin: 0 0 .75rem;
}

a {
    color: var(--primary);
    text-underline-offset: .15em;
}

img,
svg {
    max-width: 100%;
}

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

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

/* Blazor moves focus to the page heading after navigation (FocusOnNavigate);
   that is for screen readers, not a visible ring around the title. */
h1:focus,
h1:focus-visible {
    outline: none;
}

::selection {
    background: var(--accent);
    color: var(--accent-text);
}

/* ---------- Typographic helpers ---------- */

/* The small uppercase label above titles – lettered like a sign panel. */
.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    margin: 0 0 .5rem;
    color: var(--muted-text);
    font-size: .74rem;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    font-variation-settings: "wdth" 90;
}

.eyebrow::before {
    content: "";
    width: 1.6rem;
    height: 3px;
    background: var(--accent);
}

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

/* Oversized figure – kilometre-post numbers, streaks, scores. */
.figure {
    font-variation-settings: "wdth" 72;
    font-weight: 900;
    font-size: clamp(2.4rem, 6vw, 4.2rem);
    line-height: .9;
    letter-spacing: -.03em;
}

/* ---------- Page container ---------- */

.content {
    padding: 0;
}

.shell {
    width: min(100% - 2 * var(--gutter), var(--content-max));
    margin: 0 auto;
    padding-block: clamp(1.25rem, 3vw, 2.5rem) 4rem;
}

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

.primary-action,
.secondary-action,
.ghost-action {
    --btn-bg: var(--primary);
    --btn-fg: var(--primary-text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    min-height: 44px;
    padding: .6rem 1.1rem;
    border: 2px solid transparent;
    border-radius: var(--radius);
    background: var(--btn-bg);
    color: var(--btn-fg);
    font-weight: 700;
    font-variation-settings: "wdth" 88;
    letter-spacing: .01em;
    text-decoration: none;
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}

.primary-action:hover,
.secondary-action:hover,
.ghost-action:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 14px -8px color-mix(in srgb, var(--btn-bg) 60%, transparent);
}

.primary-action:active,
.secondary-action:active {
    transform: translateY(0);
}

.primary-action:disabled,
.secondary-action:disabled {
    cursor: not-allowed;
    opacity: .55;
    transform: none;
    box-shadow: none;
}

.secondary-action {
    --btn-bg: var(--surface-raised);
    --btn-fg: var(--app-text);
    border-color: var(--border-strong);
}

.ghost-action {
    --btn-bg: transparent;
    --btn-fg: var(--primary);
    border-color: transparent;
    padding-inline: .5rem;
}

.primary-action.big {
    min-height: 54px;
    padding: .8rem 1.5rem;
    font-size: 1.05rem;
}

.correcting-action {
    display: inline-flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid color-mix(in srgb, var(--primary-text) 45%, transparent);
    border-top-color: var(--primary-text);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.working-note {
    margin: 10px 0 0;
    color: var(--muted-text);
}

/* Round icon button – the speak button in compact form. */
.icon-button {
    display: inline-grid;
    place-items: center;
    width: 42px;
    height: 42px;
    padding: 0;
    border: 2px solid var(--border-strong);
    border-radius: 50%;
    background: var(--surface-raised);
    color: var(--app-text);
    cursor: pointer;
}

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

.link-button {
    border: 0;
    background: none;
    color: var(--primary);
    font: inherit;
    text-decoration: underline;
    cursor: pointer;
}

/* Pill toggle */
.toggle {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    min-height: 40px;
    padding: .35rem .8rem;
    border: 2px solid var(--border-strong);
    border-radius: 999px;
    background: var(--surface-raised);
    cursor: pointer;
    user-select: none;
    font-weight: 600;
}

.toggle input {
    accent-color: var(--primary);
}

/* ---------- Panels ---------- */

/* A "plate": the app's card. Flat, sign-like, with a hairline and a soft drop. */
.plate {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.operation-error {
    margin: 0 0 18px;
    padding: 16px;
    border: 2px solid var(--danger-border);
    border-left-width: 10px;
    border-radius: var(--radius);
    background: var(--danger-soft);
    color: var(--danger-text);
}

.operation-error p {
    margin: 6px 0 10px;
}

.operation-error pre {
    max-height: 260px;
    overflow: auto;
    padding: 10px;
    border-radius: var(--radius);
    background: var(--surface);
    white-space: pre-wrap;
}

/* Feedback after grading – coloured like a sign's border. */
.feedback {
    margin-top: 18px;
    padding: 14px 16px;
    border-radius: var(--radius);
    border: 2px solid var(--border);
    border-left-width: 10px;
    background: var(--surface-raised);
}

.feedback p {
    margin: 4px 0 0;
}

.feedback.correct {
    background: var(--success-soft);
    border-color: var(--success-border);
    border-left-color: var(--success);
}

.feedback.needs-work {
    background: var(--warning-soft);
    border-color: var(--warning-border);
    border-left-color: var(--accent);
}

/* Leitner box chip – used on study cards, repetition and guide tools. */
.box {
    display: inline-grid;
    place-items: center;
    min-width: 1.7rem;
    height: 1.7rem;
    padding: 0 .5rem;
    border-radius: 4px;
    border: 2px solid var(--border-strong);
    background: var(--surface-raised);
    font-size: .8rem;
    font-weight: 800;
    font-variation-settings: "wdth" 80;
    white-space: nowrap;
}

.box-0 {
    background: var(--warning-soft);
    border-color: var(--accent);
}

.box-1,
.box-2 {
    border-color: var(--primary);
}

.box-3,
.box-4 {
    background: var(--success-soft);
    border-color: var(--success);
}

/* Progress bar drawn as a road: dark strip with a painted line growing along it. */
.bar {
    position: relative;
    height: 10px;
    border-radius: 2px;
    background: var(--app-bg-deep);
    overflow: hidden;
}

.bar span {
    display: block;
    height: 100%;
    background: var(--accent);
    transition: width .6s cubic-bezier(.2, .7, .2, 1);
}

.bar span::after {
    content: "";
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(90deg, transparent 0 14px, color-mix(in srgb, var(--app-bg-deep) 55%, transparent) 14px 18px);
    mix-blend-mode: multiply;
    opacity: .5;
}

/* ---------- Reading text, answer field and microphone ---------- */

/* Text that is there to be read and understood, not to look like a road sign: normal width,
   moderate weight, generous leading, short lines. Used for questions, answers and coach replies.
   These are the defaults for everyone – readable text helps every learner, not only some. */
.read {
    font-variation-settings: "wdth" 100;
    font-weight: 500;
    letter-spacing: .01em;
    word-spacing: .06em;
    line-height: 1.7;
    max-width: 62ch;
    text-wrap: pretty;
}

/* ReadableText: sentences as rows, enumerations as numbered rows. */
.readable {
    display: block;
}

/* "Svar:" and the first sentence share a row. */
strong + .readable,
strong + .readable .line:first-child {
    display: inline;
}

.readable .line {
    display: block;
}

.readable .enum {
    margin: .25rem 0 .1rem;
    padding-left: 1.6rem;
}

.readable .enum li {
    margin: .15rem 0;
    padding-left: .15rem;
}

.readable .enum li::marker {
    color: var(--primary);
    font-weight: 700;
}

/* One quiet way out of a step: looks like a link, acts like a button. */
.link-action {
    padding: .35rem .2rem;
    border: none;
    background: none;
    color: var(--muted-text);
    font: inherit;
    font-weight: 600;
    text-decoration: underline;
    text-decoration-color: color-mix(in srgb, currentColor 40%, transparent);
    text-underline-offset: .2em;
    cursor: pointer;
}

.link-action:hover,
.link-action:focus-visible {
    color: var(--app-text);
    text-decoration-color: currentColor;
}

.link-action:disabled {
    opacity: .5;
    cursor: default;
}

.answer-field {
    position: relative;
    display: grid;
}

/* Grows with the answer: field-sizing where the browser has it, the inline script in
   AnswerField everywhere else. Never taller than the viewport allows, then it scrolls. */
.answer-field textarea {
    width: 100%;
    padding-right: 3.4rem;
    font-size: 1.05rem;
    line-height: 1.6;
    min-height: 5.2rem;
    max-height: 60vh;
    resize: none;
    overflow-y: auto;
    field-sizing: content;
}

.mic-button {
    position: absolute;
    right: .55rem;
    bottom: .55rem;
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid var(--border-strong);
    border-radius: 50%;
    background: var(--surface-raised);
    color: var(--app-text);
    cursor: pointer;
    touch-action: none;
    user-select: none;
    transition: transform .15s ease, background-color .15s ease;
}

.mic-button svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

.mic-button:hover,
.mic-button:focus-visible {
    border-color: var(--primary);
    color: var(--primary);
}

.mic-button.recording {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
    transform: scale(1.08);
    box-shadow: 0 0 0 6px color-mix(in srgb, var(--danger) 25%, transparent);
}

.mic-button.busy {
    color: var(--muted-text);
}

.mic-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid color-mix(in srgb, currentColor 30%, transparent);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

.mic-status {
    position: absolute;
    right: 3.6rem;
    bottom: .9rem;
    font-size: .8rem;
    color: var(--muted-text);
    pointer-events: none;
}

textarea,
input[type="text"],
input[type="number"],
select {
    padding: .7rem .85rem;
    border: 2px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface-raised);
    color: var(--app-text);
}

textarea {
    width: 100%;
    resize: vertical;
}

.question-media {
    display: grid;
    justify-items: center;
    gap: 8px;
    margin: 0;
    padding: 18px;
    border-radius: var(--radius-lg);
    background: var(--app-bg-deep);
    background-image: repeating-linear-gradient(0deg, transparent 0 22px, color-mix(in srgb, var(--line) 6%, transparent) 22px 23px);
}

.question-media img {
    width: min(240px, 60vw);
    max-height: 240px;
    object-fit: contain;
    filter: drop-shadow(0 8px 12px rgba(0, 0, 0, .25));
}

.question-media figcaption {
    color: var(--muted-text);
    font-size: .92rem;
}

/* ---------- Conversation ---------- */

.conversation-panel {
    display: grid;
    gap: 1rem;
    padding: 1.25rem;
}

.rule-heading {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
}

.conversation-log {
    min-height: 280px;
    display: grid;
    gap: 10px;
    align-content: start;
    padding: 12px 0;
}

.conversation-log p {
    margin: 0;
    max-width: 70ch;
    padding: 12px 14px;
    border-radius: var(--radius-lg);
}

.conversation-log .user {
    background: var(--conversation-user);
    justify-self: end;
    border-bottom-right-radius: 2px;
}

.conversation-log .assistant {
    background: var(--conversation-assistant);
    border-bottom-left-radius: 2px;
}

.conversation-input {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
}

.conversation-input input {
    min-width: 0;
}

.source-link {
    font-size: .92rem;
}

/* ---------- Motion primitives ---------- */

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

.rise {
    animation: rise .5s cubic-bezier(.2, .7, .2, 1) both;
}

/* Scroll-driven reveal where supported; simply visible elsewhere. */
@supports (animation-timeline: view()) {
    .reveal {
        animation: rise linear both;
        animation-timeline: view();
        animation-range: entry 0% entry 35%;
    }
}

