/* Skill Games page. Reuses taiPie.css's color variables and card/button
   styles (:root, .taitype-stage-card, .taitype-btn-primary, .taitype-tabs,
   .taitype-kicker) so this page stays visually consistent with the rest of
   taiPie -- this file only adds game-hub and per-game layout. */

/* Several elements below (the results modal, HUD pills, the Key Zap
   target) are shown/hidden via the plain HTML `hidden` attribute, but also
   declare their own `display` (flex/inline-flex) for when they're visible.
   Author-stylesheet rules beat the browser's built-in `[hidden] { display:
   none }` rule at equal specificity, which was silently overriding `hidden`
   entirely -- e.g. the results modal backdrop rendered as an empty white
   box on top of the page from the moment it loaded, instead of staying
   invisible until a game actually finished. This single rule guarantees
   `hidden` always wins, however any element on this page is styled. */
[hidden] {
  display: none !important;
}

/* Same fix as typing-tips.css: taiPie.css's `.taitype-app.container` rule
   forces a 1760px width with `!important` for the wide practice-tutor
   layout. This page needs the site's standard 1200px content width like
   every other page -- matching its specificity pattern plus `!important`
   is the only reliable way to win against it. */
.taitype-app.container.games-app {
  width: min(1200px, calc(100vw - 36px)) !important;
  max-width: 1200px !important;
  margin-left: auto !important;
  margin-right: auto !important;
  padding-left: 0 !important;
  padding-right: 0 !important;
}

.games-card {
  padding: 1.6rem 1.6rem 2rem;
  text-align: center;
}

.games-title {
  margin: 0.5rem 0 0.4rem;
  font-size: clamp(1.8rem, 3.4vw, 2.6rem);
  letter-spacing: -0.04em;
  color: var(--taitype-primary-strong);
}

.games-intro {
  max-width: 640px;
  margin: 0 auto 1.8rem;
  color: var(--taitype-muted);
  font-size: 0.94rem;
  line-height: 1.55;
}

/* ---------------------------------------------------------------------
   Game hub
--------------------------------------------------------------------- */

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.4rem;
  text-align: left;
}

.game-card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 1.4rem 1.3rem 1.5rem;
  border-radius: 22px;
  border: 1px solid var(--taitype-border);
  background: var(--taitype-surface-soft);
}

.game-card-new-badge {
  position: absolute;
  top: 14px;
  right: 14px;
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--taitype-primary), var(--taitype-zahra));
  color: #fff;
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.game-card-icon {
  width: 62px;
  height: 62px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-size: 1.6rem;
  margin-bottom: 0.9rem;
}

