/* Mobile-first responsive layer.  Keeps component-level layout rules separate from brand styling. */

html {
  overflow-x: clip;
}

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

.mobile-nav {
  display: none;
}

@media (max-width: 760px) {
  body {
    background-attachment: scroll;
  }

  .site-header {
    min-height: 64px;
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas: "brand menu member";
    gap: 8px;
    padding: 8px 14px;
  }

  .brand-mark img {
    width: 40px;
    height: 40px;
  }

  .brand-mark strong {
    font-size: 0.95rem;
  }

  .brand-mark small {
    font-size: 0.72rem;
  }

  .main-nav--desktop {
    display: none;
  }

  .mobile-nav {
    display: block;
    grid-area: menu;
    position: relative;
  }

  .mobile-nav > summary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 44px;
    min-height: 44px;
    padding: 0 10px;
    border: 1px solid rgba(212, 185, 138, 0.42);
    border-radius: 8px;
    color: var(--gold-3);
    cursor: pointer;
    list-style: none;
  }

  .mobile-nav > summary::-webkit-details-marker {
    display: none;
  }

  .mobile-nav__icon,
  .mobile-nav__icon::before,
  .mobile-nav__icon::after {
    display: block;
    width: 16px;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
    content: "";
    transition: transform 0.18s ease;
  }

  .mobile-nav__icon {
    position: relative;
  }

  .mobile-nav__icon::before,
  .mobile-nav__icon::after {
    position: absolute;
    left: 0;
  }

  .mobile-nav__icon::before { transform: translateY(-5px); }
  .mobile-nav__icon::after { transform: translateY(5px); }
  .mobile-nav[open] .mobile-nav__icon { background: transparent; }
  .mobile-nav[open] .mobile-nav__icon::before { transform: rotate(45deg); }
  .mobile-nav[open] .mobile-nav__icon::after { transform: rotate(-45deg); }

  .mobile-nav__list {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 40;
    display: grid;
    width: min(280px, calc(100vw - 28px));
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(54, 34, 99, 0.97);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
  }

  .mobile-nav__list button {
    min-height: 44px;
    border: 0;
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--muted);
    background: transparent;
    text-align: left;
    font: inherit;
  }

  .mobile-nav__list button.active {
    color: var(--text);
    background: rgba(247, 243, 233, 0.13);
  }

  .member-button {
    min-height: 44px;
    padding: 8px 10px;
    font-size: 0.85rem;
    white-space: nowrap;
  }

  .hero,
  .page-hero {
    width: min(100% - 28px, 1080px);
  }

  .hero {
    gap: 24px;
    padding: 36px 0 44px;
  }

  .page-hero {
    min-height: 0;
    padding: 38px 0 18px;
  }

  .page-hero.compact {
    min-height: 0;
  }

  .hero h1,
  .page-hero h1,
  .story-layout h1 {
    font-size: clamp(2rem, 10vw, 2.7rem);
    line-height: 1.16;
  }

  .hero p,
  .page-hero p,
  .story-layout p {
    font-size: 1rem;
    line-height: 1.7;
  }

  .section {
    padding: 32px 0;
  }

  /* Desktop reserves room beneath split workspaces; phones should move directly to the next result section. */
  .workspace {
    padding: 22px 0 36px;
  }

  .member-grid,
  .link-list,
  .story-layout,
  .checkout-layout,
  .section.product-strip {
    width: min(100% - 28px, 1160px);
  }

  .entry-grid {
    gap: 14px;
    padding: 22px 0 44px;
  }

  /* The featured product strip is four columns on desktop; its more specific desktop
     selector must be explicitly reset here so cards never collapse into narrow columns. */
  .product-strip .products-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .product-strip .product-card:first-child {
    grid-column: auto;
  }

  .feature-panel,
  .compare-grid article,
  .method-grid div,
  .future-grid article,
  .chart-result article,
  .form-card,
  .info-panel,
  .login-card,
  .checkout-card,
  .product-card {
    padding: 18px;
  }

  .feature-panel {
    min-height: 0;
  }

  .info-panel {
    position: static;
  }

  .inline-fields,
  .birth-date-fields .inline-fields {
    gap: 8px;
  }

  .data-list div,
  .planet-row {
    gap: 6px;
  }

  .planet-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .planet-row strong {
    text-align: left;
  }

  .house-ruler-table-wrap {
    margin-inline: 0;
    padding-bottom: 4px;
    scrollbar-color: var(--gold) transparent;
  }

  .natal-wheel-layout {
    margin: 22px 0;
  }

  .natal-wheel-panel {
    padding: 12px;
    border-radius: 12px;
  }

  .natal-wheel-panel-header {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    margin: 0 0 12px;
    padding: 12px;
  }

  .wheel-client-info strong {
    white-space: normal;
  }

  .wheel-controls {
    justify-content: space-between;
  }

  .wheel-mode-switch {
    flex: 1;
    justify-content: space-between;
  }

  .wheel-mode-switch button {
    min-height: 36px;
    padding-inline: 10px;
  }

  .wheel-settings-trigger {
    width: 44px;
    height: 44px;
  }

  .aspect-legend {
    max-width: none;
    margin-top: 14px;
    font-size: 0.78rem;
  }

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

  .natal-wheel-aspect-status {
    padding: 10px 12px;
  }

  .wheel-settings-sheet__panel {
    max-height: 90dvh;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  }

  .wheel-setting-row {
    grid-template-columns: minmax(0, 1fr) 68px 38px;
    gap: 8px;
    padding: 7px;
  }

  .natal-guide,
  .natal-product-prompts,
  .natal-share {
    margin-top: 40px;
  }

  .natal-guide-section {
    padding: 22px 0;
  }

  .natal-guide-section p {
    font-size: 1rem;
    line-height: 1.8;
  }

  .natal-share-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .natal-share-actions > * {
    min-height: 44px;
  }

  .share-dialog {
    width: calc(100% - 28px);
    padding: 24px 18px;
  }

  .site-footer {
    gap: 18px;
    padding: 28px 18px calc(28px + env(safe-area-inset-bottom));
  }

  .footer-links {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
  }

  .footer-links button {
    min-height: 44px;
    padding: 8px;
    text-align: left;
  }

  .support-dock {
    right: 14px;
    bottom: calc(76px + env(safe-area-inset-bottom));
    width: 50px;
    height: 50px;
  }

  .translation-dock {
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 380px) {
  .site-header {
    padding-inline: 10px;
  }

  .brand-mark span {
    display: none;
  }

  .member-button {
    font-size: 0;
    min-width: 44px;
  }

  .member-button::after {
    content: "會員";
    font-size: 0.78rem;
  }

  .birth-date-fields .inline-fields {
    grid-template-columns: 1fr 0.8fr 0.8fr;
  }

  .natal-share-actions,
  .footer-links {
    grid-template-columns: 1fr;
  }
}

