/* Shared device compatibility layer for iOS/iPadOS, Android and HarmonyOS browsers. */
:root {
  --cunnian-safe-top: env(safe-area-inset-top, 0px);
  --cunnian-safe-right: env(safe-area-inset-right, 0px);
  --cunnian-safe-bottom: env(safe-area-inset-bottom, 0px);
  --cunnian-safe-left: env(safe-area-inset-left, 0px);
}

html {
  max-width: 100%;
  overflow-x: hidden;
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: rgba(47, 138, 120, 0.16);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

button,
a,
input,
select,
textarea,
[role="button"] {
  touch-action: manipulation;
}

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

.auth-panel,
.compliance-sheet,
.usage-reminder-sheet,
.release-notes-sheet,
.screen-panel,
.bottom-sheet,
.download-card,
.content {
  overflow-wrap: anywhere;
}

@media (max-width: 860px) {
  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea {
    font-size: 16px !important;
  }
}

@media (hover: none) and (pointer: coarse) {
  .icon-button,
  .voice-small,
  .sheet-close,
  .composer button,
  .nav button,
  .nav-account,
  .nav-cta,
  .back,
  .auth-close {
    min-width: 44px;
    min-height: 44px;
  }

  .composer {
    grid-template-columns: 44px minmax(0, 1fr) 44px;
  }

  .composer input,
  .composer button,
  .composer .composer-mic,
  .voice-small,
  .sheet-close {
    width: 44px;
    height: 44px;
  }

  .composer input {
    width: 100%;
  }
}

@supports (padding: max(0px)) {
  .auth-shell {
    padding-top: max(28px, var(--cunnian-safe-top));
    padding-bottom: max(22px, var(--cunnian-safe-bottom));
  }

  .compliance-modal {
    padding-top: max(20px, var(--cunnian-safe-top));
    padding-right: max(20px, var(--cunnian-safe-right));
    padding-bottom: max(20px, var(--cunnian-safe-bottom));
    padding-left: max(20px, var(--cunnian-safe-left));
  }

  .sheet-backdrop {
    padding-top: max(18px, var(--cunnian-safe-top));
    padding-right: max(18px, var(--cunnian-safe-right));
    padding-bottom: max(18px, var(--cunnian-safe-bottom));
    padding-left: max(18px, var(--cunnian-safe-left));
  }

  .toast {
    bottom: max(24px, var(--cunnian-safe-bottom));
  }

  .topbar {
    padding-top: var(--cunnian-safe-top);
  }

  footer {
    padding-bottom: max(48px, var(--cunnian-safe-bottom));
  }

  @media (max-width: 860px) {
    .site-nav {
      top: max(10px, var(--cunnian-safe-top));
      right: max(10px, var(--cunnian-safe-right));
      left: max(10px, var(--cunnian-safe-left));
      width: auto;
      transform: none;
    }

    .hero-inner,
    .wrap,
    .footer-row {
      width: auto;
      margin-right: max(16px, var(--cunnian-safe-right));
      margin-left: max(16px, var(--cunnian-safe-left));
    }
  }

  @media (max-width: 1000px) {
    .topbar-inner,
    .layout {
      width: auto;
      margin-right: max(16px, var(--cunnian-safe-right));
      margin-left: max(16px, var(--cunnian-safe-left));
    }
  }
}

/* Installed phone experience: use the real system status area and home indicator. */
@media (max-width: 430px) {
  .workspace {
    width: 100%;
    height: 100vh;
    min-height: 100vh;
    height: 100dvh;
    min-height: 100dvh;
  }

  .phone {
    grid-template-rows: minmax(0, 1fr) calc(74px + var(--cunnian-safe-bottom));
  }

  .phone .status {
    display: none;
  }

  .phone .screen {
    padding-top: max(14px, var(--cunnian-safe-top));
    padding-right: max(18px, var(--cunnian-safe-right));
    padding-bottom: 20px;
    padding-left: max(18px, var(--cunnian-safe-left));
  }

  .phone .nav {
    height: auto;
    min-height: 74px;
    padding-right: var(--cunnian-safe-right);
    padding-bottom: var(--cunnian-safe-bottom);
    padding-left: var(--cunnian-safe-left);
  }

  .compliance-modal {
    padding-top: var(--cunnian-safe-top);
    padding-right: var(--cunnian-safe-right);
    padding-bottom: var(--cunnian-safe-bottom);
    padding-left: var(--cunnian-safe-left);
  }

  .compliance-sheet,
  .usage-reminder-sheet,
  .release-notes-sheet {
    max-height: calc(100vh - var(--cunnian-safe-top));
    max-height: calc(100dvh - var(--cunnian-safe-top));
    padding-bottom: max(24px, var(--cunnian-safe-bottom));
  }

  .bottom-sheet {
    max-height: calc(100vh - 24px - var(--cunnian-safe-top) - var(--cunnian-safe-bottom));
    max-height: calc(100dvh - 24px - var(--cunnian-safe-top) - var(--cunnian-safe-bottom));
  }

}

/* Foldables and compact tablets get a wider app surface instead of a 390px mock phone. */
@media (min-width: 431px) and (max-width: 599px) {
  .workspace {
    width: calc(100% - 24px);
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    padding: 12px 0;
  }

  .side {
    display: none;
  }

  .phone {
    width: min(100%, 560px);
    height: calc(100vh - 24px);
    height: calc(100dvh - 24px);
    min-height: 0;
    border-radius: 24px;
    grid-template-rows: minmax(0, 1fr) calc(74px + var(--cunnian-safe-bottom));
  }

  .phone .status {
    display: none;
  }
}

/* Touch tablets use a native-width canvas in portrait, landscape and split view. */
@media (hover: none) and (pointer: coarse) and (min-width: 600px) {
  .workspace {
    width: min(calc(100% - 40px), 960px);
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    padding: 20px 0;
  }

  .side {
    display: none;
  }

  .phone {
    width: 100%;
    max-width: 960px;
    height: min(980px, calc(100vh - 40px));
    height: min(980px, calc(100dvh - 40px));
    min-height: 600px;
    border-radius: 24px;
    grid-template-rows: minmax(0, 1fr) calc(74px + var(--cunnian-safe-bottom));
  }

  .phone .status {
    display: none;
  }

  .phone .screen {
    padding-top: max(20px, var(--cunnian-safe-top));
    padding-right: max(24px, var(--cunnian-safe-right));
    padding-left: max(24px, var(--cunnian-safe-left));
  }

  .phone .screen-panel {
    width: 100%;
    max-width: 760px;
    margin-right: auto;
    margin-left: auto;
  }

  .phone .nav {
    height: auto;
    min-height: 74px;
    padding-bottom: var(--cunnian-safe-bottom);
  }
}

/* Phone landscape uses a side navigation rail and leaves room for display cutouts. */
@media (max-width: 1000px) and (max-height: 520px) and (orientation: landscape) {
  body:not(.auth-active) {
    overflow: hidden;
  }

  .workspace {
    width: 100%;
    height: 100vh;
    min-height: 0;
    height: 100dvh;
    padding: 0;
  }

  .side {
    display: none;
  }

  .phone {
    width: 100%;
    max-width: none;
    height: 100%;
    min-height: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    grid-template-columns: minmax(0, 1fr) calc(76px + var(--cunnian-safe-right));
    grid-template-rows: minmax(0, 1fr);
  }

  .phone .screen {
    grid-column: 1;
    grid-row: 1;
    padding-top: max(12px, var(--cunnian-safe-top));
    padding-right: 14px;
    padding-bottom: max(12px, var(--cunnian-safe-bottom));
    padding-left: max(14px, var(--cunnian-safe-left));
  }

  .phone .screen-panel {
    max-width: none;
  }

  .phone .status {
    display: none;
  }

  .phone .nav {
    grid-column: 2;
    grid-row: 1;
    height: 100%;
    min-height: 0;
    padding-top: var(--cunnian-safe-top);
    padding-right: var(--cunnian-safe-right);
    padding-bottom: var(--cunnian-safe-bottom);
    padding-left: 0;
    border-top: 0;
    border-left: 1px solid rgba(18, 63, 64, 0.1);
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: repeat(5, minmax(0, 1fr));
  }

  .phone .nav button.active::before {
    top: auto;
    left: 0;
    width: 2px;
    height: 24px;
    border-radius: 0 2px 2px 0;
  }

  .auth-shell {
    padding-top: max(12px, var(--cunnian-safe-top));
    padding-right: max(16px, var(--cunnian-safe-right));
    padding-bottom: max(12px, var(--cunnian-safe-bottom));
    padding-left: max(16px, var(--cunnian-safe-left));
  }

  .auth-panel {
    margin-top: 14px;
  }

  .compliance-sheet,
  .usage-reminder-sheet,
  .release-notes-sheet {
    max-height: calc(100vh - var(--cunnian-safe-top) - var(--cunnian-safe-bottom));
    max-height: calc(100dvh - var(--cunnian-safe-top) - var(--cunnian-safe-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

@media (forced-colors: active) {
  a,
  button,
  input,
  select,
  textarea {
    forced-color-adjust: auto;
  }

  .nav button.active::before {
    background: CanvasText;
  }
}
