:root {
  color-scheme: light;
  --bg: #f7f6f2;
  --surface: #fff;
  --surface-soft: #f1f0eb;
  --surface-tint: #eaf1ed;
  --ink: #20221f;
  --muted: #6b6e68;
  --subtle: #92958f;
  --line: #dedfd9;
  --line-strong: #c9ccc5;
  --green: #234d40;
  --green-hover: #193d32;
  --green-soft: #e5efea;
  --logo-accent: #007cba;
  --action-bg: #234d40;
  --action-hover: #193d32;
  --hover: #e9e9e4;
  --floating-surface: rgba(255,255,255,.9);
  --backdrop: rgba(20,22,20,.3);
  --on-solid: #fff;
  --amber-soft: #f7eedc;
  --red: #9a3838;
  --red-soft: #fbefed;
  --shadow-sm: 0 1px 2px rgba(26, 31, 27, .05), 0 8px 24px rgba(26, 31, 27, .05);
  --shadow-md: 0 18px 48px rgba(26, 31, 27, .11);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --control: 44px;
  --sidebar: 260px;
  --sidebar-collapsed: 72px;
  --content: 820px;
  --page-content: 720px;
  --page-gutter: clamp(16px, 4vw, 32px);
  --font-sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
  --font-logo: "Avenir Next", Avenir, var(--font-sans);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #171a18;
  --surface: #202421;
  --surface-soft: #2a2f2b;
  --surface-tint: #25332d;
  --ink: #f0f1ed;
  --muted: #b5bab4;
  --subtle: #919890;
  --line: #363c37;
  --line-strong: #4a524b;
  --green: #79b09a;
  --green-hover: #82b8a1;
  --green-soft: #263b32;
  --action-bg: #376f5c;
  --action-hover: #407c67;
  --hover: #303531;
  --floating-surface: rgba(32,36,33,.92);
  --backdrop: rgba(0,0,0,.5);
  --on-solid: #fff;
  --amber-soft: #413621;
  --red: #ed9292;
  --red-soft: #462a29;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.22), 0 8px 24px rgba(0,0,0,.18);
  --shadow-md: 0 18px 48px rgba(0,0,0,.38);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { color: var(--ink); font-family: var(--font-sans); -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
img, svg, video { max-width: 100%; }
button, input, textarea { font: inherit; }
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='m1 1 5 5 5-5' fill='none' stroke='%236b706a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-position: right 11px center;
  background-repeat: no-repeat;
  background-size: 11px 7px;
}
button, a { touch-action: manipulation; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}


.profile { position: fixed; top: max(10px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); z-index: 55; display: flex; flex-direction: column; align-items: flex-end; }
.profile > button { width: var(--control); max-width: min(280px, 70vw); min-height: var(--control); display: inline-flex; align-items: center; justify-content: center; overflow: hidden; padding: 8px; border: 1px solid var(--line); border-radius: 13px; background: var(--floating-surface); color: var(--ink); box-shadow: var(--shadow-sm); cursor: pointer; text-overflow: ellipsis; white-space: nowrap; backdrop-filter: blur(12px); }
.profile > button:hover { background: var(--surface-soft); }
.profile > button .avatar { width: 21px; height: 21px; display: block; flex: none; fill: currentColor; }
.profile > button .profile-label { display: none; }
.profile > button.has-email { width: auto; padding: 8px 13px; }
.profile > button.has-email .avatar { display: none; }
.profile > button.has-email .profile-label { display: inline; max-width: 210px; overflow: hidden; text-overflow: ellipsis; }
.profile-menu { width: min(340px, calc(100vw - 24px)); max-height: calc(100dvh - 76px - env(safe-area-inset-top)); margin-top: 8px; padding: 16px; overflow-y: auto; overscroll-behavior: contain; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow-md); color: var(--ink); }
.profile-menu h2 { margin: 0 0 8px; font-family: var(--font-serif); font-size: 21px; font-weight: 500; letter-spacing: -.025em; overflow-wrap: anywhere; }
.profile-menu p { margin: 0 0 9px; overflow-wrap: anywhere; }
.profile-menu label { display: block; margin: 10px 0; color: var(--muted); font-size: 13px; font-weight: 600; }
.profile-menu input { width: 100%; min-height: var(--control); margin-top: 5px; padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); color: inherit; font-size: 16px; }
.profile-menu .stack { display: grid; gap: 8px; margin-top: 12px; }
.profile-menu button, .profile-menu a.pbtn { min-height: var(--control); display: inline-flex; align-items: center; justify-content: center; padding: 9px 14px; border: 1px solid var(--action-bg); border-radius: 11px; background: var(--action-bg); color: var(--on-solid); cursor: pointer; font: inherit; font-weight: 650; text-align: center; text-decoration: none; }
.profile-menu button:hover, .profile-menu a.pbtn:hover { background: var(--action-hover); }
.profile-menu button.secondary, .profile-menu a.pbtn.secondary { border-color: var(--line-strong); background: var(--surface); color: var(--ink); }
.profile-menu button.secondary:hover, .profile-menu a.pbtn.secondary:hover { background: var(--surface-soft); }
.profile-menu .err { color: var(--red); }
@media (max-width: 640px) {
  .profile { right: max(8px, env(safe-area-inset-right)); }
  .profile > button.has-email { width: var(--control); padding: 8px; }
  .profile > button.has-email .avatar { display: block; }
  .profile > button.has-email .profile-label { display: none; }
  .profile-menu { width: calc(100vw - 16px); max-height: calc(100dvh - 68px - env(safe-area-inset-top)); }
}

