:root {
  --tf-bg: #0a0f1b;
  --tf-panel: #0f1627;
  --tf-panel-2: #121c31;
  --tf-ink: #f6f7fb;
  --tf-muted: #96a0b5;
  --tf-line: rgba(255,255,255,.10);
  --tf-blue: #6d7cff;
  --tf-cyan: #67e8f9;
  --tf-green: #8cf0c2;
  --tf-red: #ff7d8d;
}

.typeflow-page {
  background:
    radial-gradient(1000px 520px at 76% 4%, rgba(76,92,255,.08), transparent 66%),
    var(--paper);
}

.tf-intro {
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  align-items: end;
  gap: clamp(40px, 8vw, 110px);
  padding: clamp(72px, 9vw, 126px) 0 clamp(48px, 6vw, 80px);
}

.tf-kicker,
.tf-section-label {
  margin: 0 0 16px;
  color: #3f58d3;
  font-size: 11px;
  font-weight: 820;
  letter-spacing: .17em;
  text-transform: uppercase;
}

.tf-intro h1 {
  margin: 0;
  font-size: clamp(72px, 11vw, 152px);
  line-height: .82;
  letter-spacing: -.08em;
  font-weight: 820;
}

.tf-intro h1 span {
  color: #5369ec;
}

.tf-intro-copy {
  padding-bottom: 4px;
}

.tf-intro-copy p {
  margin: 0 0 18px;
  max-width: 440px;
  color: #414a4c;
  font-size: clamp(21px, 2.1vw, 28px);
  line-height: 1.35;
  letter-spacing: -.025em;
}

.tf-device-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #687173;
  font-size: 12px;
  font-weight: 730;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.tf-device-label::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #667af7;
  box-shadow: 0 0 0 4px rgba(102,122,247,.10);
}

.tf-app {
  padding-bottom: clamp(90px, 11vw, 150px);
}

.tf-shell {
  position: relative;
  isolation: isolate;
  min-height: 610px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 18px;
  background:
    linear-gradient(135deg, rgba(255,255,255,.035), transparent 34%),
    radial-gradient(700px 390px at 76% -5%, rgba(109,124,255,.16), transparent 66%),
    linear-gradient(180deg, #10182a 0%, #090e19 100%);
  color: var(--tf-ink);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.09),
    0 36px 90px rgba(16,23,26,.18);
}

.tf-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(180deg, rgba(0,0,0,.66), transparent 80%);
}

.tf-glow {
  position: absolute;
  width: 520px;
  height: 520px;
  right: -190px;
  bottom: -240px;
  border-radius: 50%;
  pointer-events: none;
  background: rgba(103,232,249,.09);
  filter: blur(70px);
  transition: background .3s ease, transform .3s ease;
}

.tf-shell[data-flow-level="1"] .tf-glow { background: rgba(109,124,255,.16); transform: scale(1.05); }
.tf-shell[data-flow-level="2"] .tf-glow { background: rgba(103,232,249,.18); transform: scale(1.14); }
.tf-shell[data-flow-level="3"] .tf-glow { background: rgba(140,240,194,.21); transform: scale(1.24); }

.tf-screen[hidden] { display: none !important; }

.tf-screen {
  position: relative;
  z-index: 2;
  min-height: 610px;
  padding: clamp(32px, 5vw, 68px);
}

.tf-setup {
  display: flex;
  flex-direction: column;
}

.tf-setup-head {
  display: flex;
  justify-content: space-between;
  gap: 28px;
  align-items: baseline;
}

.tf-setup .tf-section-label,
.tf-results .tf-section-label {
  color: #91a0ff;
}

.tf-setup-note {
  margin: 0;
  color: var(--tf-muted);
  font-size: 13px;
}

.tf-modes {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  margin-top: clamp(34px, 5vw, 58px);
  border-top: 1px solid var(--tf-line);
  border-bottom: 1px solid var(--tf-line);
}

.tf-mode {
  min-width: 0;
  padding: 28px 24px 30px;
  border: 0;
  border-right: 1px solid var(--tf-line);
  background: transparent;
  color: var(--tf-ink);
  text-align: left;
  cursor: pointer;
  transition: background .2s ease, transform .2s ease;
}

