/* =========================================================================
   CJ Plans — mobile-first PWA styling
   Design goals: native feel, big touch targets, safe-area aware, no
   website-in-a-box tells (no tap highlight, no accidental text selection,
   no overscroll bounce leaking the page background).
   ========================================================================= */

:root {
  --rose: #ff6f9c;
  --rose-deep: #e0567a;
  --indigo: #7b6cff;
  --teal: #3fd0c9;
  --amber: #ffb454;
  --slate: #8892a6;
  --blue: #4d9bff;

  --bg: #12101a;
  --bg-elev: #1c1926;
  --bg-elev-2: #262233;
  --line: #322c42;
  --text: #f4f1fa;
  --text-dim: #a89fbd;
  --text-faint: #6f6786;
  --accent: var(--teal);
  --accent-2: var(--indigo);
  --grad: linear-gradient(135deg, var(--teal), var(--indigo));
  --danger: #ff5a6a;
  --ok: #45d17a;

  --radius: 16px;
  --radius-sm: 11px;
  --tap: 46px;               /* minimum finger-sized target */
  --header-h: 54px;
  --tabbar-h: 60px;

  /* Safe-area insets (notch, home indicator, gesture bar) */
  --sa-top: env(safe-area-inset-top, 0px);
  --sa-bottom: env(safe-area-inset-bottom, 0px);
  --sa-left: env(safe-area-inset-left, 0px);
  --sa-right: env(safe-area-inset-right, 0px);
}

/* Light palette: applied via the OS preference when no explicit theme is set,
   and always when [data-theme="light"] is forced. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #fdf2f6;
    --bg-elev: #ffffff;
    --bg-elev-2: #fbeef3;
    --line: #f0d9e3;
    --text: #241c2a;
    --text-dim: #6c6076;
    --text-faint: #a99db2;
  }
}
:root[data-theme="light"] {
  --bg: #fdf2f6;
  --bg-elev: #ffffff;
  --bg-elev-2: #fbeef3;
  --line: #f0d9e3;
  --text: #241c2a;
  --text-dim: #6c6076;
  --text-faint: #a99db2;
}
/* Forced dark (in case the OS is light but the user picked dark). */
:root[data-theme="dark"] {
  --bg: #12101a;
  --bg-elev: #1c1926;
  --bg-elev-2: #262233;
  --line: #322c42;
  --text: #f4f1fa;
  --text-dim: #a89fbd;
  --text-faint: #6f6786;
}

* { box-sizing: border-box; }

/* Kill the mobile-web tells */
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* No text selection by default — feels like an app, not a page. */
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;   /* removes the 300ms tap delay + double-tap zoom */
}

/* Re-enable selection only where reading/copying matters */
input, textarea, [contenteditable="true"], .selectable {
  -webkit-user-select: text;
  user-select: text;
}

