/*
  Habits: the look.
  Phone first. Everything fits a 360 px wide screen, and wider screens just
  get a centred column. Colours are variables at the top, with a dark set
  for phones in dark mode.
*/

/* ---- colours ---- */
:root {
  --bg: #f6f5f2;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6b6b70;
  --line: #dcdad5;
  --accent: #0b6bcb;
  --empty: #ebe9e4;
  --warn: #9a4b00;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121316;
    --card: #1c1d21;
    --text: #f2f2f3;
    --muted: #a0a0a8;
    --line: #34353b;
    --accent: #5aa9ff;
    --empty: #2a2b30;
    --warn: #ffb35c;
  }
}

/* ---- page ---- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
main, .top, .tabs {
  max-width: 560px;
  margin: 0 auto;
  padding-left: 16px;
  padding-right: 16px;
}
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 1.2rem 0 0.5rem; }
.card h2 { margin-top: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---- header and tabs ---- */
.top { padding-top: calc(14px + env(safe-area-inset-top)); }
.status { margin: 2px 0 0; color: var(--muted); font-size: 0.9rem; min-height: 1.3em; }
.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin-top: 12px;
  margin-bottom: 8px;
}
.tab {
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  padding: 0 4px;
}
.tab[aria-current="page"] { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ---- shared bits ---- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin: 12px 0;
}
.button {
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.button.secondary { background: transparent; color: var(--accent); border: 1px solid var(--line); }
input[type="text"] {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  margin: 4px 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}
label, .label { display: block; font-weight: 600; margin: 0; }
.hint, .small, .date { color: var(--muted); font-size: 0.9rem; }
.empty { text-align: center; padding: 32px 0; }
.warning { color: var(--warn); font-size: 0.95rem; }
.message { min-height: 1.4em; margin-bottom: 0; }
code { font-size: 0.95em; }

/* ---- today ---- */
.today-list { list-style: none; margin: 0; padding: 0; }
.tick {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 72px;
  margin: 0 0 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}
.tick-mark {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 3px solid var(--c);
  display: grid;
  place-items: center;
  color: transparent;
  transition: background 0.15s;
}
.tick[aria-pressed="true"] .tick-mark { background: var(--c); color: #fff; }
.tick-text { min-width: 0; }
.tick-name { display: block; font-weight: 600; font-size: 1.05rem; overflow-wrap: anywhere; }
.tick-streak { display: block; color: var(--muted); font-size: 0.9rem; }

/* ---- month ---- */
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.month-nav h2 { margin: 0; text-align: center; }
.arrow {
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  font-size: 1.6rem;
  line-height: 1;
}
.month-card h3 { margin: 0; font-size: 1rem; overflow-wrap: anywhere; }
.month-card .tick-streak { margin-bottom: 10px; }
.grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  max-width: 360px;
}
.grid .weekday { text-align: center; font-size: 0.75rem; color: var(--muted); }
.day {
  aspect-ratio: 1;
  min-width: 0;
  border: 0;
  border-radius: 8px;
  background: var(--empty);
  font-size: 0.8rem;
  padding: 0;
}
.day.done { background: var(--c); color: #fff; font-weight: 700; }
.day.today { box-shadow: inset 0 0 0 2px var(--text); }
.day:disabled { opacity: 0.35; cursor: default; }

/* ---- manage ---- */
.manage-list { list-style: none; margin: 0; padding: 0; }
.manage-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.manage-row { flex-wrap: wrap; }
.manage-row input[type="text"] { margin: 0; flex: 1 1 calc(100% - 52px); min-width: 0; }
.manage-row .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.manage-row .move-up { margin-left: auto; }
.dot {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 0;
  background: var(--c);
}
.small-button {
  flex: none;
  min-width: 40px;
  height: 44px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  font-size: 0.9rem;
}
.small-button:disabled { opacity: 0.35; cursor: default; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 16px; }
.swatch {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid transparent;
  background: var(--c);
}
.swatch[aria-checked="true"] { border-color: var(--text); }

/* ---- settings ---- */
.code {
  font: 700 1.6rem/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.08em;
  margin: 4px 0 12px;
}
#code-input { text-transform: uppercase; font-family: ui-monospace, Menlo, Consolas, monospace; }

/* ---- test page ---- */
.result { padding: 8px 0; border-bottom: 1px solid var(--line); }
.pass { color: #2f8a3e; font-weight: 700; }
.fail { color: #c62828; font-weight: 700; }
