/* styles.css — Summer Goals tracker */

/* Warm, calm palette drawn from the app icon (cream #f8f0e8 + orange #f08020).
   The accent is a CSS variable so a custom accent can override just --accent and
   let --accent-soft follow via color-mix (with a static fallback for old
   browsers). */
:root {
  --bg: #f6f1ea;
  --card: #fffdfa;
  --text: #2b2620;
  --muted: #8c8173;
  --line: #ece4d8;
  --accent: #df6c10;
  --accent-default: #df6c10; /* always the palette accent, immune to the custom override */
  --accent-soft: #fbe9d6;
  --accent-soft: color-mix(in srgb, var(--accent) 15%, var(--card));
  --good: #2bb673;
  --gold: #e0a800;
  --shadow: 0 2px 12px rgba(70, 50, 30, 0.07);
  --radius: 16px;
  /* Room reserved for the fixed bottom bar. Everything that has to sit clear of
     it — the page's bottom padding, the toast — measures from this one value. */
  --tabbar-h: 62px;
  /* Soft per-habit background tints (light tones). Overridden for dark below. */
  --c-rose: #f8dfe2; --c-peach: #fbe6d4; --c-sand: #f5ebcc; --c-sage: #dfebdb;
  --c-teal: #d4eae7; --c-sky: #dbe7f5; --c-lavender: #e5e1f4; --c-mauve: #f0dceb;
}

/* Dark palette. Applied when the user forces dark (data-theme="dark"), or in
   "auto" mode (no explicit data-theme, or data-theme is neither light nor dark)
   when the system prefers dark. Forcing light (data-theme="light") opts out. */
:root[data-theme="dark"] {
  --bg: #17130f;
  --card: #211c16;
  --text: #f1e9df;
  --muted: #a99e8e;
  --line: #352e25;
  --accent: #f2903a;
  --accent-default: #f2903a;
  --accent-soft: #3a2a19;
  --accent-soft: color-mix(in srgb, var(--accent) 24%, var(--card));
  --shadow: 0 2px 14px rgba(0, 0, 0, 0.45);
  --c-rose: #4a2f33; --c-peach: #4a3928; --c-sand: #453f28; --c-sage: #2f3b2e;
  --c-teal: #263b38; --c-sky: #2a394b; --c-lavender: #35304c; --c-mauve: #442f40;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg: #17130f;
    --card: #211c16;
    --text: #f1e9df;
    --muted: #a99e8e;
    --line: #352e25;
    --accent: #f2903a;
    --accent-default: #f2903a;
    --accent-soft: #3a2a19;
    --accent-soft: color-mix(in srgb, var(--accent) 24%, var(--card));
    --shadow: 0 2px 14px rgba(0, 0, 0, 0.45);
    --c-rose: #4a2f33; --c-peach: #4a3928; --c-sand: #453f28; --c-sage: #2f3b2e;
    --c-teal: #263b38; --c-sky: #2a394b; --c-lavender: #35304c; --c-mauve: #442f40;
  }
}

* { box-sizing: border-box; }

/* The hidden attribute must always win over display rules below. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
}

.container {
  max-width: 820px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

h1 { font-size: 1.6rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0; }

.subtitle { color: var(--muted); margin: 4px 0 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

/* ---------- header ---------- */
.page-head { margin-bottom: 20px; }

/* ---------- stats ---------- */
.stats-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }

.mode-toggle { display: flex; flex: 0 0 auto; gap: 4px; background: var(--bg); border-radius: 999px; padding: 4px; }
.mode-btn {
  border: none; background: transparent; color: var(--muted);
  padding: 6px 14px; border-radius: 999px; cursor: pointer; font-size: 0.85rem; font-weight: 600;
}
.mode-btn.active { background: var(--card); color: var(--accent); box-shadow: var(--shadow); }

.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
/* The selector takes whatever the D/W/M toggle leaves, and the label takes
   whatever the two arrows leave — so a habit name is only ever cut when the row
   has genuinely run out of room, not at a fixed character count. */