button, .btn { font-family: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

/* ---- Splash -------------------------------------------------------------- */
.splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(123, 108, 255, 0.22), transparent 60%),
    var(--bg);
  transition: opacity 0.4s ease;
}
.splash.hide { opacity: 0; pointer-events: none; }
.splash-mark { filter: drop-shadow(0 10px 30px rgba(63, 208, 201, 0.35)); animation: pop 0.6s ease; }
.splash-name { font-size: 26px; font-weight: 700; letter-spacing: 0.5px; }
.splash-spin {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { 0% { transform: scale(0.7); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

/* ---- App shell ----------------------------------------------------------- */
.app { min-height: 100%; display: flex; flex-direction: column; }

.appbar {
  position: sticky; top: 0; z-index: 20;
  padding-top: var(--sa-top);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(150%) blur(14px);
  -webkit-backdrop-filter: saturate(150%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.appbar-row {
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  padding-left: max(16px, var(--sa-left));
  padding-right: max(16px, var(--sa-right));
}
.appbar-title { font-size: 19px; font-weight: 700; }
.appbar-sub { font-size: 12px; color: var(--text-dim); font-weight: 500; }
.appbar-actions { display: flex; gap: 8px; }

.icon-btn {
  min-width: var(--tap); min-height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent; color: var(--text);
  border-radius: 12px; font-size: 20px; cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.icon-btn:active { background: var(--bg-elev-2); transform: scale(0.94); }

/* Scroll region between header and tab bar */
.screen {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px;
  padding-left: max(14px, var(--sa-left));
  padding-right: max(14px, var(--sa-right));
  /* keep content above the fixed tab bar + gesture area */
  padding-bottom: calc(var(--tabbar-h) + var(--sa-bottom) + 90px);
}

/* ---- Bottom tab bar ------------------------------------------------------ */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex;
  padding-bottom: var(--sa-bottom);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: saturate(160%) blur(16px);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1; min-height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; border: none; background: transparent; cursor: pointer;
  color: var(--text-faint); font-size: 10.5px; font-weight: 600;
  transition: color 0.15s;
}
.tab .ic { font-size: 21px; line-height: 1; }
.tab.active { color: var(--accent); }
.tab:active { color: var(--accent-2); }

/* ---- Cards & lists ------------------------------------------------------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card.pad-lg { padding: 18px; }
.section-title { font-size: 13px; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.6px; margin: 18px 4px 8px; }
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 10px; }

.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 6px; min-height: var(--tap);
  border-bottom: 1px solid var(--line);
}
.list-item:last-child { border-bottom: none; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  background: var(--bg-elev-2); color: var(--text-dim);
}
.pill.rose   { background: color-mix(in srgb, var(--rose) 22%, transparent); color: var(--rose); }
.pill.indigo { background: color-mix(in srgb, var(--indigo) 24%, transparent); color: var(--indigo); }
.pill.teal   { background: color-mix(in srgb, var(--teal) 22%, transparent); color: var(--teal); }
.pill.amber  { background: color-mix(in srgb, var(--amber) 26%, transparent); color: #d98a1f; }
.pill.blue   { background: color-mix(in srgb, var(--blue) 22%, transparent); color: var(--blue); }
.pill.slate  { background: color-mix(in srgb, var(--slate) 26%, transparent); color: var(--slate); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

/* ---- Buttons ------------------------------------------------------------- */
.btn {
  min-height: var(--tap); padding: 0 18px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); border-radius: 13px;
  background: var(--bg-elev-2); color: var(--text);
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: transform 0.1s, filter 0.15s, background 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--grad); border: none; color: #fff; }
.btn.primary:active { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn.block { width: 100%; }
.btn.sm { min-height: 38px; padding: 0 12px; font-size: 13px; border-radius: 10px; }

/* Floating action button */
.fab {
  position: fixed; z-index: 25;
  right: max(18px, var(--sa-right));
  bottom: calc(var(--tabbar-h) + var(--sa-bottom) + 16px);
  width: 58px; height: 58px; border-radius: 20px; border: none;
  background: var(--grad);
  color: #fff; font-size: 28px; line-height: 1; cursor: pointer;
  box-shadow: 0 12px 30px rgba(123, 108, 255, 0.4);
  transition: transform 0.12s;
}
.fab:active { transform: scale(0.92); }

/* ---- Forms --------------------------------------------------------------- */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; }
.input, textarea.input, select.input {
  width: 100%; min-height: var(--tap);
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 13px; font-size: 16px;  /* 16px avoids iOS zoom-on-focus */
  font-family: inherit;
  appearance: none; -webkit-appearance: none;
}
textarea.input { min-height: 84px; resize: vertical; line-height: 1.45; }
.input:focus { border-color: var(--accent); }
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; }

.check {
  width: 26px; height: 26px; border-radius: 8px; flex: none;
  border: 2px solid var(--line); background: transparent;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; cursor: pointer; transition: background 0.15s, border-color 0.15s;
}
.check.on { background: var(--grad); border-color: transparent; }

.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; min-height: 38px; border: none; background: transparent; color: var(--text-dim); border-radius: 9px; font-weight: 600; font-size: 13px; cursor: pointer; }
.seg button.on { background: var(--bg-elev-2); color: var(--text); }

/* ---- Sheet / modal ------------------------------------------------------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; transition: opacity 0.2s;
}
.sheet-backdrop.show { opacity: 1; }
.sheet {
  width: 100%; max-width: 560px;
  background: var(--bg-elev);
  border-radius: 22px 22px 0 0;
  border: 1px solid var(--line); border-bottom: none;
  padding: 8px 16px calc(18px + var(--sa-bottom));
  padding-left: max(16px, var(--sa-left));
  padding-right: max(16px, var(--sa-right));
  max-height: 90vh; overflow-y: auto;
  transform: translateY(100%); transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet-backdrop.show .sheet { transform: translateY(0); }
.sheet-grip { width: 40px; height: 4px; border-radius: 999px; background: var(--line); margin: 6px auto 12px; }
.sheet h2 { margin: 0 0 14px; font-size: 19px; }

/* ---- Hero / feature bits ------------------------------------------------- */
.hero {
  background: linear-gradient(140deg, color-mix(in srgb, var(--teal) 26%, var(--bg-elev)), color-mix(in srgb, var(--indigo) 26%, var(--bg-elev)));
  border: 1px solid var(--line);
  border-radius: 20px; padding: 20px; margin-bottom: 14px;
}
.count-big { font-size: 44px; font-weight: 800; letter-spacing: -1px; line-height: 1; }
.count-unit { font-size: 14px; color: var(--text-dim); font-weight: 600; }
.count-grid { display: flex; gap: 18px; margin-top: 6px; }
.count-grid > div { text-align: center; }
.count-grid .n { font-size: 30px; font-weight: 800; }
.count-grid .l { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }

.progress { height: 12px; border-radius: 999px; background: var(--bg); overflow: hidden; border: 1px solid var(--line); }
.progress > i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--teal), var(--indigo)); transition: width 0.5s ease; }

