:root {
  --stage: #100e0c;
  --ink: #171410;
  --card: #241f1a;
  --card-on: #2e2820;
  --text: #f6f1e8;
  --muted: #a3988c;
  --faint: #7a7168;
  --line: #3a332c;
  --accent: #e4b15a;
  --accent-dim: #4a3a22;
  --work: #9ec0db;
  --rail: 260px;
  --side: 292px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--stage);
  color: var(--text);
}

body {
  font: 16px/1.4 system-ui, "Segoe UI", Roboto, sans-serif;
}

button, input { font: inherit; color: inherit; }

button { cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#app, .app { height: 100%; }

.app {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  min-height: 100%;
}

.rail {
  background: #14110e;
  border-right: 1px solid var(--line);
  padding: 16px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.4px;
}

.sample {
  color: var(--accent);
  background: var(--accent-dim);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.streak {
  background: var(--card);
  border-radius: 14px;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
  align-items: center;
}

.streak-num {
  grid-row: span 2;
  font-size: 40px;
  line-height: 0.9;
  font-weight: 750;
  color: var(--accent);
  letter-spacing: -1px;
}

.streak b { font-size: 14px; }

.streak p, .hint, .empty, .legend, .foot-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.nav {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.nav button, .chip, .kind, .add, .text-btn, .cell, .strip-day, .weekday, .icon-btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  border-radius: 999px;
  min-height: 40px;
}

.nav button {
  border-radius: 12px;
  font-weight: 700;
}

.nav button[aria-current="page"], .chip[aria-pressed="true"], .kind[aria-pressed="true"], .weekday[aria-pressed="true"] {
  background: var(--accent);
  color: var(--ink);
  border-color: transparent;
}

.filters { display: flex; flex-wrap: wrap; gap: 6px; }

.chip { padding: 0 12px; }

.habit-scroll {
  flex: 1;
  min-height: 80px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 2px;
}

.habit-head, .col-head, .side-head, .panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.habit-head h2, .col h2, .side h2, .panel h2 {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.habit-block { display: flex; flex-direction: column; gap: 4px; }

.habit-line, .habit-edit {
  display: flex;
  gap: 6px;
  align-items: center;
}

.habit {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  text-align: left;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--ink);
  min-height: 40px;
  padding: 4px 8px;
  color: var(--text);
}

.habit-edit input {
  min-height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--ink);
  padding: 0 8px;
  min-width: 0;
}

.habit-edit input:first-child { flex: 1; }

.habit.on { background: var(--card-on); border-color: #6a542c; }

.box {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 1.5px solid var(--faint);
  display: grid;
  place-items: center;
  flex: none;
  font-size: 14px;
}

.habit.on .box { background: var(--accent); color: var(--ink); border-color: var(--accent); }

.amount-row, .add-row, .composer-row, .routine-line {
  display: flex;
  gap: 6px;
  align-items: center;
}

.amount-row input, .add-row input, .composer-row input, .routine-line input, .rename input {
  min-height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--ink);
  padding: 0 10px;
  min-width: 0;
}

.amount-row input { width: 72px; }
.unit-input, .time-input { width: 84px; flex: none; }
.add-row input:first-child, .composer-row input[type="text"]:not(.time-input), .routine-line input.name { flex: 1; }

.add {
  background: var(--accent);
  color: var(--ink);
  border-color: transparent;
  font-weight: 750;
  padding: 0 14px;
  min-width: 64px;
}

.add:disabled { opacity: 0.45; cursor: default; }

.field-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--faint);
  font-size: 12px;
}

.rail-foot { display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }

.tester-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.backup-row { display: flex; flex-wrap: wrap; gap: 6px; }

.backup-row .text-btn { flex: 1; }

.source-label {
  display: block;
  margin-left: 0;
  color: var(--faint);
  font-size: 12px;
  font-weight: 650;
}

.school-banner {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  align-items: center;
  background: var(--card);
  border-radius: 12px;
  padding: 8px 10px;
}

.school-banner p {
  margin: 0;
  flex: 1 1 240px;
  color: var(--muted);
  font-size: 13px;
}

.school-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 10px; }

.legend span { white-space: nowrap; }

.linkish, .text-btn {
  background: transparent;
  color: var(--accent);
  border: 0;
  min-height: 36px;
  padding: 0 8px;
  border-radius: 8px;
}

