*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  /* prevent double-tap zoom on mobile while keeping scroll */
  touch-action: manipulation;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: #0f0f0f;
  color: #ffffff;
  font-family: system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

/* ── Display area ─────────────────────────────────────────── */

#display {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
  overflow: hidden;
  cursor: pointer;
  user-select: none;
}

#display span {
  font-size: clamp(3rem, 12vw, 15rem);
  font-weight: 800;
  line-height: 1.1;
  word-break: break-word;
  text-transform: uppercase;
  transition: font-size 0.1s ease;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.15; }
}

#display.empty span {
  font-size: 4rem;
  color: #2e2e2e;
  animation: blink 1.6s ease-in-out infinite;
}

/* ── Click-to-start overlay ───────────────────────────────── */

#overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  cursor: pointer;
}

/* ── Hidden input capture ─────────────────────────────────── */

#input {
  position: fixed;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px;
  top: 0;
  left: 0;
  border: none;
  background: transparent;
  color: transparent;
  resize: none;
  outline: none;
  /* Prevent iOS Safari from zooming in when the textarea is focused */
  font-size: 16px;
}

/* ── Controls pill ────────────────────────────────────────── */

#controls {
  position: fixed;
  bottom: 1.1rem;
  right: 1.1rem;
  display: flex;
  align-items: center;
  background: #141414;
  border: 1px solid #222;
  border-radius: 999px;
  padding: 0.35rem;
  gap: 0.1rem;
  z-index: 10;
  transition: opacity 0.4s;
}

.ctrl-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: #3a3a3a;
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 999px;
  transition: color 0.15s, background 0.15s;
  line-height: 0;
  text-decoration: none;
}

.ctrl-btn:hover {
  color: #aaa;
  background: #1e1e1e;
}

.ctrl-btn svg {
  width: 18px;
  height: 18px;
  display: block;
  fill: currentColor;
}

.ctrl-divider {
  width: 1px;
  height: 14px;
  background: #2a2a2a;
  margin: 0 0.15rem;
  flex-shrink: 0;
}

/* ── Mobile responsiveness ───────────────────────────────── */

@media (max-width: 600px) {
  #display {
    padding: 1.25rem;
  }

  #display.empty span {
    font-size: 2.5rem;
  }

  #controls {
    bottom: 0.75rem;
    right: 0.75rem;
  }

  /* Larger tap targets on touch */
  .ctrl-btn {
    padding: 0.55rem;
  }

  .ctrl-btn svg {
    width: 20px;
    height: 20px;
  }
}

/* Adapt to virtual keyboard shrinking the viewport */
@supports (height: 100dvh) {
  body { height: 100dvh; }
}

/* ── Landscape on small devices ───────────────────────────── */

@media (max-height: 500px) and (orientation: landscape) {
  #display {
    padding: 0.75rem 1.25rem;
  }

  #display.empty span {
    font-size: 2rem;
  }

  #controls {
    bottom: 0.5rem;
    right: 0.5rem;
  }
}

/* ── Fullscreen adjustments ───────────────────────────────── */

:fullscreen #controls,
:-webkit-full-screen #controls {
  opacity: 0;
  pointer-events: none;
}

:fullscreen #controls.peek,
:-webkit-full-screen #controls.peek {
  opacity: 1;
  pointer-events: auto;
}

:fullscreen #display,
:-webkit-full-screen #display {
  cursor: default;
}

/* ── Touch devices: always show controls (no hover available) */

@media (hover: none) {
  :fullscreen #controls,
  :-webkit-full-screen #controls {
    opacity: 1;
    pointer-events: auto;
  }
}