.dual-time { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; }
.dual-time .who { color: var(--text-dim); font-weight: 700; }

.emoji-scale { display: flex; justify-content: space-between; gap: 6px; }
.emoji-scale button {
  flex: 1; aspect-ratio: 1; max-width: 62px;
  border: 1px solid var(--line); background: var(--bg); border-radius: 14px;
  font-size: 26px; cursor: pointer; transition: transform 0.1s, border-color 0.15s, background 0.15s;
}
.emoji-scale button.on { border-color: var(--accent); background: var(--bg-elev-2); transform: translateY(-2px) scale(1.05); }

.moodbars { display: flex; align-items: flex-end; gap: 4px; height: 56px; }
.moodbars > i { flex: 1; background: var(--bg-elev-2); border-radius: 4px 4px 0 0; min-height: 4px; }

.empty { text-align: center; color: var(--text-faint); padding: 40px 16px; }
.empty .big { font-size: 40px; margin-bottom: 8px; }

/* ---- Auth screen --------------------------------------------------------- */
.auth-wrap {
  min-height: 100%;
  display: flex; flex-direction: column; justify-content: center;
  padding: 24px;
  padding-top: calc(24px + var(--sa-top));
  padding-bottom: calc(24px + var(--sa-bottom));
  max-width: 440px; margin: 0 auto;
}
.auth-logo { text-align: center; margin-bottom: 26px; }
.auth-logo .name { font-size: 28px; font-weight: 800; margin-top: 10px; }
.auth-logo .tag { color: var(--text-dim); font-size: 14px; margin-top: 4px; }
.code-input { letter-spacing: 8px; text-align: center; font-size: 24px !important; font-weight: 700; }
.secret-box { font-family: ui-monospace, "SF Mono", Menlo, monospace; word-break: break-all; background: var(--bg); border: 1px dashed var(--line); border-radius: 12px; padding: 12px; font-size: 15px; letter-spacing: 1px; }

