/* ==========================================================
   Journal Chantal — base.css
   Variables shared by both themes. Themes override.
   ========================================================== */

:root {
  /* Color tokens — overridden by theme */
  --bg: #0f1020;
  --bg-elev: #181a30;
  --surface: #20223c;
  --surface-2: #2a2d4d;
  --text: #f4f4ff;
  --text-muted: #b9bbd4;
  --primary: #7c5cff;
  --primary-contrast: #ffffff;
  --accent: #00e5ff;
  --danger: #ff6b6b;
  --success: #2ecc71;
  --border: rgba(255, 255, 255, 0.08);

  /* Geometry — overridden */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-pill: 999px;
  --border-w: 1px;

  /* Type — overridden */
  --font-display: "Quicksand", "Inter", system-ui, sans-serif;
  --font-body: "Inter", system-ui, sans-serif;
  --fz-xs: 0.78rem;
  --fz-sm: 0.9rem;
  --fz-md: 1rem;
  --fz-lg: 1.25rem;
  --fz-xl: 1.7rem;
  --fz-display: clamp(2rem, 4.5vw, 3.4rem);

  /* Motion */
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --dur-fast: 140ms;
  --dur: 260ms;
  --dur-slow: 480ms;

  /* Layout */
  --maxw: 980px;
  --pad: clamp(1rem, 3vw, 2rem);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--fz-md);
  line-height: 1.55;
  min-height: 100%;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.15;
  margin: 0 0 0.6em;
  letter-spacing: -0.01em;
}

h1 { font-size: var(--fz-display); }
h2 { font-size: var(--fz-xl); }
h3 { font-size: var(--fz-lg); }

p { margin: 0 0 1em; color: var(--text); }
.muted { color: var(--text-muted); }
small { font-size: var(--fz-xs); color: var(--text-muted); }

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--dur-fast) var(--ease);
}
a:hover { filter: brightness(1.15); }

/* ---------- Layout ---------- */
main, header, footer { width: 100%; }
main {
  flex: 1 0 auto;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: var(--pad);
  position: relative;
  z-index: 1;
}

.row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.stack-sm { display: flex; flex-direction: column; gap: 0.5rem; }
.center { text-align: center; }
.between { justify-content: space-between; }
.hidden { display: none !important; }

/* ---------- Header ---------- */
.app-header {
  width: 100%;
  padding: 1rem var(--pad);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: relative;
  z-index: 2;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
}

.brand-mark {
  width: 30px; height: 30px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: grid; place-items: center;
  color: var(--primary-contrast);
  font-weight: 800;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(1.2rem, 3vw, 2rem);
  box-shadow: 0 10px 40px -20px rgba(0,0,0,0.55);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.card-glow {
  position: relative;
  overflow: hidden;
}
.card-glow::before {
  content: "";
  position: absolute; inset: -2px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  z-index: -1;
  border-radius: inherit;
  opacity: 0.35;
  filter: blur(20px);
}

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  border: var(--border-w) solid transparent;
  background: var(--primary);
  color: var(--primary-contrast);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: var(--fz-md);
  padding: 0.85rem 1.4rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: transform var(--dur-fast) var(--ease), filter var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--surface-2); filter: none; }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border-color: var(--primary);
}

.btn-block { width: 100%; }
.btn-sm { padding: 0.55rem 1rem; font-size: var(--fz-sm); }

/* ---------- Forms ---------- */
label {
  font-size: var(--fz-sm);
  color: var(--text-muted);
  font-weight: 600;
  display: block;
  margin-bottom: 0.35rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
textarea,
select {
  width: 100%;
  background: var(--bg-elev);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--fz-md);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent);
}

textarea {
  min-height: 220px;
  resize: vertical;
  line-height: 1.6;
}

.field { margin-bottom: 1rem; }

.checkbox {
  display: flex; gap: 0.6rem; align-items: flex-start;
  font-size: var(--fz-sm); color: var(--text-muted);
  margin: 0.4rem 0;
  cursor: pointer;
}
.checkbox input { margin-top: 3px; accent-color: var(--primary); }

.error {
  color: var(--danger);
  font-size: var(--fz-sm);
  margin: 0.4rem 0;
  min-height: 1.2em;
}

/* ---------- Likert / scales ---------- */
.likert {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.4rem;
  margin: 0.4rem 0 1rem;
}
.likert button {
  appearance: none;
  background: var(--bg-elev);
  color: var(--text);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.7rem 0.4rem;
  cursor: pointer;
  font-weight: 600;
  transition: all var(--dur-fast) var(--ease);
}
.likert button:hover { border-color: var(--primary); }
.likert button.selected {
  background: var(--primary);
  color: var(--primary-contrast);
  border-color: var(--primary);
}
.likert-labels {
  display: flex; justify-content: space-between;
  font-size: var(--fz-xs); color: var(--text-muted);
  margin-top: -0.6rem; margin-bottom: 1.2rem;
}

/* ---------- Theme selector ---------- */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.2rem;
  margin: 2rem 0;
}

