@import url("./dogeos-sdk.css") layer(dogeos-sdk);

/* Targeted overrides for DogeOS SDK styles.
 *
 * The SDK's vendored stylesheet is pulled in by the @import above rather than by
 * a second <link> in layout.js. Two reasons: the import order is then guaranteed
 * by this file instead of by link order, and nesting the SDK's own
 * `@layer base/components/theme/utilities` blocks inside one outer
 * `dogeos-sdk` layer keeps them from ever merging with a same-named layer emitted
 * by the app. Its `@layer base button { ... }` preflight reset therefore cannot
 * out-cascade laika's utilities.
 *
 * The SDK CSS ships its rules inside @layer blocks, but laika's Tailwind v3
 * output is unlayered. Unlayered styles always win over layered ones regardless of
 * specificity, which makes the SDK's `.data-[loaded=true]:opacity-100` rule lose to
 * Tailwind's `.opacity-0` — wallet icons stay invisible even after loading.
 * These unlayered overrides have the same selectors as the SDK's intended rules so
 * they participate in the cascade alongside laika's globals.css.
 *
 * NOTE: the `@property --tw-gradient-*` patch is NOT here. Re-declaring those in a
 * later stylesheet does not work (CLAUDE.md §4.4); the fix is the inline script in
 * src/app/layout.js, which rewrites the SDK's runtime-injected <style> element.
 */

img.data-\[loaded\=true\]\:opacity-100[data-loaded="true"] {
  opacity: 1;
}

/* The SDK injects a runtime <style> that scopes its HeroUI tokens to a dynamic
 * id-selector like `#_r_u_[class="light"]`. Inside that subtree, modal content
 * renders correctly. But toasts from `@tomo-inc/tomo-ui` portal to a node OUTSIDE
 * that subtree (body-level), where `var(--heroui-content1)` is empty and
 * `.bg-content1 { background-color: hsl(var(--heroui-content1) / 1) }` collapses
 * to transparent. Defining the same vars at :root makes them cascade everywhere;
 * the SDK's own #id-scoped style still wins inside the modal because id selectors
 * outrank :root. Values mirror WalletProviderInner.jsx `theme.themes`.
 */
:root {
  --heroui-foreground: 0 0% 3.92%;
  --heroui-background: 0 0% 100%;
  --heroui-content1: 0 0% 100%;
  --heroui-content2: 0 0% 96.08%;
  --heroui-content3: 0 0% 92.94%;
  --heroui-content4: 0 0% 89.8%;
  --heroui-divider: 0 0% 89.8%;
  --heroui-focus: 52 100% 50%;
  --heroui-primary: 52 100% 50%;
  --heroui-primary-foreground: 0 0% 3.92%;
}

html.dark {
  --heroui-foreground: 0 0% 98.04%;
  --heroui-background: 0 0% 3.92%;
  --heroui-content1: 0 0% 3.92%;
  --heroui-content2: 0 0% 14.9%;
  --heroui-content3: 0 0% 22.75%;
  --heroui-content4: 0 0% 32.16%;
  --heroui-divider: 0 0% 14.9%;
}

/* SDK 3.2.0-beta.4's `:root,[data-theme=light]` block in dogeos-sdk.css defines
 * --heroui-danger (the base) but omits the entire --heroui-danger-{50..900}
 * and -foreground ramp. The dark block (`.dark` / `[data-theme=dark]`) defines
 * them. HeroUI's failure toast (`addToast({ color: "danger", variant: "flat" })`)
 * renders with `bg-danger-50 text-danger-600 border-danger-100` (see
 * @heroui/theme/dist/components/toast.js compound variants). In light mode
 * `var(--heroui-danger-50)` is empty so `hsl( / 1)` is invalid and the surface
 * collapses to transparent — the symptom the user hit on Google OAuth cancel.
 * Values below are HeroUI v2's default light-mode danger ramp. Scoped to the
 * light theme so the SDK's [data-theme=dark] ramp keeps winning in dark mode.
 * The :not([data-theme]) clause covers the brief window before
 * WalletProviderInner's useEffect mirrors theme state onto <html>.
 */
