.kcps-app {
  --kcps-ink: var(--text-primary, #0f172a);
  --kcps-muted: var(--text-secondary, #526079);
  --kcps-surface: var(--surface, #ffffff);
  --kcps-surface-soft: var(--surface-secondary, #f8fafc);
  --kcps-border: var(--border-color, #d8e0eb);
  --kcps-accent: var(--accent-primary, #2563eb);
  --kcps-accent-strong: #1d4ed8;
  --kcps-accent-soft: #eff6ff;
  --kcps-good: #15803d;
  --kcps-good-soft: #f0fdf4;
  --kcps-warn: #b45309;
  --kcps-warn-soft: #fffbeb;
  --kcps-danger: #b91c1c;
  --kcps-danger-soft: #fef2f2;
  color: var(--kcps-ink);
  display: grid;
  gap: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  margin-inline: auto;
  max-width: 1180px;
  padding: 14px;
}

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

.kcps-app h3,
.kcps-app h4,
.kcps-app p,
.kcps-app pre,
.kcps-app ol {
  margin-block-start: 0;
}

.kcps-app button {
  align-items: center;
  background: var(--kcps-surface);
  border: 1px solid var(--kcps-border);
  border-radius: 10px;
  color: var(--kcps-ink);
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-weight: 750;
  justify-content: center;
  line-height: 1.2;
  min-height: 44px;
  padding: 10px 15px;
  transition: background-color .16s ease, border-color .16s ease, color .16s ease, transform .16s ease, box-shadow .16s ease;
}

.kcps-app button:hover:not(:disabled) {
  border-color: var(--kcps-accent);
  color: var(--kcps-accent-strong);
  transform: translateY(-1px);
}

.kcps-app button:focus-visible,
.kcps-capture:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--kcps-accent) 42%, transparent);
  outline-offset: 3px;
}

.kcps-app button:disabled {
  cursor: not-allowed;
  opacity: .52;
}

.kcps-intro,
.kcps-status-row,
.kcps-panel-head {
  align-items: center;
  display: flex;
  gap: 14px;
  justify-content: space-between;
}

.kcps-intro {
  background: linear-gradient(135deg, var(--kcps-accent-soft), var(--kcps-surface));
  border: 1px solid color-mix(in srgb, var(--kcps-accent) 25%, var(--kcps-border));
  border-radius: 16px;
  padding: 18px 20px;
}

.kcps-intro h3 {
  font-size: clamp(1.18rem, 2vw, 1.52rem);
  line-height: 1.25;
  margin-bottom: 0;
}

.kcps-eyebrow {
  color: var(--kcps-accent-strong);
  font-size: .74rem;
  font-weight: 850;
  letter-spacing: .1em;
  margin-bottom: 5px;
  text-transform: uppercase;
}

.kcps-privacy {
  align-items: center;
  background: var(--kcps-surface);
  border: 1px solid var(--kcps-border);
  border-radius: 999px;
  color: var(--kcps-muted);
  display: inline-flex;
  flex: 0 1 410px;
  font-size: .82rem;
  gap: 8px;
  line-height: 1.4;
  padding: 9px 13px;
}

.kcps-setup,
.kcps-cockpit,
.kcps-panel,
.kcps-history,
.kcps-limit {
  background: var(--kcps-surface);
  border: 1px solid var(--kcps-border);
  border-radius: 16px;
  box-shadow: 0 9px 28px rgba(15, 23, 42, .05);
}

.kcps-setup,
.kcps-cockpit,
.kcps-panel,
.kcps-history {
  padding: 18px;
}

.kcps-setup {
  display: grid;
  gap: 16px;
}

.kcps-fieldset {
  border: 0;
  margin: 0;
  min-width: 0;
  padding: 0;
}

.kcps-fieldset legend {
  color: var(--kcps-ink);
  font-size: .86rem;
  font-weight: 850;
  margin-bottom: 9px;
  padding: 0;
}

.kcps-presets,
.kcps-durations,
.kcps-primary-actions,
.kcps-custom-actions,
.kcps-result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.kcps-choice {
  min-width: 82px;
}

.kcps-choice.is-selected,
.kcps-choice[aria-pressed="true"] {
  background: var(--kcps-accent);
  border-color: var(--kcps-accent);
  box-shadow: 0 7px 18px color-mix(in srgb, var(--kcps-accent) 22%, transparent);
  color: #ffffff;
}

.kcps-choice.is-selected:hover:not(:disabled),
.kcps-choice[aria-pressed="true"]:hover:not(:disabled) {
  background: var(--kcps-accent-strong);
  color: #ffffff;
}

.kcps-custom {
  align-items: center;
  background: var(--kcps-accent-soft);
  border: 1px dashed color-mix(in srgb, var(--kcps-accent) 55%, var(--kcps-border));
  border-radius: 13px;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(190px, 1.3fr) minmax(180px, 1fr) auto;
  padding: 14px;
}

.kcps-custom[hidden] {
  display: none;
}

.kcps-custom strong {
  display: block;
  margin-bottom: 4px;
}

.kcps-custom p {
  color: var(--kcps-muted);
  font-size: .84rem;
  line-height: 1.5;
  margin-bottom: 0;
}

.kcps-custom-keys {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 32px;
}

.kcps-key-chip {
  background: var(--kcps-surface);
  border: 1px solid var(--kcps-border);
  border-bottom-width: 3px;
  border-radius: 7px;
  color: var(--kcps-ink);
  direction: ltr;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .79rem;
  font-weight: 800;
  line-height: 1;
  padding: 7px 9px;
}

.kcps-primary-actions {
  border-top: 1px solid var(--kcps-border);
  padding-top: 16px;
}

.kcps-app .kcps-primary {
  background: var(--kcps-accent);
  border-color: var(--kcps-accent);
  color: #ffffff;
  min-width: 145px;
}

.kcps-app .kcps-primary:hover:not(:disabled) {
  background: var(--kcps-accent-strong);
  color: #ffffff;
}

.kcps-cockpit {
  display: grid;
  gap: 14px;
}

.kcps-status-row {
  border-bottom: 1px solid var(--kcps-border);
  padding-bottom: 12px;
}

.kcps-status-row > div {
  display: grid;
  gap: 2px;
}

.kcps-status-row span {
  color: var(--kcps-muted);
  font-size: .76rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}

#kcpsStatus::before {
  content: "●";
  font-size: .72em;
  margin-inline-end: 7px;
}

#kcpsStatus[data-state="ready"]::before {
  color: var(--kcps-accent);
}

#kcpsStatus[data-state="running"]::before {
  color: var(--kcps-good);
}

