/* ══════════════════════════════════════════════════════════════
   SpinChain — App Shell
   Appbar · Tab bar · Main layout · Screen transitions
   ══════════════════════════════════════════════════════════════ */

/* ── Reset / base for chrome elements ─────────────────────── */
.appbar,
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 100;
  max-width: var(--maxw);
  margin-inline: auto;
  /* Frosted glass */
  background: var(--bg-glass);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
}

/* ════════════════════════════════════════════════════════════
   APPBAR — fixed top
   ════════════════════════════════════════════════════════════ */
.appbar {
  top: 0;
  height: calc(56px + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  padding-inline: var(--s-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* Hairline bottom border */
  border-bottom: 1px solid var(--stroke);
  /* Subtle inner glow to separate from page */
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.04),
    0 8px 24px -8px rgba(0, 0, 0, 0.5);
}

/* Brand wordmark cluster */
.appbar-brand {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  text-decoration: none;
  user-select: none;
  min-width: 0;            /* allow the brand to shrink, never push the pill off */
  flex: 0 1 auto;
  overflow: hidden;
}

.appbar-logo {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  /* Subtle drop shadow so the logo pops on glass */
  filter: drop-shadow(0 0 6px rgba(255, 200, 80, 0.55));
}

.appbar-word {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-1);
  line-height: 1;
}

/* real SPINCHAIN logo in the app bar */
.appbar-logoimg {
  height: 34px;
  width: auto;
  max-width: 100%;        /* never overflow the brand box on a narrow bar */
  display: block;
  filter: drop-shadow(0 0 8px rgba(160, 90, 255, 0.5));
}

/* Right-side action cluster (refresh + spin-pill) */
.appbar-actions {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex-shrink: 0;
}

/* ── Refresh button (always visible when signed in) ───────────── */
.appbar-refresh,
.dash-refresh {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: var(--r-pill, 999px);
  border: 1px solid var(--stroke, rgba(255, 255, 255, 0.12));
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-1, #fff);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--t-fast, 0.15s) ease, transform var(--t-fast, 0.15s) ease, color var(--t-fast, 0.15s) ease;
}
.appbar-refresh:hover,
.dash-refresh:hover { background: rgba(255, 255, 255, 0.1); color: var(--gold-2, #ffd84a); }
.appbar-refresh:active,
.dash-refresh:active { transform: scale(0.92); }
.appbar-refresh:focus-visible,
.dash-refresh:focus-visible { outline: 2px solid var(--gold-2, #ffd84a); outline-offset: 2px; }
.appbar-refresh:disabled,
.dash-refresh:disabled { cursor: default; opacity: 0.85; }
.appbar-refresh svg,
.dash-refresh svg { display: block; }
.appbar-refresh.is-spinning svg,
.dash-refresh.is-spinning svg { animation: sc-spin 0.7s linear infinite; }
@keyframes sc-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .appbar-refresh.is-spinning svg,
  .dash-refresh.is-spinning svg { animation-duration: 0.001ms; }
}

/* ── Spin-pill button ──────────────────────────────────────── */
.spin-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;         /* keep the spins counter intact, never clip it */
  padding: 0 var(--s-3);
  height: 36px;
  border-radius: var(--r-pill);
  border: 1.5px solid rgba(255, 220, 90, 0.35);
  background: var(--grad-gold);
  color: var(--text-on-gold);
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
  cursor: pointer;
  user-select: none;
  /* Gold glow */
  box-shadow:
    0 0 0 0 rgba(255, 200, 80, 0),
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    inset 0 -1px 0 rgba(0, 0, 0, 0.15),
    var(--shadow-card);
  transition:
    box-shadow var(--t-fast) var(--ease-out),
    transform   var(--t-fast) var(--ease-spring),
    filter      var(--t-fast) var(--ease-out);
  /* Sheen overlay */
  position: relative;
  overflow: hidden;
}

.spin-pill::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    105deg,
    rgba(255, 255, 255, 0) 30%,
    rgba(255, 255, 255, 0.28) 50%,
    rgba(255, 255, 255, 0) 70%
  );
  transform: translateX(-100%);
  transition: transform 0.55s var(--ease-out);
  pointer-events: none;
}

