:root {
    --bg: #f6f4ef;
    --surface: #ffffff;
    --surface-2: #eef1f6;
    --text: #1c2230;
    --muted: #5a6273;
    --border: #d9dde5;
    --accent: #1f3a68;
    --accent-text: #ffffff;
    --accent-soft: #e3eaf6;
    --good: #1e7a46;
    --good-soft: #e2f3e8;
    --bad: #b3261e;
    --bad-soft: #fbe7e5;
    --warn: #8a5a00;
    --warn-soft: #fff3d6;
    --focus: #3b82f6;
    --radius: 12px;
    --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 16px rgb(16 24 40 / 6%);
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #11151c;
        --surface: #1a2029;
        --surface-2: #232b37;
        --text: #e8ebf1;
        --muted: #a3acbb;
        --border: #333d4c;
        --accent: #8fb3ff;
        --accent-text: #0d1320;
        --accent-soft: #22324d;
        --good: #6fd49a;
        --good-soft: #173526;
        --bad: #ff8a80;
        --bad-soft: #3d1f1d;
        --warn: #f5c56b;
        --warn-soft: #3a2f16;
        --shadow: none;
        color-scheme: dark;
    }
}

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

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 17px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}

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

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

/* Headings receive focus programmatically on each screen change. */
h1[tabindex="-1"]:focus {
    outline: none;
}

.skip-link {
    position: absolute;
    left: -9999px;
}

.skip-link:focus {
    left: 16px;
    top: 16px;
    z-index: 10;
    background: var(--surface);
    padding: 8px 12px;
    border-radius: 8px;
}

.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.site-header__inner,
.page,
.site-footer {
    max-width: 880px;
    margin: 0 auto;
    padding: 0 16px;
}

.site-header__inner {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 24px;
    align-items: center;
    justify-content: space-between;
    padding-top: 12px;
    padding-bottom: 12px;
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
}

.brand__title {
    margin: 0;
    font-weight: 700;
    font-size: 1.05rem;
}

.brand__subtitle {
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.ui-language {
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 0.95rem;
    color: var(--muted);
}

.page {
    padding-top: 24px;
    padding-bottom: 48px;
    outline: none;
}

.site-footer {
    color: var(--muted);
    font-size: 0.85rem;
    padding-bottom: 32px;
}

.site-footer__source {
    margin-top: 4px;
}

h1,
h2,
h3 {
    line-height: 1.25;
    margin: 0 0 12px;
}

h1 {
    font-size: 1.6rem;
}

h2 {
    font-size: 1.25rem;
    margin-top: 28px;
}

h3 {
    font-size: 1.05rem;
}

p {
    margin: 0 0 12px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 16px;
}

.lead {
    color: var(--muted);
    font-size: 1.02rem;
}

.stack > * + * {
    margin-top: 16px;
}

.row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.btn {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 10px;
    padding: 11px 18px;
    min-height: 46px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
}

.btn:hover {
    background: var(--surface-2);
}

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

.btn--primary {
    background: var(--accent);
    color: var(--accent-text);
    border-color: var(--accent);
}

.btn--primary:hover {
    filter: brightness(1.08);
    background: var(--accent);
}

.btn--big {
    min-height: 64px;
    padding: 14px 26px;
    font-size: 1.1rem;
    border-radius: 999px;
}

.btn--listening {
    background: var(--bad);
    border-color: var(--bad);
    color: #fff;
    animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
    50% {
        box-shadow: 0 0 0 10px rgb(179 38 30 / 15%);
    }
}

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

.btn--link {
    border: none;
    background: none;
    padding: 6px 4px;
    min-height: 0;
    color: var(--accent);
    text-decoration: underline;
    font-weight: 500;
}

label.field {
    display: block;
    font-weight: 600;
}

.field input,
.field select,
.field textarea,
select {
    display: block;
    width: 100%;
    margin-top: 6px;
    font: inherit;
    font-weight: 400;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    min-height: 46px;
}

.ui-language select {
    width: auto;
    margin-top: 0;
}

.field textarea {
    min-height: 90px;
    resize: vertical;
}

.help {
    display: block;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 400;
    margin-top: 4px;
}

.notice {
    border-radius: 10px;
    padding: 10px 14px;
    background: var(--warn-soft);
    color: var(--text);
    border: 1px solid var(--border);
    font-size: 0.95rem;
}

.notice--error {
    background: var(--bad-soft);
}

.notice--info {
    background: var(--accent-soft);
}

.diag-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.diag-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.diag-card[aria-current="true"] {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent);
}