#kcpsStatus[data-state="complete"]::before {
  color: var(--kcps-good);
}

#kcpsStatus[data-state="interrupted"]::before {
  color: var(--kcps-danger);
}

#kcpsCountdown {
  color: var(--kcps-accent-strong);
  direction: ltr;
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  line-height: 1;
}

.kcps-capture {
  align-items: center;
  background:
    radial-gradient(circle at 50% 0, color-mix(in srgb, var(--kcps-accent) 14%, transparent), transparent 55%),
    var(--kcps-surface-soft);
  border: 2px dashed color-mix(in srgb, var(--kcps-accent) 45%, var(--kcps-border));
  border-radius: 15px;
  cursor: text;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 236px;
  padding: 24px 16px;
  text-align: center;
  transition: border-color .16s ease, box-shadow .16s ease, background-color .16s ease;
}

.kcps-capture:focus {
  border-style: solid;
  border-color: var(--kcps-accent);
  box-shadow: inset 0 0 0 1px var(--kcps-accent), 0 12px 32px color-mix(in srgb, var(--kcps-accent) 13%, transparent);
}

.kcps-capture[data-state="running"] {
  background:
    radial-gradient(circle at 50% 10%, color-mix(in srgb, var(--kcps-good) 17%, transparent), transparent 58%),
    var(--kcps-good-soft);
  border-color: var(--kcps-good);
}

.kcps-capture[data-state="complete"] {
  background: var(--kcps-good-soft);
  border-color: var(--kcps-good);
}

.kcps-capture[data-state="interrupted"] {
  background: var(--kcps-danger-soft);
  border-color: var(--kcps-danger);
}

.kcps-capture-icon {
  color: var(--kcps-accent);
  font-size: 2rem;
  line-height: 1;
  margin-bottom: 8px;
}

.kcps-capture h4 {
  font-size: 1.12rem;
  margin-bottom: 5px;
}

.kcps-capture > strong {
  color: var(--kcps-accent-strong);
  font-size: 1.03rem;
}

.kcps-capture p {
  color: var(--kcps-muted);
  font-size: .88rem;
  line-height: 1.55;
  margin: 7px auto 0;
  max-width: 720px;
}

