/* TypeVerse — components.css
   Buttons, segmented controls, language strip, leaderboard, history cards,
   results overlay, settings controls, heatmap keyboard, toast. */

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: var(--tap);
  padding: .55rem 1.15rem;
  border-radius: var(--radius-s);
  font-weight: 700;
  font-size: .9rem;
  border: 1px solid transparent;
  transition: background-color var(--speed) var(--ease),
              color var(--speed) var(--ease),
              transform var(--speed) var(--ease),
              border-color var(--speed) var(--ease);
}
.btn:active { transform: scale(.97); }
.btn--primary { background: var(--accent); color: var(--accent-contrast); }
.btn--primary:hover { filter: brightness(1.08); }
.btn--ghost {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}
.btn--ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled {
  opacity: .45;
  cursor: not-allowed;
  transform: none;
}

kbd {
  font-family: var(--font-mono);
  font-size: .75em;
  background: var(--kbd-bg);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: .1em .45em;
}

/* ---------- Mode badge ---------- */
.mode-badge {
  font-size: .62rem;
  font-weight: 800;
  letter-spacing: .14em;
  padding: .3rem .55rem;
  border-radius: 999px;
  background: var(--accent-tint);
  color: var(--accent);
  white-space: nowrap;
}

/* ---------- Segmented controls ---------- */
.seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: .3rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  padding: .3rem;
}
.seg--sub { background: transparent; border-color: transparent; padding: 0; }
.seg__btn {
  min-height: var(--tap);
  padding: .4rem .85rem;
  border-radius: var(--radius-s);
  font-weight: 600;
  font-size: .85rem;
  color: var(--ink-soft);
  transition: background-color var(--speed) var(--ease), color var(--speed) var(--ease);
}
.seg__btn:hover { color: var(--ink); }
.seg__btn.is-active { background: var(--accent); color: var(--accent-contrast); }
.seg--sub .seg__btn.is-active { background: var(--accent-tint); color: var(--accent); }

/* ---------- Language strip (13 items, scroll-snap on mobile) ---------- */
.lang-strip {
  display: flex;
  gap: .45rem;
  width: 100%;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  padding-bottom: .4rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.lang-strip::-webkit-scrollbar { height: 6px; }
.lang-strip::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }

.lang-btn {
  scroll-snap-align: start;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  min-height: var(--tap);
  padding: .45rem .95rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  font-family: var(--font-mono);
  font-size: .82rem;
  font-weight: 500;
  white-space: nowrap;
  transition: border-color var(--speed) var(--ease), color var(--speed) var(--ease),
              background-color var(--speed) var(--ease);
}
.lang-btn__dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--lang-accent, var(--accent));
}
.lang-btn:hover { color: var(--ink); border-color: var(--lang-accent, var(--accent)); }
.lang-btn.is-active {
  color: var(--ink);
  border-color: var(--lang-accent, var(--accent));
  background: color-mix(in srgb, var(--lang-accent, var(--accent)) 14%, var(--surface));
}

@media (min-width: 900px) {
  .lang-strip { flex-wrap: wrap; overflow-x: visible; justify-content: center; }
}

/* ---------- Custom text pill ---------- */
.custom-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .6rem;
  margin: 0 auto 1rem;
  width: fit-content;
  padding: .35rem .5rem .35rem .9rem;
  border-radius: 999px;
  background: var(--accent-tint);
  color: var(--accent);
  font-size: .8rem;
  font-weight: 700;
}
.custom-pill button {
  width: 30px; height: 30px;
  border-radius: 50%;
  color: var(--accent);
  font-size: 1.1rem;
  line-height: 1;
}
.custom-pill button:hover { background: var(--accent); color: var(--accent-contrast); }

