/* ---------------------------------------------------------------- tokens */

:root {
    color-scheme: light dark;

    --bg: #f5f6f8;
    --card: #ffffff;
    --border: #e3e6ea;
    --text: #16181d;
    --muted: #6b7280;
    --accent: #0f766e;
    --accent-hover: #0d6560;
    --accent-soft: #e6f4f2;
    --success: #15803d;
    --warn: #b45309;
    --danger: #b91c1c;
    --ring: rgba(15, 118, 110, .35);

    /* derived: ink on top of --accent, plus a translucent danger wash */
    --accent-ink: #ffffff;
    --danger-soft: rgba(185, 28, 28, .08);

    --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, Menlo, monospace;
}

/*
  Dark tokens twice, because a custom property set cannot be shared between a
  media query and a plain selector: once for "follow the system" (unless the
  reader picked light) and once for an explicit dark choice. Keep the two
  lists identical.
*/
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f1115;
        --card: #171a21;
        --border: #262a33;
        --text: #e6e8ec;
        --muted: #9aa3b2;
        --accent: #2dd4bf;
        --accent-hover: #5eead4;
        --accent-soft: #133331;
        --success: #4ade80;
        --warn: #fbbf24;
        --danger: #f87171;
        --ring: rgba(45, 212, 191, .4);

        --accent-ink: #06201e;
        --danger-soft: rgba(248, 113, 113, .12);
    }
}

:root[data-theme="dark"] {
    --bg: #0f1115;
    --card: #171a21;
    --border: #262a33;
    --text: #e6e8ec;
    --muted: #9aa3b2;
    --accent: #2dd4bf;
    --accent-hover: #5eead4;
    --accent-soft: #133331;
    --success: #4ade80;
    --warn: #fbbf24;
    --danger: #f87171;
    --ring: rgba(45, 212, 191, .4);

    --accent-ink: #06201e;
    --danger-soft: rgba(248, 113, 113, .12);
}

/* Keep form controls and scrollbars in step with an explicit choice. */
:root[data-theme="light"] {
    color-scheme: light;
}

:root[data-theme="dark"] {
    color-scheme: dark;
}

/* The pre-Blazor markup in index.html carries both languages. */
.i18n-tr {
    display: none;
}

:root[lang="tr"] .i18n-en {
    display: none;
}

:root[lang="tr"] .i18n-tr {
    display: inline;
}

/* ---------------------------------------------------------------- base */

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

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p,
ol,
ul {
    margin: 0;
}

a {
    color: var(--accent);
}

/*
  Invisible until it takes focus. It is the first focusable element in the
  page, so the first Tab offers "Skip to content" before the theme and
  language pickers.
*/
.skip-link {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.skip-link:focus {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 1001;
    width: auto;
    height: auto;
    margin: 0;
    padding: 9px 14px;
    overflow: visible;
    clip-path: none;
    background: var(--card);
    border: 1px solid var(--accent);
    border-radius: 10px;
    box-shadow: 0 0 0 3px var(--ring);
    color: var(--accent);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
}

.shell {
    max-width: 640px;
    margin: 0 auto;
    padding: 24px;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* The main landmark: a flex column, so the pages keep the shell's spacing. */
.content {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Focus arrives here from the skip link; no ring around the whole page. */
.content:focus {
    outline: none;
}

/* ---------------------------------------------------------------- top bar */

.topbar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-bottom: -6px;
}

/* A compact segmented pill: hidden radios, so arrow keys move the choice. */
.seg {
    display: flex;
    gap: 2px;
    padding: 2px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 9px;
}

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

.seg label {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 26px;
    min-width: 30px;
    padding: 0 7px;
    border-radius: 7px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .02em;
    cursor: pointer;
    user-select: none;
    transition: background-color .15s ease, color .15s ease;
}

.seg label:hover {
    color: var(--text);
}

.seg input:checked + label {
    background: var(--accent-soft);
    color: var(--accent);
}

.seg input:focus-visible + label {
    box-shadow: 0 0 0 3px var(--ring);
}

.seg-icon svg {
    width: 15px;
    height: 15px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.4;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ---------------------------------------------------------------- tabs */

.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
}

.tab {
    display: inline-flex;
    align-items: center;
    height: 36px;
    padding: 0 12px;
    margin-bottom: -1px;
    border-bottom: 2px solid transparent;
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    transition: color .15s ease, border-color .15s ease;
}

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

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab:focus-visible {
    outline: none;
    border-radius: 8px;
    box-shadow: 0 0 0 3px var(--ring);
}

/* ---------------------------------------------------------------- header */

.masthead h1 {
    font-size: 28px;
    font-weight: 650;
    letter-spacing: -0.01em;
    line-height: 1.2;
}

.subtitle {
    margin-top: 6px;
    color: var(--muted);
    font-size: 15px;
}

/* ---------------------------------------------------------------- card */

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 22px;
}

/* ---------------------------------------------------------------- fields */

.field + .field {
    margin-top: 18px;
}

.field label,
.group-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: .01em;
    margin-bottom: 6px;
}

