/* SajuName mobile UI polish
   Consolidates the previous emergency inline patches into one targeted CSS layer.
   Scope: layout/visual polish only. No product logic, privacy logic, API, copy, or native iOS changes.
*/

:root {
  --sn-safe-top: env(safe-area-inset-top, 0px);
  --sn-safe-right: env(safe-area-inset-right, 0px);
  --sn-safe-bottom: env(safe-area-inset-bottom, 0px);
  --sn-safe-left: env(safe-area-inset-left, 0px);
  --sn-mobile-gap-xs: 8px;
  --sn-mobile-gap: 12px;
  --sn-mobile-gap-lg: 18px;
}

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  background-image:
    radial-gradient(circle at 18% 22%, rgba(255, 255, 255, 0.18) 0 1px, transparent 1.4px),
    radial-gradient(circle at 82% 34%, rgba(90, 58, 36, 0.025) 0 1px, transparent 1.45px),
    linear-gradient(135deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0));
  background-size: 22px 22px, 34px 34px, 100% 100%;
}

/* Preserve the existing iOS safe-area header fix. */
.nav {
  padding-top: calc(10px + var(--sn-safe-top));
  padding-left: max(14px, var(--sn-safe-left));
  padding-right: max(14px, var(--sn-safe-right));
  min-height: calc(56px + var(--sn-safe-top));
  height: auto;
  box-sizing: border-box;
}

.nav-language select {
  max-width: 96px;
}

/* Result flow chips: Saju Preview → Five Elements → Name Direction → Korean Names → K-Name Card */
.result-flow-indicator {
  align-items: center;
  gap: 7px 6px;
  line-height: 1.2;
}

.result-flow-indicator span[aria-hidden="true"] {
  flex: 0 0 auto;
  color: rgba(82, 69, 53, 0.58);
}

.result-flow-indicator span:not([aria-hidden="true"]) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  box-sizing: border-box;
  white-space: nowrap;
  word-break: keep-all;
  overflow-wrap: normal;
  hyphens: none;
  line-height: 1.05;
}

/* Subtle paper/stationery texture. Kept quiet so cards stay polished, not noisy. */
.result-view-panel,
.panel,
.name-card,
.result-card-cta-panel,
.pronunciation-panel,
.k-name-card,
.save-result-panel,
.saved-card-preview,
.saved-summary-stack > div,
.home-action-card,
.home-note-card,
.form-card {
  background-image:
    radial-gradient(circle at 12% 18%, rgba(255, 255, 255, 0.12) 0 1px, transparent 1.28px),
    radial-gradient(circle at 88% 64%, rgba(84, 57, 36, 0.018) 0 1px, transparent 1.42px);
  background-size: 21px 21px, 36px 36px;
  background-blend-mode: soft-light, normal;
}

/* Actual full-name preview/audio area in index.html. */
.audio-preview-details {
  margin-top: 16px;
  max-width: 100%;
}

.audio-preview-details summary {
  cursor: pointer;
  min-height: 32px;
}

.pronunciation-row {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 10px;
  max-width: 100%;
}

.pronunciation-row .btn,
#listen-given,
#listen-surname,
#listen-full-name {
  min-width: 0;
  max-width: 100%;
  white-space: normal;
  text-align: center;
  line-height: 1.16;
}

.slow-toggle {
  max-width: 100%;
  box-sizing: border-box;
  min-width: 0;
  line-height: 1.2;
}

.slow-toggle span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.pronunciation-status {
  overflow-wrap: anywhere;
}

/* Result cards/sections: keep breathing room after the emergency inline removals. */
.results .result-view-panel,
.results .result-flow-indicator,
.results .saju-preview-section,
.results .daily-note-section,
.results .morning-notes-section,
.results .names-section,
.results .surname-section,
.results .result-card-cta-section,
.results .card-preview-section,
.results .feedback-section,
.results .use-section,
.results .demo-notes-section,
.results .demo-qa-section {
  scroll-margin-top: calc(74px + var(--sn-safe-top));
}

@media (max-width: 520px) {
  main,
  .wrap {
    max-width: 100%;
    box-sizing: border-box;
  }

  .wrap {
    width: calc(100vw - 36px);
  }

  .result-flow-indicator {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    margin-bottom: var(--sn-mobile-gap-lg);
    font-size: clamp(10.5px, 2.8vw, 12px);
  }

  .result-flow-indicator span:not([aria-hidden="true"]) {
    flex: 0 1 auto;
    padding: 6px 8px;
  }

  .result-flow-indicator span[data-i18n="flowKNameCard"] {
    flex: 0 0 auto;
    letter-spacing: -0.02em;
  }

  .pronunciation-panel,
  .full-name-panel,
  .audio-preview-details,
  .pronunciation-row,
  .slow-toggle {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
  }

  .pronunciation-guide-list {
    display: grid;
    gap: var(--sn-mobile-gap);
  }

  .pronunciation-guide-item strong,
  #full-pronunciation-guide,
  #guide-given,
  #guide-surname {
    overflow-wrap: anywhere;
  }

  .pronunciation-row {
    flex-direction: column;
    gap: var(--sn-mobile-gap);
    margin-top: var(--sn-mobile-gap);
  }

  .pronunciation-row .btn,
  #listen-given,
  #listen-surname,
  #listen-full-name {
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    font-size: clamp(11.5px, 3.15vw, 12.75px);
  }

  .slow-toggle {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: var(--sn-mobile-gap);
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.62);
    overflow-x: clip;
  }

  .slow-toggle #slow-pronunciation {
    flex: 0 0 auto;
    max-width: 100%;
    box-sizing: border-box;
  }

  .slow-toggle span {
    flex: 1 1 0;
    min-width: 0;
    max-width: 100%;
    font-size: clamp(12px, 3.2vw, 13px);
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .result-view-panel,
  .saju-preview-section,
  .daily-note-section,
  .morning-notes-section,
  .names-section,
  .surname-section,
  .result-card-cta-section,
  .card-preview-section,
  .feedback-section {
    margin-top: 0;
  }

  .saju-insight-grid,
  .grid-2,
  .surname-layout,
  .card-export-panel,
  .save-result-panel,
  .feedback-actions,
  .saved-actions {
    gap: var(--sn-mobile-gap-lg);
  }

  .card-export-panel .btn,
  .save-result-panel .btn,
  .feedback-actions .btn,
  .saved-actions .btn,
  .result-card-cta-panel .btn {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    white-space: normal;
  }
}

@media (max-width: 380px) {
  .wrap {
    width: calc(100vw - 32px);
  }

  .result-flow-indicator {
    gap: 6px 5px;
    font-size: clamp(10px, 2.75vw, 11.5px);
  }

  .result-flow-indicator span:not([aria-hidden="true"]) {
    padding: 6px 7px;
  }
}