.main {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px 12px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
}

.pager { display: flex; align-items: center; gap: 4px; }

.icon-btn {
  width: 40px;
  border-radius: 12px;
  font-size: 22px;
  line-height: 1;
}

.titles { flex: 1; min-width: 0; }

.kicker {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
}

.titles h2 {
  margin: 0;
  font-size: 28px;
  letter-spacing: -0.6px;
  line-height: 1.1;
}

.week-strip {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.strip-day {
  border-radius: 12px;
  min-height: 52px;
  padding: 6px 8px;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.strip-day.on { border-color: var(--accent); color: var(--text); }
.strip-day.today .dow { color: var(--accent); }
.strip-day .dow { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }
.strip-day strong { font-size: 16px; color: var(--text); }

.stage {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--side);
  gap: 10px;
  overflow: hidden;
}

.columns, .week-board {
  min-height: 0;
  min-width: 0;
  display: grid;
  gap: 10px;
  overflow: hidden;
}

.columns { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.week-board { grid-template-columns: repeat(7, minmax(0, 1fr)); }

.col, .side, .day-card, .panel, .cell {
  background: var(--card);
  min-height: 0;
}

.col, .side, .panel {
  border-radius: 14px;
  padding: 12px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.col { border-top: 3px solid var(--line); }
.col.tasks { border-top-color: var(--accent); }
.col.events { border-top-color: var(--work); }
.col.notes { border-top-color: #c7b39a; }

.entry, .line, .open-row {
  background: var(--ink);
  border-radius: 10px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.entry-main, .line, .open-row {
  flex-direction: row;
  align-items: flex-start;
  gap: 8px;
}

.mark {
  width: 28px;
  flex: none;
  text-align: center;
  color: var(--accent);
  font-size: 18px;
  background: transparent;
  border: 0;
  min-height: 28px;
  padding: 0;
}

.mark:disabled { color: var(--faint); }

.entry-text { flex: 1; min-width: 0; }

.done { text-decoration: line-through; color: var(--faint); }
.moved { color: var(--faint); }

.actions { display: flex; flex-wrap: wrap; gap: 4px; padding-left: 36px; }

.tag, .weekly {
  color: var(--work);
  font-size: 12px;
  font-weight: 700;
}

.weekly { color: var(--muted); font-weight: 600; }

.moved-label { color: var(--accent); font-size: 12px; }

.timeline-row {
  display: grid;
  grid-template-columns: 76px 18px minmax(0, 1fr);
  gap: 6px;
  align-items: baseline;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}

.when { color: var(--accent); font-variant-numeric: tabular-nums; font-size: 13px; }

.composer {
  background: var(--card);
  border-radius: 14px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.kinds, .weekdays { display: flex; flex-wrap: wrap; gap: 6px; }

.kind { padding: 0 12px; }

.day-card {
  border-radius: 12px;
  padding: 8px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: 1px solid transparent;
}

.day-card.on { border-color: var(--accent); }

.day-card header button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--text);
  min-height: 40px;
  padding: 0;
  border-radius: 8px;
}

.mini {
  font-size: 13px;
  color: var(--text);
  background: var(--ink);
  border-radius: 8px;
  padding: 4px 6px;
}

button.mini {
  width: 100%;
  text-align: left;
  border: 0;
  min-height: 36px;
  color: var(--text);
  cursor: pointer;
}

.mini .muted, .muted { color: var(--muted); }

.month-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-auto-rows: minmax(72px, 1fr);
  gap: 6px;
}

.dow-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  color: var(--faint);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-align: center;
}

.cell {
  border-radius: 10px;
  text-align: left;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-height: 72px;
  color: var(--text);
  overflow: hidden;
}

.cell.empty { background: transparent; border-color: transparent; cursor: default; }

.cell.on { border-color: var(--accent); }
.cell .num { font-weight: 750; }
.cell .num.today { color: var(--accent); }
.cell .blurb {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: transparent;
  margin-top: auto;
}

.dot.on { background: var(--accent); }
.dot.partial { background: var(--faint); }

.month-wrap {
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

@media (max-width: 1100px) {
  .app { grid-template-columns: 220px minmax(0, 1fr); }
  .stage { grid-template-columns: 1fr; }
  .columns { grid-template-columns: 1fr; }
  .week-board { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .side, .panel { max-height: 280px; }
}
