html[data-page="key-test"] {
  --brand: #6b65dc;
  --nav-brand-letter-spacing: 0;
  --nav-header-z-index: 20;
  --nav-menu-z-index: 30;
  --footer-link-mobile-padding: 4px 0;
}

html[data-page="key-test"] .hero {
  --page-hero-title-background: var(--hero-title-gradient);
  --page-hero-copy-max-width: min(760px, 100%);
  --page-hero-copy-white-space: normal;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 100;
  padding: 10px 14px;
  color: #ffffff;
  background: #332f87;
  border-radius: 10px;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-130%);
}

.skip-link:focus-visible {
  outline: 3px solid rgba(107, 101, 220, 0.35);
  outline-offset: 3px;
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.key-test-section {
  width: min(1200px, calc(100% - 32px));
  margin: var(--page-card-gap) auto;
}

.key-test-panel {
  padding: clamp(20px, 3vw, 30px);
  background: var(--surface);
  border: 0;
  border-radius: 24px;
  box-shadow: none;
}

body.key-test-fullscreen-open {
  overflow: hidden;
}

.key-test-panel.is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding: clamp(16px, 2vw, 28px);
  overflow: auto;
  border-radius: 0;
}

.key-test-panel.is-fullscreen .key-test-toolbar {
  flex: 0 0 auto;
  justify-content: flex-end;
}

.key-test-panel.is-fullscreen .key-test-heading {
  display: none;
}

.key-test-panel.is-fullscreen .keyboard-shell {
  display: flex;
  flex: 1 0 auto;
  flex-direction: column;
  margin-top: 12px;
}

.key-test-panel.is-fullscreen .key-stats,
.key-test-panel.is-fullscreen .keyboard-meta {
  flex: 0 0 auto;
}

.key-test-panel.is-fullscreen .keyboard-area {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  justify-content: center;
}

.key-test-panel.is-fullscreen .keyboard-hint {
  display: none;
}

@media (min-width: 1200px) {
  .key-test-panel.is-fullscreen .keyboard {
    --fullscreen-key-height: clamp(56px, 6.2vh, 68px);
    width: min(1600px, calc(100vw - 96px));
    min-width: min(1600px, calc(100vw - 96px));
  }

  .key-test-panel.is-fullscreen .keyboard-body {
    grid-template-columns: minmax(0, 1fr) 15.75% 20.55%;
    gap: 16px;
  }

  .key-test-panel.is-fullscreen .keyboard-function-row,
  .key-test-panel.is-fullscreen .keyboard-main-row {
    gap: 8px;
  }

  .key-test-panel.is-fullscreen .keyboard-function-row {
    margin-bottom: 14px;
  }

  .key-test-panel.is-fullscreen .keyboard-main {
    gap: 9px;
  }

  .key-test-panel.is-fullscreen .keyboard-key {
    height: var(--fullscreen-key-height);
    border-radius: 8px;
    font-size: clamp(0.74rem, 0.85vw, 0.88rem);
  }

  .key-test-panel.is-fullscreen .keyboard-key.is-small-label {
    font-size: clamp(0.64rem, 0.72vw, 0.76rem);
  }

  .key-test-panel.is-fullscreen .keyboard[data-layout="mac"] [data-code^="Control"],
  .key-test-panel.is-fullscreen .keyboard[data-layout="mac"] [data-code^="Meta"],
  .key-test-panel.is-fullscreen .keyboard[data-layout="mac"] [data-code^="Alt"] {
    font-size: clamp(0.56rem, 0.62vw, 0.66rem);
  }

  .key-test-panel.is-fullscreen .keyboard-navigation,
  .key-test-panel.is-fullscreen .keyboard-numpad {
    grid-template-rows: repeat(5, var(--fullscreen-key-height));
    gap: 9px 8px;
  }
}

.key-test-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.key-test-heading {
  min-width: 0;
}

.key-test-heading h2 {
  margin: 0;
  color: #172a3b;
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 2.4vw, 1.75rem);
  line-height: 1.15;
}

.key-test-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.key-test-actions {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 8px;
}

.layout-switch {
  display: inline-flex;
  padding: 3px;
  background: #f0f1f5;
  border-radius: 11px;
}

.layout-button,
.reset-button,
.sound-toggle-button,
.maximize-toggle-button {
  min-height: 44px;
  border: 0;
  cursor: pointer;
  font-weight: 800;
  transition: color 160ms ease, background-color 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.layout-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  color: #6c7382;
  background: transparent;
  border-radius: 8px;
  font-size: 0.82rem;
}

