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

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  color: #1a1a1a;
  background: #f8f9fa;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.top-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 0.75rem 1.25rem;
  padding-bottom: 6.25rem;
  background: transparent;
  border: none;
}

.page-with-logo {
  position: relative;
  margin-top: -2.5rem;
}

.site-logo {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translate(-50%, -50%);
  width: 200px;
  height: 200px;
  object-fit: contain;
  z-index: 1;
  pointer-events: none;
}

.site-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid #dee2e6;
  background: #e9ecef;
  margin-top: 2rem;
}

.footer-content {
  margin: 0;
  font-size: 0.875rem;
  color: #6c757d;
  text-align: center;
}

.footer-content a {
  color: #3d8084;
  text-decoration: none;
}

.footer-content a:hover {
  text-decoration: underline;
}

.footer-sep {
  margin: 0 0.5rem;
}

.footer-disclosure {
  margin: 0.5rem 0 0;
  font-size: 0.875rem;
  font-style: italic;
  color: #6c757d;
  text-align: center;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  background: #212529;
  color: #fff;
  border: 1px solid #212529;
  border-radius: 6px;
  cursor: pointer;
}

.theme-toggle .theme-icon {
  display: inline-flex;
  line-height: 0;
}

.theme-toggle .theme-icon[hidden] {
  display: none;
}

.theme-toggle:hover {
  background: #1a1a1a;
  color: #fff;
  border-color: #1a1a1a;
}

main {
  max-width: 42rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2rem;
}

.page-with-logo main {
  padding-top: 6.25rem;
}

header {
  margin-bottom: 1.5rem;
  text-align: center;
}

h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
  color: #212529;
}

.tagline {
  margin: 0;
  color: #495057;
  font-size: 1rem;
}

.intro {
  margin: 0.75rem 0 0;
  color: #495057;
  font-size: 0.9375rem;
  max-width: 36rem;
  margin-left: auto;
  margin-right: auto;
}

.wpm-control label,
.calibration-section h2 {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: #212529;
}

#speech-text {
  width: 100%;
  padding: 0.75rem 1rem;
  font: inherit;
  font-size: 1rem;
  line-height: 1.5;
  border: 1px solid #ced4da;
  border-radius: 6px;
  resize: vertical;
  min-height: 10rem;
}

#speech-text:focus {
  outline: 2px solid #3d8084;
  outline-offset: 2px;
  border-color: #3d8084;
}

.stats-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-top: 1rem;
}

.stats-row .stats {
  margin-top: 0;
  padding-top: 0;
}

.clear-btn {
  margin: 0;
  padding: 0.5rem 1rem;
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  background: transparent;
  color: #495057;
  border: 1px solid #ced4da;
  border-radius: 6px;
  cursor: pointer;
}

.clear-btn:hover {
  background: #e9ecef;
  border-color: #adb5bd;
  color: #212529;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
  font-size: 0.9375rem;
  color: #495057;
}

.stat strong {
  color: #212529;
}

.duration-verbal {
  color: #6c757d;
  font-weight: normal;
}

.wpm-control {
  margin-top: 1.5rem;
}

.wpm-control label {
  display: inline;
  margin-right: 0.5rem;
}

#wpm-input {
  width: 4.5rem;
  padding: 0.375rem 0.5rem;
  font: inherit;
  font-size: 1rem;
  border: 1px solid #ced4da;
  border-radius: 4px;
}

#wpm-input:focus {
  outline: 2px solid #3d8084;
  outline-offset: 2px;
  border-color: #3d8084;
}

#wpm-unit {
  margin-left: 0.25rem;
  color: #6c757d;
  font-size: 0.9375rem;
}

.hint {
  margin: 0.5rem 0 0;
  font-size: 0.875rem;
  color: #6c757d;
}

.using-speed {
  margin: 0.5rem 0 0;
  font-size: 0.9375rem;
  color: #3d8084;
  min-height: 1.5em;
}

.calibration-section {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid #dee2e6;
}

.calibration-section h2 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
}

.calibration-intro {
  margin: 0 0 1rem;
  font-size: 0.9375rem;
  color: #495057;
}

