/* ui-components.css — Shared casual-game component baseline.
 * Built on ui-tokens.css. This is the class vocabulary every studio game
 * converges on, so a player moving between titles meets the same buttons,
 * cards, modal and toast. Drop it in after ui-tokens.css.
 */

/* ============================ Top bar ============================ */
.topbar {
  position: sticky; top: 0; z-index: var(--z-nav);
  display: flex; align-items: center; gap: var(--sp-3);
  padding: max(var(--sp-3), env(safe-area-inset-top))
           max(var(--sp-4), env(safe-area-inset-right))
           var(--sp-3)
           max(var(--sp-4), env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.2) blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar .brand {
  font-weight: 800; font-size: var(--fs-5); text-decoration: none;
  color: var(--ink); display: flex; align-items: center; gap: var(--sp-2);
  white-space: nowrap;
}
.topbar .spacer { margin-left: auto; }
.topbar .links { display: flex; gap: var(--sp-1); align-items: center; }

/* ============================ Buttons ============================ */
.btn {
  font: 600 var(--fs-3) / 1 inherit; color: var(--ink);
  min-height: var(--tap); padding: 0 var(--sp-4);
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: linear-gradient(180deg, #ffffff 0%, #f7f3ec 100%);
  box-shadow: var(--sh-card), var(--sh-inset);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur) var(--ease),
              border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.btn:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-1px); box-shadow: var(--sh-hover), var(--sh-inset); }
.btn:active:not(:disabled) { transform: translateY(0) scale(0.97); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-ghost { background: transparent; box-shadow: none; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: color-mix(in srgb, var(--panel) 60%, transparent); }

/* ========================== Icon button ========================== */
/* Square 44px control for bars (pause, mute, language, boosters). */
.icon-btn {
  width: var(--tap); height: var(--tap); padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--panel); color: var(--muted);
  box-shadow: var(--sh-card); cursor: pointer; position: relative;
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.icon-btn:hover:not(:disabled) { background: #f7f3ec; border-color: var(--accent); transform: translateY(-1px); }
.icon-btn:active:not(:disabled) { transform: translateY(0) scale(0.96); }
.icon-btn.on, .icon-btn.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn .fill { fill: currentColor; stroke: none; }

/* Count badge sitting on an icon button's corner. */
.badge-count {
  position: absolute; top: -5px; right: -5px; min-width: 16px; height: 16px; padding: 0 4px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; line-height: 1; color: #fff; background: var(--accent);
  border: 1.5px solid var(--panel); border-radius: var(--r-pill); pointer-events: none;
}

/* ===================== Segmented control ========================= */
.seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: var(--r-pill);
       background: var(--panel); border: 1px solid var(--line);
       box-shadow: var(--sh-card), var(--sh-inset); }
.seg-item { border: 0; background: transparent; color: var(--muted);
            min-height: 36px; min-width: 36px; padding: 0 var(--sp-3);
            border-radius: var(--r-pill); cursor: pointer; font: 600 var(--fs-2) / 1 inherit;
            display: inline-flex; align-items: center; justify-content: center; }
.seg-item.on { background: var(--accent); color: var(--accent-ink); box-shadow: var(--sh-float); }

/* ============================ Panel ============================= */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg);
         padding: var(--sp-4); box-shadow: var(--sh-card), var(--sh-inset); }
.panel > h2, .panel > h3 { margin: 0 0 var(--sp-3); }

