/* Snus Tracker: clean design on warm paper colours. */

@font-face { font-family: 'DM Sans'; font-style: normal; font-weight: 400; font-display: swap;
  src: url(fonts/dm-sans-latin-400-normal.woff2) format('woff2'); }
@font-face { font-family: 'DM Sans'; font-style: normal; font-weight: 500; font-display: swap;
  src: url(fonts/dm-sans-latin-500-normal.woff2) format('woff2'); }
@font-face { font-family: 'DM Sans'; font-style: normal; font-weight: 600; font-display: swap;
  src: url(fonts/dm-sans-latin-600-normal.woff2) format('woff2'); }
@font-face { font-family: 'DM Sans'; font-style: normal; font-weight: 700; font-display: swap;
  src: url(fonts/dm-sans-latin-700-normal.woff2) format('woff2'); }

/* ---- Tokens ---- */
:root {
  --paper: #F7F5EC;
  --paper-dark: #EDE9DE;
  --ink: #252525;
  --pencil: #77766F;
  --light-pencil: #B8B5AC;
  --graphite: #484742;
  --red: #C95D50;
  --red-tint: rgba(201, 93, 80, 0.09);
  --texture: #D8D2C5;
  --on-ink: #F7F5EC;          /* text on the primary button */
  --shadow: 0 1px 2px rgba(37, 37, 37, 0.08);

  --head: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --body: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --r1: 10px;
  --r2: 10px;
  --r3: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #252522;
    --paper-dark: #30302C;
    --ink: #EAE7DD;
    --pencil: #B8B5AC;
    --light-pencil: #66655E;
    --graphite: #A8A69D;
    --red: #E1786B;
    --red-tint: rgba(225, 120, 107, 0.12);
    --texture: #3A3933;
    --on-ink: #252522;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

/* ---- Page ---- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.45 var(--body);
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}
main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(40px + env(safe-area-inset-bottom));
}
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px dashed var(--ink); outline-offset: 3px; }
[hidden] { display: none !important; }

/* ---- Headings ---- */
.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
h1 {
  font: 700 28px/1.15 var(--head);
  margin: 6px 0 0;
  letter-spacing: -0.02em;
}
.tagline { font: 400 15px/1.3 var(--body); color: var(--pencil); margin: 2px 0 0; }
h2 {
  font: 700 19px/1.2 var(--head);
  margin: 0 0 14px;
  letter-spacing: -0.01em;
}
.h-sub { font: 400 14px var(--body); color: var(--pencil); letter-spacing: 0; }
.pencil { color: var(--pencil); }
.small-text { font-size: 13px; margin: 8px 0 0; }

/* ---- Sections: notebook entries separated by a pencil stroke ---- */
.entry { padding: 22px 0 24px; position: relative; }
.entry + .entry::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: var(--light-pencil);
  opacity: 0.7;
}

/* ---- Today ---- */
.count-wrap { text-align: center; position: relative; margin-top: -6px; }
.count {
  font: 600 68px/1 var(--head);
  letter-spacing: -0.03em;
  display: inline-block;
  padding: 2px 14px;
}
.count.over { color: var(--red); }
.count-note { font: 600 15px/1 var(--body); color: var(--red); min-height: 0; margin-top: -2px; }
.count-note:empty { display: none; }
.last { text-align: center; margin: 6px 0 14px; font-size: 14px; color: var(--graphite); }

.time-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 14px 0 0; border-top: 1px solid var(--light-pencil); }
.time-row label { font-weight: 500; }

