<script lang="ts">
  import type { Snippet } from 'svelte';
  // The bottom tab bar: square borderless buttons, evenly distributed, mobile-OS feel.
  // Direct children (plain `.tab` buttons or TapConfirm wrappers) share the width.
  let { children }: { children?: Snippet } = $props();
</script>

<div class="tabbar">{@render children?.()}</div>

<style>
  .tabbar {
    display: flex;
    gap: 12px;
    padding: 8px var(--pad);
    background: var(--bg-elev);
    border-top: 1px solid var(--border);
    user-select: none;
    -webkit-user-select: none;
  }
  :global(.tabbar > *) {
    flex: 1 1 0;
    min-width: 0;
  }
  /* Tab face: an icon square (the press-highlight target) + a tiny truncated label. */
  :global(.tab) {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    background: none;
    border: none;
    padding: 1px 0;
    color: var(--text);
    width: 100%;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent; /* no WebKit flash on tap */
  }
  :global(.tab:disabled) {
    opacity: 0.4;
  }
  /* The icon square hugs the emoji (just a little padding) so the badge can sit on its
     corner. */
  :global(.tab .sq) {
    position: relative;
    display: inline-grid;
    place-items: center;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 1.75rem;
    line-height: 1;
    transition: background-color 0.12s;
  }
  /* A tab that navigates between peer views (Settings / Comms hubs) wraps its icon and label
     in a .face so the selected highlight hugs both — a filled pill with an accent underline,
     sized to the content with a small padding. A tap itself leaves no highlight (no press
     tint, and the WebKit tap flash is disabled on .tab). Plain action tabs (the lobby nav,
     the in-game controls) carry no .face and are never .active, so they are unaffected. */
  :global(.tab .face) {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    padding: 3px 10px;
    border-radius: 12px;
    transition: background-color 0.12s;
  }
  /* Inside a face the icon square needs no padding of its own — the face provides the
     surround (the bare .sq padding still applies to the unwrapped action tabs). */
  :global(.tab .face .sq) {
    padding: 0;
  }
  :global(.tab.active .face) {
    background: var(--surface-2);
    box-shadow: inset 0 -2px 0 var(--accent);
  }
  /* A small count badge on the icon square's corner (lobby ⚙️, the Friends tab, the
     hint count) — one shared style so every tab badge reads the same. */
  :global(.tab .badge) {
    position: absolute;
    top: -3px;
    right: -3px;
    font-size: 0.68rem;
    font-weight: 700;
    background: var(--accent);
    color: var(--accent-text);
    border-radius: 999px;
    min-width: 15px;
    padding: 0 3px;
    line-height: 1.4;
    text-align: center;
  }
  :global(.tab .lbl) {
    font-size: 0.62rem;
    color: var(--text-muted);
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
</style>