.theme-tile {
  position: relative;
  border-radius: var(--radius-lg);
  padding: 1.6rem;
  border: 2px solid var(--border);
  cursor: pointer;
  overflow: hidden;
  transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease);
  min-height: 180px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
}
.theme-tile h3 { margin: 0; font-size: 2rem; }
.theme-tile:hover { transform: translateY(-4px); }
.theme-tile.active { border-color: var(--primary); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 30%, transparent); }

.theme-tile-aurora {
  background: linear-gradient(135deg, #a78bfa 0%, #c4b5fd 55%, #e9d5ff 100%);
  color: #2a1c4a;
}
.theme-tile-pulse {
  background:
    radial-gradient(circle at 20% 20%, rgba(0,229,255,0.55), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(0,230,118,0.45), transparent 40%),
    linear-gradient(135deg, #0a0e2a 0%, #1a1f4a 100%);
  color: #e6faff;
}

.theme-tile h3 { color: inherit; }
.theme-tile .theme-vibe {
  font-size: var(--fz-sm);
  opacity: 0.9;
}

/* ---------- Footer ---------- */
.app-footer {
  width: 100%;
  text-align: center;
  padding: 1.5rem var(--pad);
  font-size: var(--fz-xs);
  color: var(--text-muted);
  border-top: var(--border-w) solid var(--border);
  margin-top: 3rem;
}

/* ---------- Progress ---------- */
.progress {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 0.6rem;
  margin: 1.2rem 0;
}
.progress-item {
  background: var(--bg-elev);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.8rem;
  text-align: center;
  cursor: pointer;
  font-size: var(--fz-sm);
  transition: all var(--dur-fast) var(--ease);
  position: relative;
}
.progress-item:hover { border-color: var(--primary); }
.progress-item.done {
  background: color-mix(in srgb, var(--primary) 20%, var(--bg-elev));
  border-color: var(--primary);
}
.progress-item.done::after {
  content: "✓";
  position: absolute;
  top: 4px; right: 8px;
  color: var(--primary);
  font-weight: 800;
}
.progress-item.current {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent);
}
.progress-item.locked { opacity: 0.45; cursor: not-allowed; }

/* ---------- Banners ---------- */
.banner {
  border-radius: var(--radius-md);
  padding: 0.9rem 1.1rem;
  background: var(--surface-2);
  border-left: 4px solid var(--accent);
  font-size: var(--fz-sm);
  margin: 1rem 0;
}
.banner-warn { border-left-color: var(--danger); }
.banner-info { border-left-color: var(--primary); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(6px);
  display: grid; place-items: center;
  z-index: 50;
  padding: 1rem;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 2rem;
  max-width: 460px;
  width: 100%;
  border: var(--border-w) solid var(--border);
}

/* ---------- Theme switch (in header) ---------- */
.theme-switch {
  display: inline-flex;
  background: var(--bg-elev);
  border-radius: var(--radius-pill);
  padding: 4px;
  border: var(--border-w) solid var(--border);
}
.theme-switch button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  padding: 0.35rem 0.8rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-size: var(--fz-xs);
  font-weight: 600;
  transition: all var(--dur-fast) var(--ease);
}
.theme-switch button.active {
  background: var(--primary);
  color: var(--primary-contrast);
}

/* ---------- Background art (overridden by themes) ---------- */
.bg-art {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

/* ---------- Saving indicator ---------- */
.saving {
  font-size: var(--fz-xs);
  color: var(--text-muted);
  font-style: italic;
}
.saving.ok { color: var(--success); font-style: normal; }
.saving.err { color: var(--danger); font-style: normal; }

/* ---------- Utility ---------- */
.divider { height: 1px; background: var(--border); margin: 1.5rem 0; }
.tag {
  display: inline-block;
  background: var(--surface-2);
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--fz-xs);
  color: var(--text-muted);
  margin-right: 4px;
}

/* ---------- Ink (handwriting) ---------- */
.input-mode-switch {
  display: inline-flex;
  background: var(--bg-elev);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius-pill);
  padding: 4px;
  gap: 4px;
}
.input-mode-switch .im-btn {
  appearance: none;
  background: transparent;
  color: var(--text-muted);
  border: 0;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-weight: 600;
  font-size: var(--fz-sm);
  transition: all var(--dur-fast) var(--ease);
}
.input-mode-switch .im-btn.active {
  background: var(--primary);
  color: var(--primary-contrast);
}

.ink-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 0.5rem 0;
}
.ink-colors { display: flex; gap: 0.4rem; }
.ink-color {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  padding: 0;
  transition: transform var(--dur-fast) var(--ease);
}
.ink-color:hover { transform: scale(1.1); }
.ink-color.active {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--primary);
}

.ink-canvas-wrap {
  position: relative;
  width: 100%;
  height: 55vh;
  min-height: 320px;
  max-height: 70vh;
  background: var(--bg-elev);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
#ink-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent 39px,
      color-mix(in srgb, var(--text-muted) 18%, transparent) 39px,
      color-mix(in srgb, var(--text-muted) 18%, transparent) 40px
    );
}

