:root {
  /* Pastel lavender diary theme — cream paper on a periwinkle desk */
  --bg: #e3dff3;          /* cool lavender surround */
  --card: #faf8f6;        /* soft neutral "paper" (barely warm) */
  --card-2: #efeafa;      /* inputs / secondary surfaces */
  --text: #39335a;
  --muted: #9a93b3;
  --primary: #8175d4;
  --primary-2: #a89cec;   /* gradient end */
  --accent: #efa6c9;
  --ok: #86d3b4;
  --line: #e6e1dd;        /* neutral hairline */
  --line-2: #e2dcf0;      /* cool border for inputs */
  --radius: 44px;          /* big section boxes — paired with corner-shape: squircle */
  --tap: 48px;
  --grad: linear-gradient(135deg, var(--primary), var(--primary-2));
  /* Notepad paper details */
  --rule: rgba(150, 130, 205, 0.16);
  --margin-line: rgba(239, 166, 201, 0.6);
  --shadow: 0 10px 26px rgba(120, 105, 190, 0.2);
}

/* Apple-style continuous (squircle) corners on the big section boxes.
   Native corner-shape reshapes the border, background AND shadow together;
   browsers without support fall back to the rounded border-radius above. */
.card, .step, .gate-card {
  corner-shape: squircle;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  padding-bottom: env(safe-area-inset-bottom);
}
.hidden { display: none !important; }
button { cursor: pointer; transition: transform 0.08s ease; }
button:active { transform: scale(0.97); }
.muted { color: var(--muted); font-size: 0.85rem; }
.error { color: var(--accent); }

