:root {
  --bg: #F6F8F7;
  --surface: #FFFFFF;
  --text: #14201D;
  --muted: #66756F;
  --accent: #00614A;
  --on-accent: #FFFFFF;
  --border: #E1E1E1;
  --shadow: rgba(20, 32, 29, 0.07);
  --danger: #C0392B;
  /* Fixed top edit-header's total rendered height (safe-area clearance +
     its own vertical padding + the icon-button row + its hairline
     border). Content below uses this single source of truth. */
  --app-header-height: calc(env(safe-area-inset-top) + 65px);
  /* Fixed bottom save bar's total rendered height, same idea. */
  --save-bar-height: calc(env(safe-area-inset-bottom) + 78px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0A1512;
    --surface: #101E1A;
    --text: #F3F6F4;
    --muted: #8FA39D;
    --accent: #1FBA8F;
    --on-accent: #04231C;
    --border: #1E2E29;
    --shadow: rgba(0, 0, 0, 0.3);
    --danger: #FF6B5E;
  }
}

:root[data-theme="dark"] {
  --bg: #0A1512;
  --surface: #101E1A;
  --text: #F3F6F4;
  --muted: #8FA39D;
  --accent: #1FBA8F;
  --on-accent: #04231C;
  --border: #1E2E29;
  --shadow: rgba(0, 0, 0, 0.3);
  --danger: #FF6B5E;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  overflow-x: hidden;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  touch-action: manipulation;
  overscroll-behavior-y: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* The app-wide user-select: none above is for tap-friendly chrome; this
   is a form page, so every field the user actually types into needs full
   native text interaction back. */
input,
textarea {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

img,
svg {
  -webkit-user-drag: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- ambient signal (very subtle, whole-page) ---------- */
.ambient-signal {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(ellipse 100% 40% at 50% 0%, color-mix(in srgb, var(--accent) 5%, transparent), transparent 70%);
}

/* ---------- fixed top header ---------- */
.edit-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 12px) max(14px, env(safe-area-inset-right)) 12px max(14px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

.header-icon-btn {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: transform 120ms ease, background-color 120ms ease;
}

.header-icon-btn:active {
  transform: scale(0.9);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.header-icon-btn svg {
  width: 19px;
  height: 19px;
}

.header-title {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: 16.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-save-btn {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  min-width: 52px;
  padding: 0 6px;
  border: 0;
  background: none;
  color: var(--accent);
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 150ms ease;
}

.header-save-btn:disabled {
  color: var(--muted);
  opacity: 0.55;
  cursor: default;
}

.header-save-btn:active:not(:disabled) {
  opacity: 0.6;
}

/* ---------- main content ---------- */
.edit-content {
  position: relative;
  z-index: 1;
  max-width: 480px;
  margin: 0 auto;
  padding: calc(var(--app-header-height) + 20px) max(20px, env(safe-area-inset-right)) calc(var(--save-bar-height) + 24px) max(20px, env(safe-area-inset-left));
}

/* ---------- photo section ---------- */
.edit-photo-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 30px;
}

.avatar-frame {
  position: relative;
  width: 104px;
  margin-bottom: 10px;
}

.avatar {
  width: 104px;
  height: 104px;
  border-radius: 50%;
  overflow: hidden;
  background: color-mix(in srgb, var(--accent) 9%, var(--surface));
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 26px var(--shadow);
}

.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.avatar-img[hidden] {
  display: none;
}

.avatar-placeholder {
  width: 72%;
  height: 72%;
  color: var(--accent);
}

.ph-silhouette {
  fill: color-mix(in srgb, var(--accent) 55%, transparent);
}

.ph-pulse {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.3;
  opacity: 0;
  transform-origin: 60px 60px;
  animation: avatar-pulse 3.8s ease-out infinite;
}

.ph-pulse-delay {
  animation-delay: 1.6s;
}

@keyframes avatar-pulse {
  0%   { transform: scale(0.75); opacity: 0.5; }
  70%  { opacity: 0.12; }
  100% { transform: scale(1.28); opacity: 0; }
}

.avatar-edit-btn {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--accent);
  cursor: pointer;
  transition: transform 120ms ease;
  animation: avatar-edit-glow 3.5s ease-in-out infinite;
}

.avatar-edit-btn svg {
  width: 15px;
  height: 15px;
}

.avatar-edit-btn:active {
  transform: scale(0.86);
}

@keyframes avatar-edit-glow {
  0%, 100% { box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 20%, transparent); }
  50%      { box-shadow: 0 4px 18px color-mix(in srgb, var(--accent) 40%, transparent); }
}

.change-photo-btn {
  border: 0;
  background: none;
  padding: 6px 4px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
  transition: opacity 120ms ease;
}

.change-photo-btn:active {
  opacity: 0.55;
}

/* ---------- form ---------- */
.form-section {
  margin-bottom: 26px;
}

.form-section-title {
  padding: 0 2px;
  margin-bottom: 12px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.field-group {
  margin-bottom: 14px;
}

.field-group:last-child {
  margin-bottom: 0;
}

.field-label {
  display: block;
  margin-bottom: 7px;
  padding: 0 2px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.field-input,
.field-textarea {
  display: block;
  width: 100%;
  padding: 13px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.field-input:focus,
.field-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent);
}

.field-textarea {
  min-height: 92px;
  line-height: 1.5;
  resize: vertical;
}

/* Same "chip + input" language as the phone/username fields on the login
   screen — reused here rather than inventing a second pattern. */
.prefix-input {
  display: flex;
  align-items: center;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.prefix-input:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent);
}

.prefix-input-affix {
  flex: none;
  padding: 0 2px 0 14px;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.prefix-input-field {
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: 13px 14px 13px 6px;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
}

/* ---------- fixed bottom save bar ---------- */
.save-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  padding: 12px max(20px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 12px) max(20px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
}

.save-bar-inner {
  max-width: 480px;
  margin: 0 auto;
}

.save-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 52px;
  border: 0;
  border-radius: 15px;
  background: var(--accent);
  color: var(--on-accent);
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 120ms ease, opacity 150ms ease;
}

.save-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.save-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.save-btn-spinner {
  display: none;
  width: 17px;
  height: 17px;
  border: 2.2px solid color-mix(in srgb, var(--on-accent) 35%, transparent);
  border-top-color: var(--on-accent);
  border-radius: 50%;
  animation: dvr-spin 0.7s linear infinite;
}

.save-btn.is-saving .save-btn-spinner {
  display: inline-block;
}

.save-btn.is-saving .save-btn-label {
  opacity: 0.85;
}

@keyframes dvr-spin {
  to { transform: rotate(360deg); }
}

/* ---------- unsaved-changes sheet (reused bottom-sheet pattern) ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  transition: opacity 220ms ease;
}

.sheet-backdrop.is-open {
  opacity: 1;
}

.confirm-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 41;
  max-width: 480px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 22px max(20px, env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  box-shadow: 0 -10px 30px var(--shadow);
  transform: translate3d(0, 100%, 0);
  transition: transform 260ms cubic-bezier(0.22, 0.61, 0.36, 1);
  text-align: center;
}

.confirm-sheet.is-open {
  transform: translate3d(0, 0, 0);
}

.confirm-sheet-title {
  font-size: 16.5px;
  font-weight: 700;
  margin-bottom: 6px;
}

.confirm-sheet-desc {
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--muted);
  margin-bottom: 20px;
}

.confirm-sheet-action {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 50px;
  border-radius: 14px;
  border: 0;
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, opacity 150ms ease;
}

.confirm-sheet-action:active {
  transform: scale(0.98);
  opacity: 0.9;
}

.confirm-sheet-action-primary {
  background: var(--accent);
  color: var(--on-accent);
  margin-bottom: 10px;
}

.confirm-sheet-action-danger {
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border));
  color: var(--danger);
}

@media (prefers-reduced-motion: reduce) {
  .ph-pulse,
  .avatar-edit-btn {
    animation: none;
  }
  .header-icon-btn,
  .header-save-btn,
  .avatar-edit-btn,
  .change-photo-btn,
  .field-input,
  .field-textarea,
  .prefix-input,
  .save-btn,
  .confirm-sheet-action,
  .sheet-backdrop,
  .confirm-sheet {
    transition: none;
  }
}

@media (min-width: 560px) {
  .save-bar {
    padding-bottom: calc(env(safe-area-inset-bottom) + 20px);
  }
}