.game-card-icon.tone-a { background: rgba(0, 150, 136, 0.14); color: #00695c; }
.game-card-icon.tone-b { background: rgba(230, 84, 76, 0.14); color: #c23b30; }
.game-card-icon.tone-c { background: rgba(255, 152, 0, 0.16); color: #b8790a; }
.game-card-icon.tone-d { background: rgba(142, 92, 219, 0.16); color: #6d3fbf; }
.game-card-icon.tone-e { background: rgba(91, 107, 214, 0.16); color: #4b58b8; }
.game-card-icon.tone-f { background: rgba(96, 125, 139, 0.16); color: #45606b; }
.game-card-icon.tone-g { background: rgba(3, 169, 244, 0.16); color: #0277a3; }

body.dark .game-card-icon.tone-a { background: rgba(39, 193, 180, 0.18); color: #6fe9db; }
body.dark .game-card-icon.tone-b { background: rgba(255, 138, 128, 0.2); color: #ff9a8f; }
body.dark .game-card-icon.tone-c { background: rgba(255, 179, 0, 0.2); color: #ffcf5c; }
body.dark .game-card-icon.tone-d { background: rgba(178, 140, 255, 0.22); color: #cbb3ff; }
body.dark .game-card-icon.tone-e { background: rgba(120, 134, 235, 0.22); color: #b7c0f7; }
body.dark .game-card-icon.tone-f { background: rgba(144, 175, 188, 0.22); color: #b7d4de; }
body.dark .game-card-icon.tone-g { background: rgba(79, 195, 247, 0.22); color: #9adcfb; }

.game-card h2 {
  margin: 0 0 0.4rem;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
  color: var(--taitype-primary-strong);
}

.game-card p {
  margin: 0 0 1rem;
  font-size: 0.86rem;
  line-height: 1.5;
  color: var(--taitype-muted);
  flex: 1;
}

.game-card-meta {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 1.1rem;
  font-size: 0.78rem;
  color: var(--taitype-muted);
}

.game-card-meta i {
  width: 16px;
  color: var(--taitype-zahra);
}

.game-card-meta strong {
  color: var(--taitype-primary-strong);
}

.game-play-btn {
  width: 100%;
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

/* ---------------------------------------------------------------------
   Shared game stage shell
--------------------------------------------------------------------- */

.game-stage {
  text-align: left;
}

.game-stage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.game-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid var(--taitype-border);
  background: var(--taitype-surface-soft);
  color: var(--taitype-primary);
  font-weight: 800;
  font-size: 0.82rem;
  padding: 0.55rem 0.9rem;
  border-radius: 12px;
  cursor: pointer;
}

.game-back-btn:hover {
  color: var(--taitype-primary-strong);
}

.game-hud {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.hud-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  background: var(--taitype-surface-soft);
  border: 1px solid var(--taitype-border);
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--taitype-primary-strong);
}

.hud-pill i {
  color: var(--taitype-zahra);
}

.hud-pill.hud-lives i {
  color: #e6544c;
}

.hud-pill.hud-combo {
  background: rgba(255, 152, 0, 0.14);
  border-color: rgba(255, 152, 0, 0.3);
  color: #b8790a;
}

body.dark .hud-pill.hud-combo {
  background: rgba(255, 179, 0, 0.16);
  color: #ffcf5c;
}

.game-surface {
  position: relative;
  min-height: 460px;
  border-radius: 22px;
  border: 1px solid var(--taitype-border);
  background: var(--taitype-surface);
  overflow: hidden;
}

/* ---------------------------------------------------------------------
   Pre-round "get ready" overlay, shared by all three games
--------------------------------------------------------------------- */

.game-ready {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  text-align: center;
  padding: 1.5rem;
  background: var(--taitype-surface);
  z-index: 5;
}

.game-ready h3 {
  margin: 0;
  font-size: 1.3rem;
  color: var(--taitype-primary-strong);
}

.game-ready p {
  margin: 0;
  max-width: 420px;
  color: var(--taitype-muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

/* ---------------------------------------------------------------------
   Word Rush
--------------------------------------------------------------------- */

.wordrush-surface {
  position: relative;
  height: 460px;
  background:
    linear-gradient(180deg, rgba(0, 150, 136, 0.05), transparent 40%),
    var(--taitype-surface);
}

.wordrush-groundline {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 68px;
  height: 1px;
  background: repeating-linear-gradient(90deg, var(--taitype-border) 0 10px, transparent 10px 20px);
}

.falling-word {
  position: absolute;
  top: 0;
  transform: translateY(0);
  padding: 0.3rem 0.65rem;
  border-radius: 10px;
  background: var(--taitype-surface-soft);
  border: 1px solid var(--taitype-border);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--taitype-text);
  white-space: nowrap;
  will-change: transform;
}

.falling-word .matched-part {
  color: var(--taitype-zahra);
}

.falling-word.is-targeting {
  border-color: var(--taitype-zahra);
  box-shadow: 0 0 0 2px rgba(0, 150, 136, 0.18);
}

.falling-word.is-hit {
  animation: wordrush-pop 0.22s ease forwards;
}

.falling-word.is-landed {
  animation: wordrush-land 0.28s ease forwards;
}

@keyframes wordrush-pop {
  to { transform: scale(1.4); opacity: 0; }
}

@keyframes wordrush-land {
  to { transform: translateY(0) scale(0.9); opacity: 0; }
}

.wordrush-input-row {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.8rem 0.9rem;
  background: var(--taitype-surface-soft);
  border-top: 1px solid var(--taitype-border);
}

.wordrush-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--taitype-border);
  border-radius: 12px;
  background: var(--taitype-surface);
  color: var(--taitype-text);
  font-size: 1rem;
  font-weight: 700;
  padding: 0.6rem 0.8rem;
  outline: none;
}

.wordrush-input:focus {
  border-color: var(--taitype-zahra);
}

/* ---------------------------------------------------------------------
   Key Zap
--------------------------------------------------------------------- */

.zap-surface {
  height: 460px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.4rem;
  padding: 1.5rem;
}

.zap-stage-label {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--taitype-zahra);
}

.zap-target {
  min-width: 220px;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 24px;
  background: var(--taitype-surface-soft);
  border: 2px solid var(--taitype-border);
  font-size: 3.2rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--taitype-primary-strong);
  padding: 0.5rem 1.6rem;
  transition: border-color 0.12s ease;
}

.zap-target.is-correct {
  border-color: #0a8a5c;
  color: #0a8a5c;
}

.zap-target.is-wrong {
  border-color: #c94141;
  color: #c94141;
  animation: zap-shake 0.24s ease;
}

@keyframes zap-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.zap-timer-track {
  width: min(360px, 80%);
  height: 10px;
  border-radius: 999px;
  background: var(--taitype-border);
  overflow: hidden;
}

.zap-timer-bar {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--taitype-zahra), var(--taitype-primary));
  transform-origin: left center;
}

.zap-hint {
  font-size: 0.8rem;
  color: var(--taitype-muted);
  text-align: center;
}

/* ---------------------------------------------------------------------
   Speed Sprint
--------------------------------------------------------------------- */

.sprint-surface {
  min-height: 460px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1.4rem;
  padding: 2rem 1.8rem;
}

.sprint-stats-row {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.sprint-passage-wrap {
  position: relative;
  padding: 1.4rem 1.5rem;
  border-radius: 18px;
  background: var(--taitype-surface-soft);
  border: 1px solid var(--taitype-border);
  font-size: 1.3rem;
  line-height: 1.9;
  letter-spacing: 0.01em;
  font-family: "Courier New", Courier, monospace;
}

.sprint-passage-wrap span {
  color: var(--taitype-muted);
  opacity: 0.55;
  position: relative;
}

.sprint-passage-wrap span.is-correct {
  color: var(--taitype-primary-strong);
  opacity: 1;
}

.sprint-passage-wrap span.is-incorrect {
  color: #ffffff;
  background: #c94141;
  opacity: 1;
  border-radius: 3px;
}

.sprint-passage-wrap span.is-active {
  border-bottom: 2px solid var(--taitype-zahra);
}

.sprint-ghost-marker {
  position: absolute;
  top: -6px;
  width: 2px;
  height: calc(100% + 12px);
  background: rgba(255, 152, 0, 0.55);
  pointer-events: none;
  transition: left 0.08s linear;
}

.sprint-ghost-marker::before {
  content: "ghost";
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #b8790a;
  white-space: nowrap;
}

.sprint-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  height: 1px;
  width: 1px;
}

.sprint-hint {
  text-align: center;
  font-size: 0.8rem;
  color: var(--taitype-muted);
}

/* ---------------------------------------------------------------------
   Boss Battle
--------------------------------------------------------------------- */

.boss-surface {
  min-height: 460px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1.4rem;
  padding: 2rem 1.8rem;
}

.boss-panel {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.boss-avatar-row {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.boss-avatar {
  width: 58px;
  height: 58px;
  flex-shrink: 0;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-size: 1.7rem;
  background: rgba(230, 84, 76, 0.14);
  color: #c23b30;
  transition: transform 0.18s ease;
}

body.dark .boss-avatar {
  background: rgba(255, 138, 128, 0.18);
  color: #ff9a8f;
}

.boss-avatar.is-hit {
  animation: zap-shake 0.24s ease;
}

.boss-info {
  flex: 1;
  min-width: 0;
}

.boss-name {
  display: block;
  font-weight: 800;
  font-size: 0.98rem;
  color: var(--taitype-primary-strong);
  margin-bottom: 0.3rem;
}

.boss-hp-track {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: var(--taitype-border);
  overflow: hidden;
}

.boss-hp-bar {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #e6544c, #c23b30);
  transition: width 0.22s ease;
}

.boss-attack-track {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--taitype-border);
  overflow: hidden;
}

.boss-attack-bar {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffb84d, #e6544c);
  transform-origin: left center;
}

.boss-word-target {
  align-self: center;
  min-width: 240px;
  text-align: center;
  padding: 0.9rem 1.8rem;
  border-radius: 20px;
  background: var(--taitype-surface-soft);
  border: 2px solid var(--taitype-border);
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--taitype-primary-strong);
}

.boss-word-target.is-targeting {
  border-color: var(--taitype-zahra);
  box-shadow: 0 0 0 2px rgba(0, 150, 136, 0.18);
}

.boss-input {
  align-self: center;
  width: min(360px, 100%);
  border: 1px solid var(--taitype-border);
  border-radius: 12px;
  background: var(--taitype-surface);
  color: var(--taitype-text);
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  padding: 0.6rem 0.8rem;
  outline: none;
}

.boss-input:focus {
  border-color: var(--taitype-zahra);
}

.player-hp-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--taitype-primary-strong);
}

.player-hp-row i {
  color: #0a8a5c;
}

.player-hp-track {
  flex: 1;
  height: 10px;
  border-radius: 999px;
  background: var(--taitype-border);
  overflow: hidden;
}

.player-hp-bar {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #21a679, #0a8a5c);
  transition: width 0.22s ease;
}

.game-surface.is-player-hit {
  animation: boss-player-hit-flash 0.3s ease;
}

@keyframes boss-player-hit-flash {
  0%, 100% { box-shadow: none; }
  30% { box-shadow: inset 0 0 0 4px rgba(230, 84, 76, 0.55); }
}

/* ---------------------------------------------------------------------
   Memory Chain
--------------------------------------------------------------------- */

.memory-surface {
  min-height: 460px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
  padding: 1.5rem;
  text-align: center;
}

.memory-phase-label {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--taitype-zahra);
}

.memory-word-display {
  min-width: 260px;
  min-height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1.6rem;
  border-radius: 24px;
  background: var(--taitype-surface-soft);
  border: 2px solid var(--taitype-border);
  font-size: 2.6rem;
  font-weight: 800;
  color: var(--taitype-primary-strong);
}

.memory-progress-dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
  max-width: 420px;
}

.memory-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--taitype-border);
}

.memory-input-row {
  width: min(480px, 100%);
  display: flex;
  gap: 0.6rem;
}

.memory-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--taitype-border);
  border-radius: 12px;
  background: var(--taitype-surface);
  color: var(--taitype-text);
  font-size: 1rem;
  font-weight: 700;
  padding: 0.6rem 0.8rem;
  outline: none;
}