/* ---------- Leaderboard ---------- */
.lb-table-wrap {
  margin-top: 1rem;
  overflow-x: auto; /* deliberate horizontal scroll for the table only */
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
}
.lb-table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: .9rem;
}
.lb-table th {
  text-align: left;
  font-size: .68rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  padding: .75rem .9rem;
  border-bottom: 1px solid var(--line);
}
.lb-table td {
  padding: .7rem .9rem;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.lb-table tr:last-child td { border-bottom: none; }
.lb-table .lb-wpm { font-family: var(--font-mono); font-weight: 700; color: var(--accent); }

.lb-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  border-radius: 50%;
  font-weight: 800;
  font-size: .8rem;
}
.lb-rank--1 { background: linear-gradient(135deg, #F5D06B, #C99A2C); color: #4A3708; }
.lb-rank--2 { background: linear-gradient(135deg, #DDE3EA, #9FA9B8); color: #333A45; }
.lb-rank--3 { background: linear-gradient(135deg, #E0A470, #A05F2C); color: #45260C; }

.lb-empty {
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--ink-soft);
}
.lb-empty__glyph { font-size: 2rem; display: block; margin-bottom: .5rem; }

/* Skeleton loading rows — toggled by JS while the board "loads" */
.skeleton-row {
  display: flex;
  gap: 1rem;
  padding: .85rem .9rem;
  border-bottom: 1px solid var(--line);
}
.skeleton-row:last-child { border-bottom: none; }
.skeleton-bar {
  height: 14px;
  border-radius: 7px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.1s linear infinite;
}
.skeleton-bar--rank { width: 30px; }
.skeleton-bar--name { flex: 1; }
.skeleton-bar--num { width: 60px; }

/* ---------- History ---------- */
.trend-line {
  font-size: .88rem;
  color: var(--ink-soft);
  margin-bottom: 1rem;
}
.trend-line strong { color: var(--accent); }
.trend-up { color: #2E8B57; font-weight: 700; }
.trend-down { color: var(--error); font-weight: 700; }

.history-cards {
  display: grid;
  gap: .7rem;
  grid-template-columns: 1fr;
}
@media (min-width: 640px) { .history-cards { grid-template-columns: 1fr 1fr; } }

.history-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: .35rem .9rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  padding: .85rem 1rem;
}
.history-card__wpm {
  grid-row: span 2;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.5rem;
  color: var(--accent);
}
.history-card__wpm small { display: block; font-size: .6rem; color: var(--ink-soft); letter-spacing: .1em; }
.history-card__meta { font-size: .8rem; color: var(--ink-soft); }
.history-card__badge {
  justify-self: start;
  font-size: .62rem;
  font-weight: 800;
  letter-spacing: .1em;
  padding: .18rem .5rem;
  border-radius: 999px;
  background: var(--accent-tint);
  color: var(--accent);
}
.history-card__spark { grid-row: span 2; }
.history-empty {
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius-m);
}

.export-group { display: flex; flex-wrap: wrap; gap: .45rem; position: relative; }
.export-group .btn { position: relative; }
/* tooltip on disabled export buttons */
.export-group .btn:disabled:hover::after,
.export-group .btn:disabled:focus-visible::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  font-size: .7rem;
  font-weight: 600;
  padding: .3rem .6rem;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 5;
}

/* ---------- Overlay & results ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.overlay__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 8, 14, .55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.overlay__close {
  position: absolute;
  top: .6rem; right: .6rem;
  width: var(--tap); height: var(--tap);
  border-radius: 50%;
  font-size: 1.4rem;
  color: var(--ink-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.overlay__close:hover { color: var(--ink); background: var(--accent-tint); }

.results-card {
  position: relative;
  width: min(100%, 640px);
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  padding: 1.6rem clamp(1rem, 4vw, 2rem) 1.6rem;
  box-shadow: var(--shadow);
  animation: results-pop 380ms var(--ease) both;
}

.results-card__context {
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-soft);
  text-align: center;
  margin-bottom: .6rem;
}

.results-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .35rem;
  margin-bottom: .6rem;
}
.results-wpm {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: clamp(3rem, 10vw, 4.4rem);
  line-height: 1;
  color: var(--accent);
  display: flex;
  align-items: baseline;
  gap: .4rem;
}
.results-wpm small { font-size: 1rem; color: var(--ink-soft); }
.results-rating {
  font-weight: 800;
  font-size: 1.05rem;
  padding: .3rem .95rem;
  border-radius: 999px;
  background: var(--accent-tint);
  color: var(--accent);
}
/* Reserved exclusively for >150 WPM */
.results-rating--god {
  background: linear-gradient(100deg, #8a6a12, var(--gold) 30%, #fff3c9 50%, var(--gold) 70%, #8a6a12);
  background-size: 220% 100%;
  color: #3A2C05;
  animation: gold-shimmer 2.2s linear infinite;
}

.pb-line {
  text-align: center;
  font-size: .88rem;
  color: var(--ink-soft);
  margin-bottom: 1rem;
  min-height: 1.3em;
}
.pb-line.is-newbest {
  color: var(--gold);
  font-weight: 800;
  font-size: 1rem;
  animation: pb-bounce 700ms var(--ease);
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: .5rem;
  margin-bottom: 1.2rem;
}
.results-cell {
  background: var(--surface-2);
  border-radius: var(--radius-s);
  padding: .6rem .4rem;
  text-align: center;
}
.results-cell span {
  display: block;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink);
}
.results-cell small { font-size: .65rem; color: var(--ink-soft); letter-spacing: .08em; text-transform: uppercase; }

.results-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .5rem;
  margin-top: 1.1rem;
}
.save-form {
  display: flex;
  gap: .5rem;
  margin-top: .8rem;
  justify-content: center;
  flex-wrap: wrap;
}
.save-form input[type="text"] {
  flex: 1;
  min-width: 160px;
  max-width: 260px;
  min-height: var(--tap);
  padding: .45rem .8rem;
  border-radius: var(--radius-s);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
}
.save-form input[type="text"]:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }

/* ---------- Keyboard heatmap (Results) & finger diagram (Tips) ---------- */
.heatmap, .finger-diagram {
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: center;
  margin-top: .6rem;
  user-select: none;
}
.kb-row { display: flex; gap: 5px; justify-content: center; width: 100%; }
.kb-key {
  position: relative;
  flex: 1 1 0;
  max-width: 46px;
  aspect-ratio: 1 / 0.9;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: clamp(.55rem, 2vw, .78rem);
  color: var(--ink-soft);
  transition: background-color var(--speed) var(--ease);
}
.kb-key--wide { max-width: 90px; flex-grow: 2; }
.kb-key--space { max-width: 240px; flex-grow: 6; }

/* real-keyboard bottom row (heatmap + finger diagram): modifiers + blank spacebar */
.kb-key--mod {
  max-width: 62px;
  flex-grow: 1.4;
  font-size: .6rem;
  text-transform: lowercase;
  color: var(--ink-soft);
}
.kb-key--spacebar {
  max-width: none;
  flex-grow: 7;
  aspect-ratio: auto;
  height: auto;
  align-self: stretch;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom-width: 3px;   /* keycap depth, like a real spacebar */
  border-radius: 6px;
}

/* error-frequency tiers set by heatmap.js */
.kb-key--heat1 { background: #F2D06B; border-color: #D9B23C; color: #4A3708; }
.kb-key--heat2 { background: #EFA14E; border-color: #D07E22; color: #45260C; }
.kb-key--heat3 { background: #E36B44; border-color: #B94A26; color: #fff; }
.kb-key--heat4 { background: #C03221; border-color: #8F2013; color: #fff; }

.kb-key[data-count]:hover::after {
  content: attr(data-count) " errors";
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  font-size: .66rem;
  padding: .2rem .5rem;
  border-radius: 5px;
  white-space: nowrap;
  z-index: 5;
  pointer-events: none;
}

.weak-keys {
  text-align: center;
  font-size: .84rem;
  color: var(--ink-soft);
  margin-top: .7rem;
  min-height: 1.2em;
}
.weak-keys strong { color: var(--error); font-family: var(--font-mono); }

/* finger diagram extras (tips.css adds finger colors) */

/* ---------- Settings controls ---------- */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .8rem .2rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.setting-row--stack { border-bottom: none; padding-bottom: .3rem; }
.setting-row__text strong { display: block; font-size: .95rem; }
.setting-row__text small { color: var(--ink-soft); font-size: .78rem; }

.switch {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  width: 48px; height: 28px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  position: relative;
  cursor: pointer;
  transition: background-color var(--speed) var(--ease);
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--ink-soft);
  transition: transform var(--speed) var(--ease), background-color var(--speed) var(--ease);
}
.switch:checked { background: var(--accent); border-color: var(--accent); }
.switch:checked::after { transform: translateX(20px); background: #fff; }
.switch:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

.setting-block { padding-top: .8rem; }
.setting-block textarea {
  width: 100%;
  border-radius: var(--radius-s);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  padding: .6rem .75rem;
  font-family: var(--font-mono);
  font-size: .82rem;
  resize: vertical;
  margin-block: .5rem;
}
.setting-block__row { display: flex; gap: .5rem; }
.settings-shortcuts {
  margin-top: auto;
  padding-top: 1.2rem;
  font-size: .74rem;
  color: var(--ink-soft);
  line-height: 2.1;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 1.4rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  background: var(--ink);
  color: var(--bg);
  font-weight: 700;
  font-size: .85rem;
  padding: .6rem 1.2rem;
  border-radius: 999px;
  box-shadow: var(--shadow);
  animation: toast-in 240ms var(--ease);
}