.layout-icon {
  flex: 0 0 auto;
  width: 15px;
  height: 15px;
  fill: currentColor;
}

.layout-button:hover {
  color: #3f3995;
}

.layout-button.is-active {
  color: #3f3995;
  background: #ffffff;
  box-shadow: 0 3px 10px rgba(44, 48, 62, 0.1);
}

.reset-button,
.sound-toggle-button,
.maximize-toggle-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 44px;
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  color: #aebac4;
  background: transparent;
  border: 0;
  border-radius: 10px;
}

.reset-button:hover,
.maximize-toggle-button:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.08);
}

.sound-toggle-button {
  color: #63c5a5;
}

.sound-toggle-button:hover {
  color: #8ce0c3;
  background: rgba(255, 255, 255, 0.08);
}

.sound-toggle-button.is-muted {
  color: #aebac4;
}

.layout-button:active,
.reset-button:active,
.sound-toggle-button:active,
.maximize-toggle-button:active {
  transform: translateY(1px);
}

.reset-button svg,
.sound-toggle-button svg,
.maximize-toggle-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sound-toggle-button svg {
  width: 18px;
  height: 18px;
}

.sound-icon-off,
.sound-toggle-button.is-muted .sound-icon-on {
  display: none;
}

.sound-toggle-button.is-muted .sound-icon-off {
  display: block;
}

.fullscreen-icon-collapse,
.maximize-toggle-button.is-active .fullscreen-icon-expand {
  display: none;
}

.maximize-toggle-button.is-active .fullscreen-icon-collapse {
  display: block;
}

.layout-button:focus-visible,
.reset-button:focus-visible,
.sound-toggle-button:focus-visible,
.maximize-toggle-button:focus-visible,
.keyboard-viewport:focus-visible {
  outline: 3px solid rgba(107, 101, 220, 0.34);
  outline-offset: 3px;
}

.keyboard-viewport.is-pointer-focused:focus-visible {
  outline: none;
}

.keyboard-shell {
  margin-top: 18px;
  overflow: hidden;
  color: #eef4f7;
  background: #18232d;
  border: 1px solid #111a22;
  border-radius: 18px;
}

.key-stats {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 60px;
  padding: 10px 14px;
  background: #111a22;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.key-stat-live {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  min-width: 0;
  column-gap: 9px;
}

.listening-dot {
  grid-row: 1 / 3;
  width: 9px;
  height: 9px;
  background: #55c39b;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(85, 195, 155, 0.14);
}

.key-stat-live strong {
  overflow: hidden;
  color: #ffffff;
  font-size: 0.9rem;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.key-stat-live > span:last-child {
  overflow: hidden;
  color: #98a8b5;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.69rem;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.key-stat-summary {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 14px;
  color: #aebac4;
  font-size: 0.74rem;
  font-weight: 700;
}

.key-stat-controls {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 10px;
}

.key-stat-summary span + span {
  padding-left: 14px;
  border-left: 1px solid rgba(255, 255, 255, 0.14);
}

.key-stat-summary strong {
  color: #ffffff;
  font-size: 0.88rem;
}

.keyboard-area {
  padding: 11px 12px 14px;
}

.keyboard-hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px 9px;
  color: #95a6b3;
  font-size: 0.69rem;
  font-weight: 700;
}

.scroll-hint {
  display: none;
}

.keyboard-viewport {
  overflow-x: auto;
  padding: 2px;
  border-radius: 11px;
  scrollbar-color: #526170 transparent;
  scrollbar-width: thin;
  overscroll-behavior-inline: contain;
}

.keyboard {
  width: 1080px;
  min-width: 1080px;
  margin: 0 auto;
  color: #eef3f6;
  user-select: none;
}

.keyboard-function-row,
.keyboard-main-row {
  display: flex;
  gap: 6px;
}

.keyboard-function-row {
  margin-bottom: 11px;
}

.keyboard-function-row .keyboard-key.is-group-gap {
  margin-left: 14px;
}

.keyboard-body {
  display: grid;
  grid-template-columns: 1fr 170px 222px;
  align-items: start;
  gap: 12px;
}

.keyboard-main {
  display: grid;
  gap: 7px;
}

