:root {
  color-scheme: light;
  --bg: #f4f9f8;
  --surface: #ffffff;
  --surface-2: #e7f3f1;
  --surface-3: #d6eae7;
  --text: #102524;
  --muted: #48615e;
  --primary: #0b5f59;
  --primary-hover: #084c47;
  --primary-text: #ffffff;
  --border: #aecdc8;
  --shadow: 0 16px 36px rgba(4, 45, 42, .10);
  --danger: #9f1c12;
  --danger-bg: #fff0ee;
  --success: #12643e;
  --success-bg: #eaf8ef;
  --info-bg: #eaf4fb;
  --info: #174f72;
  --focus: #9b5d00;
  --max: 1380px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #041f1e;
  --surface: #072c2a;
  --surface-2: #0a3a36;
  --surface-3: #0d4842;
  --text: #f3fffd;
  --muted: #c2ddd8;
  --primary: #67e6d4;
  --primary-hover: #8cede0;
  --primary-text: #052623;
  --border: #39746e;
  --shadow: 0 18px 42px rgba(0, 0, 0, .28);
  --danger: #ffb4aa;
  --danger-bg: #4a1714;
  --success: #a8efc3;
  --success-bg: #123e2b;
  --info-bg: #12354a;
  --info: #cceaff;
  --focus: #ffd27a;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; line-height: 1.58; }
a { color: var(--primary); font-weight: 700; text-underline-offset: .18em; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.skip-link { position: fixed; left: 1rem; top: -8rem; z-index: 9999; background: var(--surface); color: var(--text); padding: .8rem 1rem; border-radius: .7rem; box-shadow: var(--shadow); }
.skip-link:focus { top: 1rem; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important; }

.topbar { position: sticky; top: 0; z-index: 50; min-height: 74px; display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding: .7rem clamp(1rem, 3vw, 2.5rem); border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(14px); }
.brand { display: inline-flex; align-items: center; gap: .7rem; color: var(--text); text-decoration: none; min-width: 250px; }
.brand-mark { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 14px; background: var(--primary); color: var(--primary-text); font-size: 1.5rem; }
.brand strong, .brand small { display: block; line-height: 1.16; }
.brand small { color: var(--muted); font-weight: 700; margin-top: .15rem; }
.top-actions, .speech-controls, .button-row, .table-actions { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.speech-controls { padding: .28rem; border: 1px solid var(--border); border-radius: .8rem; background: var(--surface-2); }
.speech-controls button, .icon-button, .ghost-button, .secondary-button, .primary-button, .danger-button { min-height: 42px; border-radius: .72rem; border: 1px solid transparent; padding: .65rem .9rem; font-weight: 800; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: .35rem; }
.speech-controls button, .icon-button, .ghost-button, .secondary-button { background: var(--surface); border-color: var(--border); color: var(--text); }
.primary-button { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.primary-button:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.secondary-button:hover, .ghost-button:hover, .icon-button:hover, .speech-controls button:hover { background: var(--surface-3); }
.primary-button.large, .secondary-button.large { min-height: 48px; padding: .78rem 1.15rem; }
.danger-button { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.link-button { border: 0; background: none; padding: 0; cursor: pointer; font-weight: 800; text-decoration: underline; text-underline-offset: .18em; }
.danger-text { color: var(--danger); }
.inline-form { display: inline-flex; margin: 0; }

.app-shell { width: min(100%, 1800px); margin: 0 auto; display: grid; grid-template-columns: 260px minmax(0, 1fr); }
.sidebar { position: sticky; top: 75px; align-self: start; height: calc(100vh - 75px); overflow-y: auto; border-right: 1px solid var(--border); padding: 1rem .8rem 5rem; background: var(--surface); }
.sidebar nav { display: grid; gap: .25rem; }
.sidebar a, .sidebar summary { color: var(--text); text-decoration: none; padding: .62rem .72rem; border-radius: .65rem; font-weight: 750; cursor: pointer; }
.sidebar a:hover, .sidebar summary:hover { background: var(--surface-2); }
.sidebar a.is-active, .sidebar a[aria-current="page"] { background: var(--primary); color: var(--primary-text); box-shadow: inset 4px 0 0 var(--focus); }
.sidebar a.is-active:hover, .sidebar a[aria-current="page"]:hover { background: var(--primary-hover); color: var(--primary-text); }
.sidebar details { border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: .35rem 0; margin: .25rem 0; }
.sidebar details a { display: block; padding-left: 1rem; font-size: .94rem; }
.main-content { min-width: 0; padding: clamp(1.1rem, 3vw, 2.3rem); max-width: var(--max); width: 100%; margin: 0 auto; }
.public-main { grid-column: 1 / -1; max-width: 1240px; }
.page-heading { display: flex; align-items: flex-start; gap: 1rem; margin: .25rem 0 1.5rem; }
.page-icon { width: 58px; height: 58px; flex: 0 0 58px; display: grid; place-items: center; border-radius: 18px; background: var(--surface-2); border: 1px solid var(--border); font-size: 1.75rem; box-shadow: var(--shadow); }
h1, h2, h3 { line-height: 1.2; margin-top: 0; letter-spacing: -.02em; }
h1 { font-size: clamp(1.85rem, 4vw, 2.75rem); margin-bottom: .45rem; }
h2 { font-size: clamp(1.2rem, 2.3vw, 1.55rem); }
h3 { font-size: 1.05rem; }
.lede { margin: 0; color: var(--muted); max-width: 880px; font-size: 1.04rem; }
.eyebrow { color: var(--primary); font-weight: 900; letter-spacing: .08em; font-size: .79rem; }

.hero-grid { display: grid; grid-template-columns: 1.5fr .7fr; gap: 1rem; margin: 1rem 0 1.4rem; }
.hero-card, .metric-card, .feature-card, .notice-card, .callout-card, .panel-card, .score-card, .case-card, .case-detail, .list-card, .result-card, .auth-card, .manual-hero, .empty-card, .readonly-result { background: var(--surface); border: 1px solid var(--border); border-radius: 1rem; box-shadow: var(--shadow); }
.hero-card { padding: clamp(1.5rem, 4vw, 3rem); background: linear-gradient(135deg, var(--surface), var(--surface-2)); }
.hero-card h2 { font-size: clamp(2rem, 5vw, 3.6rem); max-width: 900px; margin: .55rem 0 1rem; }
.hero-card p { max-width: 760px; color: var(--muted); font-size: 1.08rem; }
.metric-card { display: grid; gap: 1px; overflow: hidden; background: var(--border); }
.metric-card > div { display: grid; place-items: center; align-content: center; min-height: 125px; padding: 1rem; background: var(--surface); text-align: center; }
.metric-card strong { font-size: 2.1rem; color: var(--primary); }
.metric-card span { color: var(--muted); font-weight: 700; }
.card-grid { display: grid; gap: 1rem; margin: 1rem 0 1.3rem; }
.card-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.feature-card, .notice-card, .callout-card, .panel-card, .score-card, .empty-card { padding: 1.2rem; }
.feature-card p, .notice-card p, .callout-card p, .panel-card p { color: var(--muted); }
.feature-card .text-link { display: inline-block; margin-top: .3rem; }
.notice-card { margin: 1.2rem 0; background: var(--surface-2); }
.notice-card.compact { padding: .85rem 1rem; }
.callout-card { margin: 1.2rem 0; border-left: 6px solid var(--primary); }
.manual-hero { padding: 1.5rem; margin-bottom: 1rem; background: linear-gradient(135deg, var(--surface-2), var(--surface)); }
.manual-hero h2 { font-size: 2rem; margin: .4rem 0; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .8rem; margin-bottom: 1.2rem; }
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: .9rem; padding: 1rem; display: grid; gap: .25rem; box-shadow: var(--shadow); }
.metric > span { font-size: 1.4rem; }
.metric strong { font-size: 1.05rem; }
.metric small { color: var(--muted); }

.alert { border-radius: .75rem; padding: .85rem 1rem; margin: .9rem 0; border: 1px solid currentColor; font-weight: 650; }
.alert-error { background: var(--danger-bg); color: var(--danger); }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-info { background: var(--info-bg); color: var(--info); }

.auth-card { width: min(100%, 620px); margin: 1rem auto; padding: 1.35rem; }
.stack-form { display: grid; gap: 1rem; }
.stack-form label, .filter-bar label, .range-grid label { display: grid; gap: .35rem; font-weight: 780; }
input, select, textarea { width: 100%; border: 1px solid var(--border); border-radius: .68rem; background: var(--surface); color: var(--text); padding: .72rem .78rem; }
select { min-height: 46px; }
textarea { min-height: 120px; resize: vertical; }
input[type="range"] { padding: .3rem 0; accent-color: var(--primary); }
.hint, .small-print { color: var(--muted); font-size: .88rem; font-weight: 550; }
.auth-links { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-top: 1rem; }
.form-section { border: 1px solid var(--border); border-radius: .9rem; padding: 1rem; background: var(--surface); }
.form-section h2 { margin-bottom: .45rem; }

.assessment-form { display: grid; gap: 1rem; }
.progress-wrap { position: sticky; top: 84px; z-index: 10; display: grid; grid-template-columns: auto minmax(120px, 1fr) auto; align-items: center; gap: .7rem; padding: .7rem 1rem; border: 1px solid var(--border); border-radius: .8rem; background: var(--surface); box-shadow: var(--shadow); }
progress { width: 100%; height: 18px; accent-color: var(--primary); }
.assessment-list { display: grid; gap: .75rem; }
.question-card { margin: 0; border: 1px solid var(--border); border-radius: .9rem; padding: 1rem; background: var(--surface); }
.question-card legend { font-weight: 780; padding: 0 .35rem; }
.question-card legend span { color: var(--primary); }
.question-card select { margin-top: .7rem; max-width: 380px; }
.range-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.range-grid output { color: var(--primary); font-size: 1.05rem; }

.score-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem; }
.score-top { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.score-top h2 { margin-bottom: 0; }
.score-top strong { color: var(--primary); font-size: 1.25rem; }
.score-card progress { margin: .8rem 0 .35rem; }

.split-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; align-items: start; }
.trait-list { list-style: none; padding: 0; margin: .8rem 0; display: grid; gap: .45rem; }
.trait-list li { display: flex; justify-content: space-between; gap: 1rem; padding: .4rem 0; border-bottom: 1px solid var(--border); }
.result-card { margin-top: 1rem; padding: 1.2rem; }
.result-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.result-section { padding: .3rem 0; }
.result-section h3 { color: var(--primary); }
.readonly-result pre { white-space: pre-wrap; word-break: break-word; max-height: 520px; overflow: auto; padding: .8rem; background: var(--surface-2); border-radius: .6rem; }

.filter-bar { display: grid; grid-template-columns: 1.4fr repeat(3, 1fr) auto auto; gap: .65rem; align-items: end; padding: .9rem; border: 1px solid var(--border); border-radius: .9rem; background: var(--surface); }
.results-summary { margin: 1rem 0; color: var(--muted); }
.case-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .9rem; }
.case-card { padding: 1rem; display: flex; flex-direction: column; align-items: flex-start; }
.case-card h2 { font-size: 1.08rem; }
.case-card p { color: var(--muted); flex: 1; }
.case-meta { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .7rem; }
.case-meta span { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: .22rem .55rem; font-size: .78rem; font-weight: 800; }
.case-detail { padding: 1.4rem; }
.case-detail > p, .case-detail li { max-width: 920px; }
.case-detail details { margin: 1rem 0; border: 1px solid var(--border); border-radius: .7rem; padding: .8rem; background: var(--surface-2); }
.case-detail summary { cursor: pointer; font-weight: 850; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 1rem; padding: 1.2rem 0; flex-wrap: wrap; }

.list-card { padding: .5rem; overflow: hidden; }
.responsive-table { border-collapse: collapse; width: 100%; }
.responsive-table th, .responsive-table td { text-align: left; padding: .8rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.responsive-table th { background: var(--surface-2); }

.guide-steps { display: grid; gap: .8rem; }
.guide-steps article { display: grid; grid-template-columns: 50px 1fr; gap: .9rem; padding: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: .9rem; }
.guide-steps article > span { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; background: var(--primary); color: var(--primary-text); font-weight: 900; }
.guide-steps h2 { margin-bottom: .35rem; }
.guide-steps p { margin: 0; color: var(--muted); }

.site-footer { margin-top: 2rem; padding: 1.2rem 0 6rem; border-top: 1px solid var(--border); color: var(--muted); font-size: .88rem; }
.site-footer p { max-width: 980px; }
.mobile-nav { display: none; }

@media (max-width: 1150px) {
  .card-grid.three, .case-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .app-shell { display: block; }
  .sidebar { display: none; }
  .main-content { padding-bottom: 7rem; }
  .mobile-nav { position: fixed; z-index: 60; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -8px 24px rgba(0,0,0,.12); padding-bottom: env(safe-area-inset-bottom); }
  .mobile-nav a { min-height: 58px; display: grid; place-items: center; align-content: center; gap: 0; color: var(--text); text-decoration: none; font-size: 1.05rem; }
  .mobile-nav span { display: block; font-size: .68rem; }
  .topbar { position: relative; }
  .progress-wrap { top: .5rem; }
  .hero-grid, .split-grid { grid-template-columns: 1fr; }
  .metric-card { grid-template-columns: repeat(3, 1fr); }
  .metric-card > div { min-height: 105px; }
}

@media (max-width: 680px) {
  .topbar { align-items: flex-start; }
  .brand { min-width: 0; }
  .top-actions { width: 100%; }
  .speech-controls { width: 100%; display: grid; grid-template-columns: repeat(4, 1fr); }
  .speech-controls button { padding: .55rem .25rem; font-size: .76rem; }
  .page-heading { gap: .7rem; }
  .page-icon { width: 48px; height: 48px; flex-basis: 48px; border-radius: 14px; }
  .card-grid.two, .card-grid.three, .case-grid, .score-grid, .range-grid, .metric-grid { grid-template-columns: 1fr; }
  .filter-bar { grid-template-columns: 1fr; }
  .metric-card { grid-template-columns: 1fr; }
  .progress-wrap { grid-template-columns: 1fr; gap: .35rem; }
  .responsive-table, .responsive-table thead, .responsive-table tbody, .responsive-table tr, .responsive-table th, .responsive-table td { display: block; }
  .responsive-table thead { position: absolute; left: -9999px; }
  .responsive-table tr { padding: .6rem; border-bottom: 1px solid var(--border); }
  .responsive-table td { border: 0; padding: .35rem; }
  .button-row > *, .button-row form, .button-row form button { width: 100%; }
}
