/* ============================================================
   Daily Tracker - clay UI
   The whole look comes from four shadow tokens below. Every
   raised surface uses one of them; nothing invents its own.
   ============================================================ */

:root {
  /* surfaces */
  --bg: #F4EAE0;
  --bg-2: #EFE2D5;
  --surface: #FFFBF7;
  --sidebar: #EDE0D2;

  /* pastel fills */
  --mint: #DCEFE2;
  --peach: #FBE3D0;
  --blush: #F9DEDE;
  --sky: #DEE9F4;

  /* accents */
  --green: #3F9463;
  --green-dark: #2F7049;
  --coral: #D9573A;

  /* study tracks - validated for colour-vision deficiency,
     do not swap these for prettier hues without re-checking */
  --track-1: #3A6FB0;
  --track-2: #D97706;
  --track-3: #9B5DE5;

  /* ink */
  --text: #3A3129;
  --muted: #8C7F72;
  --line: #E4D5C5;

  /* clay */
  --shade: 140, 104, 72;
  --clay:
    0 22px 34px -16px rgba(var(--shade), 0.34),
    0 8px 14px -8px rgba(var(--shade), 0.18),
    inset 0 10px 16px -8px rgba(255, 255, 255, 0.95),
    inset 0 -12px 20px -10px rgba(var(--shade), 0.26);
  --clay-sm:
    0 10px 16px -8px rgba(var(--shade), 0.32),
    inset 0 6px 10px -5px rgba(255, 255, 255, 0.95),
    inset 0 -7px 12px -6px rgba(var(--shade), 0.24);
  --clay-press:
    inset 0 7px 12px -3px rgba(var(--shade), 0.34),
    inset 0 -5px 10px -4px rgba(255, 255, 255, 0.7);
  --clay-inset:
    inset 0 4px 8px -2px rgba(var(--shade), 0.26),
    inset 0 -3px 6px -2px rgba(255, 255, 255, 0.8);

  --r-lg: 30px;
  --r-md: 20px;
  --r-sm: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
h1, h2, h3 { margin: 0; }
button { font-family: inherit; }

:focus-visible {
  outline: 3px solid var(--track-1);
  outline-offset: 2px;
}

.clay {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--clay);
}
.clay-sm {
  background: var(--surface);
  border-radius: var(--r-md);
  box-shadow: var(--clay-sm);
}

/* ---------- clay buttons ---------- */
.btn-clay {
  border: none;
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  font-size: 14px;
  padding: 12px 18px;
  cursor: pointer;
  box-shadow: var(--clay-sm);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn-clay:hover { transform: translateY(-1px); }
.btn-clay:active {
  transform: translateY(1px);
  box-shadow: var(--clay-press);
}
.btn-primary {
  background: var(--green);
  color: #fff;
  box-shadow:
    0 12px 20px -10px rgba(47, 112, 73, 0.7),
    inset 0 7px 12px -5px rgba(255, 255, 255, 0.45),
    inset 0 -8px 14px -6px rgba(20, 60, 38, 0.5);
}
.btn-primary:active {
  box-shadow:
    inset 0 8px 14px -3px rgba(20, 60, 38, 0.55),
    inset 0 -4px 8px -3px rgba(255, 255, 255, 0.3);
}

/* round nudge buttons (- and +) */
.nudge {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--clay-sm);
  font-size: 17px;
  font-weight: 800;
  line-height: 1;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.nudge:hover:not(:disabled) { transform: translateY(-1px); }
.nudge:active:not(:disabled) { transform: translateY(1px); box-shadow: var(--clay-press); }
.nudge:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- gate ---------- */
.gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 30% 20%, var(--bg) 0%, var(--bg-2) 100%);
}
.gate-card {
  padding: 44px 34px;
  max-width: 380px;
  width: 100%;
  text-align: center;
}
.gate-emoji {
  font-size: 34px;
  width: 76px;
  height: 76px;
  margin: 0 auto 18px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: var(--clay-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}
.gate-card h1 { font-size: 21px; margin-bottom: 10px; }
.gate-sub { color: var(--muted); font-size: 13.5px; margin: 0 0 22px; line-height: 1.55; }
.gate-card input {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--r-sm);
  border: none;
  background: var(--bg);
  box-shadow: var(--clay-inset);
  font-size: 16px;
  color: var(--text);
  margin-bottom: 14px;
  text-align: center;
  letter-spacing: 0.12em;
}
.gate-card .btn-clay { width: 100%; }
.gate-error { color: var(--coral); font-size: 13px; margin: 12px 0 0; min-height: 18px; font-weight: 600; }