html[data-theme="light"], :root:not([data-theme]) {
  --heroui-danger-50: 339.13 100% 95.49%;
  --heroui-danger-100: 340 100% 87.65%;
  --heroui-danger-200: 339.42 96.13% 78.43%;
  --heroui-danger-300: 339.46 97.41% 69.41%;
  --heroui-danger-400: 339.32 96.39% 60%;
  --heroui-danger-500: 339 90% 51.18%;
  --heroui-danger-600: 339 85.66% 41.96%;
  --heroui-danger-700: 339.06 85.61% 31.96%;
  --heroui-danger-800: 339.62 88.07% 21.96%;
  --heroui-danger-900: 340 87.5% 15.69%;
  --heroui-danger-foreground: 0 0% 100%;
}

/* The SDK modal's loading overlay (shown while the Google/X popup or email
 * sign-in is in flight) is `.absolute.inset-0.backdrop-blur-sm.z-50` holding a
 * HeroUI spinner whose rings are bordered <i> elements. Laika's unlayered
 * Tailwind v3 preflight beats both: it resets `--tw-backdrop-blur` to empty (no
 * blur, so "Loading..." sits over the email field) and sets every element's
 * border to 0px (invisible spinner). These rules restate them unlayered. The
 * selectors match SDK 4.0.1 (dist/index.js, component RJ).
 */
[role="dialog"] .absolute.inset-0.backdrop-blur-sm.z-50 {
  background-color: hsl(var(--heroui-content1) / 0.72);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border-radius: inherit;
}

[role="dialog"] .absolute.inset-0.backdrop-blur-sm.z-50 [aria-label="Loading"] i {
  border-width: 3px;
  border-color: transparent;
  border-bottom-color: hsl(var(--heroui-primary));
}

/* SDK 4.0.1's WalletConnectProvider renders a bare
 * `<div role="status">Preparing wallet connection…</div>` in place of its
 * children while it detects whether it runs inside MyDoge. Because it wraps the
 * whole app, that line of unstyled text is the entire page. On desktop it lasts
 * one frame, but on phones and iPads it lasts until window `load`. If detection
 * hasn't finished after 5s it swaps in `<div role="alert">` with a Retry
 * button. Neither element has a class, so `:not([class])` keeps these rules
 * off any styled status/alert the app or a library portals into <body>.
 * WalletProvider.jsx renders the same markup as its next/dynamic `loading`
 * state, so the screen doesn't change from first paint to the app.
 */
body > div[role="status"]:not([class]),
body > div[role="alert"]:not([class]) {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
  font-size: 14px;
  background-color: hsl(var(--heroui-background));
  color: hsl(var(--heroui-foreground) / 0.6);
}

/* Running Laika, an animated WebP (a ::before can't hold a <video>).
 * Preloaded from layout.js so it is decoded by the time this screen paints. */
body > div[role="status"]:not([class])::before {
  content: "";
  width: 90px;
  height: 72px;
  background: url("/animations/loading.webp") center / contain no-repeat;
}

body > div[role="alert"]:not([class]) p {
  max-width: 320px;
  color: hsl(var(--heroui-foreground));
}

body > div[role="alert"]:not([class]) button {
  padding: 10px 20px;
  border-radius: 9999px;
  font-weight: 700;
  background-color: hsl(var(--heroui-primary));
  color: hsl(var(--heroui-primary-foreground));
}


/* The SDK's stylesheet is Tailwind 4, where `.-translate-x-1/2` sets the `translate`
 * property. Laika's Tailwind 3 uses the same class names but sets `transform`. An
 * element with one of these classes gets both, so it moves twice: a dialog centred
 * with `left-1/2 -translate-x-1/2` lands with its bottom-right corner at the centre
 * of the screen. Tailwind 3 emits `transform` for exactly these classes, so turning
 * `translate` off is safe here, SDK elements included. Only list classes Laika also
 * uses: an SDK-only class has no `transform` to fall back on.
 * src/lib/__tests__/sdk-translate-collision.test.js fails when a new one appears.
 */
.-translate-x-1\/2,
.-translate-y-1\/2,
.-translate-y-1,
.translate-y-1 {
  translate: none;
}

/* The SDK hard-codes bg-[#ebebf4] on the "or continue with" divider; recolour it
 * to the modal's divider token in dark mode. */
html.dark .bg-\[\#ebebf4\] {
  background-color: hsl(var(--heroui-divider));
}
