/* ============================================================
   ReNew — styles
   Theming via [data-theme] on <html>. All colors are tokens.
   ============================================================ */

/* ---------- Theme tokens ---------- */
:root {
  /* Default: Sage & Terracotta — soft sage base (renewal, calm), warm cream, terracotta spark */
  --bg: #f1ebdb;
  --bg-2: #e7ddc8;
  --surface: #fbf7ee;
  --surface-2: #efe7d4;
  --text: #2b2e25;
  --text-muted: #6a6a5b;
  --primary: #4e7049;
  --primary-strong: #3b5838;
  --primary-soft: #e4eedb;
  --on-primary: #ffffff;
  --accent: #c2673f;
  --accent-soft: #f4e2d5;
  --border: #e2d7c0;
  --ring: #4e704955;
  --success: #4e7049;
  --warn: #b5831f;
  --danger: #b4452f;
  --shadow: 0 1px 2px rgba(40,38,27,.06), 0 6px 20px rgba(40,38,27,.08);
  --radius: 16px;
  --radius-sm: 10px;
  color-scheme: light;
}

:root[data-theme="ivory"] {
  /* Original Ivory & Teal (per product spec visual direction) */
  --bg: #f6f1e7;
  --bg-2: #efe7d7;
  --surface: #fffdf8;
  --surface-2: #f4eede;
  --text: #22201b;
  --text-muted: #6b655a;
  --primary: #0f6b63;
  --primary-strong: #0b534d;
  --primary-soft: #e2efed;
  --on-primary: #ffffff;
  --accent: #c79a3a;
  --accent-soft: #f6ecd2;
  --border: #e3dac6;
  --ring: #0f6b6355;
  --success: #2f7d55;
  --warn: #b5831f;
  --danger: #b4452f;
  color-scheme: light;
}

:root[data-theme="midnight"] {
  --bg: #0f1417;
  --bg-2: #0b1013;
  --surface: #171e22;
  --surface-2: #1f282d;
  --text: #e8ede9;
  --text-muted: #9aa6a2;
  --primary: #3fb9ab;
  --primary-strong: #58cdbe;
  --primary-soft: #16302d;
  --on-primary: #06201d;
  --accent: #d9b46a;
  --accent-soft: #2a2416;
  --border: #2a343a;
  --ring: #3fb9ab66;
  --success: #5bbd84;
  --warn: #d9b46a;
  --danger: #e2735c;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.45);
  color-scheme: dark;
}

:root[data-theme="sand"] {
  --bg: #f4e8d8;
  --bg-2: #ecdcc4;
  --surface: #fffaf2;
  --surface-2: #f6ead6;
  --text: #2c2418;
  --text-muted: #7a6a52;
  --primary: #b0552f;
  --primary-strong: #8f4123;
  --primary-soft: #f6e0d2;
  --on-primary: #fff7f1;
  --accent: #caa23f;
  --accent-soft: #f4e8cf;
  --border: #e4d4ba;
  --ring: #b0552f55;
  --success: #5a7d3a;
  --warn: #b5831f;
  --danger: #b4452f;
  --shadow: 0 1px 2px rgba(44,36,24,.06), 0 6px 20px rgba(44,36,24,.1);
  color-scheme: light;
}

:root[data-theme="forest"] {
  --bg: #eef2ea;
  --bg-2: #e2e9db;
  --surface: #ffffff;
  --surface-2: #eef3ea;
  --text: #1d241b;
  --text-muted: #5f6b58;
  --primary: #2f6b3a;
  --primary-strong: #234f2c;
  --primary-soft: #e0efe2;
  --on-primary: #ffffff;
  --accent: #b78b2e;
  --accent-soft: #f0ead3;
  --border: #d7e0cf;
  --ring: #2f6b3a55;
  --success: #2f7d55;
  --warn: #b5831f;
  --danger: #b4452f;
  --shadow: 0 1px 2px rgba(29,36,27,.06), 0 6px 20px rgba(29,36,27,.08);
  color-scheme: light;
}

:root[data-theme="slate"] {
  --bg: #eef1f4;
  --bg-2: #e2e7ec;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --text: #1b2127;
  --text-muted: #5c6670;
  --primary: #3a5a8c;
  --primary-strong: #2b456b;
  --primary-soft: #e2e9f3;
  --on-primary: #ffffff;
  --accent: #b08534;
  --accent-soft: #f0e9d5;
  --border: #d5dde4;
  --ring: #3a5a8c55;
  --success: #2f7d55;
  --warn: #b5831f;
  --danger: #b4452f;
  --shadow: 0 1px 2px rgba(27,33,39,.06), 0 6px 20px rgba(27,33,39,.08);
  color-scheme: light;
}