.kcps-live-key {
  align-items: center;
  background: var(--kcps-surface);
  border: 1px solid var(--kcps-border);
  border-bottom-width: 4px;
  border-radius: 10px;
  direction: ltr;
  display: inline-flex;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1rem;
  font-weight: 900;
  justify-content: center;
  margin-top: 15px;
  min-height: 44px;
  min-width: 88px;
  padding: 8px 14px;
}

.kcps-live-key.is-hit {
  animation: kcps-key-hit .14s ease-out;
  background: var(--kcps-accent);
  border-color: var(--kcps-accent-strong);
  color: #ffffff;
}

@keyframes kcps-key-hit {
  50% { transform: translateY(2px) scale(.97); }
}

.kcps-metrics {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.kcps-metrics article {
  background: var(--kcps-surface-soft);
  border: 1px solid var(--kcps-border);
  border-radius: 12px;
  display: grid;
  gap: 5px;
  min-height: 89px;
  padding: 13px;
}

.kcps-metrics span {
  color: var(--kcps-muted);
  font-size: .74rem;
  font-weight: 750;
  line-height: 1.3;
}

.kcps-metrics strong {
  align-self: end;
  direction: ltr;
  font-size: 1.34rem;
  font-variant-numeric: tabular-nums;
  font-weight: 900;
}

.kcps-metric-best {
  background: var(--kcps-accent-soft) !important;
  border-color: color-mix(in srgb, var(--kcps-accent) 35%, var(--kcps-border)) !important;
  grid-column: span 2;
}

.kcps-results {
  display: grid;
  gap: 14px;
}

.kcps-result-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr 1fr;
}

.kcps-panel-head {
  border-bottom: 1px solid var(--kcps-border);
  margin-bottom: 13px;
  padding-bottom: 10px;
}

.kcps-panel-head h4 {
  font-size: 1rem;
  margin-bottom: 0;
}

.kcps-table-wrap {
  max-height: 310px;
  overflow: auto;
}

.kcps-app table {
  border-collapse: collapse;
  font-size: .86rem;
  width: 100%;
}

.kcps-app th,
.kcps-app td {
  border-bottom: 1px solid var(--kcps-border);
  padding: 10px 8px;
  text-align: start;
}

