:root {
  color-scheme: light;
  --bg: #f5f4ef;
  --card: #ffffff;
  --ink: #1f2420;
  --muted: #6b6f68;
  --faint: #9a9d96;
  --line: #e5e3dc;
  --accent: #3d6b4f;
  --accent-ink: #ffffff;
  --accent-soft: #e6eee8;
  --warn: #b4462f;
  --warn-soft: #f8e9e4;
  --gold: #9a6b14;
  --gold-soft: #f6eedb;
  --radius: 14px;
  --tabs-h: 64px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 var(--font); -webkit-font-smoothing: antialiased;
}
body.sheet-open { overflow: hidden; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.ic { flex: none; display: block; }
.emoji { font-size: 18px; width: 20px; text-align: center; line-height: 20px; }
[hidden] { display: none !important; }

/* busy bar */
body::before {
  content: ""; position: fixed; top: 0; left: 0; height: 2px; width: 0; background: var(--accent);
  z-index: 100; transition: width .3s, opacity .3s; opacity: 0;
}
body.busy::before { width: 70%; opacity: 1; transition: width 8s cubic-bezier(.1,.8,.2,1); }

/* ------------------------------------------------------------ layout ---- */

.layout { min-height: 100vh; }
#view { max-width: 720px; margin: 0 auto; padding: calc(16px + env(safe-area-inset-top)) 16px calc(var(--tabs-h) + 28px + env(safe-area-inset-bottom)); outline: none; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: rgba(255,255,255,.96); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); backdrop-filter: saturate(1.4) blur(10px);
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 2px 8px; color: var(--faint); text-decoration: none; font-size: 11px; font-weight: 500;
  min-height: var(--tabs-h);
}
.tabs a.on { color: var(--accent); }
.side { display: none; }

@media (min-width: 960px) {
  .layout { display: grid; grid-template-columns: 232px 1fr; }
  .tabs { display: none; }
  .side {
    display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh;
    padding: 20px 12px; border-right: 1px solid var(--line); background: #faf9f6; overflow-y: auto;
  }
  .side .brand { padding: 4px 10px 18px; }
  .side a {
    display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px;
    color: var(--ink); text-decoration: none; font-size: 15px;
  }
  .side a:hover { background: #f0efe9; }
  .side a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
  .side a.muted-link { color: var(--muted); }
  .side-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); padding: 16px 10px 4px; }
  .side-foot { margin-top: auto; padding-top: 12px; }
  #view { padding: 32px 32px 64px; }
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 20px; color: var(--accent); }
.brand span { color: var(--ink); }

/* --------------------------------------------------------- page bits ---- */