/* ---------- shell ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 216px;
  background: var(--sidebar);
  padding: 26px 18px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.brand { font-weight: 800; font-size: 17px; margin-bottom: 30px; padding-left: 8px; }
.nav { display: flex; flex-direction: column; gap: 10px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px 15px;
  border: none;
  background: transparent;
  border-radius: var(--r-sm);
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
  transition: transform 0.12s ease, box-shadow 0.12s ease, color 0.12s ease;
}
.nav-ico { font-size: 15px; }
.nav-item:hover { color: var(--text); }
.nav-item.active {
  background: var(--surface);
  color: var(--green-dark);
  box-shadow: var(--clay-sm);
}
.logout-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 14px;
  cursor: pointer;
  text-align: left;
  border-radius: var(--r-sm);
}
.logout-btn:hover { color: var(--coral); }

.main { flex: 1; padding: 30px 34px 70px; max-width: 980px; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.topbar h1 { font-size: 24px; margin-bottom: 5px; }
.date-label { color: var(--muted); font-size: 13.5px; margin: 0; }
.badges { display: flex; gap: 12px; }
.badge {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 18px 11px 13px;
  border-radius: 999px;
}
.badge-ico { font-size: 19px; }
.badge b { display: block; font-size: 17px; line-height: 1.1; }
.badge small { display: block; font-size: 10.5px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.badge.streak b { color: var(--coral); }
.badge.xp b { color: var(--track-1); }

/* ---------- today card ---------- */
.today-card { padding: 26px 28px; margin-bottom: 20px; }

.date-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 2px solid var(--bg-2);
}
.date-bar-label { min-width: 168px; text-align: center; }
.date-bar-label b { display: block; font-size: 15px; font-weight: 800; }
.date-bar-label small { display: block; font-size: 11.5px; color: var(--muted); font-weight: 600; margin-top: 2px; }
.btn-back-today {
  margin-left: auto;
  border: none;
  border-radius: 999px;
  padding: 9px 16px;
  background: var(--mint);
  color: var(--green-dark);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--clay-sm);
}
.btn-back-today:active { box-shadow: var(--clay-press); }
/* Editing a past day should never feel like editing today. */
.today-card.past { background: #FFF8F0; }
.today-card.past .ring-fill { stroke: var(--track-1); }

.today-head { display: flex; align-items: center; gap: 22px; margin-bottom: 8px; }

.ring-wrap { position: relative; width: 108px; height: 108px; flex-shrink: 0; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--bg-2); stroke-width: 13; }
.ring-fill {
  fill: none;
  stroke: var(--green);
  stroke-width: 13;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ring-label b { font-size: 24px; font-weight: 800; }

.today-head-text h2 { font-size: 20px; margin-bottom: 6px; }
.today-summary { margin: 0 0 4px; font-size: 14.5px; font-weight: 600; }
.today-hint { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.5; }

.today-block { margin-top: 24px; padding-top: 22px; border-top: 2px solid var(--bg-2); }
.block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.block-head h3 { font-size: 15.5px; }
.block-note { margin: 0 0 14px; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.chip {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  background: var(--bg);
  box-shadow: var(--clay-inset);
  padding: 5px 12px;
  border-radius: 999px;
}
.chip.good { color: var(--green-dark); background: var(--mint); }

/* ---------- study tracks ---------- */
.track-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  flex-wrap: wrap;
}
.track-dot { width: 13px; height: 13px; border-radius: 50%; flex-shrink: 0; box-shadow: var(--clay-sm); }
.track-name { font-size: 13.5px; font-weight: 700; width: 96px; flex-shrink: 0; }
.track-bar-bg {
  flex: 1;
  min-width: 90px;
  height: 15px;
  background: var(--bg);
  border-radius: 999px;
  box-shadow: var(--clay-inset);
  overflow: hidden;
}
.track-bar-fill { height: 100%; border-radius: 999px; transition: width 0.35s ease; }
.track-input {
  width: 62px;
  flex-shrink: 0;
  padding: 8px 6px;
  border: none;
  border-radius: var(--r-sm);
  background: var(--bg);
  box-shadow: var(--clay-inset);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  color: var(--text);
  font-family: inherit;
}
.track-goal { font-size: 12.5px; font-weight: 700; color: var(--muted); width: 34px; flex-shrink: 0; }
.track-btns { display: flex; gap: 7px; flex-shrink: 0; }

/* ---------- habit checklist ---------- */
.today-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  margin-bottom: 9px;
  border: none;
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--clay-sm);
  font-family: inherit;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
