:root {
  --bg: #141413;
  --surface: #1c1c1a;
  --surface-2: #232320;
  --text: #f2eee8;
  --muted: #a7a199;
  --line: #3a3934;
  --accent: #d97757;
  --accent-soft: rgba(217, 119, 87, 0.16);
  --blue: #7296b8;
  --amber: #b79358;
  --radius: 12px;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button, select { font: inherit; }

.shell {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 18px max(48px, env(safe-area-inset-bottom));
}

.hero { padding: 14px 2px 26px; }

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .16em;
}

h1, h2, h3 { margin: 0; font-family: Georgia, "Times New Roman", serif; }
h1 { max-width: 700px; font-size: clamp(38px, 8vw, 68px); line-height: .98; letter-spacing: -.035em; }
h1 em { color: var(--accent); font-weight: 500; }
.lead { max-width: 620px; margin: 16px 0 0; color: var(--muted); line-height: 1.55; }

.controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}

.field { display: grid; gap: 7px; min-width: 0; }
.field > span { color: var(--muted); font-size: 12px; }

select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 44px;
  padding: 0 38px 0 13px;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  background: var(--surface-2);
}

select:focus { border-color: var(--accent); }

.period { display: flex; align-items: end; gap: 6px; }
.period-button {
  min-height: 44px;
  padding: 0 13px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  transition: .2s ease;
}
.period-button.is-active { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }

.status { padding: 34px 4px; color: var(--muted); text-align: center; }
.status.error { color: #e5a08d; }

.habit-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px;
  margin-top: 18px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}

.habit-head h2 { margin-top: 9px; font-size: clamp(28px, 6vw, 42px); line-height: 1.04; }
.muted { margin: 9px 0 0; color: var(--muted); }
.state-pill { display: inline-flex; padding: 5px 8px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.state-pill.active { color: var(--accent); border-color: rgba(217, 119, 87, .55); }
.state-pill.paused { color: var(--amber); border-color: rgba(183, 147, 88, .55); }

.summary { display: grid; grid-template-columns: repeat(2, minmax(100px, 1fr)); gap: 8px; align-content: start; }
.metric { min-width: 112px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.metric strong { display: block; font-size: 21px; font-weight: 650; }
.metric span { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }

.legend { display: flex; flex-wrap: wrap; gap: 12px 18px; padding: 18px 4px 12px; color: var(--muted); font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend-dot { width: 11px; height: 11px; border: 1px solid var(--line); border-radius: 3px; }
.legend-dot.done { border-color: var(--accent); background: var(--accent); }
.legend-dot.missed { background: var(--surface-2); }
.legend-dot.excused { border: 1px dashed var(--blue); }
.legend-dot.paused { border: 1px dashed var(--amber); }

.months { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.month { min-width: 0; padding: 17px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.month-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; margin-bottom: 15px; }
.month h3 { font-size: 22px; }
.month-count { color: var(--muted); font-size: 12px; white-space: nowrap; }
.weekdays, .days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; }
.weekdays { margin-bottom: 6px; color: var(--muted); font-size: 10px; text-align: center; }
.day { aspect-ratio: 1; display: grid; place-items: center; min-width: 0; border: 1px solid transparent; border-radius: 7px; color: #b9b4ad; font-size: 12px; }
.day.empty { visibility: hidden; }
.day.done { color: #fff; background: var(--accent); }
.day.missed { border-color: var(--line); background: var(--surface-2); }
.day.excused { border: 1px dashed var(--blue); color: #9dbbd6; }
.day.paused { border: 1px dashed var(--amber); color: #ceb27d; }
.day.future, .day.inactive { color: #5d5b56; }

.timeline-section { margin-top: 18px; padding: 20px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.section-heading h3 { font-size: 26px; }
.timeline { margin-top: 16px; display: grid; gap: 8px; }
.timeline-row { display: flex; justify-content: space-between; gap: 16px; padding: 11px 0; border-top: 1px solid var(--line); }
.timeline-row span:last-child { color: var(--muted); text-align: right; }

@media (max-width: 700px) {
  .shell { padding-left: 14px; padding-right: 14px; }
  .controls { grid-template-columns: 1fr; }
  .period { align-items: stretch; }
  .period-button { flex: 1; }
  .habit-head { grid-template-columns: 1fr; padding: 18px; }
  .summary { grid-template-columns: repeat(2, 1fr); }
  .months { grid-template-columns: 1fr; }
}

@media (max-width: 380px) {
  .month { padding: 13px; }
  .day { font-size: 11px; }
  .summary { grid-template-columns: 1fr 1fr; }
}