.page-head { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin: 4px 0 16px; }
.page-head h1 { font-size: 28px; letter-spacing: -.01em; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.back { display: inline-flex; align-items: center; gap: 2px; color: var(--muted); text-decoration: none; margin-bottom: 6px; font-size: 15px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 12px;
}
.card > h2, .section-title {
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
  margin-bottom: 8px; display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.card > h2 a, .section-title a { text-transform: none; letter-spacing: 0; font-weight: 500; font-size: 14px; text-decoration: none; }
.empty { color: var(--muted); padding: 6px 0; }

.rows > * + * { border-top: 1px solid var(--line); }
.row { display: flex; align-items: flex-start; gap: 12px; padding: 10px 0; min-height: 44px; }
.row.tap { cursor: pointer; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 500; overflow-wrap: anywhere; }
.row .meta { color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 1px; }
.row .meta span { display: inline-flex; align-items: center; gap: 3px; }
.row .when { width: 66px; flex: none; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; padding-top: 1px; }
.row .when b { color: var(--ink); font-weight: 600; display: block; }
.row .side-val { color: var(--muted); font-size: 14px; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; margin-top: 7px; }

.tag { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; font-weight: 600; padding: 1px 7px; border-radius: 99px; background: #efede6; color: var(--muted); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.good { background: var(--accent-soft); color: var(--accent); }
.tag.gold { background: var(--gold-soft); color: var(--gold); }
.late { color: var(--warn) !important; font-weight: 600; }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.tile .n { font-size: 26px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tile .l { color: var(--muted); font-size: 13px; }

.quick { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 14px; padding: 2px 16px 4px; scrollbar-width: none; }
.quick::-webkit-scrollbar { display: none; }

/* ------------------------------------------------------------ controls ---- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-size: 15px; font-weight: 600; min-height: 42px; padding: 0 16px;
  border-radius: 11px; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #fafaf7; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #355f45; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.danger { color: var(--warn); }
.btn.block { width: 100%; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; border-radius: 9px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn {
  width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center;
  border: 0; background: transparent; color: var(--muted); border-radius: 10px; cursor: pointer; flex: none;
}
.icon-btn:hover { background: #f0efe9; color: var(--ink); }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  font: inherit; font-size: 14px; padding: 6px 12px; min-height: 34px; border-radius: 99px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.tick {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid #c9c7bf; background: var(--card);
  flex: none; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; color: transparent; padding: 0; margin-top: 1px;
}
.tick:hover { border-color: var(--accent); }
.tick.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.done .title { color: var(--faint); text-decoration: line-through; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  font: inherit; font-size: 16px; width: 100%; color: var(--ink); background: var(--card);
  border: 1px solid #d9d7cf; border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
textarea { resize: vertical; min-height: 84px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }
.inline { display: flex; gap: 10px; align-items: flex-end; }
.inline > * { flex: 1; min-width: 0; }
.inline > .fit { flex: none; }
.check-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; cursor: pointer; }
.hint { font-size: 13px; color: var(--muted); margin-top: 5px; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; }
.form-actions .btn.primary { flex: 1; }
.add-bar { display: flex; gap: 8px; margin-bottom: 12px; }
.add-bar input { flex: 1; }
.search { position: relative; margin-bottom: 12px; }
.search .ic { position: absolute; left: 12px; top: 12px; color: var(--faint); }
.search input { padding-left: 40px; }

.suggest { display: none; border: 1px solid var(--line); border-radius: 10px; margin-top: 4px; overflow: hidden; background: var(--card); box-shadow: 0 6px 18px rgba(0,0,0,.07); }
.suggest.open { display: block; }
.suggest button { display: flex; justify-content: space-between; gap: 10px; width: 100%; text-align: left; border: 0; background: none; font: inherit; padding: 10px 12px; cursor: pointer; }
.suggest button + button { border-top: 1px solid var(--line); }
.suggest button.active, .suggest button:hover { background: var(--accent-soft); }
.suggest small { color: var(--muted); }

.seg { display: inline-flex; background: #ecebe5; border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; font: inherit; font-size: 14px; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.stars { display: inline-flex; gap: 2px; }
.stars button { border: 0; background: none; font-size: 26px; line-height: 1; padding: 2px; cursor: pointer; color: #d6d3c9; }
.stars button.on { color: var(--gold); }

/* --------------------------------------------------------- sheets ---- */

.sheet-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(20,24,20,0); display: flex; align-items: flex-end; justify-content: center; transition: background .18s; }
.sheet-wrap.open { background: rgba(20,24,20,.35); }
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; background: var(--card);
  border-radius: 18px 18px 0 0; padding: 0 18px calc(20px + env(safe-area-inset-bottom));
  transform: translateY(30px); opacity: 0; transition: transform .18s, opacity .18s;
}
.sheet.wide { max-width: 720px; }
.sheet-wrap.open .sheet { transform: none; opacity: 1; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; position: sticky; top: 0; background: var(--card); padding: 14px 0 10px; z-index: 1; }
.sheet-head h3 { font-size: 18px; }
@media (min-width: 700px) {
  .sheet-wrap { align-items: center; }
  .sheet { border-radius: 18px; max-height: 86vh; }
}

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + 18px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: #26302a; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 15px; z-index: 80;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--warn); }
@media (min-width: 960px) { #toast { bottom: 24px; } }

/* ------------------------------------------------------- sign in ---- */

.signin { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.signin-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 26px 22px; }
.signin-card .brand { font-size: 26px; margin-bottom: 6px; }
.signin-card .muted { margin-bottom: 18px; }
.signin-card .btn + .btn { margin-top: 8px; }
.note { background: var(--gold-soft); color: var(--gold); padding: 8px 12px; border-radius: 10px; font-size: 14px; }

/* ---------------------------------------------------- module bits ---- */

.day-head { font-weight: 700; font-size: 15px; padding: 14px 0 4px; display: flex; gap: 8px; align-items: baseline; }
.day-head.today { color: var(--accent); }
.day-head small { color: var(--muted); font-weight: 500; }
.week-nav { display: flex; align-items: center; gap: 4px; margin-bottom: 12px; }
.week-nav .label { flex: 1; font-weight: 600; }

.bars { display: flex; align-items: flex-end; gap: 4px; height: 90px; padding-top: 6px; }
.bars div { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 3px; }
.bars i { display: block; width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .85; }
.bars span { font-size: 10px; color: var(--faint); }

.journal-text { font-size: 17px; line-height: 1.5; }
.about { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.memory { border-left: 3px solid var(--gold); padding-left: 12px; margin-top: 16px; }
.memory:first-child { margin-top: 0; }

.grid-links { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.grid-links a {
  display: flex; flex-direction: column; gap: 8px; padding: 14px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); text-decoration: none; color: var(--ink); font-weight: 600; min-height: 86px;
}
.grid-links a .ic, .grid-links a .emoji { color: var(--accent); }
.grid-links a small { color: var(--muted); font-weight: 400; }

.field-row { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px; }
.templates { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-bottom: 14px; }
.templates button { text-align: left; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 10px 12px; font: inherit; cursor: pointer; }
.templates button b { display: block; }
.templates button small { color: var(--muted); }
.templates button.on { border-color: var(--accent); background: var(--accent-soft); }
.spark { width: 100%; height: 56px; display: block; }
.icon-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.icon-pick button { width: 40px; height: 40px; font-size: 20px; border: 1px solid var(--line); background: var(--card); border-radius: 10px; cursor: pointer; }
.icon-pick button.on { border-color: var(--accent); background: var(--accent-soft); }

.cal-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.cal-table td, .cal-table th { padding: 8px 4px; border-top: 1px solid var(--line); text-align: left; vertical-align: middle; }
.cal-table th { font-size: 12px; color: var(--muted); font-weight: 600; border-top: 0; }
.cal-table input[type=text] { min-height: 36px; padding: 6px 8px; font-size: 14px; }
.cal-table .c { text-align: center; width: 56px; }
