* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  touch-action: manipulation;
}

:root {
  --background: hsl(0, 0%, 80%);
  --color: hsl(0, 0%, 21%);
  --color-25: hsla(0, 0%, 21%, 0.25);
  --color-50: hsla(0, 0%, 21%, 0.5);
  --btn-prominent-bg: hsla(0, 0%, 21%, 0.8);
  --btn-prominent-bg-hover: hsl(0, 0%, 21%);
  --btn-prominent-icon: hsl(0, 0%, 100%);
  --btn-subtle-bg: hsla(0, 0%, 21%, 0.1);
  --btn-subtle-bg-hover: hsla(0, 0%, 21%, 0.25);
  --btn-subtle-icon: hsl(0, 0%, 21%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: hsl(0, 0%, 27%);
    --color: hsl(0, 0%, 83%);
    --color-25: hsla(0, 0%, 83%, 0.25);
    --color-50: hsla(0, 0%, 83%, 0.5);
    --btn-prominent-bg: hsla(0, 0%, 100%, 0.8);
    --btn-prominent-bg-hover: hsl(0, 0%, 100%);
    --btn-prominent-icon: hsl(0, 0%, 27%);
    --btn-subtle-bg: hsla(0, 0%, 100%, 0.1);
    --btn-subtle-bg-hover: hsla(0, 0%, 100%, 0.25);
    --btn-subtle-icon: hsl(0, 0%, 100%);
  }
}

body {
  -moz-osx-font-smoothing: grayscale;
  -webkit-font-smoothing: antialiased;
  align-items: center;
  background: var(--background);
  color: var(--color);
  display: flex;
  flex-direction: column;
  font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
  gap: 24px;
  height: 100vh;
  height: 100dvh;
  justify-content: flex-start;
  overflow: hidden;
  padding-bottom: calc(24px - env(safe-area-inset-bottom, 0px));
  padding-left: 24px;
  padding-right: 24px;
  padding-top: calc(24px + env(safe-area-inset-top));
  position: relative;
  text-rendering: optimizeLegibility;
  touch-action: manipulation;
  width: 100vw;
}

@media (hover: hover) {
  body::before {
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.5' numOctaves='8' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.5'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 200px 200px;
    bottom: 0;
    content: "";
    left: 0;
    mix-blend-mode: overlay;
    pointer-events: none;
    position: absolute;
    right: 0;
    top: 0;
    z-index: 0;
  }
}

body.font-monospace {
  font-family: ui-monospace, "Courier New", monospace;
}

body.font-rounded {
  font-family: ui-rounded, system-ui, sans-serif;
}

body.font-serif {
  font-family: ui-serif, Georgia, serif;
}

body.theme-light {
  --background: hsl(0, 0%, 80%);
  --color: hsl(0, 0%, 21%);
  --color-25: hsla(0, 0%, 21%, 0.25);
  --color-50: hsla(0, 0%, 21%, 0.5);
  --btn-prominent-bg: hsla(0, 0%, 21%, 0.8);
  --btn-prominent-bg-hover: hsl(0, 0%, 21%);
  --btn-prominent-icon: hsl(0, 0%, 100%);
  --btn-subtle-bg: hsla(0, 0%, 21%, 0.1);
  --btn-subtle-bg-hover: hsla(0, 0%, 21%, 0.25);
  --btn-subtle-icon: hsl(0, 0%, 21%);
}

body.theme-dark {
  --background: hsl(0, 0%, 27%);
  --color: hsl(0, 0%, 83%);
  --color-25: hsla(0, 0%, 83%, 0.25);
  --color-50: hsla(0, 0%, 83%, 0.5);
  --btn-prominent-bg: hsla(0, 0%, 100%, 0.8);
  --btn-prominent-bg-hover: hsl(0, 0%, 100%);
  --btn-prominent-icon: hsl(0, 0%, 27%);
  --btn-subtle-bg: hsla(0, 0%, 100%, 0.1);
  --btn-subtle-bg-hover: hsla(0, 0%, 100%, 0.25);
  --btn-subtle-icon: hsl(0, 0%, 100%);
}