.diag-card__name {
    font-weight: 700;
}

.diag-card__text {
    flex: 1;
}

.check {
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 0.95rem;
}

.check input {
    width: 20px;
    height: 20px;
}

.meter {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
    color: var(--muted);
    font-size: 0.95rem;
}

.progress {
    height: 8px;
    background: var(--surface-2);
    border-radius: 999px;
    overflow: hidden;
}

.progress__bar {
    height: 100%;
    background: var(--accent);
    width: 0;
    transition: width 0.3s;
}

.question {
    font-size: 1.35rem;
    font-weight: 650;
    line-height: 1.35;
}

.question-en {
    color: var(--muted);
    font-size: 0.95rem;
}

.heard {
    background: var(--surface-2);
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 1.1rem;
}

.result {
    border-radius: 10px;
    padding: 14px;
    border: 1px solid var(--border);
}

.result--good {
    background: var(--good-soft);
}

.result--bad {
    background: var(--bad-soft);
}

.result__title {
    font-weight: 700;
    font-size: 1.15rem;
}

.result--good .result__title {
    color: var(--good);
}

.result--bad .result__title {
    color: var(--bad);
}

.answers {
    margin: 6px 0 0;
    padding-left: 20px;
}

.method {
    color: var(--muted);
    font-size: 0.85rem;
}

.lang-switch {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.lang-switch select {
    width: auto;
    margin: 0;
}

.sentence {
    font-size: 1.5rem;
    font-weight: 650;
    text-align: center;
    padding: 18px 10px;
}

.summary {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.stat {
    background: var(--surface-2);
    border-radius: 10px;
    padding: 12px 14px;
}

.stat__label {
    color: var(--muted);
    font-size: 0.85rem;
}

.stat__value {
    font-size: 1.3rem;
    font-weight: 700;
}

.stat__value--good {
    color: var(--good);
}

.stat__value--bad {
    color: var(--bad);
}

.recommend {
    border-left: 4px solid var(--accent);
    padding: 10px 14px;
    background: var(--accent-soft);
    border-radius: 0 10px 10px 0;
    font-size: 1.05rem;
}

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.93rem;
}

th,
td {
    text-align: left;
    vertical-align: top;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}

th {
    color: var(--muted);
    font-weight: 600;
    white-space: nowrap;
}

td.num,
th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

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

.tag {
    display: inline-block;
    white-space: nowrap;
    border-radius: 999px;
    padding: 1px 9px;
    font-size: 0.8rem;
    font-weight: 700;
}

.tag--good {
    background: var(--good-soft);
    color: var(--good);
}

.tag--bad {
    background: var(--bad-soft);
    color: var(--bad);
}

.feedback {
    color: var(--muted);
    font-size: 0.88rem;
    margin-top: 4px;
}

.history li {
    margin-bottom: 6px;
}

.hidden {
    display: none !important;
}

@media (max-width: 560px) {
    body {
        font-size: 16px;
    }

    .question {
        font-size: 1.2rem;
    }

    .btn--big {
        width: 100%;
    }
}

@media print {
    :root {
        --bg: #fff;
        --surface: #fff;
        --surface-2: #f3f3f3;
        --text: #000;
        --muted: #444;
        --border: #bbb;
    }

    .site-header,
    .no-print,
    .skip-link {
        display: none !important;
    }

    .card {
        box-shadow: none;
        break-inside: avoid;
    }

    tr {
        break-inside: avoid;
    }

    .table-wrap {
        overflow: visible;
    }
}

/* Admin page */
.page--wide {
    max-width: 1180px;
}

td.pre {
    white-space: pre-line;
    min-width: 220px;
}

td.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.tag:not(.tag--good):not(.tag--bad) {
    background: var(--surface-2);
    color: var(--muted);
}
