/* Naramya mobile-only stability and layout refinements.
   Desktop styles remain untouched: every visual rule is scoped below 768px. */

@media (max-width: 767px) {
  html {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body,
  #root,
  #top {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: clip;
  }

  body {
    position: relative;
    overscroll-behavior-x: none;
  }

  #top > section,
  #top > footer,
  header {
    width: 100%;
    max-width: 100vw;
    min-width: 0;
  }

  img,
  video,
  svg,
  canvas {
    max-width: 100%;
  }

  button,
  a,
  input,
  textarea,
  select {
    touch-action: manipulation;
  }

  /* Header: compact but still premium and tap-friendly. */
  header > div {
    height: 68px !important;
    grid-template-columns: minmax(0, 1fr) auto !important;
    column-gap: 10px !important;
    padding-left: max(14px, env(safe-area-inset-left)) !important;
    padding-right: max(14px, env(safe-area-inset-right)) !important;
  }

  header a[href="#top"] {
    min-width: 0;
    gap: 7px !important;
    font-size: 1.1rem !important;
    letter-spacing: 0.15em !important;
    line-height: 1 !important;
    white-space: nowrap;
  }

  header a[href="#top"] img {
    width: 16px !important;
    height: 22px !important;
    flex: 0 0 auto;
  }

  header a[href="#top"] span {
    min-width: 0;
    white-space: nowrap;
  }

  header > div > div:last-child {
    min-width: 0;
    gap: 0 !important;
  }

  header > div > div:last-child > button {
    display: none !important;
  }

  header > div > div:last-child > a {
    min-height: 40px;
    padding: 8px 11px !important;
    font-size: 10px !important;
    letter-spacing: 0.07em !important;
    line-height: 1.15 !important;
    white-space: nowrap;
  }

  /* Opening section. */
  #home {
    padding-top: 68px !important;
  }

  #home > div:nth-of-type(1) {
    min-height: 0 !important;
    align-items: flex-start !important;
    padding: 42px 20px 36px !important;
  }

  #home > div:nth-of-type(1) > div {
    width: 100%;
    max-width: 100% !important;
  }

  #home h1 {
    margin-top: 24px !important;
    font-size: clamp(3rem, 15.2vw, 4.1rem) !important;
    line-height: 0.94 !important;
    overflow-wrap: normal;
  }

  #home h1 + * {
    max-width: 100%;
  }

  #home p {
    margin-top: 24px !important;
    max-width: 100% !important;
    font-size: 15px !important;
    line-height: 1.7 !important;
  }

  #home [class*="tracking-[0.4em]"] {
    max-width: 100%;
    font-size: 9px !important;
    line-height: 1.8;
    letter-spacing: 0.28em !important;
  }

  #home > div:nth-of-type(1) [class*="flex-wrap"] {
    width: 100%;
    margin-top: 30px !important;
    gap: 10px !important;
  }

  #home > div:nth-of-type(1) [class*="flex-wrap"] > a,
  #home > div:nth-of-type(1) [class*="flex-wrap"] > button {
    min-height: 46px;
    padding: 13px 18px !important;
    font-size: 10px !important;
    letter-spacing: 0.2em !important;
  }

  #home > div:nth-of-type(2) {
    height: 58svh !important;
    min-height: 410px !important;
    max-height: 610px;
  }

  #home > div:nth-of-type(2) img {
    object-position: 50% 50% !important;
  }

  /* Animated word ribbon must never enlarge the page width. */
  .naramya-marquee-section {
    overflow: hidden !important;
    padding-top: 22px !important;
    padding-bottom: 22px !important;
  }

  .animate-naramya-marquee {
    width: max-content;
    max-width: none;
    will-change: transform;
  }

  .animate-naramya-marquee > span {
    padding-left: 20px !important;
    padding-right: 20px !important;
    gap: 20px !important;
    font-size: 1.65rem !important;
  }

  /* Shared mobile section rhythm. */
  #rituals,
  #ingredients,
  #ritual,
  #journal {
    padding-left: 20px !important;
    padding-right: 20px !important;
  }

  #rituals,
  #ingredients,
  #ritual,
  #journal,
  #philosophy {
    padding-top: 76px !important;
    padding-bottom: 76px !important;
  }

  #rituals {
    gap: 42px !important;
  }

  #rituals > div:first-child {
    width: 100%;
    max-width: 100%;
  }

  #rituals > div:last-child img {
    width: 100%;
    height: min(62svh, 520px) !important;
    min-height: 360px;
    object-position: center;
  }

  /* 100-wash transition: the original fixed 56px circles overflow at 320px. */
  #rituals + section {
    padding-top: 76px !important;
    padding-bottom: 76px !important;
  }

  #rituals + section > div {
    padding-left: 20px !important;
    padding-right: 20px !important;
  }

  #rituals + section [class*="grid-cols-5"] {
    grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
    column-gap: 7px !important;
    row-gap: 18px !important;
  }

  #rituals + section [class*="grid-cols-5"] > div {
    min-width: 0;
    gap: 7px !important;
  }

  #rituals + section [class*="grid-cols-5"] > div > div:first-child {
    width: clamp(40px, 12vw, 52px) !important;
    height: clamp(40px, 12vw, 52px) !important;
  }

  #rituals + section [class*="grid-cols-5"] span {
    font-size: 12px !important;
  }

  #rituals + section [class*="mt-16"][class*="text-center"] {
    margin-top: 42px !important;
  }

  /* Ancient texts / science imagery. */
  #ingredients [class*="mt-20"][class*="grid"] {
    margin-top: 52px !important;
    gap: 42px !important;
  }

  #ingredients [class*="mt-20"][class*="grid"] img {
    height: auto !important;
    aspect-ratio: 4 / 3;
    object-fit: cover;
  }

  #ingredients [class*="mt-20"][class*="grid"] p {
    margin-top: 16px !important;
    font-size: 10px !important;
    line-height: 1.6;
    letter-spacing: 0.2em !important;
  }

  /* Ingredient library. */
  #ingredients + section {
    padding: 76px 20px !important;
  }

  #ingredients + section [class*="grid-cols-2"] {
    margin-top: 52px !important;
    column-gap: 12px !important;
    row-gap: 38px !important;
  }

  #ingredients + section [class*="grid-cols-2"] > div {
    min-width: 0;
  }

  #ingredients + section [class*="grid-cols-2"] > div > div:first-child {
    width: min(34vw, 132px) !important;
    height: min(34vw, 132px) !important;
  }

  #ingredients + section [class*="grid-cols-2"] > div > p:nth-of-type(1) {
    min-height: 0 !important;
    margin-top: 14px !important;
    font-size: 1rem !important;
    line-height: 1.2;
  }

  #ingredients + section [class*="grid-cols-2"] > div > p:nth-of-type(2) {
    min-height: 0 !important;
    margin-top: 6px !important;
    font-size: 11px !important;
    line-height: 1.45 !important;
  }

  #ingredients + section [class*="grid-cols-2"] > div:last-child:nth-child(odd) {
    grid-column: 1 / -1;
    justify-self: center;
    width: 50%;
  }

  /* Ritual moments. */
  #ritual [class*="grid-cols-2"] {
    margin-top: 52px !important;
    column-gap: 18px !important;
    row-gap: 38px !important;
  }

  #ritual h3 {
    font-size: 1.45rem !important;
  }

  /* Product section. */
  #product > div:first-child {
    min-height: 50svh !important;
    max-height: 590px;
  }

  #product > div:first-child img {
    object-position: 50% 50%;
  }

  #product > div:last-child {
    padding: 64px 20px !important;
  }

  #product [class*="items-baseline"] {
    flex-wrap: wrap;
    gap: 10px 18px !important;
  }

  #product [class*="flex-wrap"][class*="gap-8"] {
    gap: 24px !important;
  }

  /* Validation, philosophy, journal and value cards. */
  #product + section {
    padding-top: 76px !important;
    padding-bottom: 76px !important;
  }

  #product + section > div {
    padding-left: 20px !important;
    padding-right: 20px !important;
  }

  #product + section [class*="mt-20"] {
    margin-top: 52px !important;
  }

  #philosophy {
    min-height: 0;
  }

  #philosophy > div:last-child {
    padding-left: 20px !important;
    padding-right: 20px !important;
  }

  #philosophy p:first-of-type {
    margin-top: 32px !important;
    font-size: clamp(2rem, 10vw, 2.7rem) !important;
  }

  #journal {
    gap: 42px !important;
  }

  #journal h2 {
    font-size: clamp(2.6rem, 12vw, 3.7rem) !important;
  }

  #journal + section {
    padding-top: 76px !important;
    padding-bottom: 76px !important;
  }

  #journal + section > div {
    padding-left: 20px !important;
    padding-right: 20px !important;
  }

  #journal + section [class*="grid-cols-2"] {
    margin-top: 52px !important;
    column-gap: 18px !important;
    row-gap: 36px !important;
  }

  #journal + section [class*="grid-cols-2"] h3 {
    font-size: 1.2rem !important;
    line-height: 1.2;
  }

  /* Footer. */
  footer#shop {
    padding-top: 72px !important;
    padding-bottom: max(36px, env(safe-area-inset-bottom)) !important;
  }

  footer#shop > div {
    padding-left: 20px !important;
    padding-right: 20px !important;
  }

  footer#shop [class*="gap-16"] {
    gap: 48px !important;
    padding-bottom: 56px !important;
  }

  footer#shop [class*="tracking-[0.3em]"] {
    overflow-wrap: anywhere;
  }

  footer#shop input {
    min-width: 0;
    font-size: 16px !important;
  }

  /* Waitlist modal: no iPhone input zoom, safe-area aware and scrollable on short screens. */
  [role="dialog"] {
    min-height: 100dvh;
    align-items: center !important;
    overflow-y: auto;
    padding:
      max(18px, env(safe-area-inset-top))
      max(16px, env(safe-area-inset-right))
      max(18px, env(safe-area-inset-bottom))
      max(16px, env(safe-area-inset-left)) !important;
  }

  [role="dialog"] > div:last-child {
    width: 100%;
    max-height: calc(100dvh - 36px);
    overflow-y: auto;
    padding: 28px 22px !important;
    -webkit-overflow-scrolling: touch;
  }

  [role="dialog"] input,
  [role="dialog"] textarea,
  [role="dialog"] select {
    font-size: 16px !important;
  }

  [role="dialog"] button[aria-label="Close"] {
    display: grid;
    width: 44px;
    height: 44px;
    place-items: center;
    top: 8px !important;
    right: 8px !important;
  }

  [role="dialog"] #waitlist-title {
    padding-right: 28px;
    font-size: 2.35rem !important;
    line-height: 1;
  }

  [role="dialog"] form {
    margin-top: 26px !important;
  }
}

