:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

html {
  max-width: 100%;
  overflow-x: clip;
}

body {
  max-width: 100%;
  min-width: 0;
}

.landing-reference-page,
.auth-reference-page,
.public-page,
.dynamic-embed-page,
.standard-embed-editor-page {
  min-height: 100svh;
  min-height: 100dvh;
}

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

@media (pointer: coarse) {
  button,
  .button,
  [role="button"],
  input:not([type="range"]):not([type="color"]):not([type="checkbox"]):not([type="radio"]),
  select {
    min-height: 44px;
  }

  .icon-button,
  .carousel-arrow,
  .asset-picker-close,
  .social-modal-close,
  .link-card-summary-actions button,
  .link-card-summary-actions a {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
  }
}

@media (max-width: 820px) {
  input,
  select,
  textarea {
    font-size: 16px !important;
  }

  .landing-reference-layout {
    width: min(100%, 620px);
    padding-top: max(42px, calc(var(--safe-top) + 24px));
    padding-right: max(16px, var(--safe-right));
    padding-bottom: max(42px, calc(var(--safe-bottom) + 24px));
    padding-left: max(16px, var(--safe-left));
  }

  .landing-reference-logo img {
    display: block;
    max-width: min(100%, 360px);
    height: auto;
    margin-inline: auto;
  }

  .landing-reference-actions .button,
  .landing-reference-links > div {
    min-height: 56px;
  }

  .landing-reference-profile {
    width: 100%;
  }

  .auth-reference-shell {
    width: auto;
    margin-right: max(16px, var(--safe-right));
    margin-left: max(16px, var(--safe-left));
  }

  .auth-reference-header {
    padding-top: var(--safe-top);
  }

  .auth-reference-main {
    min-height: auto;
    padding-right: 0;
    padding-left: 0;
  }

  .auth-reference-card {
    width: 100%;
  }

  .auth-reference-footer {
    padding-bottom: max(20px, var(--safe-bottom));
  }

  .dashboard-page {
    width: auto;
    margin-inline: max(12px, var(--safe-left)) max(12px, var(--safe-right));
  }

  .dashboard-topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    min-height: calc(64px + var(--safe-top));
    padding-top: var(--safe-top);
    background: rgba(0, 0, 0, .94);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
  }

  .dashboard-topbar-actions {
    width: auto;
    margin-left: auto;
    justify-content: flex-end;
    gap: 8px;
  }

  .dashboard-topbar-center {
    display: flex;
    flex: 0 0 auto;
    margin-left: 0;
  }

  .dashboard-topbar-center .topbar-breadcrumb {
    display: none;
  }

  .dashboard-topbar-actions .button {
    min-height: 44px;
  }

  .dashboard-topbar .mobile-menu {
    display: none !important;
  }

  .dashboard-layout {
    display: block;
    padding: 0 0 max(40px, var(--safe-bottom));
  }

  .dashboard-sidebar {
    position: sticky;
    top: calc(64px + var(--safe-top));
    z-index: 35;
    width: calc(100% + 24px);
    min-height: 0;
    margin-left: -12px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, .94);
    border-bottom: 1px solid rgba(255, 255, 255, .14);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
  }

  .dashboard-sidebar > .sidebar-brand,
  .dashboard-sidebar > .sidebar-rule,
  .dashboard-sidebar > .sidebar-label,
  .dashboard-sidebar > .sidebar-account,
  .dashboard-sidebar > .sidebar-bottom {
    display: none !important;
  }

  .dashboard-nav-list {
    display: flex;
    width: 100%;
    max-height: none;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 0 2px;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
  }

  .dashboard-nav-list::-webkit-scrollbar {
    display: none;
  }

  .dashboard-nav-list .sidebar-item {
    flex: 0 0 auto;
    min-height: 44px;
    padding: 0 13px;
    scroll-snap-align: start;
  }

  .dashboard-main {
    width: 100%;
    min-width: 0;
    padding-top: 18px;
  }

  .dashboard-grid,
  .field-grid,
  .account-grid,
  .link-fields,
  .discord-settings-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .dashboard-grid {
    gap: 14px;
  }

  .editor-panel,
  .preview-sticky {
    min-width: 0;
    padding: 18px 16px;
  }

  .panel-heading {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 14px;
  }

  .panel-heading > .button {
    width: 100%;
  }

  .preview-column {
    min-width: 0;
  }

  .dashboard-preview {
    min-height: min(460px, 62svh);
  }

  .custom-card,
  .link-platform-picker,
  .badge-admin-result,
  .discord-account-card {
    min-width: 0;
    padding: 15px 13px;
  }

  .toggle-row,
  .discord-setting-toggle,
  .embed-mode-option,
  .name-effect-option,
  .particle-option,
  .cursor-effect-option {
    min-height: 48px;
  }

  .color-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .particle-picker {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

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

  .carousel-arrow {
    width: 44px;
    height: 44px;
  }

  .embed-preview-shell iframe {
    height: min(520px, 68svh);
  }

  .discord-connect-card {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .discord-connect-card .button {
    width: 100%;
    grid-column: 1 / -1;
  }

  .discord-account-head,
  .discord-action-row {
    align-items: stretch;
    flex-direction: column;
  }

  .discord-action-row .button {
    width: 100%;
  }

  .asset-picker-backdrop,
  .social-modal-backdrop {
    align-items: end;
    min-height: 100dvh;
    padding: max(10px, var(--safe-top)) max(10px, var(--safe-right)) max(10px, var(--safe-bottom)) max(10px, var(--safe-left));
  }

  .asset-picker-dialog,
  .social-modal {
    width: 100%;
    max-height: calc(100dvh - max(20px, var(--safe-top)) - max(20px, var(--safe-bottom)));
    overflow: auto;
    overscroll-behavior: contain;
    border-radius: 18px;
  }

  .asset-picker-close,
  .social-modal-close {
    flex: 0 0 44px;
  }

  .asset-picker-foot {
    position: sticky;
    bottom: 0;
    margin-inline: -19px;
    margin-bottom: -19px;
    padding: 14px 19px max(14px, var(--safe-bottom));
    background: #101014;
  }

  .public-page:not(.dynamic-embed-page):not(.is-embed-editor) {
    padding-top: max(18px, var(--safe-top));
    padding-right: max(16px, var(--safe-right));
    padding-bottom: max(18px, var(--safe-bottom));
    padding-left: max(16px, var(--safe-left));
  }

  .public-page:not(.dynamic-embed-page):not(.is-embed-editor) .public-main {
    width: 100%;
    padding: 0;
  }

  .public-page:not(.dynamic-embed-page):not(.is-embed-editor) .public-card {
    width: min(100%, var(--profile-card-width, 520px));
    max-width: 100%;
    padding: 24px 18px 20px;
  }

  .public-page .profile-link {
    min-height: 56px;
  }

  .public-page:not(.dynamic-embed-page):not(.is-embed-editor):has(.profile-audio-widget) .public-main {
    padding-bottom: calc(88px + var(--safe-bottom));
  }

  .public-page:not(.dynamic-embed-page):not(.is-embed-editor) > .profile-audio-widget {
    right: max(12px, var(--safe-right));
    bottom: max(12px, var(--safe-bottom));
    left: max(12px, var(--safe-left));
    display: grid;
    width: auto;
    grid-template-columns: auto minmax(80px, 1fr);
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: rgba(5, 5, 7, .9);
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 18px;
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
  }

  .public-page:not(.dynamic-embed-page):not(.is-embed-editor) > .profile-audio-widget .profile-audio-toggle {
    min-height: 44px;
  }

  .public-page:not(.dynamic-embed-page):not(.is-embed-editor) > .profile-audio-widget .profile-audio-volume {
    width: auto;
    padding-right: 8px;
  }

  .dynamic-embed-page:not(.is-embed-editor) {
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .dynamic-embed-page:not(.is-embed-editor) .dynamic-embed-main {
    display: grid;
    width: min(100%, 590px);
    min-height: 100dvh;
    align-content: center;
    gap: 14px;
    margin: 0 auto;
    padding-top: max(24px, var(--safe-top));
    padding-right: max(16px, var(--safe-right));
    padding-bottom: max(28px, var(--safe-bottom));
    padding-left: max(16px, var(--safe-left));
  }

  .dynamic-embed-page:not(.is-embed-editor) [data-dynamic-tile] {
    position: relative !important;
    inset: auto !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    left: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: none !important;
    min-height: 0;
    margin: 0 !important;
    translate: none !important;
    transform: none !important;
    touch-action: auto;
    will-change: auto;
  }

  .dynamic-embed-page:not(.is-embed-editor) .embed-profile-card,
  .dynamic-embed-page:not(.is-embed-editor) .embed-connections-card,
  .dynamic-embed-page:not(.is-embed-editor) .embed-badges-card,
  .dynamic-embed-page:not(.is-embed-editor) .dynamic-audio-widget,
  .dynamic-embed-page:not(.is-embed-editor) .dynamic-lyrics-widget,
  .dynamic-embed-page:not(.is-embed-editor) .dynamic-discord-profile-widget {
    border-radius: 20px;
  }

  .dynamic-embed-page .embed-connection,
  .dynamic-embed-page .dynamic-audio-control {
    min-height: 44px;
  }

  .dynamic-embed-page .dynamic-audio-control {
    flex: 0 0 44px;
    min-width: 44px;
  }

  .dynamic-embed-page:not(.is-embed-editor) .dynamic-lyrics-viewport {
    max-height: min(340px, 42svh);
  }

  .embed-editor-toolbar {
    top: max(8px, var(--safe-top));
    width: calc(100% - max(16px, var(--safe-left)) - max(16px, var(--safe-right)));
    gap: 8px;
    padding: 8px;
    color: #f5f6fb;
    border-radius: 16px;
    --text: #f5f6fb;
    --muted: #aeb5c1;
    --dim: #8e96a4;
  }

  .embed-editor-copy {
    display: none;
  }

  .embed-editor-actions {
    display: grid;
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .embed-editor-status {
    grid-column: 1 / -1;
    width: 100%;
    text-align: center;
  }

  .embed-editor-actions .button {
    width: 100%;
    min-height: 44px;
    padding-inline: 10px;
    color: #fff !important;
  }

  .dynamic-embed-page.is-embed-editor,
  .standard-embed-editor-page.is-embed-editor {
    min-height: 100dvh;
  }

  .dynamic-embed-page.is-embed-editor .dynamic-embed-main,
  .standard-embed-editor-page.is-embed-editor .public-main {
    width: 100%;
    height: calc(100dvh - 82px - var(--safe-top));
    min-height: calc(100dvh - 82px - var(--safe-top));
    margin-top: calc(82px + var(--safe-top));
  }

  .dynamic-embed-page.is-embed-editor [data-dynamic-tile],
  .standard-embed-editor-page.is-embed-editor [data-standard-tile] {
    max-width: calc(100vw - max(32px, var(--safe-left) + var(--safe-right) + 16px));
    max-height: calc(100dvh - 116px - var(--safe-top) - var(--safe-bottom));
  }

  .standard-embed-editor-page.is-embed-editor .public-brand {
    display: none !important;
  }
}

@media (max-width: 480px) {
  .landing-reference-layout {
    gap: 36px;
  }

  .landing-reference-copy h1 {
    font-size: clamp(3rem, 18vw, 4.4rem);
  }

  .landing-reference-actions {
    gap: 12px;
  }

  .landing-reference-actions .button {
    min-height: 50px;
    padding-inline: 8px;
    font-size: .82rem;
  }

  .landing-reference-profile {
    min-height: 0;
  }

  .auth-reference-pitch h1 {
    font-size: clamp(3rem, 15vw, 4.5rem);
  }

  .auth-reference-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
  }

  .auth-reference-actions a {
    justify-content: center;
    min-width: 0;
  }

  .dashboard-topbar-actions #view-profile {
    width: 44px;
    min-width: 44px;
    padding: 0;
    overflow: hidden;
    font-size: 0;
  }

  .dashboard-topbar-actions #view-profile svg {
    width: 18px;
    height: 18px;
  }

  .editor-panel,
  .preview-sticky {
    padding: 15px 12px;
  }

  .dashboard-nav-list .sidebar-item {
    padding-inline: 11px;
  }

  .dashboard-nav-list .sidebar-item kbd {
    display: none;
  }

  .link-platform-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .link-card-summary {
    grid-template-columns: 18px 44px minmax(0, 1fr);
    gap: 8px;
  }

  .link-card-brand {
    width: 44px;
    height: 44px;
  }

  .link-card-summary-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
    gap: 6px;
    padding-top: 8px;
    border-top: 1px solid var(--line);
  }

  .asset-picker-foot,
  .social-modal-footer {
    display: grid;
    grid-template-columns: 1fr;
  }

  .asset-picker-foot .button,
  .social-modal-footer .button {
    width: 100%;
  }

  .dynamic-embed-page:not(.is-embed-editor) .dynamic-embed-main {
    align-content: start;
  }
}