.chart-select { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1 1 auto; }
.chart-label {
  font-weight: 700; font-size: 0.95rem; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1 1 auto; min-width: 0;
  /* Capped so a wide window doesn't stretch one habit name across the header —
     the slack goes back to `space-between`, which is what keeps the selector
     and the D/W/M toggle apart. */
  max-width: 22rem;
}
.chart-arrow {
  flex: 0 0 auto; width: 28px; height: 28px; border-radius: 8px; cursor: pointer; line-height: 1;
  border: 1px solid var(--line); background: var(--card); color: var(--muted); font-size: 1rem;
}
.chart-arrow:hover { border-color: var(--accent); color: var(--accent); }
.summary-item { background: var(--bg); border-radius: 12px; padding: 12px; text-align: center; }
.summary-num { display: block; font-size: 1.4rem; font-weight: 700; color: var(--accent); }
.summary-label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.chart-wrap { position: relative; height: 240px; }

/* ---------- calendar ---------- */
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.nav-btn {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  width: 36px; height: 36px; border-radius: 10px; font-size: 1.2rem; cursor: pointer;
}
.nav-btn:hover { border-color: var(--accent); color: var(--accent); }

/* minmax(0, 1fr) — not the default 1fr (= minmax(auto, 1fr)) — so the seven
   columns can shrink to fit narrow phones instead of spilling the last day
   off-screen. */
.cal-weekdays, .cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-weekdays { margin-bottom: 6px; }
.cal-weekdays span { text-align: center; font-size: 0.72rem; color: var(--muted); font-weight: 600; }

.cal-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  min-width: 0; /* let the grid track size the cell; don't force a floor width */
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--text);
  background: var(--card);
  transition: transform 0.08s, border-color 0.08s;
}
/* Old browsers without aspect-ratio (iOS Safari < 15): give cells a height.
   Safe here because, lacking aspect-ratio, it can't force a minimum width. */
@supports not (aspect-ratio: 1 / 1) {
  .cal-cell { min-height: 44px; }
}
a.cal-cell:hover { border-color: var(--accent); transform: translateY(-2px); }
.cal-cell.empty { border: none; background: transparent; }
.cal-cell.disabled { opacity: 0.35; cursor: default; }
.cal-cell.today { border-color: var(--accent); border-width: 2px; }
a.cal-cell.readonly { opacity: 0.7; }
a.cal-cell.readonly:hover { border-color: var(--line); transform: none; }
.cal-cell.has-points { background: var(--accent-soft); }
.cal-day { font-size: 0.9rem; font-weight: 600; }
.cal-points { font-size: 0.7rem; color: var(--accent); font-weight: 700; }

/* ---------- footer ---------- */
.page-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.ghost-btn {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; font-size: 0.85rem; font-weight: 600;
}
.ghost-btn:hover { border-color: var(--accent); color: var(--accent); }
.foot-note { color: var(--muted); font-size: 0.78rem; margin: 0; flex-basis: 100%; }

/* ---------- day page ---------- */
.day-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.back-btn {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; font-size: 0.9rem; font-weight: 600;
}
.back-btn:hover { border-color: var(--accent); color: var(--accent); }
.day-titles { flex: 1; }
.day-titles h1 { font-size: 1.25rem; }
.day-total {
  background: var(--accent); color: #fff; font-weight: 700;
  padding: 8px 14px; border-radius: 999px; font-size: 0.95rem; white-space: nowrap;
}

.readonly-banner {
  background: var(--accent-soft); color: var(--accent); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 16px; margin-bottom: 14px; font-size: 0.88rem; font-weight: 600;
}
.goal-card input[type="range"]:disabled { opacity: 0.5; }
.toggle:disabled { opacity: 0.6; cursor: default; }

.goals-list { display: flex; flex-direction: column; gap: 14px; }
.goal-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px;
  -webkit-touch-callout: none; /* no long-press menu when picking a card up */
  -webkit-tap-highlight-color: transparent; /* no grey flash on long-press */
}
/* Long-press drag-to-reorder feedback: the held card floats under the finger,
   on top of everything, while a placeholder holds its old slot. */
.reorderable.dragging {
  position: fixed; z-index: 50; margin: 0; box-sizing: border-box;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4); transform: scale(1.03);
  cursor: grabbing; touch-action: none; pointer-events: none;
}
/* The reserved gap the dragged card left behind (same size, kept empty). */
.drag-placeholder {
  border: 2px dashed var(--line); border-radius: var(--radius);
  background: rgba(127, 127, 127, 0.06);
  background: color-mix(in srgb, var(--accent) 6%, transparent);
  box-sizing: border-box;
}
.reordering { user-select: none; -webkit-user-select: none; }

/* Per-habit background tint. Applied to the today card, the backlog row, the
   habit hub and the editor preview; !important so it wins over each base bg. */