/* ---- Inputs ---- */
.field {
  min-height: 44px;
  padding: 8px 12px;
  background: var(--paper-dark);
  border: 1.5px solid var(--light-pencil);
  border-radius: var(--r2);
  color: var(--ink);
  min-width: 0;
}
.field:focus { border-color: var(--ink); outline: none; }
.field::placeholder { color: var(--pencil); opacity: 1; }
input[type=time].field { width: 8.5em; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 16px;
  border: 1.5px solid var(--ink);
  border-radius: var(--r1);
  background: transparent;
  color: var(--ink);
  font: 500 16px/1.2 var(--body);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 80ms ease, box-shadow 80ms ease;
}
.btn:active { transform: translateY(2px); box-shadow: 0 0 0 transparent; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.small { min-height: 44px; padding: 6px 14px; font-size: 15px; border-color: var(--graphite); }
.btn.primary {
  display: flex;
  width: 100%;
  min-height: 60px;
  margin: 16px 0 10px;
  border: 2px solid var(--ink);
  border-radius: var(--r3);
  font: 600 20px/1 var(--head);
  color: var(--on-ink);
  background: var(--ink);
}
.btn.secondary { display: flex; width: 100%; font: 500 17px/1 var(--body); border-color: var(--light-pencil); box-shadow: none; }
.btn.danger { color: var(--red); border-color: var(--red); }
.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 0; background: transparent; color: var(--ink);
  border-radius: 50%;
  cursor: pointer;
  margin-top: 4px;
}
.link-btn {
  display: block;
  margin: 8px auto 0;
  min-height: 44px;
  padding: 0 12px;
  background: none;
  border: 0;
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--light-pencil);
  text-underline-offset: 5px;
  cursor: pointer;
}
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---- Activity chips ---- */
.ask { margin-top: 14px; }
.ask-label { margin: 0 0 10px; }
.ask-label strong { font-weight: 500; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px;
  padding: 6px 14px;
  border: 1.5px solid var(--light-pencil);
  border-radius: 22px;
  background: transparent;
  color: var(--ink);
  font: 500 15px/1.1 var(--body);
  cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.chip[aria-pressed="true"]::before { content: '✓ '; }
.chip.skip { border-style: dashed; color: var(--pencil); }
.chip-input {
  min-height: 44px;
  width: 9.5em;
  padding: 6px 14px;
  border: 1.5px dashed var(--light-pencil);
  border-radius: 22px;
  background: transparent;
  font: 500 15px/1.1 var(--body);
}
.chip-input.filled { border-style: solid; background: var(--ink); color: var(--on-ink); }
.chip-input:focus { outline: none; border-color: var(--ink); border-style: solid; }

/* ---- Feedback notes ---- */
.notes { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 10px; }
.note {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 14px;
  background: var(--paper-dark);
  border: 1.5px solid var(--light-pencil);
  border-radius: var(--r1);
  font-size: 15px;
}
.note svg { flex: none; margin-top: 1px; }
.note.good { font-weight: 500; }
.note.bad { background: var(--red-tint); border-color: var(--red); }
.note.bad svg { color: var(--red); }

/* ---- Progress ---- */
.prog { display: grid; grid-template-columns: 6.5em 1fr auto; align-items: center; gap: 4px 12px; margin-bottom: 14px; }
.prog-label { font-weight: 500; }
.prog-count { font: 600 16px/1 var(--head); text-align: right; min-width: 3.2em; }
.prog-sub { grid-column: 2 / 4; font-size: 12.5px; color: var(--pencil); margin-top: -2px; }
.prog-sub.over { color: var(--red); font-weight: 600; }
.bar {
  height: 10px;
  border-radius: 5px;
  background: var(--paper-dark);
  box-shadow: inset 0 0 0 1px var(--texture);
  overflow: hidden;
}
.bar > span {
  display: block; height: 100%;
  background: var(--ink);
  border-radius: 5px;
}
.bar.over > span { background: var(--red); }

/* ---- Ruled lists ---- */
.ruled { list-style: none; margin: 0; padding: 0; }
.ruled li {
  display: flex; align-items: center; gap: 10px;
  min-height: 52px;
  padding: 4px 0;
  border-bottom: 1px solid var(--light-pencil);
}
.ruled li.empty { color: var(--pencil); border: 0; }
.entry-time {
  width: 7.6em; flex: none; min-height: 44px; padding: 0 2px;
  border: 0; border-bottom: 1.5px dashed transparent; border-radius: 0;
  background: transparent; font-weight: 500;
}
.entry-time:focus { border-bottom-color: var(--ink); outline: none; }
.entry-act {
  flex: 1; min-width: 0; min-height: 40px;
  padding: 6px 10px;
  background: transparent;
  border: 1.5px solid var(--light-pencil);
  border-radius: var(--r2);
  color: var(--ink);
}
.entry-act.unset { color: var(--pencil); }
.del {
  min-height: 44px; min-width: 44px;
  padding: 4px 12px;
  background: transparent;
  border: 1.5px solid var(--light-pencil);
  border-radius: var(--r1);
  color: var(--pencil);
  font-size: 14px;
  cursor: pointer;
}
.hist-day { width: 7.5em; }
.hist-count { width: 2em; text-align: right; font-weight: 600; }
.hist-mark { flex: 1; color: var(--pencil); font-size: 14px; }
.hist-mark::before { content: '•  '; }
.hist-row.over .hist-mark, .hist-row.over .hist-count { color: var(--red); }

/* ---- Segmented switch ---- */
.seg { display: flex; gap: 8px; margin: 2px 0 12px; }
.seg button {
  flex: 1; min-height: 44px;
  border: 1.5px solid var(--light-pencil);
  border-radius: var(--r1);
  background: transparent; color: var(--ink);
  font: 500 15px var(--body);
  cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }

/* ---- Charts ---- */
#chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.cols { display: flex; align-items: flex-end; gap: 12px; height: 150px; padding-top: 8px; border-bottom: 1px solid var(--light-pencil); }
.col { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.col-n { font: 600 15px var(--head); margin-bottom: 4px; }
.col-bar {
  width: 70%; max-width: 46px;
  min-height: 2px;
  border-radius: 6px 6px 0 0;
  background: var(--graphite);
}
.col-labels { display: flex; gap: 12px; margin-top: 6px; }
.col-labels span { flex: 1; min-width: 0; text-align: center; font-size: 12.5px; color: var(--graphite); overflow-wrap: anywhere; line-height: 1.2; }
.breakdown { margin-top: 18px; }
.bd-head { display: flex; justify-content: space-between; font-size: 12px; font-weight: 600; color: var(--pencil); text-transform: uppercase; letter-spacing: 0.04em; padding-bottom: 6px; border-bottom: 1px solid var(--light-pencil); }
.bd-row { padding: 10px 0; border-bottom: 1px solid var(--light-pencil); }
.bd-row.child { padding: 7px 0 7px 14px; margin-left: 4px; border-left: 2px solid var(--light-pencil); border-bottom: 0; }
.bd-row.child + .bd-row:not(.child) { border-top: 1px solid var(--light-pencil); }
.bd-row.zero { color: var(--pencil); }
.bd-main { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.bd-name { font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
.bd-row.child .bd-name { font-weight: 400; font-size: 14px; }
.bd-nums { display: flex; gap: 14px; font-variant-numeric: tabular-nums; flex: none; }
.bd-count { color: var(--pencil); min-width: 2ch; text-align: right; }
.bd-pct { font-weight: 600; min-width: 4ch; text-align: right; }
.bd-bar { height: 4px; margin-top: 6px; border-radius: 2px; background: var(--paper-dark); overflow: hidden; }
.bd-bar > span { display: block; height: 100%; background: var(--graphite); border-radius: 2px; }
.bd-row.child .bd-bar > span { background: var(--light-pencil); }
.bd-sub { margin-top: 4px; font-size: 12.5px; color: var(--pencil); }
.bd-foot { margin: 10px 0 0; font-size: 12.5px; color: var(--pencil); }
.empty-chart { color: var(--pencil); align-self: center; margin: auto; }

/* ---- Limits ---- */
.limits { display: grid; grid-template-columns: 6em 7em 1fr; align-items: center; gap: 10px 12px; }
.limits label { font-weight: 500; }
.limits .pencil { font-size: 13px; }

/* ---- Toast: a little paper note ---- */
.toast {
  position: fixed; left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  background: var(--ink);
  color: var(--on-ink);
  border: 0;
  border-radius: var(--r2);
  box-shadow: var(--shadow);
  font: 500 15px/1.3 var(--body);
  z-index: 10;
}

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