.keyboard-key {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: var(--key-width, 1) 1 0;
  min-width: 0;
  height: 49px;
  padding: 4px;
  color: #e8eef2;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid #b9c5ce;
  border-radius: 7px;
  box-shadow: none;
  font-family: var(--font-sans);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.05;
  text-align: center;
  white-space: pre-line;
  transition: color 120ms ease, background-color 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.keyboard-key.is-small-label {
  font-size: 0.59rem;
}

.keyboard-key.is-stacked-label {
  line-height: 1.32;
}

.keyboard-key.is-wide-label {
  justify-content: flex-start;
  padding-left: 8px;
}

.keyboard[data-layout="mac"] [data-code^="Control"],
.keyboard[data-layout="mac"] [data-code^="Meta"],
.keyboard[data-layout="mac"] [data-code^="Alt"] {
  font-size: 0.49rem;
  letter-spacing: -0.02em;
}

.keyboard-key.is-tested {
  color: #ffffff;
  background: #267f67;
  border-color: #63c5a5;
}

.keyboard-key.is-tested::before {
  content: "✓";
  position: absolute;
  top: 3px;
  left: 5px;
  color: #c8f6e6;
  font-size: 0.5rem;
  font-weight: 900;
  line-height: 1;
}

.keyboard-key.is-pressed {
  color: #372a0c;
  background: #f3c65e;
  border-color: #ffe09a;
  transform: translateY(1px);
}

.keyboard-key.is-pressed::before {
  content: none;
}

.keyboard-key.is-locked::after {
  content: "";
  position: absolute;
  top: 5px;
  right: 5px;
  width: 5px;
  height: 5px;
  background: #79dfbc;
  border-radius: 50%;
}

.keyboard-navigation {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(5, 49px);
  gap: 7px 6px;
}

.keyboard-numpad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(5, 49px);
  gap: 7px 6px;
}

.keyboard-navigation .keyboard-key,
.keyboard-numpad .keyboard-key {
  width: auto;
  height: auto;
}

.keyboard-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 54px;
  padding: 9px 14px;
  background: #111a22;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.key-legend,
.mouse-test,
.mouse-buttons {
  display: flex;
  align-items: center;
}

.key-legend {
  flex-wrap: wrap;
  gap: 8px 16px;
  color: #aebbc5;
  font-size: 0.7rem;
  font-weight: 700;
}

.key-legend > span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  color: #e8eef2;
  background: transparent;
  border: 1px solid #9baab5;
  border-radius: 5px;
  font-size: 0.62rem;
  font-style: normal;
  font-weight: 900;
}

.legend-key.is-pressed {
  color: #372a0c;
  background: #f3c65e;
  border-color: #ffe09a;
}

.legend-key.is-tested {
  color: #ffffff;
  background: #267f67;
  border-color: #63c5a5;
}

.mouse-test {
  flex: 0 0 auto;
  gap: 9px;
  color: #aebbc5;
  font-size: 0.7rem;
  font-weight: 800;
}

.mouse-buttons {
  gap: 5px;
}

.mouse-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 50px;
  min-height: 32px;
  padding: 5px 8px;
  color: #e8eef2;
  background: transparent;
  border: 1px solid #9baab5;
  border-radius: 7px;
  font-size: 0.65rem;
  font-weight: 800;
  transition: color 120ms ease, background-color 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.mouse-button.is-tested {
  color: #ffffff;
  background: #267f67;
  border-color: #63c5a5;
}

.mouse-button.is-pressed {
  color: #372a0c;
  background: #f3c65e;
  border-color: #ffe09a;
  transform: translateY(1px);
}

@media (max-width: 900px) {
  .scroll-hint {
    display: inline;
  }

  .keyboard {
    margin-left: 0;
  }
}

@media (max-width: 620px) {
  .key-test-toolbar {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }

  .key-test-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .layout-switch {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }

  .key-stats {
    gap: 10px;
    min-height: 56px;
    padding: 9px 10px;
  }

  .key-stat-live {
    max-width: min(55vw, 190px);
  }

  .key-stat-summary {
    align-items: flex-end;
    flex-direction: column;
    gap: 2px;
    font-size: 0.67rem;
  }

  .key-stat-controls {
    gap: 6px;
  }

  .key-stat-summary span + span {
    padding-left: 0;
    border-left: 0;
  }

  .keyboard-area {
    padding: 9px 8px 11px;
  }

  .keyboard-hint {
    align-items: flex-start;
    flex-direction: column;
    gap: 1px;
  }

  .keyboard-meta {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
  }

  .mouse-test {
    justify-content: space-between;
    width: 100%;
  }
}

@media (max-width: 420px) {
  .key-legend {
    gap: 7px 11px;
  }

  .mouse-buttons {
    flex: 1 1 auto;
  }

  .mouse-button {
    flex: 1 1 0;
    min-width: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .keyboard-key,
  .mouse-button,
  .layout-button,
  .reset-button,
  .sound-toggle-button,
  .maximize-toggle-button {
    transition: none;
  }
}