button.today-row { cursor: pointer; }
button.today-row:hover { transform: translateY(-1px); }
button.today-row:active { transform: translateY(1px); box-shadow: var(--clay-press); }
.today-row.done { background: var(--mint); }
.today-row-name { flex: 1; display: flex; align-items: center; gap: 11px; font-size: 14px; font-weight: 700; }
.habit-swatch {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
  box-shadow: var(--clay-sm);
}
.today-check {
  width: 30px; height: 30px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: var(--clay-inset);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  color: transparent;
}
.today-row.done .today-check {
  background: var(--green);
  color: #fff;
  box-shadow: var(--clay-sm);
}
.count-control { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.count-input {
  width: 54px;
  padding: 7px 4px;
  border: none;
  border-radius: var(--r-sm);
  background: var(--bg);
  box-shadow: var(--clay-inset);
  font-size: 13.5px;
  font-weight: 700;
  text-align: center;
  color: var(--text);
  font-family: inherit;
}
.count-goal { font-size: 12.5px; font-weight: 700; color: var(--muted); }

.empty {
  margin: 0;
  padding: 18px;
  border-radius: var(--r-md);
  background: var(--bg);
  box-shadow: var(--clay-inset);
  color: var(--muted);
  font-size: 13.5px;
  text-align: center;
  line-height: 1.6;
}
.empty a { color: var(--green-dark); font-weight: 700; cursor: pointer; text-decoration: underline; }

/* ---------- stat cards ---------- */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
.stat-card { padding: 18px 20px 20px; }
.stat-card.mint { background: var(--mint); }
.stat-card.peach { background: var(--peach); }
.stat-card.blush { background: var(--blush); }
.stat-card.sky { background: var(--sky); }
.stat-label {
  font-size: 11px;
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}
.stat-value { font-size: 25px; font-weight: 800; line-height: 1.15; }
.stat-sub { font-size: 11.5px; color: var(--muted); font-weight: 600; margin-top: 4px; }
.level-bar {
  height: 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.65);
  box-shadow: var(--clay-inset);
  margin-top: 10px;
  overflow: hidden;
}
.level-bar-fill { height: 100%; border-radius: 999px; background: var(--track-1); transition: width 0.4s ease; }

/* ---------- panels & chart ---------- */
.panel { padding: 22px 24px 24px; margin-bottom: 20px; }
.panel h3 { font-size: 15.5px; margin-bottom: 6px; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 700; color: var(--muted); }
.legend-dot { width: 11px; height: 11px; border-radius: 50%; box-shadow: var(--clay-sm); }

.chart {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 190px;
  margin: 18px 0 6px;
}
.bar-col {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: default;
}
.bar-plot {
  position: relative;
  flex: 1;
  width: 100%;
  max-width: 52px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  border-radius: var(--r-sm);
  background: var(--bg);
  box-shadow: var(--clay-inset);
  overflow: hidden;
}
.seg { width: 100%; flex-shrink: 0; }
/* column-reverse so the first segment sits at the bottom; the stack needs a
   definite height or the segments' percentage heights resolve to zero. */
.bar-stack {
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-start;
  height: 100%;
  gap: 2px;
}
.bar-target {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  border-top: 2px dashed rgba(58, 49, 41, 0.4);
  pointer-events: none;
}
.bar-label { font-size: 11.5px; font-weight: 700; color: var(--muted); }
.bar-col.is-today .bar-label { color: var(--green-dark); }
.bar-col.is-today .bar-plot { box-shadow: var(--clay-inset), 0 0 0 2px var(--green); }

