:root {
  --profile-border: rgba(0,0,0,.1);
  --profile-field: #f5f5f7;
  --profile-muted: #6e6e73;
  --profile-primary: #007aff;
}
html[data-theme="dark"] {
  --profile-border: rgba(255,255,255,.12);
  --profile-field: #2c2c2e;
  --profile-muted: #a1a1a6;
}

html, body { margin:0; min-height:100%; background:var(--rb-bg,#f5f5f7); }
body {
  min-height:100vh;
  min-height:100dvh;
  display:flex;
  flex-direction:column;
  color:var(--rb-text,#1d1d1f);
}
button, input, textarea { font:inherit; }
button { cursor:pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline:3px solid var(--profile-primary);
  outline-offset:3px;
}
[hidden] { display:none !important; }

.top { flex:0 0 48px; }
.top-link { display:inline-flex; align-items:center; gap:8px; min-height:44px; color:#fff; }
.top-link svg { width:18px; height:18px; }
.wrap { flex:1; width:min(100%,560px); margin:0 auto; padding:28px 24px 40px; }
.state-loading { min-height:45vh; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:12px; color:var(--profile-muted); }
.spinner { width:22px; height:22px; border:2px solid var(--profile-border); border-top-color:var(--profile-primary); border-radius:50%; animation:profile-spin .8s linear infinite; }
@keyframes profile-spin { to { transform:rotate(360deg); } }
#main[data-state="loading"] .state-ready, #main[data-state="ready"] .state-loading { display:none; }
#main[data-state="ready"] .state-ready { display:block; }
.col { width:100%; max-width:440px; margin:0 auto; }
.profile-intro { margin:0 0 22px; }
.profile-intro h1 { color:var(--rb-text-strong,#1d1d1f); font-size:26px; line-height:1.2; font-weight:650; letter-spacing:-.7px; }
.avatar {
  display:block;
  position:relative;
  width:128px;
  height:128px;
  margin:22px auto 24px;
  padding:0;
  overflow:hidden;
  border:1px solid var(--profile-border);
  border-radius:28px;
  background:var(--profile-field);
  box-shadow:0 8px 24px rgba(0,0,0,.08);
}
.avatar img { width:100%; height:100%; object-fit:cover; }
.avatar-edit {
  position:absolute;
  right:0;
  bottom:0;
  display:grid;
  width:32px;
  height:32px;
  place-items:center;
  border:3px solid var(--rb-bg,#f5f5f7);
  border-radius:50%;
  background:#0c0c0c;
  color:#fff;
}
.avatar-edit svg { width:15px; height:15px; fill:currentColor; }
.avatar-input { display:none; }
.stats {
  display:flex;
  align-items:center;
  justify-content:center;
  min-height:88px;
  margin:0 0 24px;
  border:1px solid var(--profile-border);
  border-radius:18px;
  background:var(--rb-surface,#fff);
  box-shadow:0 6px 24px rgba(0,0,0,.05);
}
.stat { display:flex; flex:1; flex-direction:column; align-items:center; gap:6px; }
.stat-num { color:var(--rb-text-strong,#1d1d1f); font-size:24px; font-weight:650; }
.stat-label { color:var(--profile-muted); font-size:12px; font-weight:600; letter-spacing:.04em; text-transform:uppercase; }
.stat-sep { width:1px; height:36px; background:var(--profile-border); }
.fields { display:grid; gap:16px; }
.field-row.inline { display:grid; grid-template-columns:minmax(0,1fr) minmax(0,1fr); gap:12px; }
.field { min-width:0; }
.field label { display:block; margin:0 0 7px 3px; color:var(--profile-muted); font-size:11px; font-weight:650; letter-spacing:.06em; text-transform:uppercase; }
.field input, .field textarea, .field.readonly .value {
  display:block;
  width:100%;
  min-height:52px;
  padding:14px 15px;
  border:1px solid var(--profile-border);
  border-radius:14px;
  background:var(--profile-field);
  color:var(--rb-text,#1d1d1f);
  font-size:15px;
}
.field textarea { min-height:92px; resize:vertical; }
.field input::placeholder, .field textarea::placeholder { color:var(--profile-muted); opacity:1; }
.field.readonly .value { display:flex; align-items:center; gap:10px; overflow-wrap:anywhere; font-weight:600; }
.field.readonly svg { width:16px; height:16px; flex:0 0 auto; fill:var(--profile-muted); }
.profile-save-btn, #continueToPost {
  display:flex;
  width:100%;
  min-height:52px;
  align-items:center;
  justify-content:center;
  margin-top:24px;
  padding:14px 18px;
  border:0;
  border-radius:14px;
  background:var(--profile-primary);
  color:#fff;
  font-size:15px;
  font-weight:650;
}
.profile-save-btn:disabled, #continueToPost:disabled { cursor:not-allowed; opacity:.42; }
#postReturn { margin-top:0 !important; }
#postReturnError { color:#c62828; }
.sign-out-action {
  display:block;
  min-height:48px;
  margin:8px auto 0;
  padding:12px 16px;
  border:0;
  border-radius:12px;
  background:transparent;
  color:var(--profile-muted);
  font-size:14px;
}
.profile-save-error { color:#c9342b; font-size:13px; line-height:1.5; margin:12px 0; }

/* Signup profile uses the same single primary action as the app flow. */
body.is-onboarding { min-height:100vh; min-height:100dvh; }
body.is-onboarding .wrap { display:flex; width:min(100%,480px); padding:20px 18px calc(12px + env(safe-area-inset-bottom)); }
body.is-onboarding .state-ready { display:flex !important; flex:1; }
body.is-onboarding .col { display:flex; flex:1; flex-direction:column; max-width:none; }
body.is-onboarding .profile-intro { margin:4px 2px 10px; }
body.is-onboarding .profile-intro h1 { font-size:24px; }
body.is-onboarding .avatar { margin:16px auto 22px; }
body.is-onboarding .stats { margin-bottom:22px; }
body.is-onboarding #saveProfileBtn { display:none !important; }
body.is-onboarding #postReturn { margin-top:auto !important; padding-top:20px; }
body.is-onboarding #continueToPost { margin-top:0; }
body.is-onboarding .sign-out-action { margin-top:6px; }

@media(max-width:520px) {
  .wrap { width:100%; padding:22px 18px 32px; }
  .field-row.inline { gap:10px; }
  body.is-onboarding .wrap { padding-top:22px; }
}
@media(prefers-reduced-motion:reduce) { .spinner { animation-duration:1.5s; } }