/* ---------- Dashboard hub cards ---------- */
.hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 2rem;
}
.hub-card { padding: 1.2rem; }
.hub-card h3 { margin: 0; font-size: 1.15rem; }
.hub-card p { font-size: var(--fz-sm); margin: .3rem 0 .8rem; }

/* ---------- Habit tracker ---------- */
.habit-row {
  display: flex; align-items: center; gap: .8rem;
  padding: .7rem .8rem;
  background: var(--bg-elev);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: .5rem;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease);
}
.habit-row:hover { background: var(--surface-2); }
.habit-row.done { background: color-mix(in srgb, var(--success) 18%, var(--bg-elev)); }
.habit-row .emoji { font-size: 1.4rem; }
.habit-row .name { flex: 1; font-weight: 600; }
.habit-row .check {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: grid; place-items: center;
  font-size: .9rem;
  color: transparent;
  transition: all var(--dur-fast) var(--ease);
}
.habit-row.done .check {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}
.habit-row.done .check::before { content: "✓"; font-weight: 800; }

.habit-edit-row {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: .5rem;
  align-items: center;
  margin-bottom: .5rem;
}
.habit-edit-row input[type="text"] { font-size: var(--fz-sm); padding: .6rem .8rem; }
.habit-emoji-input {
  text-align: center; font-size: 1.4rem; padding: .4rem !important;
}

.habits-history {
  display: grid;
  grid-template-columns: 100px repeat(7, 1fr);
  gap: .25rem;
  font-size: var(--fz-xs);
}
.habits-history .hh-cell {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  height: 28px;
  display: grid; place-items: center;
}
.habits-history .hh-cell.done {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}
.habits-history .hh-name {
  font-weight: 600;
  display: flex; align-items: center;
  font-size: var(--fz-sm);
  padding: 0 .3rem;
}
.habits-history .hh-head {
  font-weight: 700;
  color: var(--text-muted);
  text-align: center;
  height: 22px;
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* ---------- Mood picker (named emojis) ---------- */
.mood-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: .5rem;
  margin: .6rem 0 1rem;
}
.mood-grid button {
  appearance: none;
  background: var(--bg-elev);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius-md);
  padding: .8rem .4rem .6rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .35rem;
  transition: all var(--dur-fast) var(--ease);
  font-family: inherit;
  color: var(--text);
}
.mood-grid button:hover { border-color: var(--primary); transform: translateY(-2px); }
.mood-grid button.selected {
  background: color-mix(in srgb, var(--primary) 20%, var(--bg-elev));
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
}
.mood-grid .me { font-size: 1.8rem; line-height: 1; }
.mood-grid .ml { font-size: var(--fz-xs); font-weight: 600; color: var(--text-muted); }
.mood-grid button.selected .ml { color: var(--text); }

@media (max-width: 540px) {
  .mood-grid { gap: .3rem; }
  .mood-grid button { padding: .5rem .15rem .4rem; }
  .mood-grid .me { font-size: 1.4rem; }
  .mood-grid .ml { font-size: 10px; }
}

/* ---------- Free entry card ---------- */
.free-card {
  background: var(--surface);
  border: var(--border-w) solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: .6rem;
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease);
}
.free-card:hover { border-color: var(--primary); }
.free-card .free-meta {
  display: flex; justify-content: space-between;
  font-size: var(--fz-xs); color: var(--text-muted);
  margin-bottom: .3rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 700px) {
  .theme-grid { grid-template-columns: 1fr 1fr; gap: .8rem; }
  .theme-tile { min-height: 140px; padding: 1.2rem; }
  .theme-tile h3 { font-size: 1.5rem; }
  .progress { grid-template-columns: repeat(auto-fit, minmax(75px, 1fr)); }
  .ink-canvas-wrap { height: 50vh; min-height: 280px; }
}

@media (max-width: 540px) {
  h1 { font-size: 1.9rem; }
  main { padding: 1rem; }
  .card { padding: 1.1rem; }
  .likert { grid-template-columns: repeat(5, 1fr); gap: 0.25rem; }
  .likert button { padding: 0.55rem 0.2rem; font-size: var(--fz-sm); }
  .app-header { flex-wrap: wrap; gap: .5rem; padding: .8rem 1rem; }
  .brand span { font-size: 1rem; }
  .theme-switch button { padding: .3rem .55rem; }
  .btn { padding: .7rem 1rem; font-size: var(--fz-sm); }
  .modal { padding: 1.4rem; }
  .input-mode-switch { display: flex; width: 100%; }
  .input-mode-switch .im-btn { flex: 1; padding: .55rem .4rem; font-size: var(--fz-xs); }
  .ink-canvas-wrap { height: 60vh; min-height: 360px; }
}

/* Hide PSC-17 third option label on very narrow screens but keep accessibility */
@media (max-width: 380px) {
  .progress { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
  .habits-history {
    grid-template-columns: 80px repeat(7, 1fr);
    font-size: 10px;
  }
  .habits-history .hh-name { font-size: .75rem; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