.memory-input:focus {
  border-color: var(--taitype-zahra);
}

.memory-input.is-wrong {
  animation: zap-shake 0.24s ease;
  border-color: #c94141;
}

/* ---------------------------------------------------------------------
   Iron Mode
--------------------------------------------------------------------- */

.iron-passage-wrap {
  border-color: rgba(230, 84, 76, 0.35) !important;
  box-shadow: 0 0 0 3px rgba(230, 84, 76, 0.08);
}

.iron-warning {
  text-align: center;
  font-size: 0.8rem;
  font-weight: 800;
  color: #c23b30;
}

body.dark .iron-warning {
  color: #ff9a8f;
}

/* ---------------------------------------------------------------------
   Typing Race
--------------------------------------------------------------------- */

.race-track {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.race-lane {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.race-lane-label {
  width: 64px;
  flex-shrink: 0;
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--taitype-muted);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.race-lane-track {
  position: relative;
  flex: 1;
  height: 40px;
  border-radius: 12px;
  background: var(--taitype-surface-soft);
  border: 1px solid var(--taitype-border);
  overflow: hidden;
}

.race-finish-flag {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--taitype-zahra);
  font-size: 1rem;
}

.race-runner {
  position: absolute;
  top: 50%;
  left: calc(0% - 14px);
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--taitype-zahra);
  color: #fff;
  font-size: 0.85rem;
  transition: left 0.12s linear;
  z-index: 2;
}

