*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

:root {
  color-scheme: dark;
  --bg: #000;
  --card: #08090b;
  --row: #101216;
  --line: #1a1d23;
  --text: #e9ecf1;
  --muted: #7f899c;
  --dim: #4c5568;
  --title: #8a95ad;
  --label: #56709f;
  --accent: #3fe0a0;
  --danger: #ff7a7a;
  --l0: #1b1d22;
  --l1: #10402f;
  --l2: #187050;
  --l3: #25a874;
  --l4: #3fe0a0;
  --cell: 16px;
  --gap: 5px;
  --r: 4px;
  --mh: 14px;
}

html { background: var(--bg); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
body.noscroll { overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.wrap {
  max-width: 680px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px;
  padding: calc(env(safe-area-inset-top) + 14px) calc(env(safe-area-inset-right) + 16px)
           calc(env(safe-area-inset-bottom) + 32px) calc(env(safe-area-inset-left) + 16px);
}
.loading { color: var(--dim); text-align: center; margin-top: 30vh; }

/* header */
.top { display: flex; align-items: flex-end; justify-content: space-between; padding: 6px 2px 2px; }
.eyebrow { color: var(--muted); font-size: 13px; letter-spacing: .03em; }
h1 { margin: 2px 0 0; font-size: 28px; font-weight: 700; letter-spacing: -.01em; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none;
  border-radius: 12px; color: var(--muted); transition: background .15s, color .15s;
}
.icon-btn:hover { background: #15181d; color: var(--text); }
.icon-btn.small { width: 34px; height: 34px; border-radius: 10px; }
.icon-btn:disabled { opacity: .3; cursor: default; background: none; }

/* cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 18px 16px; }
.card-title {
  margin: 0 0 14px 2px; font-size: 12px; font-weight: 600; letter-spacing: .24em;
  text-transform: uppercase; color: var(--title);
}
.empty { color: var(--muted); margin: 0; }

/* today */
.habits { display: flex; flex-direction: column; gap: 8px; }
.habit {
  display: flex; align-items: center; gap: 12px; min-height: 62px; padding: 10px 12px;
  border-radius: 14px; background: var(--row); border: 1px solid var(--line);
  cursor: pointer; user-select: none; -webkit-user-select: none; transition: background .15s, border-color .15s;
}
.habit.done { background: rgba(63, 224, 160, .07); border-color: rgba(63, 224, 160, .28); }
.emoji { flex: none; width: 30px; font-size: 22px; text-align: center; }
.hb-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.hb-name { font-size: 16px; font-weight: 600; }
.hb-meta, .hb-note { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hb-note { color: #aab3c4; }
.check {
  flex: none; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid #2b303a; color: transparent; transition: background .15s, border-color .15s;
}
.habit.done .check { background: var(--accent); border-color: var(--accent); color: #03140d; }

/* consistency */
.chips { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px 16px; padding: 0 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 6px 12px; border-radius: 999px; background: var(--row); border: 1px solid var(--line);
  color: var(--muted); font-size: 13px; white-space: nowrap;
}
.chip.on { background: rgba(63, 224, 160, .12); border-color: rgba(63, 224, 160, .4); color: var(--text); }

.grid-wrap { display: flex; gap: 10px; }
.days {
  flex: none; width: 12px; display: grid; grid-template-rows: repeat(7, var(--cell)); gap: var(--gap);
  margin-top: calc(var(--mh) + var(--gap)); font-size: 11px; font-weight: 600; color: var(--label);
}
.days span { line-height: var(--cell); text-align: center; }
.grid-scroll { flex: 1; min-width: 0; overflow: hidden; }
.months {
  display: grid; grid-auto-flow: column; grid-auto-columns: var(--cell); gap: var(--gap);
  height: var(--mh); font-size: 10px; color: var(--dim);
}
.months span { white-space: nowrap; line-height: var(--mh); }
.grid {
  display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, var(--cell));
  grid-auto-columns: var(--cell); gap: var(--gap); margin-top: var(--gap);
}
.cell { display: block; width: var(--cell); height: var(--cell); border-radius: var(--r); background: var(--l0); }
.cell.l1 { background: var(--l1); }
.cell.l2 { background: var(--l2); }
.cell.l3 { background: var(--l3); }
.cell.l4 { background: var(--l4); }
.cell.future { background: transparent; }
.cell.today { box-shadow: 0 0 0 1.5px var(--bg), 0 0 0 3px rgba(233, 236, 241, .45); }
button.cell { transition: filter .1s; }
button.cell:hover { filter: brightness(1.35); }

.legend { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin-top: 12px; font-size: 11px; color: var(--dim); }
.legend .cell { width: 11px; height: 11px; border-radius: 3px; }
.legend span:first-child { margin-right: 4px; }
.legend span:last-child { margin-left: 4px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.stat { background: var(--row); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.stat b { display: block; font-size: 20px; font-weight: 700; }
.stat span { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* sheet */
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .66); animation: fade .15s; }
.panel {
  position: relative; width: 100%; max-width: 680px; max-height: 88vh; overflow: auto; overscroll-behavior: contain;
  background: #0c0d10; border: 1px solid var(--line); border-bottom: 0; border-radius: 20px 20px 0 0;
  padding: 0 16px calc(env(safe-area-inset-bottom) + 20px); animation: up .2s ease-out;
}
.panel-head {
  position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0 10px; background: #0c0d10;
}
.panel-head h2 { margin: 0; font-size: 18px; }
@media (min-width: 720px) {
  .sheet { align-items: center; }
  .panel { border-radius: 20px; border-bottom: 1px solid var(--line); max-height: 82vh; padding-bottom: 20px; }
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } }

/* forms */
.in {
  width: 100%; min-height: 42px; padding: 9px 12px; border-radius: 10px; font: inherit; font-size: 16px;
  background: #121419; border: 1px solid #232730; color: var(--text); -webkit-appearance: none; appearance: none;
}
.in:focus { outline: none; border-color: var(--accent); }
.in::placeholder { color: var(--dim); }
textarea.in { min-height: 90px; resize: vertical; }
select.in { padding-right: 28px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 0 16px;
  border-radius: 12px; background: #171a20; border: 1px solid #242832; color: var(--text);
  font-weight: 600; font-size: 14px; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #1d2128; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #03140d; }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.inline-form { display: flex; gap: 8px; margin-top: 10px; }
.inline-form .in { flex: 1; min-width: 0; }
.inline-form .emoji-in { flex: none; }

.sec { margin-top: 22px; }
.sec:first-child { margin-top: 4px; }
.sec h3 { margin: 0 0 10px 2px; font-size: 12px; font-weight: 600; letter-spacing: .2em; text-transform: uppercase; color: var(--title); }
.sec p, .steps { color: var(--muted); font-size: 14px; margin: 0 0 6px; }
.sec p b { color: var(--text); }
.steps { padding-left: 20px; }
.steps li { margin-bottom: 4px; }
.hint { color: var(--dim); font-size: 13px; }

.hedit { display: flex; flex-direction: column; gap: 8px; padding: 10px; margin-bottom: 8px; border-radius: 14px; background: var(--row); border: 1px solid var(--line); }
.hedit-row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.emoji-in { flex: none; width: 54px; text-align: center; padding: 9px 4px; }
.hedit-row > .in:not(.emoji-in) { flex: 1; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 130px; font-size: 12px; color: var(--muted); }
.hedit-actions { display: flex; gap: 2px; margin-left: auto; }
.archived-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 4px; color: var(--muted); }

.day-row { margin-bottom: 8px; }
.day-row .in { margin-top: 6px; }

/* auth */
.auth { min-height: 78vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; }
.auth h1 { font-size: 26px; }
.auth p { color: var(--muted); margin: 0; max-width: 320px; }
.auth-form { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 10px; }
.logo { display: grid; grid-template-columns: repeat(4, 14px); gap: 4px; margin-bottom: 6px; }
.logo .cell { width: 14px; height: 14px; }
.err { min-height: 1.3em; margin: 0; color: var(--danger); font-size: 14px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px); transform: translateX(-50%); z-index: 60;
  max-width: 90vw; padding: 10px 16px; border-radius: 12px; background: #1d2027; border: 1px solid #2b303a; font-size: 14px;
}

@media (max-width: 360px) {
  :root { --cell: 14px; --gap: 4px; }
  .stat b { font-size: 18px; }
}