.field input[type="text"] {
    width: 100%;
    height: 44px;
    padding: 0 13px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    font-size: 16px;
    line-height: 1.5;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.field input[type="text"]::placeholder {
    color: var(--muted);
    opacity: .8;
}

.field input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--ring);
}

.field input[type="text"]:disabled {
    opacity: .55;
    cursor: not-allowed;
}

.field input.invalid,
.field textarea.invalid {
    border-color: var(--danger);
}

.field textarea {
    display: block;
    width: 100%;
    padding: 10px 13px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 15px;
    line-height: 1.6;
    resize: vertical;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.field textarea::placeholder {
    color: var(--muted);
    opacity: .8;
}

.field textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--ring);
}

.field textarea:disabled {
    opacity: .55;
    cursor: not-allowed;
}

.count {
    font-variant-numeric: tabular-nums;
}

/* The heuristic caveat under the many-numbers form. */
.notice {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    color: var(--muted);
}

.helper {
    margin-top: 6px;
    font-size: 13px;
    color: var(--muted);
}

.error {
    margin-top: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--danger);
}

/* ---------------------------------------------------------------- chips */

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.chip {
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1;
    padding: 5px 9px;
    border-radius: 7px;
    background: var(--accent-soft);
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

.chip-bad {
    background: var(--danger-soft);
    color: var(--danger);
    text-decoration: line-through;
}

/* ------------------------------------------------------- segmented control */

.segmented {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3px;
    padding: 3px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 11px;
}

.segmented-3 {
    grid-template-columns: repeat(3, 1fr);
}

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

.segmented label {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 36px;
    padding: 0 10px;
    margin: 0;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--muted);
    cursor: pointer;
    text-align: center;
    user-select: none;
    transition: background-color .15s ease, color .15s ease;
}

.segmented label:hover {
    color: var(--text);
}

.segmented input:checked + label {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

.segmented input:focus-visible + label {
    box-shadow: 0 0 0 3px var(--ring);
}

.segmented input:disabled + label {
    opacity: .55;
    cursor: not-allowed;
}

/* ---------------------------------------------------------------- buttons */

.actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    height: 44px;
    padding: 0 20px;
    border: 1px solid transparent;
    border-radius: 10px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}

.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--ring);
}

.btn:disabled {
    opacity: .65;
    cursor: not-allowed;
}

.btn-primary {
    flex: 1 1 auto;
    background: var(--accent);
    color: var(--accent-ink);
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--text);
}

.btn-ghost:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
}

/* ---------------------------------------------------------------- spinner */

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin .7s linear infinite;
    flex: none;
}

.spinner-lg {
    width: 26px;
    height: 26px;
    border-width: 3px;
    color: var(--accent);
}

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

/* ---------------------------------------------------------------- result */

.result {
    animation: fade-in .15s ease-out both;
}

@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

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