@media (hover: none) and (pointer: coarse) {
  :root {
    --btn-prominent-bg: hsl(0, 0%, 21%);
    --btn-subtle-icon: hsl(0, 0%, 21%);
  }

  @media (prefers-color-scheme: dark) {
    :root {
      --btn-prominent-bg: hsl(0, 0%, 100%);
      --btn-subtle-icon: hsl(0, 0%, 100%);
    }
  }

  body.theme-light {
    --btn-prominent-bg: hsl(0, 0%, 21%);
    --btn-subtle-icon: hsl(0, 0%, 21%);
  }

  body.theme-dark {
    --btn-prominent-bg: hsl(0, 0%, 100%);
    --btn-subtle-icon: hsl(0, 0%, 100%);
  }
}

.view {
  align-items: center;
  display: flex;
  flex-direction: column;
  flex: 1;
  justify-content: center;
  min-height: 0;
  position: relative;
  width: 100%;
  z-index: 1;
}

.view.hidden {
  display: none;
}

.fixed-controls {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  max-width: 640px;
  position: relative;
  width: 100%;
  z-index: 1;
}

.controls-group {
  display: flex;
  gap: 12px;
}

.fixed-controls .hidden {
  display: none;
}

#text-input {
  background: white;
  border: none;
  border-radius: 8px;
  box-shadow: 0 16px 32px 0 hsla(0, 0%, 0%, 0.08);
  color: hsl(0, 0%, 21%);
  font-family: inherit;
  font-size: 1rem;
  height: 100%;
  line-height: 1.4;
  max-width: 640px;
  overflow: auto;
  padding: 24px;
  resize: none;
  transition: box-shadow 0.3s, transform 0.3s;
  width: 100%;
}

#text-input::placeholder {
  color: hsla(0, 0%, 21%, 0.5);
}

#text-input:hover {
  box-shadow: 0 16px 32px 0 hsla(0, 0%, 0%, 0.16);
  transform: scale(1.01);
}

#text-input:focus {
  box-shadow: 0 16px 32px 0 hsla(0, 0%, 0%, 0.16);
  outline: none;
  transform: scale(1.01);
}

#text-input:focus::placeholder {
  color: hsla(0, 0%, 21%, 0.25);
}

.btn {
  -webkit-backdrop-filter: blur(10px);
  align-items: center;
  backdrop-filter: blur(10px);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  font-family: system-ui, sans-serif;
  font-size: 1rem;
  height: 56px;
  justify-content: center;
  padding: 0;
  transition: background 0.3s, box-shadow 0.3s;
  width: 56px;
}

#speed-btn {
  font-family: system-ui, sans-serif;
  font-size: 1.125rem;
  font-weight: 500;
}

.btn-subtle {
  background: var(--btn-subtle-bg);
  box-shadow: none;
  color: var(--btn-subtle-icon);
}

.btn-subtle:hover {
  background: var(--btn-subtle-bg-hover);
  box-shadow: none;
}

.btn-prominent {
  background: var(--btn-prominent-bg);
  box-shadow: 0 4px 8px hsla(0, 0%, 0%, 0.16);
  color: var(--btn-prominent-icon);
}

.btn-prominent:hover {
  background: var(--btn-prominent-bg-hover);
}

.btn i {
  align-items: center;
  display: flex;
  height: 24px;
  justify-content: center;
  width: 24px;
}

.btn i svg {
  height: 24px;
  width: 24px;
}

.btn-subtle i svg {
  color: var(--btn-subtle-icon);
  stroke: var(--btn-subtle-icon);
}

.btn-prominent i svg {
  color: var(--btn-prominent-icon);
  stroke: var(--btn-prominent-icon);
}

#start-btn i svg {
  transform: translateX(2px);
}

.reader-display {
  align-items: center;
  display: flex;
  justify-content: center;
  min-height: 300px;
  padding: 60px 40px;
}

.word-display {
  color: var(--color);
  font-size: 4rem;
  font-weight: normal;
  line-height: 1.4;
  max-width: 100%;
  text-align: center;
  word-wrap: break-word;
}

.word-display .word {
  display: inline-block;
  padding: 0 5px;
}

@media (max-width: 768px) {
  .btn {
    height: 48px;
    width: 48px;
  }

  .controls-group {
    gap: 8px;
  }

  .fixed-controls {
    gap: 8px;
  }

  .reader-display {
    padding: 40px 20px;
  }

  .word-display {
    font-size: 3rem;
  }
}