@media (max-width: 340px) {
  header > div {
    padding-left: 10px !important;
    padding-right: 10px !important;
    column-gap: 6px !important;
  }

  header a[href="#top"] {
    gap: 5px !important;
    font-size: 1rem !important;
    letter-spacing: 0.11em !important;
  }

  header a[href="#top"] img {
    width: 14px !important;
    height: 20px !important;
  }

  header > div > div:last-child > a {
    padding-left: 8px !important;
    padding-right: 8px !important;
    font-size: 9px !important;
  }

  #home h1 {
    font-size: 2.85rem !important;
  }

  #home > div:nth-of-type(1) [class*="flex-wrap"] > a,
  #home > div:nth-of-type(1) [class*="flex-wrap"] > button {
    padding-left: 14px !important;
    padding-right: 14px !important;
  }

  #journal + section [class*="grid-cols-2"] {
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  header > div {
    height: 62px !important;
  }

  #home {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    padding-top: 62px !important;
  }

  #home > div:nth-of-type(1) {
    min-height: calc(100svh - 62px) !important;
    padding: 28px 24px !important;
  }

  #home > div:nth-of-type(2) {
    height: calc(100svh - 62px) !important;
    min-height: 330px !important;
    max-height: none;
  }

  #home h1 {
    margin-top: 16px !important;
    font-size: clamp(2.65rem, 7vw, 3.8rem) !important;
  }

  #home p {
    margin-top: 16px !important;
    font-size: 13px !important;
    line-height: 1.55 !important;
  }

  #home > div:nth-of-type(1) [class*="flex-wrap"] {
    margin-top: 20px !important;
  }

  [role="dialog"] {
    align-items: flex-start !important;
  }

  [role="dialog"] > div:last-child {
    max-height: calc(100dvh - 24px);
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto !important;
  }

  .animate-naramya-marquee {
    animation-play-state: paused !important;
  }
}