.c-rose { background: var(--c-rose) !important; }
.c-peach { background: var(--c-peach) !important; }
.c-sand { background: var(--c-sand) !important; }
.c-sage { background: var(--c-sage) !important; }
.c-teal { background: var(--c-teal) !important; }
.c-sky { background: var(--c-sky) !important; }
.c-lavender { background: var(--c-lavender) !important; }
.c-mauve { background: var(--c-mauve) !important; }

/* Colour picker in the editor. */
.color-swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.color-swatch {
  width: 32px; height: 32px; border-radius: 50%; padding: 0; cursor: pointer;
  border: 2px solid var(--line);
}
.color-swatch.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.color-swatch.is-default {
  background: var(--card);
  background-image: linear-gradient(135deg, transparent 44%, var(--muted) 44%, var(--muted) 56%, transparent 56%);
}

/* Habit hub panel on the stats page — carries the habit's colour. */
.goal-hero { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.goal-hero h1 { margin: 0; font-size: 1.35rem; display: flex; align-items: center; gap: 10px; }
.goal-hero .hub-actions { margin-bottom: 0; }
.goal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.goal-icon { font-size: 1.2rem; }
.goal-name { flex: 1; font-weight: 600; }
.goal-open {
  display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0;
  border: none; background: transparent; cursor: pointer; color: var(--text);
  font: inherit; text-align: left; padding: 0;
}
.goal-open:hover .goal-name { color: var(--accent); }

/* ---------- day: Today / Backlog tabs ---------- */
.day-tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.tab-btn {
  flex: 1; padding: 10px; border-radius: 12px; cursor: pointer; font-weight: 700; font-size: 0.9rem;
  border: 1px solid var(--line); background: var(--card); color: var(--muted);
}
.tab-btn.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.backlog-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 14px;
}
.backlog-info {
  display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0;
  border: none; background: transparent; cursor: pointer; color: var(--text);
  font: inherit; text-align: left; padding: 0;
}
.backlog-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.backlog-text .goal-name { font-weight: 600; }
.backlog-text .goal-desc { margin: 0; font-size: 0.8rem; color: var(--muted); }
.backlog-info:hover .goal-name { color: var(--accent); }

/* ---------- goal hub actions ---------- */
.hub-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.goal-pts {
  font-size: 0.82rem; font-weight: 700; color: var(--muted);
  background: var(--bg); padding: 4px 10px; border-radius: 999px;
}
.goal-pts.earned { color: var(--accent); background: var(--accent-soft); }

.slider-row { display: flex; align-items: center; gap: 14px; }
.slider-row input[type="range"] {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 10px; border-radius: 999px; cursor: pointer;
  /* Filled progress up to --fill (set in JS), track colour after it. */
  background: linear-gradient(to right,
    var(--accent) 0 var(--fill, 0%), var(--line) var(--fill, 0%) 100%);
  /* Vertical scroll still works; horizontal drags move the thumb. */
  touch-action: pan-y;
}
/* Big, easy-to-grab thumb so a drag is hard to miss. */
.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--card);
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.3); cursor: grab;
}
.slider-row input[type="range"]::-moz-range-thumb {
  width: 28px; height: 28px; border: 3px solid var(--card); border-radius: 50%;
  background: var(--accent); box-shadow: 0 1px 5px rgba(0, 0, 0, 0.3); cursor: grab;
}
.slider-row input[type="range"]:active::-webkit-slider-thumb { cursor: grabbing; }
.slider-row input[type="range"]:active::-moz-range-thumb { cursor: grabbing; }
.readout { min-width: 78px; text-align: right; }
.readout-val { font-size: 1.3rem; font-weight: 700; }
.readout-unit { color: var(--muted); font-size: 0.8rem; }
/* Tap the value to type an exact number (day view). */
.readout-val.editable-val { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }

.goal-desc { margin: -6px 0 12px; font-size: 0.85rem; color: var(--muted); line-height: 1.35; }

.goal-note { margin-top: 8px; font-size: 0.8rem; color: var(--muted); }
.goal-note.record { color: var(--gold); font-weight: 600; }

.toggle {
  width: 100%; padding: 14px; border-radius: 12px; cursor: pointer;
  border: 2px solid var(--line); background: var(--bg); color: var(--muted);
  font-size: 1rem; font-weight: 700;
}
.toggle.on { border-color: var(--good); background: rgba(43, 182, 115, 0.12); color: var(--good); }