.tf-mode:last-child { border-right: 0; }

.tf-mode:hover {
  background: rgba(255,255,255,.035);
}

.tf-mode.is-active {
  background:
    linear-gradient(180deg, rgba(109,124,255,.14), rgba(109,124,255,.035));
  box-shadow: inset 0 2px 0 #7183ff;
}

.tf-mode span,
.tf-mode small {
  display: block;
  color: var(--tf-muted);
  font-size: 11px;
  font-weight: 720;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.tf-mode strong {
  display: block;
  margin: 14px 0 10px;
  font-size: clamp(19px, 2vw, 25px);
  letter-spacing: -.04em;
}

.tf-mode small {
  max-width: 180px;
  line-height: 1.5;
  letter-spacing: 0;
  text-transform: none;
  font-weight: 560;
}

.tf-custom {
  margin-top: 28px;
}

.tf-custom label {
  display: block;
  margin-bottom: 10px;
  color: #dce1ed;
  font-size: 12px;
  font-weight: 760;
}

.tf-custom textarea {
  width: 100%;
  resize: vertical;
  min-height: 150px;
  padding: 18px;
  border: 1px solid var(--tf-line);
  border-radius: 10px;
  outline: 0;
  background: rgba(5,9,16,.48);
  color: var(--tf-ink);
  font: inherit;
  font-size: 15px;
  line-height: 1.6;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.025);
}

.tf-custom textarea:focus {
  border-color: rgba(109,124,255,.70);
  box-shadow: 0 0 0 3px rgba(109,124,255,.10);
}

.tf-custom-meta {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 8px;
  color: #758096;
  font-size: 11px;
}

#customError { color: #ff9aa7; }

.tf-setup-actions {
  display: flex;
  align-items: center;
  gap: 22px;
  margin-top: auto;
  padding-top: 42px;
}

.tf-start,
.tf-secondary,
.tf-sound,
.tf-controls button,
.tf-pause-layer button {
  appearance: none;
  border: 0;
  font: inherit;
  cursor: pointer;
}

.tf-start {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 54px;
  padding: 0 24px;
  border-radius: 999px;
  background: linear-gradient(135deg, #eef1ff, #ffffff);
  color: #101727;
  font-size: 14px;
  font-weight: 800;
  box-shadow: 0 12px 32px rgba(0,0,0,.22), inset 0 1px 0 rgba(255,255,255,.9);
  transition: transform .2s ease, box-shadow .2s ease;
}

.tf-start:hover { transform: translateY(-2px); box-shadow: 0 17px 40px rgba(0,0,0,.27); }
.tf-start:active { transform: translateY(0); }

.tf-best {
  color: #a8b1c4;
  font-size: 12px;
}

.tf-sound {
  margin-left: auto;
  padding: 9px 0;
  background: transparent;
  color: #9da7ba;
  font-size: 12px;
  border-bottom: 1px solid rgba(255,255,255,.18);
}

.tf-game {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  min-height: 610px;
}

.tf-stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  border-bottom: 1px solid var(--tf-line);
}

.tf-stats div {
  padding: 0 20px 22px;
  border-right: 1px solid var(--tf-line);
}

.tf-stats div:first-child { padding-left: 0; }
.tf-stats div:last-child { border-right: 0; }

.tf-stats span,
.tf-result-grid span {
  display: block;
  margin-bottom: 7px;
  color: #7f8aa1;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.tf-stats strong {
  display: block;
  font-size: clamp(24px, 3vw, 34px);
  letter-spacing: -.045em;
  font-variant-numeric: tabular-nums;
}

.tf-flow-meter {
  height: 3px;
  margin-top: -1px;
  background: rgba(255,255,255,.045);
  overflow: hidden;
}

.tf-flow-meter i {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #6375ff, #64e5f6, #8cf0c2);
  box-shadow: 0 0 16px rgba(103,232,249,.45);
  transition: width .22s ease;
}

