/* ==========================================================================
   Game: Word Sprint (type-sprint)
   Self-contained — every class is prefixed .tsp-. Racing-track look: a dark
   panel in both site themes with neon speed stripes. Uses site tokens from
   common.css.
   ========================================================================== */

.tsp {
  --tsp-bg: #0f1424;
  --tsp-card: rgba(255, 255, 255, .06);
  --tsp-card-hover: rgba(255, 255, 255, .11);
  --tsp-line: rgba(255, 255, 255, .13);
  --tsp-text: #fff;
  --tsp-sub: rgba(255, 255, 255, .7);
  --tsp-good: #3ee0a1;
  --tsp-bad: #ff5c7a;
  --tsp-warn: #ffb547;
  --tsp-accent: var(--hot);
  --tsp-speed: #ff7a45;
  --tsp-mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;

  position: relative;
  margin: 10px 0 40px;
  padding: 36px;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background:
    radial-gradient(100% 80% at 100% 0%, rgba(255, 122, 69, .3), transparent 55%),
    radial-gradient(90% 80% at 0% 100%, rgba(91, 61, 245, .45), transparent 60%),
    var(--tsp-bg);
  color: var(--tsp-text);
  isolation: isolate;
  min-height: 520px;
}
:root[data-theme="dark"] .tsp { border: 1px solid var(--line); }

/* Speed stripes (decorative) */
.tsp::before {
  content: "";
  position: absolute;
  top: 26px;
  right: -60px;
  z-index: -1;
  width: 420px;
  height: 120px;
  background:
    linear-gradient(90deg, transparent, rgba(255, 122, 69, .55)) 0 0 / 100% 10px no-repeat,
    linear-gradient(90deg, transparent, rgba(255, 216, 77, .45)) 60px 26px / 100% 6px no-repeat,
    linear-gradient(90deg, transparent, rgba(255, 92, 122, .4)) 20px 46px / 100% 14px no-repeat,
    linear-gradient(90deg, transparent, rgba(169, 155, 255, .4)) 120px 76px / 100% 5px no-repeat;
  transform: skewX(-24deg);
  opacity: .5;
  animation: tsp-zoom 3.5s ease-in-out infinite alternate;
}
@keyframes tsp-zoom { to { transform: skewX(-24deg) translateX(-40px); } }

.tsp-screen[hidden] { display: none !important; }
.tsp-screen { animation: tsp-fade .35s var(--ease); }
@keyframes tsp-fade {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.tsp-ico { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Buttons ---------- */
.tsp-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 18px;
  border: 1px solid var(--tsp-line);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--tsp-text);
  font: 600 .875rem/1.2 var(--font);
  cursor: pointer;
  transition: background-color .2s var(--ease), border-color .2s var(--ease);
}
.tsp-ghost:hover { background: var(--tsp-card-hover); }
.tsp-ghost[hidden] { display: none; }
.tsp-ghost--small { min-height: 44px; padding: 8px 16px; }
.tsp-ghost--danger { color: var(--tsp-sub); }
.tsp-ghost--danger.is-confirm { border-color: var(--tsp-bad); color: var(--tsp-bad); }
.tsp-ghost .tsp-ico--off { display: none; }
.tsp-ghost.is-off .tsp-ico--on { display: none; }
.tsp-ghost.is-off .tsp-ico--off { display: block; }

.tsp-icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  padding: 0;
  border: 1px solid var(--tsp-line);
  border-radius: 50%;
  background: var(--tsp-card);
  color: var(--tsp-text);
  cursor: pointer;
  transition: background-color .2s var(--ease);
}
.tsp-icon-btn:hover { background: var(--tsp-card-hover); }

.tsp .btn-pill { min-height: 46px; padding: 11px 24px; }
.tsp .btn-pill:not(.btn-pill--hot) { background: var(--brand-soft); color: var(--night); }
.tsp button:focus-visible { outline: 3px solid var(--tsp-accent); outline-offset: 2px; }

/* ==========================================================================
   Home
   ========================================================================== */
.tsp-home__head { display: flex; align-items: flex-start; gap: 22px; max-width: 760px; }