.spin-pill:hover::before {
  transform: translateX(100%);
}

.spin-pill:hover,
.spin-pill:focus-visible {
  box-shadow:
    var(--glow-gold),
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    inset 0 -1px 0 rgba(0, 0, 0, 0.15);
  filter: brightness(1.07);
}

.spin-pill:active {
  transform: scale(0.94);
  box-shadow:
    0 0 12px rgba(255, 200, 80, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    inset 0 -1px 0 rgba(0, 0, 0, 0.15);
}

.spin-pill-ico {
  font-size: 16px;
  line-height: 1;
  /* keep crisp on all renderers */
  display: block;
}

/* ════════════════════════════════════════════════════════════
   MAIN CONTENT AREA
   ════════════════════════════════════════════════════════════ */
#app {
  max-width: var(--maxw);
  margin-inline: auto;
  /* Clear fixed appbar (56px + safe-area) and tabbar (64px + safe-area) */
  padding-top: calc(72px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  padding-inline: 0;
  min-height: 100dvh;
  /* Contain paint for child animations */
  contain: layout style;
}

/* ════════════════════════════════════════════════════════════
   TABBAR — fixed bottom nav
   ════════════════════════════════════════════════════════════ */
.tabbar {
  bottom: 0;
  height: calc(64px + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-inline: var(--s-2);
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  gap: 0;
  border-top: 1px solid var(--stroke);
  box-shadow:
    0 -1px 0 rgba(255, 255, 255, 0.03),
    0 -12px 32px -12px rgba(0, 0, 0, 0.45);
}

/* ── Individual tab button ─────────────────────────────────── */
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: var(--s-2) 0;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-3);
  border-radius: var(--r-sm);
  position: relative;
  transition:
    color      var(--t-fast) var(--ease-out),
    background var(--t-fast) var(--ease-out);
}

.tab:active {
  background: rgba(255, 255, 255, 0.04);
}

/* Icon */
.tab-ico {
  font-size: 20px;
  line-height: 1;
  display: block;
  transition: transform var(--t-fast) var(--ease-spring);
}

/* Label */
.tab-lbl {
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  line-height: 1;
  transition: color var(--t-fast) var(--ease-out);
}

/* ── Active tab state ──────────────────────────────────────── */
.tab.active {
  color: var(--gold-2);
}

.tab.active .tab-ico {
  transform: scale(1.2) translateY(-1px);
  filter: drop-shadow(0 0 5px rgba(255, 200, 80, 0.7));
}

.tab.active .tab-lbl {
  color: var(--gold-1);
}

/* Glowing active indicator dot */
.tab.active::after {
  content: '';
  position: absolute;
  bottom: 5px;
  left: 50%;
  transform: translateX(-50%);
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--gold-2);
  box-shadow: 0 0 8px 2px rgba(255, 200, 80, 0.7);
}

/* ════════════════════════════════════════════════════════════
   SCREEN ENTER ANIMATION
   ════════════════════════════════════════════════════════════ */
@keyframes screenEnter {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#app.screen-enter {
  animation: screenEnter var(--t-med) var(--ease-out) both;
}

/* ════════════════════════════════════════════════════════════
   FULL-WIDTH BODY BACKGROUND EXTENSION
   ════════════════════════════════════════════════════════════ */
/* Ensure the appbar + tabbar glass effect spans the real viewport
   on devices wider than --maxw */
@media (min-width: 480px) {
  .appbar,
  .tabbar {
    /* Let the frosted glass extend edge-to-edge */
    max-width: 100%;
  }

  .appbar .appbar-brand,
  .appbar .spin-pill,
  .tabbar .tab {
    /* Inner content still respects the app column */
  }

  /* Add a visual separator column */
  #app,
  .appbar,
  .tabbar {
    max-width: var(--maxw);
  }
}

/* Accessibility: honour the OS "reduce motion" setting — pause the perpetual
   sheen/pulse/glow animations and heavy transitions for users who opt out. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