.tf-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 330px;
  padding: 38px 10px 34px;
  text-align: center;
}

.tf-upcoming {
  display: flex;
  justify-content: center;
  gap: clamp(14px, 2.5vw, 32px);
  min-height: 22px;
  margin-bottom: 36px;
  color: #5f6a80;
  font-size: clamp(13px, 1.5vw, 18px);
  letter-spacing: -.02em;
}

.tf-upcoming span:first-child { color: #8994aa; }

.tf-current {
  min-height: 96px;
  max-width: 100%;
  font-size: clamp(54px, 8vw, 106px);
  font-weight: 780;
  line-height: .95;
  letter-spacing: -.06em;
  word-break: break-word;
}

.tf-char {
  color: #eff2f9;
  transition: color .08s ease, text-shadow .08s ease;
}

.tf-char.is-correct {
  color: #92f2c8;
  text-shadow: 0 0 22px rgba(140,240,194,.18);
}

.tf-char.is-wrong,
.tf-char.is-extra {
  color: #ff8494;
  text-shadow: 0 0 18px rgba(255,125,141,.16);
}

.tf-char.is-next {
  text-decoration: underline;
  text-decoration-color: rgba(109,124,255,.55);
  text-underline-offset: .16em;
  text-decoration-thickness: 2px;
}

.tf-capture {
  position: absolute;
  left: 50%;
  bottom: 72px;
  transform: translateX(-50%);
  width: min(680px, calc(100% - 28px));
  height: 52px;
  border: 0;
  outline: 0;
  opacity: .01;
  color: transparent;
  background: transparent;
  caret-color: transparent;
}

.tf-cue {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 28px;
  color: #738096;
}

.tf-cue > span {
  color: #aab5cb;
  font-size: 11px;
  font-weight: 820;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.tf-cue small {
  font-size: 12px;
}

.tf-controls {
  display: flex;
  gap: 24px;
  padding-top: 22px;
  border-top: 1px solid var(--tf-line);
}

.tf-controls button {
  padding: 4px 0;
  background: transparent;
  color: #8e99ad;
  font-size: 12px;
  border-bottom: 1px solid transparent;
}

.tf-controls button:hover {
  color: #fff;
  border-bottom-color: rgba(255,255,255,.28);
}

.tf-pause-layer {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-content: center;
  gap: 24px;
  text-align: center;
  background: rgba(7,11,20,.82);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.tf-pause-layer[hidden] { display: none; }

.tf-pause-layer p {
  margin: 0;
  font-size: clamp(38px, 6vw, 70px);
  font-weight: 780;
  letter-spacing: -.06em;
}

.tf-pause-layer button,
.tf-secondary {
  min-height: 46px;
  padding: 0 18px;
  border: 1px solid rgba(255,255,255,.20);
  border-radius: 999px;
  background: rgba(255,255,255,.06);
  color: white;
  font-size: 13px;
  font-weight: 750;
}

.tf-results {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.tf-result-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
}

.tf-result-heading h2 {
  margin: 0;
  font-size: clamp(54px, 8vw, 104px);
  line-height: .9;
  letter-spacing: -.065em;
}

#newBestBadge {
  flex: 0 0 auto;
  margin-bottom: 8px;
  padding: 7px 10px;
  border: 1px solid rgba(140,240,194,.28);
  border-radius: 999px;
  color: #9bf4ce;
  font-size: 10px;
  font-weight: 820;
  letter-spacing: .10em;
  text-transform: uppercase;
}

.tf-result-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin-top: 54px;
  border-top: 1px solid var(--tf-line);
  border-bottom: 1px solid var(--tf-line);
}

.tf-result-grid div {
  padding: 26px 24px;
  border-right: 1px solid var(--tf-line);
}

.tf-result-grid div:first-child { padding-left: 0; }
.tf-result-grid div:last-child { border-right: 0; }

.tf-result-grid strong {
  font-size: clamp(28px, 4vw, 48px);
  letter-spacing: -.05em;
  font-variant-numeric: tabular-nums;
}

.tf-result-copy {
  max-width: 640px;
  margin: 30px 0 0;
  color: #9ba6b9;
  font-size: 16px;
  line-height: 1.65;
}

.tf-result-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 32px;
}