.tsp-keys { display: flex; gap: 6px; flex: none; padding-top: 6px; }
.tsp-keys span {
  display: grid;
  place-items: center;
  width: 40px;
  height: 44px;
  border-radius: 9px;
  background: linear-gradient(180deg, #2a3150, #1a1f36);
  box-shadow: 0 4px 0 #090c18, inset 0 1px 0 rgba(255, 255, 255, .15);
  color: var(--tsp-accent);
  font: 800 1rem/1 var(--tsp-mono);
  animation: tsp-press 2.4s ease-in-out infinite;
}
.tsp-keys span:nth-child(2) { animation-delay: .3s; color: var(--tsp-speed); }
.tsp-keys span:nth-child(3) { animation-delay: .6s; color: var(--brand-soft); }
@keyframes tsp-press {
  0%, 70%, 100% { transform: none; box-shadow: 0 4px 0 #090c18, inset 0 1px 0 rgba(255, 255, 255, .15); }
  78% { transform: translateY(3px); box-shadow: 0 1px 0 #090c18, inset 0 1px 0 rgba(255, 255, 255, .15); }
}

.tsp-kicker {
  display: inline-block;
  margin-bottom: 8px;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  background: rgba(255, 122, 69, .18);
  color: var(--tsp-accent);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.tsp-title { margin: 0 0 8px; font-size: clamp(2rem, 4.4vw, 3rem); font-style: italic; letter-spacing: -.035em; line-height: 1.05; }
.tsp-lead { margin: 0; color: var(--tsp-sub); }

.tsp-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; margin: 28px 0 20px; }
.tsp-chips { display: flex; flex-wrap: wrap; gap: 10px; margin: 0; padding: 0; list-style: none; }
.tsp-chip { display: inline-flex; align-items: baseline; gap: 8px; padding: 8px 16px; border: 1px solid var(--tsp-line); border-radius: var(--radius-pill); background: var(--tsp-card); }
.tsp-chip__label { color: var(--tsp-sub); font-size: .78rem; font-weight: 500; }
.tsp-chip strong { color: var(--tsp-accent); font-size: 1rem; }
.tsp-toolbar__actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* Free run card */
.tsp-free {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px 20px;
  margin-bottom: 28px;
  padding: 18px 20px;
  border: 1px solid rgba(255, 122, 69, .45);
  border-radius: var(--radius-md);
  background: linear-gradient(110deg, rgba(255, 122, 69, .2), rgba(255, 122, 69, .03));
}
.tsp-free__info { display: flex; flex-direction: column; gap: 3px; flex: 1 1 280px; min-width: 0; }
.tsp-free__title { font-size: 1.1rem; font-weight: 700; }
.tsp-free__meta { color: var(--tsp-sub); font-size: .86rem; }
.tsp-free__meta span { color: var(--tsp-accent); font-weight: 600; }
.tsp-free__controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.tsp-durs { display: inline-flex; padding: 4px; border: 1px solid var(--tsp-line); border-radius: var(--radius-pill); background: rgba(0, 0, 0, .2); }
.tsp-dur {
  min-height: 36px;
  padding: 6px 14px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--tsp-sub);
  font: 600 .82rem/1 var(--font);
  cursor: pointer;
  transition: background-color .2s var(--ease), color .2s var(--ease);
}
.tsp-dur:hover { color: var(--tsp-text); }
.tsp-dur.is-on { background: var(--tsp-speed); color: #1a0b04; }

.tsp-subtitle { margin: 0 0 14px; font-size: 1rem; letter-spacing: .06em; text-transform: uppercase; color: var(--tsp-sub); }

.tsp-stages { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; margin: 0; padding: 0; list-style: none; }
.tsp-stage {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  height: 100%;
  padding: 18px;
  border: 1px solid var(--tsp-line);
  border-radius: var(--radius-md);
  background: var(--tsp-card);
  color: var(--tsp-text);
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
  transition: transform .2s var(--ease), background-color .2s var(--ease), border-color .2s var(--ease);
}
.tsp-stage:hover:not(:disabled) { transform: translateY(-3px); border-color: rgba(255, 122, 69, .6); background: var(--tsp-card-hover); }
.tsp-stage.is-cleared { border-color: rgba(62, 224, 161, .45); }
.tsp-stage.is-locked { cursor: not-allowed; opacity: .5; }
.tsp-stage__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.tsp-stage__num { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--tsp-accent); color: var(--night); font-size: 1.1rem; font-weight: 700; }
.tsp-stage.is-locked .tsp-stage__num { background: rgba(255, 255, 255, .14); color: var(--tsp-text); }
.tsp-stage__target { color: var(--tsp-sub); font-size: .78rem; font-weight: 600; }
.tsp-stage__target strong { color: var(--tsp-speed); font-size: 1.35rem; font-style: italic; font-weight: 800; }
.tsp-stage__body { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.tsp-stage__name { font-size: 1rem; font-weight: 700; line-height: 1.3; }
.tsp-stage__blurb { color: var(--tsp-sub); font-size: .82rem; line-height: 1.45; }
.tsp-stage__foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 10px; border-top: 1px solid var(--tsp-line); }
.tsp-stage__best { color: var(--tsp-sub); font-size: .78rem; font-weight: 600; }

.tsp-star { color: rgba(255, 255, 255, .22); font-size: 1.05rem; line-height: 1; }
.tsp-star.is-on { color: var(--tsp-accent); text-shadow: 0 0 12px rgba(255, 216, 77, .5); }
.tsp-noscript { margin: 16px 0 0; padding: 14px 18px; border-radius: var(--radius-sm); background: rgba(255, 92, 138, .15); }

/* ==========================================================================
   Play
   ========================================================================== */
.tsp-play { position: relative; max-width: 960px; margin: 0 auto; }
.tsp-hud { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.tsp-hud__info { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.tsp-hud__stage { padding: 6px 14px; border-radius: var(--radius-pill); background: var(--tsp-speed); color: #1a0b04; font-size: .8rem; font-weight: 700; }
.tsp-hud__goal { padding: 6px 14px; border: 1px solid var(--tsp-line); border-radius: var(--radius-pill); font-size: .8rem; font-weight: 600; }
.tsp-hud__actions { display: flex; align-items: center; gap: 8px; }

.tsp-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 10px; }
.tsp-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 6px;
  border: 1px solid var(--tsp-line);
  border-radius: var(--radius-sm);
  background: var(--tsp-card);
  line-height: 1.15;
}
.tsp-stat__label { color: var(--tsp-sub); font-size: .66rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; white-space: nowrap; }
.tsp-stat strong { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; transition: color .2s var(--ease); }
.tsp-stat.is-good strong { color: var(--tsp-good); }
.tsp-stat.is-bad strong { color: var(--tsp-bad); }
.tsp-stat--time strong { color: var(--tsp-accent); }
.tsp-stat--combo.is-hot strong { color: var(--tsp-speed); }
.tsp-stat--combo.is-hot strong::after { content: " 🔥"; font-size: .7em; }

.tsp-timebar { height: 5px; margin-bottom: 18px; overflow: hidden; border-radius: 5px; background: rgba(255, 255, 255, .1); }
.tsp-timebar span { display: block; height: 100%; background: linear-gradient(90deg, var(--tsp-speed), var(--tsp-accent)); transform-origin: left center; transition: transform .1s linear; }

/* Text box */
.tsp-box {
  --tsp-lh: 1.75;
  --tsp-fs: 1.45rem;
  position: relative;
  padding: 22px 26px;
  overflow: hidden;
  border: 1px solid var(--tsp-line);
  border-radius: var(--radius-md);
  background: rgba(5, 8, 20, .55);
  box-shadow: inset 0 2px 16px rgba(0, 0, 0, .35);
  cursor: text;
  transition: border-color .2s var(--ease);
}
.tsp-box:focus-within { border-color: rgba(255, 216, 77, .55); }
.tsp-box.is-shake { animation: tsp-shake .18s ease; }
@keyframes tsp-shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

.tsp-view { height: calc(var(--tsp-fs) * var(--tsp-lh) * 3); overflow: hidden; }
.tsp-scroll { position: relative; transition: transform .18s var(--ease); }
.tsp-text {
  font: 500 var(--tsp-fs)/var(--tsp-lh) var(--tsp-mono);
  white-space: pre-wrap;
  overflow-wrap: normal;
  word-break: normal;
  color: rgba(255, 255, 255, .42);
  -webkit-user-select: none;
  user-select: none;
}
.tsp-w { white-space: nowrap; }
.tsp-c { border-radius: 3px; transition: color .08s linear; }
.tsp-c.is-ok { color: #fff; }
.tsp-c.is-bad { color: var(--tsp-bad); background: rgba(255, 92, 122, .18); text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; }
.tsp-c--sp.is-bad { background: rgba(255, 92, 122, .45); }

.tsp-caret {
  position: absolute;
  top: 0;
  left: 0;
  width: 2px;
  height: 1.6rem;
  margin-left: -1px;
  border-radius: 2px;
  background: var(--tsp-accent);
  box-shadow: 0 0 10px rgba(255, 216, 77, .7);
  transition: transform .09s linear;
  animation: tsp-blink 1s steps(1) infinite;
}
.tsp-box:not(:focus-within) .tsp-caret { opacity: .35; animation: none; }
@keyframes tsp-blink { 50% { opacity: .2; } }

/* The real input covers the box (transparent), so a tap focuses it and opens the keyboard */
.tsp-input {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: transparent;
  caret-color: transparent;
  font-size: 16px;
  opacity: 0;
  cursor: text;
  -webkit-tap-highlight-color: transparent;
}

.tsp-focus-hint {
  position: absolute;
  left: 50%;
  bottom: 10px;
  z-index: 1;
  display: none;
  margin: 0;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  background: rgba(255, 216, 77, .95);
  color: var(--night);
  font-size: .8rem;
  font-weight: 700;
  transform: translateX(-50%);
  pointer-events: none;
}
.tsp-play.is-blurred:not(.is-done):not(.is-paused) .tsp-focus-hint { display: block; }

.tsp-count {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  background: rgba(10, 13, 28, .72);
  color: var(--tsp-accent);
  font: 800 4rem/1 var(--font);
  font-style: italic;
  pointer-events: none;
  animation: tsp-countin .75s var(--ease) infinite;
}
.tsp-count[hidden] { display: none; }
.tsp-count.is-go { color: var(--tsp-good); background: transparent; }
@keyframes tsp-countin {
  from { transform: scale(1.4); opacity: .3; }
  30%  { transform: scale(1); opacity: 1; }
}

.tsp-msg {
  position: absolute;
  top: 8px;
  left: 50%;
  z-index: 3;
  margin: 0;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  background: var(--tsp-bad);
  color: #fff;
  font-size: .8rem;
  font-weight: 700;
  white-space: nowrap;
  transform: translateX(-50%);
  pointer-events: none;
}
.tsp-msg[hidden] { display: none; }

.tsp-combo-pop {
  position: absolute;
  right: 16px;
  top: 10px;
  z-index: 3;
  color: var(--tsp-speed);
  font: 800 1.1rem/1 var(--font);
  font-style: italic;
  pointer-events: none;
  animation: tsp-pop 1s var(--ease) forwards;
}
@keyframes tsp-pop {
  from { opacity: 0; transform: translateY(10px) scale(.8); }
  20%  { opacity: 1; transform: none; }
  to   { opacity: 0; transform: translateY(-14px); }
}

.tsp-tip { margin: 12px 0 0; color: var(--tsp-sub); font-size: .82rem; text-align: center; }

/* Pause */
.tsp-play.is-paused .tsp-box { filter: blur(10px); pointer-events: none; }
.tsp-paused { position: absolute; inset: 0; z-index: 5; display: grid; place-items: start center; padding: 70px 16px 16px; }
.tsp-paused[hidden] { display: none; }
.tsp-paused__card { max-width: 380px; padding: 28px; border: 1px solid var(--tsp-line); border-radius: var(--radius-md); background: rgba(15, 20, 36, .96); box-shadow: 0 20px 50px rgba(0, 0, 0, .45); text-align: center; }
.tsp-paused__title { margin: 0 0 6px; font-size: 1.6rem; }
.tsp-paused__card p { margin: 0 0 20px; color: var(--tsp-sub); font-size: .9rem; }
.tsp-paused__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }

/* ==========================================================================
   Results
   ========================================================================== */
.tsp-result { max-width: 700px; margin: 0 auto; padding: 10px 0; text-align: center; }
.tsp-result__stars { display: flex; justify-content: center; gap: 10px; margin-bottom: 8px; }
.tsp-star--big { font-size: clamp(3rem, 9vw, 4.25rem); opacity: 0; animation: tsp-star-in .5s var(--ease) forwards; }
@keyframes tsp-star-in { from { opacity: 0; transform: scale(.3) rotate(-30deg); } to { opacity: 1; transform: none; } }
.tsp-result__title { outline: none; margin: 0 0 6px; font-size: clamp(1.8rem, 4vw, 2.5rem); font-style: italic; }
.tsp-result__new { display: inline-block; margin: 0 0 10px; padding: 4px 14px; border-radius: var(--radius-pill); background: var(--tsp-accent); color: var(--night); font-size: .8rem; font-weight: 700; }
.tsp-result__new[hidden] { display: none; }
.tsp-result__text { margin: 0 auto 24px; max-width: 480px; color: var(--tsp-sub); }
.tsp-result__stats { display: grid; grid-template-columns: 1.3fr repeat(4, minmax(0, 1fr)); gap: 10px; margin: 0 0 26px; }
.tsp-result__stats div { display: flex; flex-direction: column; justify-content: center; padding: 14px 8px; border: 1px solid var(--tsp-line); border-radius: var(--radius-sm); background: var(--tsp-card); }
.tsp-result__stats dt { color: var(--tsp-sub); font-size: .66rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.tsp-result__stats dd { margin: 2px 0 0; font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tsp-result__big { border-color: rgba(255, 122, 69, .6) !important; background: rgba(255, 122, 69, .14) !important; }
.tsp-result__big dd { color: var(--tsp-speed); font-size: 2.2rem; font-style: italic; font-weight: 800; }
.tsp-result__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.tsp-result__actions [hidden] { display: none; }

/* ==========================================================================
   How-to-play (site theme)
   ========================================================================== */
.tsp-guide { margin: 0 0 56px; }
.tsp-guide .section-head__title { margin-bottom: 22px; }
.tsp-guide__item { height: 100%; padding: 22px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow); }
.tsp-guide__item h3 { margin: 12px 0 6px; font-size: 1.05rem; }
.tsp-guide__item p { margin: 0; color: var(--sub); font-size: .9rem; }
.tsp-guide__num { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--brand); color: var(--onbrand); font-weight: 700; }
.tsp-guide__back { margin: 24px 0 0; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 767.98px) {
  .tsp { padding: 24px 20px; min-height: 0; }
  .tsp-result__stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tsp-result__big { grid-column: 1 / -1; }
  .tsp-box { --tsp-lh: 1.7; --tsp-fs: 1.2rem; padding: 16px; }
}

@media (max-width: 575.98px) {
  .tsp { margin-left: -4px; margin-right: -4px; padding: 20px 14px; border-radius: var(--radius-md); }
  .tsp-home__head { flex-direction: column; gap: 14px; }
  .tsp-toolbar { flex-direction: column; align-items: stretch; }
  .tsp-toolbar__actions .tsp-ghost { flex: 1; }
  .tsp-stages { grid-template-columns: 1fr; }
  .tsp-free { padding: 16px; }
  .tsp-free__controls, .tsp-durs { width: 100%; }
  .tsp-dur { flex: 1; padding: 6px 4px; }
  .tsp-free__go { width: 100%; }
  .tsp-hud { margin-bottom: 10px; }
  .tsp-stats { gap: 6px; }
  .tsp-stat { padding: 8px 2px; }
  .tsp-stat__label { font-size: .58rem; letter-spacing: .04em; }
  .tsp-stat strong { font-size: 1.2rem; }
  .tsp-timebar { margin-bottom: 12px; }
  .tsp-box { --tsp-lh: 1.65; --tsp-fs: 1.1rem; padding: 14px 12px; }
  .tsp-count { font-size: 3rem; }
  .tsp-paused { padding-top: 40px; }
  .tsp-paused__actions .btn-pill, .tsp-paused__actions .tsp-ghost { width: 100%; }
  .tsp::before { width: 260px; right: -90px; }
}

@media (prefers-reduced-motion: reduce) {
  .tsp::before, .tsp-keys span, .tsp-caret, .tsp-count, .tsp-screen, .tsp-combo-pop { animation: none; }
  .tsp-scroll, .tsp-caret, .tsp-timebar span { transition: none; }
  .tsp-star--big { opacity: 1; animation: none; }
}