/* The marquee is intentionally wider than the viewport. Isolate it so it can
   animate without changing the document's layout viewport or causing zoom-out. */
.naramya-marquee-section {
  width: 100%;
  max-width: 100vw;
  overflow: hidden;
}

@media (max-width: 1023px) {
  #top {
    width: 100%;
    max-width: 100%;
    overflow-x: clip;
  }

  .naramya-marquee-section {
    position: relative;
    height: 76px;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    contain: inline-size layout paint;
  }

  .naramya-marquee-section .animate-naramya-marquee {
    position: absolute;
    top: 19px;
    left: 0;
    width: max-content;
    min-width: max-content;
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  #home > div:nth-of-type(1) {
    padding-top: 18px !important;
    padding-bottom: 18px !important;
  }

  #home [class*="tracking-[0.4em]"] {
    font-size: 8px !important;
    line-height: 1.5;
    letter-spacing: 0.24em !important;
  }

  #home h1 {
    margin-top: 12px !important;
    font-size: clamp(2.35rem, 6vw, 3.2rem) !important;
    line-height: 0.92 !important;
  }

  #home p {
    margin-top: 12px !important;
    font-size: 12px !important;
    line-height: 1.45 !important;
  }

  #home > div:nth-of-type(1) [class*="flex-wrap"] {
    margin-top: 14px !important;
    gap: 8px !important;
  }

  #home > div:nth-of-type(1) [class*="flex-wrap"] > a,
  #home > div:nth-of-type(1) [class*="flex-wrap"] > button {
    min-height: 38px;
    padding: 9px 13px !important;
    font-size: 9px !important;
    letter-spacing: 0.16em !important;
  }
}