/* ---------- Key gate ---------- */
.gate { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; }
.gate-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px 24px; width: 100%; max-width: 380px;
}
.gate-card h1 {
  margin: 0 0 8px; font-size: 1.8rem; letter-spacing: -0.6px;
  font-family: Didot, "Bodoni 72", "Times New Roman", Times, serif;
}
.gate-card p { color: var(--muted); margin: 0 0 18px; }
.gate-card input {
  width: 100%; height: var(--tap); border-radius: 12px; border: 1px solid var(--line);
  background: var(--card-2); color: var(--text); padding: 0 14px; font-size: 1rem; margin-bottom: 14px;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px calc(14px + env(safe-area-inset-top));
  padding-top: max(14px, env(safe-area-inset-top));
  background: rgba(238,234,250,0.85); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line-2);
}
.brand {
  font-family: Didot, "Bodoni 72", "Times New Roman", Times, serif;
  font-weight: 700; font-size: 1.3rem; letter-spacing: -0.6px;
}
.icon-btn {
  background: var(--card-2); border: 1px solid var(--line); color: var(--text);
  width: 40px; height: 40px; border-radius: 10px; font-size: 1.1rem;
}
.banner { background: #f3e9ff; color: #6a5fb0; padding: 10px 18px; font-size: 0.85rem; text-align: center; }

/* ---------- Layout ---------- */
.container { max-width: 720px; margin: 0 auto; padding: 16px 16px 120px; }
.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tab {
  flex: 1; height: 44px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--muted); font-weight: 600; font-size: 0.95rem;
}
.tab.active { background: var(--grad); color: #fff; border-color: transparent; }

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

/* Each log step is ONE ruled notebook page */
.step {
  position: relative;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 14px;
  padding: 20px 20px 22px 52px;
  background-image:
    linear-gradient(var(--rule) 1px, transparent 1px),
    linear-gradient(to right,
      transparent 38px, var(--margin-line) 38px,
      var(--margin-line) 40px, transparent 40px);
  background-size: 100% 30px, 100% 100%;
  background-position: 0 24px, 0 0;
}

/* Panels on a page are plain sections — the page is the card now */
.step .card {
  background: none; border: none; border-radius: 0;
  box-shadow: none; padding: 0; margin: 0;
}

/* Even spacing between sections on the same page */
.step .card > *:last-child { margin-bottom: 0; }
.step .card + .card { margin-top: 22px; }

/* ---------- Stepper ---------- */
.stepper-top { margin-bottom: 16px; }
.stepper-progress { height: 6px; background: var(--card-2); border-radius: 999px; overflow: hidden; }
.stepper-bar {
  height: 100%; width: 20%; background: var(--grad);
  border-radius: 999px; transition: width 0.25s ease;
}
.step-meta { display: flex; justify-content: space-between; align-items: baseline; margin-top: 8px; }
.step-meta #stepTitle { font-weight: 700; font-size: 1.05rem; }
.step-nav {
  display: flex; gap: 12px; position: sticky; bottom: 16px; margin-top: 4px;
}
.step-nav .btn {
  flex: 1; height: 54px; font-size: 1.05rem; box-shadow: var(--shadow);
}
.step-nav #backBtn { flex: 0 0 38%; }
.field-label { font-weight: 600; margin: 6px 0 10px; }
.sub-label { display: block; color: var(--muted); font-size: 0.82rem; margin-bottom: 6px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
/* Mobile-first: stack so wide counters never overflow the frame. */
.grid2 { display: grid; grid-template-columns: 1fr; gap: 12px; margin: 8px 0 14px; align-items: stretch; }
@media (min-width: 520px) { .grid2 { grid-template-columns: 1fr 1fr; } }

/* ---------- Inputs ---------- */
.date-input, .hour-select {
  width: 100%; height: var(--tap); border-radius: 12px; border: 1px solid var(--line);
  background: var(--card-2); color: var(--text); padding: 0 12px; font-size: 1rem;
}
.notes {
  width: 100%; min-height: 72px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card-2); color: var(--text); padding: 12px; font-size: 1rem; resize: vertical;
}

/* ---------- Big toggle (migraine yes/no) ---------- */
.bigtoggle { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.bigtoggle-opt {
  height: 64px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--card-2); color: var(--text); font-size: 1.1rem; font-weight: 700;
}
.bigtoggle-opt.active[data-val="yes"] { background: var(--accent); border-color: var(--accent); color: #2a0f1c; }
.bigtoggle-opt.active[data-val="no"] { background: var(--ok); border-color: var(--ok); color: #062417; }

/* ---------- Small toggle (yes/no) ---------- */
.toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.toggle-opt {
  height: var(--tap); border-radius: 12px; border: 1px solid var(--line);
  background: var(--card-2); color: var(--muted); font-weight: 600;
}
.toggle-opt.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.togglegrid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.toggle-field .sub-label { min-height: 1.2em; }

/* ---------- Chips ---------- */
.chiprow { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip {
  min-height: var(--tap); padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card-2); color: var(--text);
  font-size: 0.95rem; display: inline-flex; align-items: center;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.scale .chip { min-width: 48px; justify-content: center; padding: 0 10px; }

/* ---------- Pain location: two columns (Left / Right) ---------- */
.pain-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.pain-col-head {
  text-align: center; color: var(--muted); font-size: 0.78rem;
  font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 8px;
}
.pain-col .chip { width: 100%; justify-content: center; margin-bottom: 8px; }

/* ---------- Week strip ---------- */
.weekstrip-wrap { margin-bottom: 16px; }
.weekstrip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.day-cell {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer;
}
.day-cell .dow { font-size: 0.66rem; color: var(--muted); text-transform: uppercase; }
.day-cell .dom { font-size: 0.95rem; font-weight: 700; }
.day-cell.filled { background: var(--grad); border-color: transparent; color: #fff; }
.day-cell.filled .dow { color: rgba(255, 255, 255, 0.8); }
.day-cell.today { box-shadow: 0 0 0 2px var(--accent); }

/* ---------- Reveal animation for conditional fields ---------- */
@keyframes reveal {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
.revealable:not(.hidden) { animation: reveal 0.18s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.revealable { margin-bottom: 14px; }

/* ---------- Counter ---------- */
.counter {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--card-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 12px; margin-bottom: 14px; min-width: 0;
}
.counter-label { font-size: 0.9rem; min-width: 0; }
.counter-controls { display: flex; align-items: center; gap: 10px; }
.counter-btn {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-size: 1.3rem; line-height: 1;
}
.counter-value { min-width: 36px; text-align: center; font-weight: 700; font-size: 1.05rem; }
.counter-bare { height: var(--tap); margin-bottom: 0; padding: 0 8px; }
.counter-bare .counter-value { flex: 1; text-align: center; }

.duration-hint { color: var(--muted); font-size: 0.85rem; margin: -6px 0 14px; min-height: 1em; }

/* ---------- Buttons ---------- */
.btn {
  height: var(--tap); padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card-2); color: var(--text); font-weight: 600; font-size: 1rem;
}
.btn.primary { background: var(--grad); border-color: transparent; color: #fff; }
.btn.block { width: 100%; }
.sticky-save {
  position: sticky; bottom: 16px; height: 54px; font-size: 1.05rem;
  box-shadow: var(--shadow);
}

/* ---------- Weather ---------- */
.weather-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.btn.small { height: 36px; padding: 0 12px; font-size: 0.85rem; }
.weather-vals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; text-align: center; }
.weather-vals > div {
  background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 6px;
}
.weather-vals b { font-size: 1.3rem; display: block; }
.weather-vals span { color: var(--muted); font-size: 0.75rem; }
.weather-note { margin-top: 10px; font-size: 0.78rem; min-height: 1em; }

/* ---------- History ---------- */
.history-actions { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
#chart { width: 100%; display: block; margin-bottom: 16px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
th { color: var(--muted); font-weight: 600; }
.row-del { background: none; border: none; color: var(--accent); font-size: 1rem; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: var(--ok); color: #062417; padding: 12px 20px; border-radius: 999px;
  font-weight: 600; z-index: 20; box-shadow: var(--shadow);
}

/* ---------- Desktop ---------- */
@media (min-width: 640px) {
  .togglegrid { grid-template-columns: repeat(4, 1fr); }
}
