/* MyMetrics — calm, encouraging, mobile-first. Tokens up top for easy re-skin. */
:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --card: #1e293b;
  --card-2: #243349;
  --line: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #38bdf8;     /* sky */
  --accent-2: #34d399;   /* emerald — "done" */
  --warm: #fbbf24;       /* gold — water */
  --danger: #fb7185;
  --radius: 18px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  /* heat scale */
  --h0: #243349;
  --h1: #14532d;
  --h2: #166534;
  --h3: #15803d;
  --h4: #22c55e;
  --h5: #4ade80;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: radial-gradient(1200px 600px at 50% -10%, #15233f 0%, var(--bg) 55%) fixed;
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

main { max-width: 720px; margin: 0 auto; padding: 16px 16px 40px; }

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 4px 16px;
}
.greeting { margin: 0; color: var(--muted); font-size: 14px; }
.logo { margin: 0; font-size: 26px; letter-spacing: -0.02em; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.header-actions form { margin: 0; }
.icon-btn {
  display: inline-grid; place-items: center; text-decoration: none;
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  width: 42px; height: 42px; border-radius: 12px; font-size: 18px; cursor: pointer;
}
.notice { padding: 11px 14px; border-radius: 12px; font-size: 14px; margin: 0 0 14px; }
.notice.ok { background: rgba(52, 211, 153, 0.12); border: 1px solid var(--accent-2); color: #a7f3d0; }
.notice.error { background: rgba(251, 113, 133, 0.12); border: 1px solid var(--danger); color: #fecdd3; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow);
  overflow: hidden; /* nothing (e.g. a chart canvas) ever spills past the rounded card */
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.card-head h2, .inline { margin: 0; font-size: 18px; }
.muted { color: var(--muted); font-size: 13px; }

/* habits */
.habits { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.habits li { margin: 0; }
.habits form { margin: 0; }
.habit {
  display: flex; align-items: center; gap: 14px; cursor: pointer; user-select: none;
  width: 100%; text-align: left; font: inherit; color: var(--text);
  background: var(--card-2); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px; transition: transform .08s ease, border-color .15s, background .15s;
}
.habit:active { transform: scale(0.99); }
.habit .check {
  width: 26px; height: 26px; flex: 0 0 26px; border-radius: 8px;
  border: 2px solid var(--line); display: grid; place-items: center;
  font-size: 16px; color: transparent; transition: all .15s;
}
.habit .label { font-weight: 600; }
.habit .sub { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.habit.done { border-color: var(--accent-2); background: rgba(52, 211, 153, 0.12); }
.habit.done .check { background: var(--accent-2); border-color: var(--accent-2); color: #06281c; }

/* water */
.water { margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--line); }
.water-top { display: flex; align-items: baseline; gap: 8px; }
.water-top strong { font-size: 22px; color: var(--warm); margin-left: auto; }
.water-top span:first-child { font-weight: 600; }
.water-bar { height: 10px; background: var(--card-2); border-radius: 999px; overflow: hidden; margin: 10px 0 12px; }
.water-fill { height: 100%; width: 0; background: linear-gradient(90deg, #f59e0b, var(--warm)); transition: width .3s; }
.water-actions { display: flex; gap: 8px; }
.water-form { flex: 1; margin: 0; }
.water-btn {
  width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--warm); color: #3a2a05; font-weight: 700; cursor: pointer; font: inherit;
}
.water-btn.ghost { background: transparent; color: var(--muted); }

/* streak grid */
.grid-wrap { overflow-x: auto; }
.streak-grid {
  display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr);
  gap: 5px; min-width: max-content;
}
.cell { width: 16px; height: 16px; border-radius: 4px; background: var(--h0); }
.cell.l0 { background: var(--h0); } .cell.l1 { background: var(--h1); }
.cell.l2 { background: var(--h2); } .cell.l3 { background: var(--h3); }
.cell.l4 { background: var(--h4); } .cell.l5 { background: var(--h5); }
.cell.future { opacity: 0.25; }
.legend { display: flex; align-items: center; gap: 5px; margin-top: 12px; color: var(--muted); font-size: 12px; }
.sw { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.sw.l0 { background: var(--h0); } .sw.l1 { background: var(--h1); } .sw.l2 { background: var(--h2); }
.sw.l3 { background: var(--h3); } .sw.l4 { background: var(--h4); } .sw.l5 { background: var(--h5); }

/* summary stats */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 560px) { .stats { grid-template-columns: repeat(3, 1fr); } }
.stat { background: var(--card-2); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.stat .num { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
.stat .num.good { color: var(--accent-2); }
.stat .num.accent { color: var(--accent); }
.stat .lbl { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* charts */
.chart-stats { display: flex; gap: 28px; margin: 2px 0 16px; }
.chart-stats .cs { display: flex; flex-direction: column; gap: 2px; }
.chart-stats .cs-num { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.chart-stats .cs-num.accent { color: var(--accent); }
.chart-stats .cs-unit { font-size: 13px; font-weight: 600; color: var(--muted); margin-left: 3px; }
.chart-stats .cs-lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.chart-box { position: relative; height: 240px; min-width: 0; width: 100%; }
.chart-box.small { height: 190px; }
.chart-box.small h3 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
/* Chart.js draws an inline-sized canvas; keep it from ever exceeding its box. */
.chart-box canvas { display: block; max-width: 100% !important; }
.chart-grid { display: grid; gap: 20px; }
/* three even trend charts in one row on wider screens; stack on mobile.
   minmax(0,1fr) lets columns shrink below the canvas's intrinsic width (prevents the
   chart from blowing out past the card). */
@media (min-width: 600px) { .chart-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* metric form */
.metric-form { display: grid; gap: 10px; margin-top: 12px; }
.metric-form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.metric-form input {
  background: var(--card-2); border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); padding: 11px 12px; font-size: 16px;
}
.metric-form button, .gate button {
  background: var(--accent); color: #06283d; border: 0; border-radius: 12px;
  padding: 13px; font-weight: 700; font-size: 16px; cursor: pointer;
}
details summary { cursor: pointer; list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary h2::after { content: " +"; color: var(--muted); }
details[open] summary h2::after { content: " −"; }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 8px 16px 0; }
.error { color: var(--danger); }

/* token gate */
.gate { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; background: var(--bg); z-index: 10; }
.gate-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px 22px; max-width: 380px; width: 100%; box-shadow: var(--shadow); }
.gate-card h1 { margin: 0 0 6px; }
.gate-card p { color: var(--muted); margin: 0 0 16px; }
.gate-card input { width: 100%; background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; color: var(--text); padding: 13px; font-size: 16px; margin-bottom: 12px; }
.gate-card button { width: 100%; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