.result-label {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.result-label.exact {
    color: var(--success);
}

.result-label.near {
    color: var(--warn);
}

/* A heuristic verdict is a sentence, not a badge. */
.result-label.long {
    font-size: 14px;
    font-weight: 650;
    letter-spacing: 0;
    text-transform: none;
}

.expression {
    margin-top: 10px;
    font-family: var(--font-mono);
    font-size: 22px;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.expression .eq,
.steps .eq {
    color: var(--muted);
    padding: 0 .15em;
}

.expression .value,
.steps .value {
    font-weight: 700;
}

.expression .prefix {
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 600;
    color: var(--muted);
    margin-right: .5em;
}

.trivial {
    margin-top: 10px;
    font-size: 15px;
    color: var(--muted);
}

.off-by {
    margin-top: 8px;
    font-size: 14px;
    color: var(--muted);
}

.off-by strong {
    color: var(--text);
    font-family: var(--font-mono);
    font-weight: 700;
}

.steps-title {
    margin-top: 20px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
}

.steps {
    margin-top: 8px;
    padding: 0;
    list-style: none;
    counter-reset: step;
    border-top: 1px solid var(--border);
}

.steps li {
    counter-increment: step;
    display: flex;
    align-items: baseline;
    gap: 12px;
    padding: 9px 2px;
    border-bottom: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 15px;
    overflow-wrap: anywhere;
}

.steps li::before {
    content: counter(step);
    flex: none;
    min-width: 1.25em;
    color: var(--muted);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.usage {
    margin-top: 14px;
    font-size: 14px;
    color: var(--muted);
}

.stats {
    margin-top: 4px;
    font-size: 13px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------- other solutions */

.solutions {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.solutions-title {
    font-weight: 400;
    font-size: 13px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.solutions-list {
    margin-top: 8px;
    padding: 0;
    list-style: none;
}

/*
  Rank, expression and badge on one line while they fit; the expression takes
  the slack and may break inside itself, and on a narrow screen the badge
  drops to a line of its own instead of squeezing the expression.
*/
.solution-row {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 12px;
    padding: 8px 2px;
    border-top: 1px solid var(--border);
}

.solution-rank {
    flex: none;
    min-width: 1.25em;
    color: var(--muted);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.solution-expr {
    flex: 1 1 12ch;
    min-width: 0;
    font-family: var(--font-mono);
    font-size: 15px;
    overflow-wrap: anywhere;
}

.solution-badge {
    flex: none;
    margin-left: auto;
    padding: 2px 8px;
    border-radius: 7px;
    background: var(--bg);
    color: var(--muted);
    font-size: 12px;
    line-height: 1.4;
    white-space: nowrap;
}

/* ---------------------------------------------------------------- footer */

.footer {
    margin-top: auto;
    padding-top: 8px;
    font-size: 13px;
    color: var(--muted);
}

.textlink {
    font-weight: 600;
}

/* ------------------------------------------------------- loading placeholder */

/*
  The pre-Blazor markup: a centred column with the title and the bilingual
  description a crawler reads before the runtime replaces all of it.
*/
.boot {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 24px;
    text-align: center;
}

.boot-title {
    max-width: 640px;
    font-size: 28px;
    font-weight: 650;
    letter-spacing: -0.01em;
    line-height: 1.2;
}

.boot-lede {
    max-width: 640px;
    color: var(--muted);
    font-size: 15px;
}

.boot-text {
    color: var(--muted);
    font-size: 15px;
}

/* Shown only when scripting is off; same copy as the boot screen. */
.noscript {
    max-width: 640px;
    margin: 0 auto;
    padding: 24px;
}

.noscript h2 {
    margin-top: 20px;
    font-size: 20px;
    font-weight: 650;
}

.noscript p {
    margin-top: 8px;
    color: var(--muted);
    font-size: 15px;
}

/* ---------------------------------------------------------------- error bar */

#blazor-error-ui {
    display: none;
    position: fixed;
    inset: auto 0 0 0;
    z-index: 1000;
    align-items: center;
    gap: 14px;
    padding: 14px 20px;
    background: var(--card);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 12px rgba(16, 24, 40, .08);
    color: var(--text);
    font-size: 14px;
}

#blazor-error-ui .reload {
    color: var(--accent);
    font-weight: 600;
}

#blazor-error-ui .dismiss {
    margin-left: auto;
    cursor: pointer;
    color: var(--muted);
}

/* ---------------------------------------------------------------- narrow */

@media (max-width: 480px) {
    .shell {
        padding: 16px;
        gap: 16px;
    }

    .content {
        gap: 16px;
    }

    .card {
        padding: 18px;
    }

    .masthead h1 {
        font-size: 25px;
    }

    .expression {
        font-size: 19px;
    }

    .actions {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
    }

    .spinner {
        animation: spin 1.4s linear infinite !important;
    }
}