.tf-secondary {
  background: transparent;
}

.tf-footnote {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 2px 0;
  color: #7c8587;
  font-size: 11px;
}

.tf-about {
  display: grid;
  grid-template-columns: .55fr 1.45fr;
  gap: clamp(40px, 8vw, 110px);
  padding-bottom: clamp(100px, 13vw, 170px);
}

.tf-about h2 {
  margin: 0;
  max-width: 850px;
  font-size: clamp(44px, 7vw, 86px);
  line-height: .94;
  letter-spacing: -.06em;
}

.tf-about > div p {
  max-width: 680px;
  margin: 28px 0 0;
  color: #535c5e;
  font-size: 18px;
  line-height: 1.72;
}

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

.tf-page-running {
  overscroll-behavior: none;
}

@media (max-width: 900px) {
  .tf-intro,
  .tf-about {
    grid-template-columns: 1fr;
  }

  .tf-intro {
    gap: 30px;
  }

  .tf-intro-copy {
    max-width: 620px;
  }

  .tf-modes {
    grid-template-columns: 1fr 1fr;
  }

  .tf-mode:nth-child(2) {
    border-right: 0;
  }

  .tf-mode:nth-child(-n+2) {
    border-bottom: 1px solid var(--tf-line);
  }

  .tf-stats {
    grid-template-columns: repeat(3, 1fr);
  }

  .tf-stats div {
    padding: 0 14px 18px;
  }

  .tf-stats div:nth-child(3) { border-right: 0; }
  .tf-stats div:nth-child(4),
  .tf-stats div:nth-child(5) { padding-top: 16px; }

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

  .tf-result-grid div:nth-child(2) { border-right: 0; }
  .tf-result-grid div:nth-child(-n+2) { border-bottom: 1px solid var(--tf-line); }
}

@media (max-width: 620px) {
  .typeflow-page .site-header {
    transition: transform .2s ease;
  }

  .tf-page-running .site-header {
    display: none;
  }

  .tf-intro {
    padding: 54px 0 38px;
  }

  .tf-intro h1 {
    font-size: clamp(66px, 22vw, 92px);
  }

  .tf-intro-copy p {
    font-size: 19px;
  }

  .tf-app {
    width: 100%;
    padding-bottom: 78px;
  }

  .tf-shell {
    min-height: 560px;
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }

  .tf-screen {
    min-height: 560px;
    padding: 24px 16px max(22px, env(safe-area-inset-bottom));
  }

  .tf-setup-head {
    display: block;
  }

  .tf-setup-note {
    margin-top: 8px;
    line-height: 1.5;
  }

  .tf-modes {
    margin-top: 26px;
  }

  .tf-mode {
    min-height: 136px;
    padding: 20px 14px 22px;
  }

  .tf-mode strong {
    margin: 10px 0 7px;
    font-size: 19px;
  }

  .tf-mode small {
    font-size: 10px;
  }

  .tf-setup-actions {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 14px;
    padding-top: 28px;
  }

  .tf-start {
    min-height: 52px;
  }

  .tf-best {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .tf-sound {
    margin-left: 0;
  }

  .tf-game {
    grid-template-rows: auto auto minmax(190px, 1fr) auto;
    min-height: min(100dvh, 680px);
  }

  .tf-stats {
    grid-template-columns: repeat(3, 1fr);
  }

  .tf-stats div {
    min-width: 0;
    padding: 0 10px 13px;
  }

  .tf-stats div:nth-child(4),
  .tf-stats div:nth-child(5) {
    padding-top: 12px;
  }

  .tf-stats strong {
    font-size: 23px;
  }

  .tf-stage {
    min-height: 210px;
    padding: 24px 4px 20px;
  }

  .tf-upcoming {
    max-width: 100%;
    gap: 12px;
    margin-bottom: 24px;
    overflow: hidden;
    white-space: nowrap;
    font-size: 12px;
  }

  .tf-upcoming span:nth-child(n+4) {
    display: none;
  }

  .tf-current {
    min-height: 70px;
    font-size: clamp(46px, 15vw, 68px);
  }

  .tf-capture {
    bottom: 44px;
  }

  .tf-cue {
    margin-top: 17px;
    gap: 8px;
  }

  .tf-cue small {
    font-size: 10px;
  }

  .tf-controls {
    justify-content: space-between;
    gap: 12px;
    padding-top: 16px;
  }

  .tf-controls button {
    font-size: 11px;
  }

  .tf-result-heading {
    display: block;
  }

  #newBestBadge {
    display: inline-block;
    margin: 16px 0 0;
  }

  #newBestBadge[hidden] { display: none; }

  .tf-result-grid {
    margin-top: 34px;
  }

  .tf-result-grid div {
    padding: 20px 12px;
  }

  .tf-result-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .tf-secondary {
    width: 100%;
  }

  .tf-footnote {
    padding-inline: 16px;
    flex-direction: column;
    gap: 4px;
  }

  .tf-about {
    padding-top: 10px;
  }

  .tf-about h2 {
    font-size: 48px;
  }
}

