/**
 * Keyboard Diagnostics Pro - presentation layer
 * ------------------------------------------------
 * Responsive, accessible styling for the local keyboard diagnostics interface.
 * No third-party fonts, frameworks or remote assets are used.
 */
:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #edf2f8;
  --text: #142035;
  --muted: #5d6b80;
  --line: #d9e1ec;
  --brand: #335cff;
  --brand-strong: #2445cc;
  --good: #0b8f61;
  --warning: #d98000;
  --danger: #c43d4d;
  --pressed: #7c4dff;
  --shadow: 0 12px 32px rgba(31, 45, 68, 0.09);
  --radius: 18px;
  --key-unit: 44px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1422;
  --surface: #151f30;
  --surface-2: #202c40;
  --text: #f2f6fc;
  --muted: #aebbd0;
  --line: #314057;
  --brand: #7893ff;
  --brand-strong: #9aabff;
  --good: #45d19a;
  --warning: #ffb84d;
  --danger: #ff8090;
  --pressed: #ad8cff;
  --shadow: 0 16px 38px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); font: 15px/1.55 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, select, input { font: inherit; }
button, select { color: inherit; }
button:focus-visible, select:focus-visible, input:focus-visible, [tabindex]:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 3px; }
.skip-link { position: fixed; z-index: 100; top: 8px; left: 8px; transform: translateY(-160%); background: var(--surface); color: var(--text); padding: 10px 14px; border-radius: 10px; }
.skip-link:focus { transform: none; }
.site-header, .app-shell, footer { width: min(1500px, calc(100% - 32px)); margin-inline: auto; }
@media (min-width: 1920px) {
  .site-header, .app-shell, footer { width: min(clamp(1500px, calc(1500px + (100vw - 1920px) * 0.78125), 2000px), calc(100% - 32px)); }
}
.site-header { display: flex; align-items: centre; align-items: center; justify-content: space-between; gap: 20px; padding: 34px 0 20px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(2rem, 4vw, 3.5rem); line-height: 1.05; letter-spacing: -0.045em; }
h2 { margin-bottom: 14px; font-size: 1.15rem; letter-spacing: -0.015em; }
.subtitle, .hint, .result-text, footer, .export-panel p { color: var(--muted); }
.eyebrow { margin-bottom: 5px; color: var(--brand); font-size: .73rem; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
.header-actions, .export-actions, .combo-tools { display: flex; flex-wrap: wrap; gap: 8px; }
.button { border: 1px solid var(--line); border-radius: 11px; padding: 9px 13px; background: var(--surface); cursor: pointer; font-weight: 700; transition: transform .12s, border-color .12s, background .12s; }
.button:hover:not(:disabled) { transform: translateY(-1px); border-color: var(--brand); }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button-primary { background: var(--brand); border-color: var(--brand); color: white; }
.button-secondary { background: var(--surface-2); }
.button-danger { color: var(--danger); }
.button-small { padding: 6px 10px; font-size: .82rem; }
.app-shell { display: grid; gap: 16px; }
.panel, .notice, .metric-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.notice { display: flex; justify-content: space-between; gap: 18px; align-items: center; padding: 17px 20px; border-left: 5px solid var(--warning); }
.notice h2, .notice p { margin-bottom: 0; }
.badge { display: inline-flex; align-items: center; white-space: nowrap; min-height: 27px; padding: 4px 9px; border-radius: 999px; background: var(--surface-2); font-size: .77rem; font-weight: 800; }
.badge-good { color: var(--good); }
.metrics-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.metric-card { padding: 16px; }
.metric-card span, .metric-card small { display: block; color: var(--muted); }
.metric-card strong { display: block; margin: 4px 0 1px; font-size: 1.65rem; line-height: 1.15; }
.metric-card small { font-size: .72rem; }
.control-panel { display: grid; grid-template-columns: 1.2fr repeat(3, 1fr) auto auto; gap: 18px; align-items: end; padding: 18px; }
.control-panel h2 { margin: 0; }
.control-panel label { display: grid; gap: 6px; color: var(--muted); font-size: .82rem; font-weight: 700; }
.control-panel select { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px; background: var(--surface-2); }
.switch-label { grid-template-columns: auto 1fr !important; align-items: center; }
.range-row { display: flex; gap: 8px; align-items: center; }
.range-row input { min-width: 90px; width: 100%; accent-color: var(--brand); }
.range-row output { min-width: 45px; color: var(--text); }
.keyboard-panel { padding: 20px; overflow: hidden; }
.section-heading { display: flex; align-items: start; justify-content: space-between; gap: 15px; }
.legend { display: flex; gap: 13px; flex-wrap: wrap; color: var(--muted); font-size: .75rem; }
.legend span { display: inline-flex; gap: 5px; align-items: center; }
.legend-swatch { width: 12px; height: 12px; border-radius: 4px; border: 1px solid var(--line); }
.legend-swatch.tested { background: color-mix(in srgb, var(--good) 28%, var(--surface)); }
.legend-swatch.pressed { background: var(--pressed); }
.legend-swatch.warning { background: var(--warning); }
.progress-track { height: 8px; overflow: hidden; margin-bottom: 19px; border-radius: 99px; background: var(--surface-2); }
.progress-track span { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--brand), var(--good)); transition: width .2s; }
.keyboard { display: grid; gap: 7px; min-width: 1120px; overflow-x: auto; padding-bottom: 10px; }
.key-row { display: flex; gap: 6px; }
.key { position: relative; display: grid; place-items: center; flex: 0 0 calc(var(--key-unit) * var(--width, 1)); min-height: 44px; padding: 4px; border: 1px solid var(--line); border-bottom-width: 3px; border-radius: 8px; background: var(--surface-2); color: var(--text); font-size: .71rem; font-weight: 750; text-align: center; user-select: none; transition: transform .06s, background .1s, color .1s, box-shadow .1s; }
.key.tested { background: color-mix(in srgb, var(--good) calc(14% + var(--heat, 0) * 48%), var(--surface)); border-color: color-mix(in srgb, var(--good) 45%, var(--line)); }
.key.pressed { transform: translateY(2px); background: var(--pressed); border-color: var(--pressed); color: white; box-shadow: 0 0 0 4px color-mix(in srgb, var(--pressed) 20%, transparent); }
.key.flagged:not(.pressed) { background: color-mix(in srgb, var(--warning) 30%, var(--surface)); border-color: var(--warning); }
.key .count { position: absolute; right: 4px; bottom: 2px; font-size: .58rem; opacity: .65; }
.key-spacer { flex: 0 0 calc(var(--key-unit) * var(--width, 1)); }
.dashboard-grid { display: grid; grid-template-columns: 1.1fr .8fr 1.1fr; gap: 16px; }
.dashboard-grid > .panel { min-width: 0; padding: 18px; }
.matrix { display: flex; flex-wrap: wrap; gap: 8px; min-height: 88px; align-content: flex-start; margin-bottom: 14px; padding: 13px; border: 1px dashed var(--line); border-radius: 13px; background: var(--surface-2); }
.matrix-key { padding: 7px 10px; border-radius: 9px; background: var(--pressed); color: white; font-weight: 800; }
.empty-state { color: var(--muted); font-style: italic; }
.result-text { min-height: 44px; margin: 12px 0 0; font-size: .83rem; }
.analytics-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; margin: 0; }
.analytics-list div { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.analytics-list dt { color: var(--muted); }
.analytics-list dd { margin: 0; font-weight: 800; text-align: right; }
.inspector-panel pre { min-height: 230px; max-height: 330px; overflow: auto; margin: 0; padding: 13px; border-radius: 12px; background: #08101d; color: #b8f7d0; font: 12px/1.55 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: pre-wrap; }
.lower-grid { grid-template-columns: 1.25fr .9fr .85fr; }
.history-list { max-height: 270px; overflow: auto; margin: 0; padding: 0; list-style: none; }
.history-list li { display: grid; grid-template-columns: 75px 1fr auto; gap: 9px; padding: 7px 3px; border-bottom: 1px solid var(--line); font: 12px/1.4 ui-monospace, monospace; }
.history-list time, .history-list .event-kind { color: var(--muted); }
.export-actions { margin-top: 20px; }
.methodology { padding: 20px; }
.methodology ol { margin-bottom: 0; padding-left: 22px; }
.methodology li + li { margin-top: 7px; }
footer { padding: 25px 0 40px; text-align: center; }
.toast { position: fixed; z-index: 50; right: 20px; bottom: 20px; transform: translateY(160%); max-width: 360px; padding: 12px 16px; border-radius: 12px; background: var(--text); color: var(--surface); box-shadow: var(--shadow); transition: transform .2s; }
.toast.visible { transform: none; }

@media (max-width: 1100px) {
  .metrics-grid { grid-template-columns: repeat(3, 1fr); }
  .control-panel { grid-template-columns: repeat(3, 1fr); }
  .dashboard-grid, .lower-grid { grid-template-columns: 1fr 1fr; }
  .inspector-panel, .history-panel { grid-column: 1 / -1; }
}
@media (max-width: 700px) {
  .site-header { align-items: flex-start; flex-direction: column; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .control-panel, .dashboard-grid, .lower-grid { grid-template-columns: 1fr; }
  .inspector-panel, .history-panel { grid-column: auto; }
  .section-heading { flex-direction: column; }
  .notice { align-items: flex-start; flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behaviour: auto !important; scroll-behavior: auto !important; transition: none !important; }
}
@media print {
  .header-actions, .control-panel, .combo-tools, .button, .toast, .hint { display: none !important; }
  body { background: white; color: black; }
  .site-header, .app-shell, footer { width: 100%; }
  .panel, .notice, .metric-card { break-inside: avoid; box-shadow: none; }
  .keyboard { transform: scale(.72); transform-origin: top left; width: 139%; margin-bottom: -100px; }
}
.brand-link { color: inherit; text-decoration: none; }
.brand-link:hover, .brand-link:focus-visible { text-decoration: underline; }
#matrixTitle { color: var(--brand); font-size: 1.38rem; }