.kcps-app th {
  color: var(--kcps-muted);
  font-size: .72rem;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.kcps-app td:nth-child(n+2),
.kcps-app th:nth-child(n+2) {
  direction: ltr;
  font-variant-numeric: tabular-nums;
  text-align: end;
}

.kcps-timeline {
  align-items: end;
  border-bottom: 1px solid var(--kcps-border);
  display: flex;
  gap: 5px;
  min-height: 224px;
  overflow-x: auto;
  padding: 24px 5px 0;
}

.kcps-timeline__item {
  align-items: center;
  display: flex;
  flex: 1 0 26px;
  flex-direction: column;
  height: 190px;
  justify-content: end;
  min-width: 26px;
}

.kcps-timeline__bar {
  background: linear-gradient(180deg, var(--kcps-accent), var(--kcps-accent-strong));
  border-radius: 6px 6px 2px 2px;
  min-height: 3px;
  position: relative;
  width: min(34px, 84%);
}

.kcps-timeline__bar b {
  color: var(--kcps-ink);
  direction: ltr;
  font-size: .7rem;
  left: 50%;
  position: absolute;
  top: -20px;
  transform: translateX(-50%);
}

.kcps-timeline__item small {
  color: var(--kcps-muted);
  direction: ltr;
  font-size: .65rem;
  margin-top: 5px;
}

.kcps-report pre {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 12px;
  color: #e2e8f0;
  direction: ltr;
  font: 500 .82rem/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  max-height: 360px;
  overflow: auto;
  padding: 15px;
  text-align: start;
  white-space: pre-wrap;
  word-break: break-word;
}

.kcps-tier {
  background: var(--kcps-surface-soft);
  border: 1px solid var(--kcps-border);
  border-radius: 999px;
  direction: ltr;
  font-size: .75rem;
  font-weight: 850;
  padding: 6px 10px;
}

.kcps-tier[data-tier="warmup"] { background: var(--kcps-warn-soft); color: var(--kcps-warn); }
.kcps-tier[data-tier="steady"] { background: var(--kcps-accent-soft); color: var(--kcps-accent-strong); }
.kcps-tier[data-tier="fast"],
.kcps-tier[data-tier="rapid"] { background: var(--kcps-good-soft); color: var(--kcps-good); }

.kcps-result-actions {
  margin-top: 12px;
}

.kcps-history ol {
  display: grid;
  gap: 8px;
  list-style: none;
  margin-bottom: 0;
  padding: 0;
}

.kcps-history li {
  align-items: center;
  background: var(--kcps-surface-soft);
  border: 1px solid var(--kcps-border);
  border-radius: 10px;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 10px 12px;
}

.kcps-history li span {
  color: var(--kcps-muted);
  font-size: .79rem;
}

.kcps-history li strong {
  direction: ltr;
  font-variant-numeric: tabular-nums;
}

.kcps-limit {
  background: var(--kcps-warn-soft);
  border-color: #f5d59a;
  border-inline-start: 5px solid var(--kcps-warn);
  padding: 14px 16px;
}

.kcps-limit strong {
  color: #7c2d12;
}

.kcps-limit p {
  color: #713f12;
  font-size: .86rem;
  line-height: 1.65;
  margin: 5px 0 0;
}

.kcps-sr-only {
  border: 0 !important;
  clip: rect(0 0 0 0) !important;
  clip-path: inset(50%) !important;
  height: 1px !important;
  margin: -1px !important;
  overflow: hidden !important;
  padding: 0 !important;
  position: absolute !important;
  white-space: nowrap !important;
  width: 1px !important;
}

[dir="rtl"] .kcps-app,
.kcps-app[dir="rtl"] {
  text-align: right;
}

html.dark-theme .kcps-app,
[data-theme="dark"] .kcps-app {
  --kcps-ink: #f1f5f9;
  --kcps-muted: #b8c4d5;
  --kcps-surface: #172033;
  --kcps-surface-soft: #101827;
  --kcps-border: #3a4960;
  --kcps-accent: #60a5fa;
  --kcps-accent-strong: #93c5fd;
  --kcps-accent-soft: #172b49;
  --kcps-good: #86efac;
  --kcps-good-soft: #123222;
  --kcps-warn: #fbbf24;
  --kcps-warn-soft: #3a2a10;
  --kcps-danger: #fca5a5;
  --kcps-danger-soft: #431b1b;
}

html.dark-theme .kcps-limit,
[data-theme="dark"] .kcps-limit {
  border-color: #765621;
}

html.dark-theme .kcps-limit strong,
[data-theme="dark"] .kcps-limit strong {
  color: #fde68a;
}

html.dark-theme .kcps-limit p,
[data-theme="dark"] .kcps-limit p {
  color: #fef3c7;
}

@media (max-width: 900px) {
  .kcps-custom {
    grid-template-columns: 1fr;
  }

  .kcps-custom-actions {
    justify-content: flex-start;
  }

  .kcps-metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .kcps-metric-best {
    grid-column: span 3;
  }

  .kcps-result-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .kcps-app {
    gap: 13px;
    padding: 7px;
  }

  .kcps-intro,
  .kcps-status-row,
  .kcps-panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .kcps-intro,
  .kcps-setup,
  .kcps-cockpit,
  .kcps-panel,
  .kcps-history {
    padding: 14px;
  }

  .kcps-privacy {
    border-radius: 11px;
    flex-basis: auto;
    width: 100%;
  }

  .kcps-presets,
  .kcps-durations {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .kcps-choice {
    min-width: 0;
    width: 100%;
  }

  .kcps-primary-actions,
  .kcps-result-actions,
  .kcps-custom-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .kcps-primary-actions .kcps-primary,
  .kcps-result-actions button:first-child {
    grid-column: 1 / -1;
  }

  .kcps-capture {
    min-height: 218px;
    padding: 20px 12px;
  }

  .kcps-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .kcps-metric-best {
    grid-column: span 2;
  }

  .kcps-history li {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 380px) {
  .kcps-presets,
  .kcps-durations,
  .kcps-primary-actions,
  .kcps-result-actions,
  .kcps-custom-actions,
  .kcps-metrics {
    grid-template-columns: 1fr;
  }

  .kcps-primary-actions .kcps-primary,
  .kcps-result-actions button:first-child,
  .kcps-metric-best {
    grid-column: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .kcps-app *,
  .kcps-app *::before,
  .kcps-app *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}

@media (forced-colors: active) {
  .kcps-choice.is-selected,
  .kcps-choice[aria-pressed="true"],
  .kcps-app .kcps-primary,
  .kcps-live-key.is-hit {
    border: 2px solid ButtonText;
  }

  .kcps-capture:focus {
    outline: 3px solid Highlight;
  }
}