:root[data-theme="rose"] {
  --bg: #f7eef0;
  --bg-2: #efe0e4;
  --surface: #fffafb;
  --surface-2: #f7eaee;
  --text: #2a1f23;
  --text-muted: #77636b;
  --primary: #a23e63;
  --primary-strong: #822f4d;
  --primary-soft: #f6e0e8;
  --on-primary: #fff7fa;
  --accent: #c0923f;
  --accent-soft: #f4ead2;
  --border: #e8d3da;
  --ring: #a23e6355;
  --success: #2f7d55;
  --warn: #b5831f;
  --danger: #b4452f;
  --shadow: 0 1px 2px rgba(42,31,35,.06), 0 6px 20px rgba(42,31,35,.08);
  color-scheme: light;
}

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100dvh;
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
h1,h2,h3,h4 { line-height: 1.2; margin: 0 0 .4em; font-weight: 700; letter-spacing: -.01em; }
p { margin: 0 0 .8em; }
a { color: var(--primary); }
img { max-width: 100%; display: block; }
button { font: inherit; }

/* Focus */
:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 2px;
  border-radius: 6px;
}

.noscript { padding: 2rem; text-align: center; }

/* ---------- Layout shell ---------- */
#app { min-height: 100dvh; }

.shell {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px calc(96px + env(safe-area-inset-bottom)) 16px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.2) blur(10px);
  -webkit-backdrop-filter: saturate(1.2) blur(10px);
  border-bottom: 1px solid var(--border);
  margin: 0 -16px 16px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
.topbar-inner {
  max-width: 640px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.topbar h1 { margin: 0; font-size: 1.15rem; }
.topbar .sub { color: var(--text-muted); font-size: .82rem; }

/* ---------- Brand mark ---------- */
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  display: grid; place-items: center; color: var(--on-primary);
  font-weight: 800; box-shadow: var(--shadow);
}
.brand .brand-mark { width: 32px; height: auto; display: block; }
.brand .wordmark { font-weight: 800; letter-spacing: -.02em; }
.brand .wordmark span { color: var(--primary); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.card.flat { box-shadow: none; }
.card h2 { font-size: 1.02rem; }
.card .label { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); font-weight: 700; }

.muted { color: var(--text-muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: 1px solid transparent; cursor: pointer;
  background: var(--primary); color: var(--on-primary);
  padding: 12px 16px; border-radius: 12px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .06s ease, filter .15s ease, background .15s ease;
  min-height: 44px; text-decoration: none;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }
.btn.block { width: 100%; }
.btn.secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn.ghost { background: transparent; color: var(--primary); border-color: var(--border); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: 8px 12px; min-height: 36px; font-size: .9rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; font-size: .9rem;
  min-height: 40px;
}
.chip[aria-pressed="true"], .chip.active {
  background: var(--primary-soft); border-color: var(--primary); color: var(--primary-strong); font-weight: 700;
}

/* ---------- Forms ---------- */
label.field { display: block; margin-bottom: 14px; }
label.field > .lab { display: block; font-weight: 700; margin-bottom: 6px; font-size: .92rem; }
label.field > .hint { display:block; color: var(--text-muted); font-size: .82rem; margin-bottom: 6px; }
input, textarea, select {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 14px; min-height: 44px;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--primary); }
.inline-fields { display: flex; gap: 10px; }
.inline-fields > * { flex: 1; }