/* ---------- stopwatch goal ---------- */
.stopwatch { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.sw-display {
  font-size: 2.6rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: 1px;
}
.sw-controls { display: flex; gap: 10px; width: 100%; }
.sw-btn {
  flex: 1; padding: 12px; border-radius: 12px; cursor: pointer; font-weight: 700; font-size: 0.95rem;
  border: 2px solid var(--line); background: var(--bg); color: var(--text);
}
.sw-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.sw-btn:hover { filter: brightness(1.03); }
.sw-adjust { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.sw-adj {
  padding: 6px 12px; border-radius: 999px; cursor: pointer; font-size: 0.85rem; font-weight: 600;
  border: 1px solid var(--line); background: var(--card); color: var(--muted);
}
.sw-adj:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- goal head pencil + add-goal card ---------- */
.icon-btn {
  border: none; background: transparent; cursor: pointer; font-size: 0.95rem;
  padding: 4px 6px; border-radius: 8px; line-height: 1; opacity: 0.65;
}
.icon-btn:hover { opacity: 1; background: var(--bg); }

.add-goal-card {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 16px; border-radius: var(--radius); cursor: pointer;
  border: 2px dashed var(--line); background: transparent; color: var(--muted);
  font-size: 0.95rem; font-weight: 600;
}
.add-goal-card:hover { border-color: var(--accent); color: var(--accent); }
.add-plus { font-size: 1.2rem; line-height: 1; }

/* The reorderable "add habit" tile: small width, centred, and clearly the
   accent action. Overrides the full-width .goal-card box it borrows for drag. */
.goal-card.add-tile {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  align-self: center; width: auto; max-width: 100%;
  padding: 8px 18px; border: 2px dashed var(--accent); border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font: inherit; font-weight: 700; box-shadow: none; cursor: pointer;
}
.goal-card.add-tile:hover { background: var(--accent); color: #fff; }

/* Preset habit picker (new-habit editor). */
.preset-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.preset-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; font-size: 0.9rem; cursor: pointer;
}
.preset-chip:hover { border-color: var(--accent); color: var(--accent); }
.preset-chip-icon { font-size: 1.05rem; }

/* ---------- goal editor form ---------- */
.goal-form { display: flex; flex-direction: column; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 0.82rem; font-weight: 600; color: var(--muted); }
.field-note { font-size: 0.78rem; color: var(--muted); margin: 0; }
.goal-form input[type="text"],
.goal-form input[type="number"],
.goal-form select {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: 0.95rem;
}
.goal-form input:focus, .goal-form select:focus { outline: none; border-color: var(--accent); }
.goal-form select:disabled { opacity: 0.6; }

.checkbox-field { flex-direction: row; align-items: center; gap: 10px; }
.checkbox-field input { width: 18px; height: 18px; accent-color: var(--accent); }
.checkbox-field span { font-size: 0.9rem; }

/* Preview, paste box and search button share one row. The box holds at most an
   emoji, so it yields width to the button rather than claiming the row. `wrap`
   is the safety net for a font or zoom level that outgrows the measurements
   below — at every shipped language and width the three fit on one line. */
.emoji-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.emoji-preview {
  font-size: 1.8rem; width: 52px; height: 52px; display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg); flex: 0 0 auto;
}
.emoji-input { flex: 1 1 3rem; min-width: 3rem; }
.days-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.day-chip {
  padding: 8px 12px; border-radius: 999px; cursor: pointer; font-size: 0.85rem; font-weight: 600;
  border: 1px solid var(--line); background: var(--card); color: var(--muted);
}
.day-chip.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.days-summary { color: var(--accent); font-weight: 700; }

.emoji-toggle {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  font-size: 0.9rem; font-weight: 600;
}
/* On a phone the row cannot hold preview + box + a label that reads
   "Rechercher des emojis…". The emoji carries the button; the name it exposes
   to assistive tech comes from aria-label, which is set in every language. */
@media (max-width: 480px) { .emoji-toggle-text { display: none; } }
.emoji-toggle:hover { border-color: var(--accent); color: var(--accent); }
emoji-picker {
  width: 100%; margin-top: 8px;
  --background: var(--card);
  --border-color: var(--line);
  --indicator-color: var(--accent);
  --input-border-color: var(--line);
  --button-active-background: var(--accent-soft);
}

.form-actions { display: flex; gap: 10px; margin-top: 4px; }
.primary-btn {
  flex: 1; padding: 12px; border-radius: 12px; border: none; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 0.95rem; font-weight: 700;
}
.primary-btn:hover { filter: brightness(1.05); }
.danger-btn {
  padding: 12px 18px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: #c0392b; font-weight: 600;
}
.danger-btn:hover { border-color: #c0392b; }
.danger-btn.full-width { width: 100%; padding: 10px; font-size: 0.9rem; }

@media (max-width: 520px) {
  .emoji-grid { grid-template-columns: repeat(6, 1fr); }
}

/* ---------- social / friends ---------- */
.add-friend { display: flex; gap: 10px; margin-bottom: 8px; }
.add-friend input {
  flex: 1; min-width: 0; /* let the field shrink so the row never overflows narrow screens */
  padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: 0.95rem;
}
.add-friend input:focus { outline: none; border-color: var(--accent); }
.add-friend .primary-btn { flex: 0 0 auto; padding: 10px 18px; }

.friends-list { display: flex; flex-direction: column; gap: 8px; }
.friend-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
}
.friend-info { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.friend-name { font-weight: 600; }
.friend-tag {
  font-size: 0.72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: var(--card); color: var(--muted);
}
.friend-tag.connected { color: var(--good); background: rgba(43, 182, 115, 0.12); }
.friend-tag.pending { color: var(--accent); background: var(--accent-soft); }
.friend-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.ghost-btn.small, .primary-btn.small {
  flex: 0 0 auto; padding: 6px 12px; font-size: 0.82rem; border-radius: 999px;
  text-decoration: none; line-height: 1.4;
}

/* ---------- misc ---------- */
.error-box { padding: 24px; text-align: center; color: var(--muted); }
.error-box code { background: var(--bg); padding: 2px 6px; border-radius: 6px; }

/* Sits above the bottom bar (z-index 50) rather than behind it, and is anchored
   by both edges so a long message wraps inside the screen instead of being
   capped at half of it — `left: 50%` alone left only half the width available. */
.toast {
  position: fixed; z-index: 60; bottom: 20px; left: 16px; right: 16px;
  width: fit-content; max-width: min(560px, calc(100% - 32px)); margin-inline: auto;
  transform: translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 14px;
  font-size: 0.85rem; font-weight: 600; text-align: center; opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #c0392b; color: #fff; }
/* Clear the bottom bar on the screens that have one (every screen but the
   editor). Without this the toast lands entirely inside the bar's strip. */
body.has-tabbar .toast { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 12px); }

/* ---------- auth ---------- */
.auth-loading {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 0.95rem;
}

.signin-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.signin-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 40px 32px; text-align: center; max-width: 380px; width: 100%;
}
.signin-card h1 { margin-bottom: 6px; }
.signin-card p { color: var(--muted); margin: 0 0 24px; }
.signin-card .signin-tagline { color: var(--accent); font-weight: 600; margin: 0 0 18px; }
.google-btn {
  display: inline-flex; align-items: center; gap: 10px; justify-content: center;
  width: 100%; padding: 12px 16px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  font-size: 0.95rem; font-weight: 600;
}
.google-btn:hover { border-color: var(--accent); }
.g-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%; background: #fff; color: #4285f4;
  font-weight: 800; font-family: Arial, sans-serif;
}
.auth-error { color: #c0392b; font-size: 0.82rem; margin: 14px 0 0; min-height: 1em; }

.head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.user-box { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.user-name { font-size: 0.85rem; color: var(--muted); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- settings popover (appearance + accent) ---------- */
.settings-wrap { position: relative; }
.icon-btn { padding: 7px 10px; font-size: 1rem; line-height: 1; }
.settings-panel {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 40;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 14px; width: 240px;
}
.settings-group + .settings-group { margin-top: 16px; }
.settings-label {
  display: block; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); font-weight: 700; margin-bottom: 8px;
}
.seg { display: flex; gap: 4px; background: var(--bg); border-radius: 10px; padding: 4px; }
.seg-btn {
  flex: 1; border: none; background: transparent; color: var(--muted);
  padding: 7px 0; border-radius: 8px; font-weight: 600; font-size: 0.82rem; cursor: pointer;
}
.seg-btn.active { background: var(--card); color: var(--accent); box-shadow: var(--shadow); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line);
  cursor: pointer; padding: 0;
}
.swatch.active { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--accent); }
/* Hidden shared colour input the swatches open programmatically. */
.swatch-input { position: absolute; width: 0; height: 0; opacity: 0; border: 0; padding: 0; }
.swatch-hint { display: block; margin-top: 10px; font-size: 0.72rem; color: var(--muted); }