.sample-paragraph {
  padding: 1rem 1.25rem;
  background: #fff;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  font-size: 1rem;
  line-height: 1.6;
  color: #212529;
  margin-bottom: 1rem;
}

.timer-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
}

.timer-display {
  font-variant-numeric: tabular-nums;
  font-size: 1.5rem;
  font-weight: 600;
  min-width: 4ch;
}

.timer-buttons {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

button:not(.clear-btn) {
  padding: 0.5rem 1rem;
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  border: 1px solid #212529;
  border-radius: 6px;
  background: #212529;
  color: #fff;
  cursor: pointer;
}

button:not(.clear-btn):hover:not(:disabled) {
  background: #1a1a1a;
  border-color: #1a1a1a;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

button:focus {
  outline: 2px solid #3d8084;
  outline-offset: 2px;
}

.use-speed-btn {
  background: #212529;
  border-color: #212529;
}

.use-speed-btn:hover {
  background: #1a1a1a;
  border-color: #1a1a1a;
}

.calibration-message {
  width: 100%;
  margin: 0;
  font-size: 0.9375rem;
  min-height: 1.5em;
}

.calibration-message.error {
  color: #dc3545;
}

.calibration-message.success {
  color: #198754;
}

/* Dark mode */
html.dark body {
  color: #e9ecef;
  background: #212529;
}

html.dark .top-bar {
  background: #212529;
}

html.dark .site-footer {
  background: #343a40;
  border-top-color: #495057;
}

html.dark .footer-content,
html.dark .footer-disclosure {
  color: #868e96;
}

html.dark .theme-toggle {
  background: #495057;
  color: #f8f9fa;
  border-color: #495057;
}

html.dark .theme-toggle:hover {
  background: #6c757d;
  color: #f8f9fa;
  border-color: #6c757d;
}

html.dark h1,
html.dark .wpm-control label,
html.dark .calibration-section h2,
html.dark .stat strong {
  color: #f8f9fa;
}

html.dark .tagline,
html.dark .intro,
html.dark .calibration-intro {
  color: #adb5bd;
}

html.dark .stats,
html.dark .duration-verbal,
html.dark #wpm-unit,
html.dark .hint {
  color: #adb5bd;
}

html.dark #speech-text {
  background: #343a40;
  border-color: #495057;
  color: #f8f9fa;
}

html.dark #speech-text::placeholder {
  color: #868e96;
}

html.dark #speech-text:focus {
  border-color: #61f1f5;
  outline-color: #61f1f5;
}

html.dark .clear-btn {
  color: #adb5bd;
  border-color: #495057;
}

html.dark .clear-btn:hover {
  background: #495057;
  border-color: #6c757d;
  color: #f8f9fa;
}

html.dark #wpm-input {
  background: #343a40;
  border-color: #495057;
  color: #f8f9fa;
}

html.dark #wpm-input:focus {
  outline-color: #61f1f5;
  border-color: #61f1f5;
}

html.dark .using-speed {
  color: #74c0fc;
}

html.dark .calibration-section {
  border-top-color: #495057;
}

html.dark .sample-paragraph {
  background: #343a40;
  border-color: #495057;
  color: #e9ecef;
}

html.dark .calibration-message.error {
  color: #ff6b6b;
}

html.dark .calibration-message.success {
  color: #69db7c;
}

html.dark button:not(.theme-toggle):not(.clear-btn) {
  border-color: #495057;
  background: #495057;
}

html.dark button:not(.theme-toggle):not(.clear-btn):hover:not(:disabled) {
  background: #6c757d;
  border-color: #6c757d;
}

html.dark .use-speed-btn {
  background: #495057;
  border-color: #495057;
}

html.dark .use-speed-btn:hover {
  background: #6c757d;
  border-color: #6c757d;
}

html.dark button:focus {
  outline-color: #61f1f5;
}

html.dark .footer-content a {
  color: #61f1f5;
}

html.dark .footer-content a:hover {
  color: #7df4f7;
}

@media (min-width: 480px) {
  main {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }

  .top-bar,
  .site-footer {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }

  h1 {
    font-size: 2rem;
  }
}