.race-runner.is-bot {
  background: #6d3fbf;
}

/* ---------------------------------------------------------------------
   Results modal
--------------------------------------------------------------------- */

.game-modal-backdrop {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(9, 19, 27, 0.55);
  backdrop-filter: blur(6px);
  z-index: 4000;
}

.game-modal {
  width: min(420px, 100%);
  border-radius: 26px;
  background: var(--taitype-surface);
  border: 1px solid var(--taitype-border);
  box-shadow: var(--taitype-shadow);
  padding: 1.8rem 1.6rem;
  text-align: center;
}

.game-modal-kicker {
  display: inline-flex;
  padding: 0.32rem 0.7rem;
  border-radius: 999px;
  background: rgba(0, 150, 136, 0.14);
  color: var(--taitype-zahra);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.7rem;
}

.game-modal h2 {
  margin: 0 0 0.9rem;
  font-size: 1.5rem;
  color: var(--taitype-primary-strong);
}

.game-modal-grade {
  width: 84px;
  height: 84px;
  margin: 0 auto 1rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 2.1rem;
  font-weight: 900;
  background: linear-gradient(135deg, var(--taitype-primary), var(--taitype-zahra));
  color: #fff;
}

.game-modal-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
  margin-bottom: 1.2rem;
}

.game-modal-stat {
  padding: 0.7rem;
  border-radius: 14px;
  background: var(--taitype-surface-soft);
  border: 1px solid var(--taitype-border);
}

.game-modal-stat span {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--taitype-muted);
  margin-bottom: 0.25rem;
}

.game-modal-stat strong {
  font-size: 1.15rem;
  color: var(--taitype-primary-strong);
}

.game-modal-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 1.1rem;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  background: rgba(255, 152, 0, 0.16);
  color: #b8790a;
  font-size: 0.78rem;
  font-weight: 800;
}

body.dark .game-modal-badge {
  background: rgba(255, 179, 0, 0.2);
  color: #ffcf5c;
}

.game-modal-actions {
  display: flex;
  gap: 0.6rem;
}

@media (max-width: 760px) {
  .games-card {
    padding: 1.1rem 0.9rem 1.4rem;
  }

  .games-grid {
    grid-template-columns: 1fr;
  }

  .game-surface,
  .wordrush-surface,
  .zap-surface {
    height: 420px;
    min-height: 420px;
  }

  .zap-target {
    font-size: 2.3rem;
    min-width: 170px;
    min-height: 96px;
  }

  .sprint-passage-wrap {
    font-size: 1.05rem;
    line-height: 1.75;
  }

  .game-modal-stats {
    grid-template-columns: 1fr;
  }
}