@media (max-width: 340px) {
  .landing-reference-profile {
    padding-right: 17px;
    padding-left: 17px;
  }

  .landing-reference-profile footer {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .dashboard-page {
    margin-inline: 8px;
  }

  .dashboard-sidebar {
    width: calc(100% + 16px);
    margin-left: -8px;
    padding-inline: 8px;
  }

  .particle-picker {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 820px) and (max-height: 600px) and (orientation: landscape) {
  .landing-reference-layout {
    display: grid;
    width: min(100%, 920px);
    grid-template-columns: minmax(260px, .8fr) minmax(320px, 1fr);
    gap: 30px;
    padding-block: max(18px, var(--safe-top)) max(18px, var(--safe-bottom));
  }

  .landing-reference-copy {
    text-align: left;
  }

  .landing-reference-actions {
    justify-content: flex-start;
  }

  .landing-reference-profile {
    min-height: 0;
    padding-top: 60px;
  }

  .landing-reference-links {
    margin-top: 24px;
  }

  .landing-reference-links > div {
    min-height: 52px;
  }

  .landing-reference-profile footer {
    margin-top: 24px;
  }

  .auth-reference-main {
    grid-template-columns: minmax(0, 1fr) minmax(340px, 1fr);
    gap: 34px;
    align-items: start;
    padding-block: 26px;
  }

  .auth-reference-pitch h1 {
    font-size: clamp(3rem, 8vw, 4.5rem);
  }

  .dynamic-embed-page:not(.is-embed-editor) .dynamic-embed-main {
    width: min(100%, 920px);
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: start;
  }
}

@media (min-width: 821px) and (max-width: 920px) and (max-height: 600px) and (orientation: landscape) {
  .dynamic-embed-page:not(.is-embed-editor) {
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .dynamic-embed-page:not(.is-embed-editor) .dynamic-embed-main {
    display: grid;
    width: min(100%, 920px);
    min-height: 100dvh;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: start;
    gap: 14px;
    margin: 0 auto;
    padding-top: max(18px, var(--safe-top));
    padding-right: max(16px, var(--safe-right));
    padding-bottom: max(18px, var(--safe-bottom));
    padding-left: max(16px, var(--safe-left));
  }

  .dynamic-embed-page:not(.is-embed-editor) [data-dynamic-tile] {
    position: relative !important;
    inset: auto !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    left: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: none !important;
    min-height: 0;
    margin: 0 !important;
    translate: none !important;
    transform: none !important;
    touch-action: auto;
    will-change: auto;
  }

  .dynamic-embed-page .dynamic-audio-control {
    width: 44px;
    min-width: 44px;
    height: 44px;
    flex: 0 0 44px;
  }
}

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