/* ---------- bottom tab bar (js/nav.js) ---------- */

/* Fixed to the bottom on every signed-in screen. The inline safe-area padding
   keeps the labels clear of the gesture bar in the installed Android app. */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex; align-items: stretch;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
/* Reserve the bar's height so a page's last card is never trapped underneath. */
body.has-tabbar { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px)); }

.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; padding: 8px 4px 7px; position: relative;
  color: var(--muted); text-decoration: none; font-size: 0.68rem; font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}
.tab.active { color: var(--accent); }
.tab-icon { width: 23px; height: 23px; display: block; }
.tab-label { line-height: 1; }

/* Pending friend invites — otherwise invisible now Friends is off the home screen. */
.tab-badge {
  position: absolute; top: 5px; left: 50%; margin-left: 4px;
  min-width: 16px; height: 16px; padding: 0 4px; box-sizing: border-box;
  border-radius: 8px; background: #c0392b; color: #fff;
  font-size: 0.62rem; font-weight: 700; line-height: 16px; text-align: center;
}

/* ---------- profile screen ---------- */

.profile-id { display: flex; align-items: center; gap: 12px; }
.profile-id-text { display: flex; flex-direction: column; min-width: 0; }
.user-avatar.lg { width: 52px; height: 52px; }
.profile-name { font-size: 1.05rem; font-weight: 700; }
.profile-email {
  font-size: 0.8rem; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* The import control is a <label> wrapping a hidden file input. */
.file-btn { display: block; text-align: center; cursor: pointer; }
.ghost-btn.full-width { width: 100%; padding: 10px; margin-bottom: 8px; }
.date-range { display: flex; gap: 8px; margin-bottom: 10px; }
.date-field { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.date-field > span {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); font-weight: 700;
}
.date-field > input {
  width: 100%; box-sizing: border-box; padding: 7px 8px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  font-size: 0.82rem; font-family: inherit;
}
.lang-select {
  width: 100%; padding: 8px 10px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  font-size: 0.9rem; font-family: inherit;
}

@media (max-width: 520px) {
  .summary { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .summary-item { padding: 10px 6px; }
  .summary-num { font-size: 1.2rem; }
  h1 { font-size: 1.35rem; }
  .head-row { flex-direction: column; }
  .user-name { max-width: none; }
}

/* Suggestions box (profile screen). */
.feedback-text {
  width: 100%; box-sizing: border-box; resize: vertical; margin-bottom: 8px;
  padding: 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text);
  font-family: inherit; font-size: 0.9rem; line-height: 1.4;
}
.feedback-text:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.primary-btn.full-width { width: 100%; padding: 10px; }

/* ---------- goal editor: grouped sections ---------- */

/* The editor is long, so the fields are grouped: what the habit is (always
   visible), how it scores, and everything optional folded away by default. */
.form-group {
  border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; margin-bottom: 16px; background: var(--bg);
}
.group-title {
  display: block; font-size: 0.7rem; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted); font-weight: 700; margin-bottom: 10px;
}
.form-group .field:last-of-type { margin-bottom: 0; }

/* <details> handles the folding natively — no JS, and it stays keyboard
   accessible and searchable by the browser's find-in-page. */
.more-options > summary {
  cursor: pointer; margin-bottom: 0; list-style: none;
  display: flex; align-items: center; gap: 6px;
}
.more-options > summary::-webkit-details-marker { display: none; }
.more-options > summary::before { content: "▸"; font-size: 0.9rem; line-height: 1; }
.more-options[open] > summary::before { content: "▾"; }
.more-options[open] > summary { margin-bottom: 14px; }

/* What the habit is actually worth, so the numbers don't have to be reasoned
   about — and a warning when they add up to something unintended. */
.score-preview {
  margin: 12px 0 0; padding-top: 12px; border-top: 1px solid var(--line);
  font-size: 0.85rem; font-weight: 700; color: var(--accent);
}
.score-warning {
  margin: 8px 0 0; padding: 8px 10px; border-radius: 8px;
  background: color-mix(in srgb, #c0392b 12%, var(--card));
  color: var(--text); font-size: 0.78rem; line-height: 1.35;
}
#f-step, #f-cb-step {
  width: 100%; padding: 10px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  font-size: 0.95rem; font-family: inherit;
}