.chart-tip {
  position: absolute;
  z-index: 5;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  background: var(--text);
  color: #fff;
  font-size: 12px;
  line-height: 1.55;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -100%);
  transition: opacity 0.12s ease;
}
.chart-tip.show { opacity: 1; }
.chart-tip b { font-size: 12.5px; }
.tip-row { display: flex; align-items: center; gap: 7px; }
.tip-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ---------- heatmap ----------
   Sequential single-hue ramp, light to dark, encoding "how much of the day
   did you finish". Grey is a separate state (nothing was required). */
.heat-legend { display: flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; color: var(--muted); }
.heat-key { width: 13px; height: 13px; border-radius: 4px; }
.heat-key.l1, .heat-cell.l1 { background: #CFE6D9; }
.heat-key.l2, .heat-cell.l2 { background: #A5D2B9; }
.heat-key.l3, .heat-cell.l3 { background: #6FB58E; }
.heat-key.l4, .heat-cell.l4 { background: #3F9463; }

.heat {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 7px;
  margin-top: 16px;
}
.heat-head {
  font-size: 10.5px;
  font-weight: 800;
  color: var(--muted);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-bottom: 2px;
}
.heat-cell {
  aspect-ratio: 1 / 1;
  border: none;
  border-radius: 9px;
  padding: 0;
  background: var(--bg);
  box-shadow: var(--clay-inset);
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.12s ease;
}
.heat-cell.l1, .heat-cell.l2, .heat-cell.l3, .heat-cell.l4 { box-shadow: var(--clay-sm); }
.heat-cell.none { background: var(--bg-2); box-shadow: none; }
.heat-cell.future {
  background: transparent;
  box-shadow: none;
  border: 2px dashed var(--bg-2);
  cursor: not-allowed;
}
.heat-cell.out-of-range { opacity: 0.35; cursor: not-allowed; }
.heat-cell:not(:disabled):hover { transform: scale(1.12); }
.heat-cell.selected { outline: 3px solid var(--track-1); outline-offset: 2px; }
.heat-cell.is-today { outline: 3px solid var(--coral); outline-offset: 2px; }

/* ---------- habit management ---------- */
.habit-form {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  align-items: end;
  margin-top: 16px;
}
.field { display: flex; flex-direction: column; gap: 7px; }
.field > span { font-size: 12px; font-weight: 700; color: var(--muted); }
.field-name { grid-column: 1 / -1; }
.habit-form input, .habit-form select {
  padding: 12px 14px;
  border-radius: var(--r-sm);
  border: none;
  background: var(--bg);
  box-shadow: var(--clay-inset);
  font-size: 14px;
  color: var(--text);
  font-family: inherit;
  width: 100%;
}
.habit-form .btn-clay { grid-column: 1 / -1; }

.habit-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  margin-bottom: 10px;
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--clay-sm);
}
.habit-item-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.habit-name { font-weight: 700; font-size: 14px; }
.habit-meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.habit-archive-btn {
  flex-shrink: 0;
  border: none;
  background: var(--blush);
  color: var(--coral);
  border-radius: var(--r-sm);
  padding: 9px 15px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--clay-sm);
  font-family: inherit;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.habit-archive-btn:hover { transform: translateY(-1px); }
.habit-archive-btn:active { transform: translateY(1px); box-shadow: var(--clay-press); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 20px);
  padding: 13px 22px;
  border-radius: var(--r-sm);
  background: var(--text);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 16px 30px -12px rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
  max-width: min(92vw, 460px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--coral); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
  }
  .brand { margin-bottom: 0; font-size: 15px; }
  .brand span { display: none; }
  .nav { flex-direction: row; gap: 8px; }
  .nav-item { padding: 10px 14px; font-size: 13px; }
  .logout-btn { margin-left: auto; }
  .main { padding: 22px 16px 60px; }
  .topbar h1 { font-size: 21px; }
  .today-card { padding: 22px 18px; }
  .today-head { gap: 16px; }
  .ring-wrap { width: 88px; height: 88px; }
  .ring-label b { font-size: 20px; }
  .track-name { width: 100%; }
  .track-bar-bg { order: 3; flex-basis: 100%; }
  .habit-form { grid-template-columns: 1fr; }
  .chart { height: 165px; gap: 6px; }
}
@media (max-width: 420px) {
  .stat-cards { grid-template-columns: 1fr; }
  .badges { width: 100%; }
  .badge { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .btn-clay:hover, .nudge:hover, button.today-row:hover, .habit-archive-btn:hover { transform: none; }
}