/* Authentication stays in the profile popover, with its own reading hierarchy. */
.profile-menu.profile-auth { position: relative; width: min(400px, calc(100vw - 24px)); padding: 32px; border-radius: 22px; }
.profile-auth .auth-mark { display: grid; place-items: center; width: 48px; height: 48px; margin-bottom: 22px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface-tint); color: var(--green); }
.profile-auth .auth-mark svg { width: 25px; height: 25px; }
.profile-auth .auth-title { margin: 0 28px 12px 0; font-size: 32px; line-height: 1.12; letter-spacing: -.035em; }
.profile-auth .auth-title:focus { outline: none; }
.profile-auth .auth-description { margin: 0 0 20px; color: var(--muted); font-size: 14px; line-height: 1.65; }
.profile-auth .auth-email { margin: -10px 0 18px; font-size: 15px; font-weight: 650; line-height: 1.5; overflow-wrap: anywhere; }
.profile-auth label { margin: 24px 0 0; color: var(--ink); font-size: 13px; }
.profile-auth input { min-height: 50px; margin-top: 9px; padding: 12px 14px; border-radius: 12px; font-family: inherit; font-weight: 400; }
.profile-auth input::placeholder { color: var(--muted); opacity: 1; }
.profile-auth input:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }
.profile-auth .stack { gap: 6px; margin-top: 22px; }
.profile-auth .stack > button { min-height: 48px; border-radius: 12px; font-size: 14px; }
.profile-auth button:disabled { opacity: .65; cursor: wait; }
.profile-auth button.auth-close { position: absolute; top: 14px; right: 14px; width: 40px; min-height: 40px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--muted); font-size: 26px; font-weight: 400; }
.profile-auth button.auth-close:hover { background: var(--surface-soft); color: var(--ink); }
.profile-auth button.auth-text-button { border-color: transparent; background: transparent; color: var(--muted); font-weight: 500; }
.profile-auth button.auth-text-button:hover { background: var(--surface-soft); color: var(--ink); }
.profile-auth .auth-detail { padding: 16px 18px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-soft); }
.profile-auth .auth-detail p { margin: 0; font-size: 12px; line-height: 1.65; color: var(--muted); }
.profile-auth .auth-detail p + p { margin-top: 8px; }
.profile-auth .auth-detail p:first-child { color: var(--ink); font-weight: 600; }
.profile-auth .auth-footnote { margin: 20px 0 0; padding-top: 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; line-height: 1.65; text-align: center; }
.profile-auth .err { margin-top: 16px; font-size: 13px; line-height: 1.6; }
@media (max-width: 640px) {
  .profile-menu.profile-auth { width: calc(100vw - 16px); padding: 28px 24px 24px; }
  .profile-auth .auth-title { font-size: 30px; }
}

.profile-menu.profile-account { width: min(360px, calc(100vw - 24px)); padding: 12px; border-radius: 20px; }
.profile-identity { display: flex; align-items: center; gap: 12px; padding: 14px 10px 20px; }
.profile-initial { display: grid; flex: none; place-items: center; width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-tint); color: var(--green); font-size: 19px; font-weight: 650; }
.profile-identity-copy { min-width: 0; }
.profile-account .profile-eyebrow { margin: 0 0 4px; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.profile-account h2.profile-email { margin: 0; font-family: var(--font-sans); font-size: 14px; font-weight: 600; line-height: 1.5; letter-spacing: 0; overflow-wrap: anywhere; }
.profile-plan-badge { display: inline-block; margin-top: 7px; padding: 2px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); color: var(--muted); font-size: 11px; font-weight: 650; line-height: 1.5; }
.profile-nav { display: grid; gap: 3px; padding-top: 8px; border-top: 1px solid var(--line); }
.profile-nav-item { display: flex; align-items: center; gap: 12px; min-height: 68px; padding: 10px 12px; border-radius: 12px; color: var(--ink); text-decoration: none; }
.profile-nav-item:hover { background: var(--surface-soft); }
.profile-nav-icon { display: grid; flex: none; place-items: center; width: 24px; height: 24px; color: var(--muted); }
.profile-nav-icon svg { width: 21px; height: 21px; }
.profile-nav-copy { display: grid; min-width: 0; gap: 3px; }
.profile-nav-label { font-size: 14px; font-weight: 600; line-height: 1.3; }
.profile-nav-help { color: var(--muted); font-size: 11px; line-height: 1.5; }
.profile-nav-arrow { margin-left: auto; color: var(--muted); font-size: 22px; }
.profile-account button.profile-logout { justify-content: flex-start; margin-top: 8px; padding: 12px; border: 0; border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 500; }
.profile-account button.profile-logout:hover { background: var(--surface-soft); color: var(--ink); }
.profile-plan { margin: 0 4px 14px; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-tint); }
.profile-plan h3 { margin: 0 0 7px; font-family: var(--font-serif); font-size: 21px; font-weight: 500; line-height: 1.2; letter-spacing: -.02em; }
.profile-plan p { margin: 0 0 10px; color: var(--muted); font-size: 12px; line-height: 1.65; }
.profile-plan-link { color: var(--green); font-size: 12px; font-weight: 650; line-height: 1.6; text-underline-offset: 3px; }
.profile-account :is(a, button):focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }
@media (max-width: 640px) { .profile-menu.profile-account { width: calc(100vw - 16px); } }


/* Keep touch controls above Safari's focus-zoom threshold, including landscape
   and tablet layouts. This invariant must survive component font shorthands. */
@media (pointer: coarse) {
  input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"], [type="hidden"], [type="button"], [type="submit"], [type="reset"]),
  textarea, select, [contenteditable="true"] { font-size: max(16px, 1em) !important; }
}