/* Tablet and desktop retain the four-corner chart card; only phones decouple it. */
@media (min-width: 601px) and (max-width: 919px) {
  .natal-wheel-panel > .natal-chart-wheel {
    display: block;
    width: min(100%, 600px);
    margin: 0 auto;
  }

  .aspect-legend {
    position: absolute;
    right: 20px;
    bottom: 28px;
    width: 168px;
    margin: 0;
  }
}

/*
 * Compact chart layouts also apply to wide-screen phones with enlarged display
 * settings. Keeping this breakpoint aligned with the mobile navigation avoids
 * a mixed layout where the header is mobile but the chart content is desktop.
 */
@media (max-width: 760px) {
  /* One shared content column keeps all natal-data cards aligned. */
  .chart-result {
    inline-size: min(720px, calc(100% - 36px));
    min-inline-size: 0;
    margin-inline: auto;
  }

  /*
   * Framed cards already have 18px internal padding. Give unframed headings
   * and controls the same reading start without narrowing their card lists or
   * share buttons. This prevents the visual "jump left" seen between sections.
   */
  .chart-result > .section-title,
  .chart-result > details > summary,
  .chart-result > .natal-guide > .natal-guide-heading,
  .chart-result > .natal-product-prompts > .natal-guide-heading,
  .chart-result > .natal-share > :first-child,
  .chart-result > .natal-share > .natal-share-status {
    box-sizing: border-box;
    padding-inline: 18px;
  }

  .chart-result > .summary-panel,
  .chart-result > .core-chart-data,
  .chart-result > .chart-distribution,
  .chart-result > details {
    inline-size: 100%;
    min-inline-size: 0;
    max-inline-size: none;
  }

  .chart-result > .core-chart-data {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
  }

  .chart-result > .core-chart-data > article {
    inline-size: 100%;
    min-inline-size: 0;
  }

  .chart-result .house-ruler-table-wrap {
    inline-size: 100%;
    max-inline-size: 100%;
    margin-inline: 0;
  }

  .natal-wheel-panel {
    padding: 16px 12px 14px;
  }

  .natal-wheel-panel-header {
    align-items: center;
    flex-direction: row;
    justify-content: space-between;
    width: 100%;
    min-width: 0;
    margin-bottom: 12px;
    padding: 0 4px;
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  .wheel-client-info {
    flex: 0 1 auto;
    min-width: 0;
    max-width: 34%;
  }

  .wheel-client-info strong {
    color: var(--deep-text);
    font-size: 13px;
    line-height: 1.25;
  }

  .wheel-client-info span {
    color: #746783;
    font-size: 11px;
    line-height: 1.35;
  }

  .wheel-controls {
    flex: 0 0 auto;
    gap: 6px;
  }

  .wheel-mode-switch {
    flex: 0 0 auto;
    gap: 2px;
    padding: 3px;
  }

  .wheel-mode-switch button {
    min-height: 34px;
    padding: 4px 7px;
    font-size: 11px;
  }

  .wheel-settings-trigger {
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
  }

  .natal-wheel-panel > .natal-chart-wheel {
    display: block;
    width: min(100%, 360px);
    max-width: 360px;
    aspect-ratio: 1 / 1;
    margin: 0 auto;
  }

  .aspect-legend {
    position: static;
    display: block;
    width: 100%;
    max-width: none;
    margin: 14px 0 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    backdrop-filter: none;
    color: var(--deep-text);
    font-size: 11px;
  }

  .aspect-legend ul {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 14px;
    width: 100%;
    margin: 0;
  }

  .aspect-legend li {
    gap: 4px;
    white-space: nowrap;
  }

  .aspect-legend > small {
    display: block;
    margin-top: 8px;
    text-align: center;
  }

  .wheel-settings-sheet__panel {
    width: 100%;
    max-width: none;
    max-height: 75dvh;
    padding-top: 30px;
    -webkit-overflow-scrolling: touch;
  }

  .wheel-settings-sheet__panel::before {
    display: block;
    width: 38px;
    height: 4px;
    margin: -16px auto 14px;
    border-radius: 999px;
    background: #c5bccc;
    content: "";
  }
}

@media (max-width: 380px) {
  .wheel-client-info {
    max-width: 28%;
  }

  .wheel-mode-switch button {
    padding-inline: 5px;
    font-size: 10px;
  }
}