/* ========================= Score box ============================ */
.score-box {
  position: relative; background: linear-gradient(135deg, #ffffff 0%, #fbf8f2 100%);
  border: 1px solid var(--line); border-left: 5px solid var(--accent);
  border-radius: var(--r-md); padding: var(--sp-3) var(--sp-4);
  box-shadow: var(--sh-card), var(--sh-inset); display: flex; flex-direction: column;
}
.score-box .label { font-size: var(--fs-0); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.score-box .value { font-size: var(--fs-6); font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

/* ========================= Modal / sheet ======================= */
.modal {
  position: fixed; inset: 0; z-index: var(--z-modal);
  display: flex; align-items: center; justify-content: center;
  padding: max(var(--sp-5), env(safe-area-inset-top)) var(--sp-5) max(var(--sp-5), env(safe-area-inset-bottom));
  background: rgba(48, 42, 32, 0.55); backdrop-filter: blur(4px);
  animation: modalBgIn var(--dur) var(--ease) both;
}
.modal[hidden] { display: none; }
.sheet {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-xl);
  padding: var(--sp-5); max-width: 420px; width: 100%; max-height: 90vh; overflow: auto;
  box-shadow: var(--sh-deep); animation: sheetIn var(--dur) var(--ease) both;
}
.sheet h2 { margin: 0 0 var(--sp-4); font-size: var(--fs-6); }
@keyframes modalBgIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheetIn { from { opacity: 0; transform: translateY(16px) scale(0.96); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* ============================ Toast ============================= */
.toasts {
  position: fixed; left: 50%; bottom: max(var(--sp-5), env(safe-area-inset-bottom));
  transform: translateX(-50%); display: grid; gap: var(--sp-2);
  z-index: var(--z-toast); pointer-events: none; width: max-content; max-width: 92vw;
}
.toast {
  background: color-mix(in srgb, var(--ink) 92%, transparent); color: #fff;
  border-radius: var(--r-pill); padding: var(--sp-3) var(--sp-5);
  font-size: var(--fs-2); font-weight: 700; box-shadow: var(--sh-deep);
  animation: toastRise var(--dur) var(--ease) both;
}
.toast.out { animation: toastFade var(--dur-slow) var(--ease) both; }
@keyframes toastRise { from { opacity: 0; transform: translateY(12px) scale(0.96); } }
@keyframes toastFade { to { opacity: 0; transform: translateY(-6px) scale(0.98); } }

/* ===================== State placeholders ======================= */
/* loading / empty / error — every async surface (leaderboard, share
 * card, level load) should render one of these instead of a blank box. */
.state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp-3); padding: var(--sp-6); text-align: center; color: var(--muted);
}
.state.error { color: var(--danger); }
.state .state-title { font: 700 var(--fs-4) / 1.3 inherit; color: var(--ink); }
.spinner {
  width: 28px; height: 28px; border: 3px solid var(--line);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===================== Leaderboard / ranking ===================== */
/* One ranking look across every studio game. Engine-agnostic: style your
 * <ol>/<ul> of .lb-row items and they read identically everywhere. The theme
 * hue comes from --accent, so the SHAPE is studio-wide consistent while each
 * game keeps its own color. */
.leaderboard {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  box-shadow: var(--sh-card), var(--sh-inset);
}
.leaderboard > .lb-head {
  font-size: var(--fs-0); letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); margin: 0 0 var(--sp-3); font-weight: 700;
}
.lb-list { list-style: none; margin: 0; padding: 0; }
.lb-row {
  display: flex; align-items: baseline; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-top: 1px solid var(--line);
  font-size: var(--fs-2);
}
.lb-row:first-child { border-top: 0; }
.lb-rank {
  min-width: 2.4em; flex: none; text-align: right;
  font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 700;
}
.lb-name {
  flex: 1 1 auto; min-width: 0; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lb-meta { flex: none; color: var(--muted); font-size: var(--fs-0); }
.lb-score { flex: none; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--ink); }
.lb-row.top1 .lb-rank, .lb-row.top2 .lb-rank, .lb-row.top3 .lb-rank { color: var(--accent); }
.lb-row.me { background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: var(--r-sm); }
.lb-row.me .lb-rank { color: var(--accent); }
.lb-row.me .lb-name, .lb-row.me .lb-score { font-weight: 800; }
.lb-row.empty, .lb-empty { color: var(--muted); font-style: italic; justify-content: center; }

/* ===================== Button size helpers ===================== */
.btn-block { display: flex; width: 100%; }
.btn-sm { min-height: 36px; padding: 0 var(--sp-3); font-size: var(--fs-2); }
.btn-lg { min-height: var(--tap-lg, 48px); padding: 0 var(--sp-5); font-size: var(--fs-4); }
.btn-row { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.btn-row.end { justify-content: flex-end; }
.btn-row.center { justify-content: center; }