/* ---------- Status pills (non-color-dependent via glyph + text) ---------- */
.status { display:inline-flex; align-items:center; gap:6px; font-weight:700; font-size:.82rem; padding:4px 9px; border-radius:999px; border:1px solid var(--border); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status.done   { color: var(--success); background: color-mix(in srgb, var(--success) 14%, transparent); border-color: color-mix(in srgb, var(--success) 35%, transparent); }
.status.partly { color: var(--warn);    background: color-mix(in srgb, var(--warn) 14%, transparent);    border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.status.skipped{ color: var(--text-muted); background: var(--surface-2); }
.status.none   { color: var(--text-muted); background: transparent; border-style: dashed; }

/* ---------- Commitment logger ---------- */
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seg button {
  appearance: none; cursor: pointer; border: 1px solid var(--border); background: var(--surface);
  color: var(--text-muted); border-radius: 10px; padding: 9px 4px; font-size: .78rem; font-weight: 700;
  display: flex; flex-direction: column; align-items: center; gap: 4px; min-height: 52px;
}
.seg button .ico { font-size: 1rem; line-height: 1; }
.seg button[aria-pressed="true"].v-done   { background: color-mix(in srgb, var(--success) 16%, var(--surface)); border-color: var(--success); color: var(--success); }
.seg button[aria-pressed="true"].v-partly { background: color-mix(in srgb, var(--warn) 16%, var(--surface));    border-color: var(--warn);    color: var(--warn); }
.seg button[aria-pressed="true"].v-skipped{ background: var(--surface-2); border-color: var(--text-muted); color: var(--text); }
.seg button[aria-pressed="true"].v-none   { background: var(--surface-2); border-color: var(--border); color: var(--text); }

/* ---------- Progress bars / meters ---------- */
.meter { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.meter > span { display:block; height:100%; background: linear-gradient(90deg, var(--primary), var(--primary-strong)); border-radius: 999px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.stat { background: var(--surface-2); border:1px solid var(--border); border-radius: 12px; padding: 12px; }
.stat .n { font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; }
.stat .d { color: var(--text-muted); font-size: .8rem; }

/* ---------- Journey day cards ---------- */
.day-list { display: grid; gap: 10px; }
.day {
  display: grid; grid-template-columns: 46px 1fr auto; gap: 12px; align-items: center;
  background: var(--surface); border:1px solid var(--border); border-radius: 14px; padding: 12px; width: 100%;
  text-align: left; cursor: pointer; color: inherit;
}
.day .num { width: 46px; height: 46px; border-radius: 12px; display:grid; place-items:center; font-weight:800;
  background: var(--surface-2); color: var(--text-muted); font-size: 1.05rem; }
.day.is-today { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.day.is-today .num { background: var(--primary); color: var(--on-primary); }
.day.is-done .num { background: color-mix(in srgb, var(--success) 20%, var(--surface)); color: var(--success); }
.day.is-future { opacity: .72; }
.day .t { font-weight: 700; }
.day .meta { color: var(--text-muted); font-size: .82rem; }
.day .tag { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); }

/* ---------- Bottom nav ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  display: flex; justify-content: center; gap: 2px;
}
.tabbar .inner { display: flex; width: 100%; max-width: 640px; justify-content: space-between; }
.tabbar a {
  flex: 1; text-decoration: none; color: var(--text-muted);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: .68rem; font-weight: 700; padding: 6px 2px; border-radius: 10px;
}
.tabbar a .ico { font-size: 1.25rem; }
.tabbar a[aria-current="page"] { color: var(--primary); }
.tabbar a[aria-current="page"] .ico { transform: translateY(-1px); }

/* ---------- Auth / splash ---------- */
.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; position: relative; overflow: hidden; }
.auth-card { width: 100%; max-width: 420px; position: relative; z-index: 2; }

/* Real lotus photo overlay — blooms in on load */
.lotus-stage { position: absolute; inset: 0; display: grid; place-items: center; z-index: 0; pointer-events: none; }
.lotus-photo {
  width: min(390px, 70vmin); height: auto; transform-origin: center 48%;
  margin-top: -7vh;   /* sit higher so it clears the footer / Writers Depot logo */
  opacity: 0; transform: scale(.52) rotate(-8deg);
  animation: lotusPhotoBloom 4s cubic-bezier(.32,.86,.3,1) .15s forwards,
             lotusPhotoBreathe 9s ease-in-out 4.6s infinite;
}
/* expand beyond the login box, then shrink to a subtle bloom tucked behind the card */
@keyframes lotusPhotoBloom {
  0%   { opacity: 0;    transform: scale(.52) rotate(-8deg); }
  42%  { opacity: .9;   transform: scale(1.7)  rotate(2deg); }
  58%  { opacity: .9;   transform: scale(1.7)  rotate(2deg); }
  100% { opacity: .62;  transform: scale(1)    rotate(0); }
}
@keyframes lotusPhotoBreathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.03); } }
:root[data-theme="midnight"] .lotus-photo { animation-name: lotusPhotoBloomDark, lotusPhotoBreathe; }
@keyframes lotusPhotoBloomDark {
  0%   { opacity: 0;    transform: scale(.52) rotate(-8deg); }
  42%  { opacity: .82;  transform: scale(1.7)  rotate(2deg); }
  58%  { opacity: .82;  transform: scale(1.7)  rotate(2deg); }
  100% { opacity: .55;  transform: scale(1)    rotate(0); }
}
@media (prefers-reduced-motion: reduce) {
  .lotus-photo { animation: none; opacity: .62; transform: none; }
}
/* keep hero/footer text legible over the lotus */
.auth-hero .renew-word, .auth-hero .tagline, .auth-hero .brand-tag,
.auth-wrap > .auth-card ~ .center, .auth-wrap .wd-byline + .center {
  text-shadow: 0 1px 10px var(--bg), 0 0 6px var(--bg), 0 1px 2px var(--bg);
}
.auth-hero { text-align: center; margin-bottom: 18px; }
.renew-mark { width: 104px; height: auto; margin: 0 auto 6px; display: block; }
.renew-word { font-size: 2rem; letter-spacing: -.02em; margin: 0; }
.renew-word span { color: var(--accent); }
.brand-tag { font-size: .74rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); margin-top: 4px; }
.wd-byline { display: flex; justify-content: center; margin: 2px 0 8px; opacity: .9; }
.wd-byline img { width: 118px; height: auto; display: block; }
.auth-hero .logo-lg {
  width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 12px;
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  display: grid; place-items: center; color: var(--on-primary); font-weight: 800; font-size: 1.6rem;
  box-shadow: var(--shadow);
}
.auth-hero h1 { font-size: 1.8rem; }
.tagline { color: var(--text-muted); }
.auth-switch { text-align: center; margin-top: 12px; }
.auth-switch button { background: none; border: none; color: var(--primary); font-weight: 700; cursor: pointer; }
.form-error { color: var(--danger); font-weight: 600; font-size: .9rem; margin: 4px 0 8px; }
.pw-meter { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.pw-meter > span { display:block; height:100%; transition: width .2s ease, background .2s ease; }

/* ---------- Theme picker ---------- */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px,1fr)); gap: 10px; }
.theme-swatch {
  cursor: pointer; border: 2px solid var(--border); border-radius: 12px; padding: 8px; background: var(--surface);
  display: flex; flex-direction: column; gap: 8px; text-align: left;
}
.theme-swatch[aria-pressed="true"] { border-color: var(--primary); }
.theme-swatch .dots { display: flex; gap: 4px; }
.theme-swatch .dots i { width: 16px; height: 16px; border-radius: 50%; display:block; border: 1px solid rgba(0,0,0,.08); }
.theme-swatch .name { font-size: .8rem; font-weight: 700; }

