*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; }
body.rr-v2 {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
  background:
    radial-gradient(ellipse 90% 60% at 10% -10%, var(--glow-amber), transparent 55%),
    radial-gradient(ellipse 70% 50% at 100% 0%, var(--glow-cool), transparent 50%),
    linear-gradient(165deg, var(--page-0) 0%, var(--page-1) 42%, var(--page-2) 100%);
  background-attachment: fixed;
}
body.rr-v2::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.35;
  background-image: repeating-linear-gradient(
    -18deg, transparent 0, transparent 46px, var(--stripe) 46px, var(--stripe) 48px
  );
  z-index: 0;
}
.rr-app {
  position: relative;
  z-index: 1;
  display: grid;
  min-height: 100dvh;
  grid-template-rows: auto 1fr auto;
}
.rr-appbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: calc(var(--appbar-h) + var(--safe-top));
  padding: var(--safe-top) max(1rem, var(--safe-right)) 0.5rem max(1rem, var(--safe-left));
  background: color-mix(in srgb, var(--canvas) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.rr-brand {
  font-family: var(--font-display);
  font-size: 1.85rem;
  letter-spacing: 0.04em;
  line-height: 1;
  color: var(--ink);
  text-decoration: none;
}
.rr-brand span { color: var(--accent); }
.rr-appbar-actions { display: flex; align-items: center; gap: 0.35rem; }
.rr-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.rr-icon-btn:hover { background: var(--chip); }
.rr-icon-btn svg { width: 22px; height: 22px; }
.rr-bell-dot {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
}
.rr-main {
  width: min(72rem, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1rem 0 calc(1.25rem + var(--tabbar-h) + var(--safe-bottom));
}
.rr-main.wide { width: min(82rem, calc(100% - 2rem)); }
.rr-crumb { margin: 0 0 0.75rem; }
.rr-crumb a { color: var(--muted); text-decoration: none; }
.rr-tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 45;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  min-height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding: 0.25rem 0.35rem var(--safe-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.rr-tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  min-height: 52px;
  padding: 0.35rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 12px;
}
.rr-tab svg { width: 22px; height: 22px; }
.rr-tab.active { color: var(--primary); background: var(--accent-soft); }
.rr-tab .badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 18px);
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--primary-fg);
  font-size: 0.65rem;
  line-height: 16px;
  text-align: center;
}
.rr-tab .badge.danger { background: var(--danger); color: #fff; }
.rr-sidebar, .rr-rail { display: none; }
.rr-portal { position: relative; z-index: 100; }

/* Background library upload — visible on every page while a batch runs */
.rr-bg-upload {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 4.25rem);
  transform: translateX(-50%);
  z-index: 115;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: min(28rem, calc(100% - 1.5rem));
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  background: color-mix(in srgb, var(--ink) 92%, transparent);
  color: var(--canvas);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  font-weight: 600;
}
.rr-bg-upload[hidden] { display: none !important; }
.rr-bg-upload-link {
  margin-left: auto;
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
  white-space: nowrap;
}
@media (min-width: 768px) {
  .rr-bg-upload { bottom: 1.25rem; }
}

@media (min-width: 768px) {
  .rr-tabbar { display: none; }
  .rr-app {
    grid-template-columns: var(--rail-w) 1fr;
    grid-template-rows: auto 1fr;
  }
  .rr-appbar { grid-column: 2; }
  .rr-main {
    grid-column: 2;
    padding-bottom: 2rem;
  }
  .rr-rail {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    grid-row: 1 / -1;
    position: sticky;
    top: 0;
    height: 100dvh;
    padding: calc(0.75rem + var(--safe-top)) 0.5rem 1rem;
    border-right: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface) 88%, transparent);
  }
  .rr-rail a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
    width: 64px;
    padding: 0.55rem 0.25rem;
    border-radius: 12px;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.68rem;
    font-weight: 600;
  }
  .rr-rail a svg { width: 22px; height: 22px; }
  .rr-rail a.active { color: var(--primary); background: var(--accent-soft); }
  .rr-rail .rail-foot { margin-top: auto; display: flex; flex-direction: column; gap: 0.35rem; }
}

@media (min-width: 1100px) {
  .rr-app { grid-template-columns: var(--sidebar-w) 1fr; }
  .rr-rail { display: none; }
  .rr-sidebar {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    grid-row: 1 / -1;
    position: sticky;
    top: 0;
    height: 100dvh;
    padding: calc(1rem + var(--safe-top)) 0.85rem 1rem;
    border-right: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface) 90%, transparent);
  }
  .rr-sidebar .rr-brand { margin: 0 0.4rem 1rem; font-size: 2.2rem; }
  .rr-sidebar a.nav {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.7rem 0.85rem;
    border-radius: 12px;
    color: var(--ink);
    text-decoration: none;
    font-weight: 600;
  }
  .rr-sidebar a.nav svg { width: 20px; height: 20px; color: var(--muted); }
  .rr-sidebar a.nav.active { background: var(--accent-soft); color: var(--primary); }
  .rr-sidebar a.nav.active svg { color: var(--primary); }
  .rr-sidebar .side-foot {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--line);
  }
  body.rr-nav-collapsed .rr-app { grid-template-columns: 72px 1fr; }
  body.rr-nav-collapsed .rr-sidebar .label,
  body.rr-nav-collapsed .rr-sidebar .rr-brand { display: none; }
  body.rr-nav-collapsed .rr-sidebar a.nav { justify-content: center; padding: 0.75rem; }
  .rr-appbar .rr-brand { display: none; }
}

@media (max-height: 500px) and (min-width: 600px) {
  .rr-tabbar { display: none; }
  .rr-rail { display: flex; }
  .rr-app { grid-template-columns: var(--rail-w) 1fr; }
  .rr-main { padding-bottom: 1.5rem; }
}

/* Dock / inspector */
.rr-dock-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(10, 12, 16, 0.45);
  border: 0; padding: 0; cursor: pointer;
}
.rr-dock {
  position: fixed; z-index: 70;
  display: flex; flex-direction: column;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.rr-dock.mode-float {
  left: 0; right: 0; bottom: 0;
  height: min(92dvh, 720px);
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
}
.rr-dock.mode-pinned {
  top: 0; right: 0; bottom: 0;
  width: min(var(--dock-w), 100vw);
  border-left: 1px solid var(--line);
}
/* Phone: never side-pin — always a bottom sheet when open */
@media (max-width: 767px) {
  .rr-dock.mode-pinned,
  .rr-dock.mode-float {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: min(92dvh, 720px);
    border-left: 0;
    border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
    transform: none !important;
  }
}
.rr-dock[hidden], .rr-dock-backdrop[hidden] { display: none !important; }
.rr-dock-head {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--line);
}
.rr-dock-title { margin: 0; font-weight: 700; flex: 1; }
.rr-dock-body {
  flex: 1; overflow: auto; padding: 0.75rem;
  font-family: var(--font-mono); font-size: 0.8rem; white-space: pre-wrap;
}

@media (min-width: 1440px) {
  .rr-main.wide { width: min(92rem, calc(100% - 2rem)); }
}