/* ---- 2FA QR + key fallback ----------------------------------------------- */
.qr-box { background: #fff; padding: 14px; border-radius: 16px; display: flex; justify-content: center; margin: 4px auto 12px; width: fit-content; }
.qr-canvas { display: block; image-rendering: pixelated; border-radius: 4px; }
.key-fallback { margin-bottom: 4px; }
.key-fallback > summary { cursor: pointer; color: var(--text-dim); font-size: 13px; padding: 6px 0; list-style: none; }
.key-fallback > summary::-webkit-details-marker { display: none; }
.key-fallback > summary::before { content: "▸ "; }
.key-fallback[open] > summary::before { content: "▾ "; }

/* ---- Autocomplete (city picker) ------------------------------------------ */
.ac-menu {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 6; margin-top: 6px;
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden; max-height: 260px; overflow-y: auto;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}
.ac-item {
  display: block; width: 100%; text-align: left; padding: 13px 14px;
  background: transparent; border: none; border-bottom: 1px solid var(--line);
  color: var(--text); font-size: 14.5px; cursor: pointer; min-height: var(--tap);
}
.ac-item:last-child { border-bottom: none; }
.ac-item:active { background: var(--bg-elev-2); }

/* ---- Toasts -------------------------------------------------------------- */
.toasts {
  position: fixed; left: 0; right: 0; z-index: 60;
  bottom: calc(var(--tabbar-h) + var(--sa-bottom) + 14px);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none; padding: 0 16px;
}
.toast {
  background: var(--bg-elev-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 16px; font-size: 14px; font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  animation: toastin 0.2s ease; max-width: 90%;
}
.toast.err { border-color: color-mix(in srgb, var(--danger) 50%, var(--line)); }
.toast.ok { border-color: color-mix(in srgb, var(--ok) 50%, var(--line)); }
@keyframes toastin { from { transform: translateY(10px); opacity: 0; } }

/* ---- Calendar month grid ------------------------------------------------- */
.cal-title { background: transparent; border: none; color: var(--text); font-weight: 800; font-size: 18px; padding: 8px 14px; border-radius: 10px; cursor: pointer; }
.cal-title:active { background: var(--bg-elev-2); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; margin-bottom: 4px; }
.cal-wd { text-align: center; font-size: 10.5px; font-weight: 700; color: var(--text-faint); padding-bottom: 2px; }
.cal-cell {
  position: relative; aspect-ratio: 1 / 0.78;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 1px solid transparent; border-radius: 11px;
  background: var(--bg-elev); color: var(--text);
  font-size: 14px; cursor: pointer; padding: 0;
  transition: transform 0.08s, background 0.15s, border-color 0.15s;
}
.cal-cell:active { transform: scale(0.92); }
.cal-cell.dim { background: transparent; color: var(--text-faint); }
.cal-cell.today .cal-num { color: var(--accent); font-weight: 800; }
.cal-cell.sel { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, var(--bg-elev)); }
.cal-num { line-height: 1; }
.cal-dots { position: absolute; bottom: 5px; display: flex; gap: 3px; height: 5px; }
.cal-dots > i { width: 5px; height: 5px; border-radius: 50%; }

/* ---- "Us" presence widget ------------------------------------------------ */
.presence {
  background: linear-gradient(140deg, color-mix(in srgb, var(--teal) 18%, var(--bg-elev)), color-mix(in srgb, var(--indigo) 18%, var(--bg-elev)));
  border: 1px solid var(--line); border-radius: 20px; padding: 18px 16px; margin-bottom: 14px;
}
.presence-cols { display: flex; align-items: stretch; }
.presence-col { flex: 1; text-align: center; min-width: 0; }
.presence-divider { width: 1px; background: var(--line); margin: 4px 8px; flex: none; }
.presence-name { font-weight: 800; font-size: 13px; }
.presence-time { font-size: 27px; font-weight: 800; letter-spacing: -0.5px; margin-top: 2px; }
.presence-state { font-size: 11.5px; }
.presence-weather { font-size: 13.5px; margin-top: 3px; }
.presence-meta { text-align: center; margin-top: 12px; font-size: 13px; color: var(--text-dim); }
.presence-meta b { color: var(--text); }
.presence-incoming { text-align: center; font-size: 12px; margin-top: 6px; }
.presence-incoming:empty { display: none; }
.heart-btn { margin-top: 12px; }

.heart-fly { position: fixed; z-index: 80; font-size: 22px; pointer-events: none; animation: heartFly 1.3s ease-out forwards; }
@keyframes heartFly {
  0% { transform: translate(0, 0) scale(0.6); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: translate(var(--dx, 0), -170px) scale(1.25); opacity: 0; }
}

/* ---- Question of the day ------------------------------------------------- */
.qotd-card { border: 1px solid color-mix(in srgb, var(--teal) 30%, var(--line)); }
.qotd-answer { background: var(--bg); border-radius: 12px; padding: 10px 12px; margin-top: 10px; font-size: 14.5px; line-height: 1.45; }

.hidden { display: none !important; }
a { color: var(--accent); }
.view-enter { animation: viewin 0.22s ease; }
@keyframes viewin { from { opacity: 0; transform: translateY(6px); } }

/* Respect users who ask the OS to reduce motion — disable the animated
   flourishes (view transitions, splash, spinner, sheet slide). */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .view-enter { animation: none; opacity: 1; }
}

/* ---- Calendar event-title chips (desktop grid) --------------------------- */
.cal-chips { display: none; flex-direction: column; gap: 3px; width: 100%; overflow: hidden; }
.cal-chip {
  display: block; font-size: 11px; line-height: 1.4; padding: 1px 6px; border-radius: 6px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left;
}
.cal-more { font-size: 10.5px; color: var(--text-faint); padding-left: 4px; }

/* ---- Desktop / wide screens: center the app, roomy calendar -------------- */
@media (min-width: 820px) {
  .appbar-row { max-width: 760px; margin-inline: auto; width: 100%; }
  .screen { max-width: 760px; margin-inline: auto; width: 100%; }
  .screen.wide { max-width: 1060px; }
  .tabbar {
    left: 50%; right: auto; transform: translateX(-50%);
    width: 100%; max-width: 760px; border-radius: 18px 18px 0 0;
  }
  .toasts { max-width: 760px; margin-inline: auto; }

  /* Roomy month grid with event titles instead of dots. */
  .wide .cal-grid { gap: 6px; }
  .wide .cal-cell {
    aspect-ratio: auto; min-height: 108px;
    flex-direction: column; align-items: stretch; justify-content: flex-start;
    padding: 6px 7px; gap: 4px; font-size: 13px;
  }
  .wide .cal-num { align-self: flex-start; }
  .wide .cal-dots { display: none; }
  .wide .cal-chips { display: flex; }
  .wide .cal-cell.sel { box-shadow: inset 0 0 0 1px var(--accent); }
}