/* ---------- Proof gallery ---------- */
.proof-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px,1fr)); gap: 10px; }
.proof-item { background: var(--surface); border:1px solid var(--border); border-radius: 12px; overflow: hidden; display:flex; flex-direction:column; }
.proof-item img { width: 100%; aspect-ratio: 4/3; object-fit: cover; }
.proof-item .txt { padding: 10px 12px; }
.proof-item .cap { font-size: .85rem; }
.proof-item .pday { font-size: .7rem; color: var(--accent); font-weight: 700; text-transform: uppercase; }
.proof-text-tile { aspect-ratio: 4/3; background: var(--primary-soft); color: var(--primary-strong); display:grid; place-items:center; padding:12px; font-weight:700; text-align:center; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: grid; place-items: end center; }
@media (min-width: 560px){ .modal-backdrop { place-items: center; } }
.modal {
  background: var(--surface); width: 100%; max-width: 560px; border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); box-shadow: var(--shadow);
  max-height: 92dvh; overflow: auto;
}
@media (min-width: 560px){ .modal { border-radius: 20px; } }
.modal h3 { font-size: 1.1rem; }
.modal-close { float: right; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; width: 36px; height: 36px; cursor: pointer; color: var(--text); font-size: 1.1rem; }

/* ---------- Pills row / segmented ---------- */
.pills { display: flex; gap: 8px; flex-wrap: wrap; }
.segmented { display:flex; background: var(--surface-2); border:1px solid var(--border); border-radius: 12px; padding: 3px; }
.segmented button { flex:1; border:none; background:transparent; padding:9px; border-radius:9px; font-weight:700; color: var(--text-muted); cursor:pointer; }
.segmented button[aria-pressed="true"]{ background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Saved indicator ---------- */
.saved-state { font-size: .78rem; color: var(--text-muted); display:inline-flex; align-items:center; gap:6px; }
.saved-state.ok { color: var(--success); }
.saved-state.err { color: var(--danger); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px);
  bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 60;
  background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 12px;
  font-weight: 600; font-size: .9rem; box-shadow: var(--shadow); opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Progress ring (today header) ---------- */
.ring { --p: 0; width: 56px; height: 56px; border-radius: 50%;
  background: conic-gradient(var(--primary) calc(var(--p)*1%), var(--surface-2) 0);
  display:grid; place-items:center; }
.ring > span { width: 44px; height: 44px; border-radius:50%; background: var(--surface); display:grid; place-items:center; font-weight:800; font-size:.8rem; }

/* ---------- Misc ---------- */
.divider { height:1px; background: var(--border); margin: 14px 0; border:0; }
.pill-note { background: var(--accent-soft); border:1px solid color-mix(in srgb, var(--accent) 35%, transparent); color: var(--text); padding: 10px 12px; border-radius: 12px; font-size:.88rem; }
.empty { text-align:center; padding: 28px 16px; color: var(--text-muted); }
.empty .big { font-size: 2.2rem; margin-bottom: 8px; }
ul.clean { list-style:none; padding:0; margin:0; }
.kbd-row { display:flex; gap:8px; flex-wrap:wrap; }
.sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); border:0; }