@media (max-height: 720px) and (max-width: 620px) {
  .tf-game {
    min-height: calc(100dvh - env(safe-area-inset-bottom));
  }

  .tf-stage {
    min-height: 160px;
    padding-block: 16px;
  }

  .tf-upcoming {
    margin-bottom: 14px;
  }

  .tf-current {
    font-size: 48px;
    min-height: 54px;
  }

  .tf-cue {
    margin-top: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tf-glow,
  .tf-char,
  .tf-flow-meter i,
  .tf-start,
  .tf-feature-image {
    transition: none !important;
  }
}

/* v18 mobile keyboard stability */
@media (max-width: 620px) {
  .tf-page-running {
    overflow: hidden;
    height: 100%;
  }

  .tf-page-running .tf-intro,
  .tf-page-running .tf-footnote,
  .tf-page-running .tf-about,
  .tf-page-running .site-footer {
    display: none !important;
  }

  .tf-page-running .tf-app {
    position: fixed;
    z-index: 9000;
    top: var(--tf-vv-top, 0px);
    left: 0;
    right: 0;
    width: 100%;
    height: var(--tf-vv-height, 100dvh);
    padding: 0;
    margin: 0;
  }

  .tf-page-running .tf-shell {
    width: 100%;
    height: 100%;
    min-height: 0;
    border: 0;
    border-radius: 0;
  }

  .tf-page-running .tf-screen {
    height: 100%;
    min-height: 0;
    padding: 12px 16px max(10px, env(safe-area-inset-bottom));
  }

  .tf-page-running .tf-game {
    height: 100%;
    min-height: 0;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
  }

  .tf-page-running .tf-stage {
    min-height: 0;
    padding: 12px 4px 10px;
    overflow: hidden;
  }

  .tf-page-running .tf-upcoming {
    margin-bottom: 12px;
  }

  .tf-page-running .tf-current {
    min-height: 54px;
    font-size: clamp(42px, 13vw, 60px);
  }

  .tf-page-running .tf-cue {
    margin-top: 10px;
  }

  .tf-page-running .tf-controls {
    padding-top: 10px;
  }

  .tf-page-running .tf-capture {
    position: fixed;
    z-index: -1;
    top: 45%;
    left: 50%;
    bottom: auto;
    width: 2px;
    height: 2px;
    min-width: 2px;
    min-height: 2px;
    padding: 0;
    border: 0;
    transform: none;
    opacity: .01;
    font-size: 16px;
    line-height: 16px;
    caret-color: transparent;
  }
}

/* v19 share card */
.tf-share-preview {
  margin-top: 30px;
}
.tf-share-preview canvas {
  display: block;
  width: min(100%, 660px);
  height: auto;
  border-radius: 12px;
  box-shadow: 0 18px 46px rgba(0,0,0,.24);
}
@media (max-width: 620px) {
  .tf-share-preview { margin-top: 22px; }
  .tf-share-preview canvas { border-radius: 9px; }
}
