:root {
  color-scheme: light;
  --bg: #faf8f3;
  --ink: #2f3833;
  --muted: #7a807a;
  --line: #e8e4da;
  --card: #fefdfa;
  --surface-secondary: #f3f0e8;
  --accent: #5e7866;
  --accent-hover: #526b5a;
  --purple: #8a9070;
  --purple-soft: #f0f1e7;
  --orange: #c98a64;
  --orange-soft: #f7ebe1;
  --blue: #8aa19b;
  --brand-ink: #2f4a3e;
  --green: #7f9670;
  --green-soft: #eef2e8;
  --danger: #a65a47;
  --danger-soft: #f8ece8;
  --danger-line: #ead2ca;
  --miss: #ebe7dd;
  --shadow: 0 5px 18px rgba(40, 48, 44, 0.045);

  --font: "Segoe UI", system-ui, sans-serif;
  --text-xs: 12px;
  --text-sm: 14px;
  --text-md: 16px;
  --text-lg: 17px;
  --text-xl: 20px;
  --text-2xl: 24px;
  --text-3xl: 32px;

  --weight-body: 400;
  --weight-label: 600;
  --weight-display: 600;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-pill: 999px;

  --control: 44px;
  --gap: 12px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--text-md);
  font-weight: var(--weight-body);
  line-height: 1.4;
}

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

.app {
  width: min(440px, 100%);
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  margin: -20px -16px 16px;
  padding: 12px 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: var(--text-xl);
  font-weight: var(--weight-display);
  letter-spacing: -0.02em;
  color: var(--brand-ink);
}

.brand img {
  width: 30px;
  height: 30px;
}

h1 {
  margin: 0;
  font-size: var(--text-2xl);
  font-weight: var(--weight-display);
  line-height: 1.15;
  letter-spacing: -0.03em;
}

h2 {
  margin: 0 0 12px;
  font-size: var(--text-lg);
  font-weight: var(--weight-display);
}

h3 {
  margin: 0;
  font-size: var(--text-md);
  font-weight: var(--weight-label);
}

.muted, .note, .foot, .save-status, .export-status {
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-body);
}

.day-nav {
  display: grid;
  grid-template-columns: var(--control) 1fr var(--control) auto;
  gap: 6px;
  margin: 10px 0 14px;
}

.arrow-btn {
  font-size: var(--text-xl);
  line-height: 1;
  padding: 0;
}

.day-picker {
  min-width: 0;
  min-height: var(--control);
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: var(--r-md);
  padding: 0 10px;
  font-size: var(--text-md);
  font-weight: var(--weight-label);
  color: var(--ink);
}

.nav-btn, .choice-row button, .pair-row button, .scale-row button, .period-row button, .weekday-row button, .template-chip, .counter-btn {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: var(--r-md);
  min-height: var(--control);
  padding: 8px 10px;
  font-size: var(--text-sm);
  font-weight: var(--weight-label);
}

.nav-btn:disabled, .counter-btn:disabled { opacity: 0.4; }

.block, .habit-card, .habit-item, .history-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow);
}

.block {
  padding: 16px;
  margin-bottom: 12px;
}

.field, .check { display: block; margin: 0 0 10px; }

.field, legend {
  font-size: var(--text-sm);
  font-weight: var(--weight-label);
  color: var(--muted);
}

.field input, .field textarea, .habit-editor select, .meal-note {
  display: block;
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: var(--r-md);
  padding: 12px;
  font-size: var(--text-lg);
  font-weight: var(--weight-body);
  color: var(--ink);
}

.habit-editor select {
  background: var(--card);
  font: inherit;
  font-size: var(--text-lg);
  font-weight: var(--weight-body);
}

.field textarea { resize: vertical; }

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--control);
  font-size: var(--text-lg);
  font-weight: var(--weight-label);
  color: var(--ink);
}

.check input {
  width: 22px;
  height: 22px;
  accent-color: var(--green);
}

.meal {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.meal .check { flex: 0 0 104px; margin: 0; }

.meal-note {
  flex: 1;
  width: auto;
  min-width: 0;
  margin-top: 0;
  padding: 10px;
}

.meal-extra {
  flex: 1;
  display: flex;
  gap: 8px;
  min-width: 0;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--gap);
}

.field b {
  color: var(--ink);
  font-weight: var(--weight-display);
}

.stars { display: flex; gap: 4px; }

.star {
  position: relative;
  width: var(--control);
  height: var(--control);
  font-size: 38px;
  line-height: var(--control);
  text-align: center;
}

.star::before {
  content: "★";
  color: var(--line);
}

.star.is-full::before { color: var(--orange); }

.star.is-half::before {
  background: linear-gradient(90deg, var(--orange) 50%, var(--line) 50%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.star-half {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

.star-half.is-left { left: 0; }
.star-half.is-right { right: 0; }

fieldset {
  border: 0;
  margin: 0 0 12px;
  padding: 0;
}

legend { margin-bottom: 8px; }

.scale-row, .choice-row, .pair-row {
  display: flex;
  gap: 6px;
}

.scale-row button, .choice-row button, .pair-row button { flex: 1; }

.scale-row button[aria-pressed="true"],
.choice-row button[aria-pressed="true"],
.pair-row button[aria-pressed="true"],
.weekday-row button[aria-pressed="true"],
.period-row button[aria-pressed="true"] {
  background: var(--purple-soft);
  border-color: transparent;
  color: var(--purple);
}

.choice-row button[data-value="moved"][aria-pressed="true"] {
  background: var(--orange-soft);
  color: var(--orange);
}

.note { margin: -2px 0 10px; }

.foot { text-align: center; margin: 8px 0 0; }

.tabs {
  display: flex;
  gap: 1px;
  margin-top: 8px;
  padding: 3px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}

.tabs button {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: transparent;
  border-radius: var(--r-sm);
  min-height: 38px;
  padding: 0 1px;
  font-size: clamp(10px, 3.3vw, 14px);
  font-weight: var(--weight-label);
  letter-spacing: -0.02em;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tabs button[aria-pressed="true"] {
  background: var(--orange-soft);
  color: var(--orange);
}

.view h1 { margin-bottom: 4px; }

.view > .muted { margin: 0 0 14px; }

.save-bar {
  position: sticky;
  bottom: 0;
  display: grid;
  gap: 6px;
  margin: 4px -16px 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 75%, rgba(255, 250, 245, 0));
}

.save-status {
  margin: 0;
  text-align: center;
}

.primary-btn {
  border: 0;
  border-radius: var(--r-md);
  min-height: 50px;
  background: var(--ink);
  color: white;
  font-size: var(--text-lg);
  font-weight: var(--weight-display);
}

.primary-btn:active { transform: translateY(1px); }

.wide-btn { width: 100%; }

.history-list, .habits-list, .habit-list { display: grid; gap: 10px; }

.habits-list { margin-top: 12px; }

.empty {
  margin: 0;
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: var(--r-lg);
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-body);
  text-align: center;
}

.history-item { overflow: hidden; }

.history-item summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  list-style: none;
}

.history-item summary::-webkit-details-marker { display: none; }

.history-item summary::after {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  margin-left: 4px;
  transition: transform 0.15s;
}

.history-item[open] summary::after { transform: rotate(-135deg); }

.history-date { display: grid; gap: 2px; flex: 1; }

.history-date strong {
  font-size: var(--text-lg);
  font-weight: var(--weight-label);
}

.history-date span {
  font-size: var(--text-xs);
  font-weight: var(--weight-body);
  color: var(--muted);
}

.history-score,
.habit-goal,
.habit-streak {
  padding: 3px 8px;
  border-radius: var(--r-pill);
  font-size: var(--text-xs);
  font-weight: var(--weight-display);
  white-space: nowrap;
}

.history-score,
.habit-goal {
  background: var(--purple-soft);
  color: var(--purple);
}

.habit-streak {
  background: var(--orange-soft);
  color: var(--orange);
}

.history-body {
  padding: 0 16px 16px;
  border-top: 1px solid var(--line);
}

.history-group { padding-top: 12px; }

.history-group h3 {
  margin: 0 0 6px;
  font-size: var(--text-xs);
  font-weight: var(--weight-display);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--orange);
}

.history-group dl {
  display: grid;
  grid-template-columns: minmax(110px, auto) 1fr;
  gap: 6px 12px;
  margin: 0;
  font-size: var(--text-sm);
}

.history-group dt {
  color: var(--muted);
  font-weight: var(--weight-body);
}

.history-group dd {
  margin: 0;
  font-weight: var(--weight-body);
  word-break: break-word;
  white-space: pre-wrap;
}

.history-actions, .editor-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
  margin-top: 14px;
}

.danger-btn {
  color: var(--danger);
  border-color: var(--danger-line);
  background: var(--danger-soft);
}

.habit-card {
  margin: 14px 0;
  padding: 16px;
}

.habit-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.habit-head h2 { margin: 0; }

.habit-count, .habit-item-stat, .habit-grid-title span {
  font-size: var(--text-sm);
  font-weight: var(--weight-label);
  color: var(--green);
}

.habit-count { margin: 2px 0 0; }

.link-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-label);
  min-height: 36px;
  padding: 0 8px;
}

.small-btn {
  border: 0;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: white;
  font-size: var(--text-sm);
  font-weight: var(--weight-display);
  min-height: 36px;
  padding: 0 12px;
}

.habit-editor { margin-top: 12px; }

.field-error {
  margin: -4px 0 10px;
  font-size: var(--text-sm);
  font-weight: var(--weight-label);
  color: var(--danger);
}

.weekday-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 8px;
}

.weekday-row button {
  border-radius: var(--r-sm);
  min-height: 40px;
  padding: 0;
  color: var(--muted);
}

.editor-actions { margin-top: 8px; }

.section-title {
  margin: 20px 0 0;
  font-size: var(--text-md);
  font-weight: var(--weight-label);
  color: var(--muted);
}

.habit-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px;
  border-radius: var(--r-lg);
}

.habit-item.is-paused { opacity: 0.75; box-shadow: none; }

.habit-item-main {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 4px;
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
  cursor: pointer;
  color: inherit;
  font: inherit;
}

.habit-item-main strong,
.habit-text strong {
  font-size: var(--text-lg);
  font-weight: var(--weight-label);
  word-break: break-word;
}

.habit-item-meta, .habit-item-stat, .habit-amount {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: var(--weight-body);
  color: var(--muted);
}

.habit-item-stat { font-weight: var(--weight-label); color: var(--green); }

.habit-templates { margin: 10px 0 4px; }

.habit-templates .note { margin: 0 0 8px; }

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

.template-chip {
  border-radius: var(--r-pill);
  min-height: 36px;
  padding: 0 12px;
  color: var(--ink);
}

.template-chip:active {
  background: var(--purple-soft);
  color: var(--purple);
}

.habit-detail { margin-top: 12px; }

.detail-back { margin: 0 0 8px -8px; }

.habit-detail h2 {
  margin: 0 0 4px;
  font-size: var(--text-xl);
  word-break: break-word;
}

.habit-detail > .muted { margin: 0 0 8px; }

.habit-detail > .habit-meta { margin-bottom: 14px; }

.detail-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
  margin-bottom: 16px;
}

.detail-stat {
  display: grid;
  gap: 2px;
  padding: 12px;
  border-radius: var(--r-md);
  background: var(--bg);
  border: 1px solid var(--line);
}

.detail-stat-value {
  font-size: var(--text-xl);
  font-weight: var(--weight-display);
  letter-spacing: -0.03em;
}

.detail-stat-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-label);
  color: var(--muted);
}

.habit-calendar { margin-bottom: 8px; }

.cal-head {
  display: grid;
  grid-template-columns: var(--control) 1fr var(--control);
  gap: var(--gap);
  align-items: center;
  margin-bottom: 10px;
}

.cal-head h3 {
  margin: 0;
  text-align: center;
  font-size: var(--text-md);
  font-weight: var(--weight-label);
}

.cal-weekdays,
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-weekdays {
  margin-bottom: 4px;
  text-align: center;
  font-size: var(--text-xs);
  font-weight: var(--weight-label);
  color: var(--muted);
}

.cal-cell {
  aspect-ratio: 1;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  font: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-label);
  color: var(--ink);
  padding: 0;
  display: grid;
  place-content: center;
}

.cal-cell small {
  font-size: 10px;
  font-weight: var(--weight-display);
  color: inherit;
  opacity: 0.85;
}

.cal-cell.is-pad { visibility: hidden; }

.cal-cell.is-muted { color: var(--muted); opacity: 0.45; }

.cal-cell.is-off {
  color: var(--muted);
  border: 1px dashed var(--line);
}

.cal-cell.is-done {
  background: var(--green);
  color: white;
}

.cal-cell.is-miss { background: var(--miss); color: var(--muted); }

.cal-cell.is-empty { background: var(--bg); }

.cal-cell.is-today { box-shadow: inset 0 0 0 2px var(--orange); }

.cal-cell:disabled { cursor: default; }

.cal-cell:not(:disabled) { cursor: pointer; }

.cal-legend { margin: 10px 0 0; }

.habit-item-actions {
  display: grid;
  grid-template-columns: 40px 40px;
  gap: 4px;
  justify-items: stretch;
}

.habit-item-actions .arrow-btn {
  min-height: 40px;
  font-size: var(--text-md);
}

.habit-item-actions .link-btn,
.habit-item-actions .small-btn { grid-column: 1 / -1; }

.counter { display: flex; gap: 6px; }

.counter-btn {
  width: var(--control);
  height: var(--control);
  padding: 0;
  font-size: var(--text-xl);
  line-height: 1;
}

.counter-plus {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.habit-row {
  display: flex;
  align-items: center;
  gap: var(--gap);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg);
  padding: 4px 8px 4px 12px;
}

.habit-row.is-done {
  background: var(--green-soft);
  border-color: transparent;
}

.habit-check {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  cursor: pointer;
}

.habit-check input {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  accent-color: var(--green);
}

.habit-text { display: grid; gap: 4px; }

.habit-row.is-done .habit-text strong {
  color: var(--muted);
  text-decoration: line-through;
}

.habit-row.is-done .habit-amount { color: var(--green); }

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

.period-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.period-row button { padding-inline: 4px; }

.chart-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.chart-head h2 { margin: 0; }

.chart-stat {
  font-size: var(--text-sm);
  font-weight: var(--weight-label);
  color: var(--muted);
  text-align: right;
}

.chart-svg { display: block; width: 100%; height: auto; }

.chart-svg .bar { fill: var(--purple); }

.chart-svg .bar-empty { fill: var(--line); }

.chart-svg .bar-score { fill: var(--blue); }

.chart-svg .bar-mood { fill: var(--orange); }

.legend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.legend .is-score { background: var(--blue); }
.legend .is-mood { background: var(--orange); }

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
  margin-bottom: 12px;
}

.stat-tile {
  display: grid;
  align-content: start;
  gap: 2px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 14px;
  box-shadow: var(--shadow);
}

.stat-label {
  font-size: var(--text-sm);
  font-weight: var(--weight-label);
  color: var(--muted);
}

.stat-value {
  font-size: var(--text-2xl);
  font-weight: var(--weight-display);
  letter-spacing: -0.03em;
  color: var(--ink);
}

.stat-value {
  white-space: nowrap;
}

.stat-value small {
  font-size: var(--text-sm);
  font-weight: var(--weight-label);
  letter-spacing: 0;
  color: var(--muted);
}

.stat-hint {
  font-size: var(--text-xs);
  font-weight: var(--weight-body);
  color: var(--muted);
}

.fact-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.fact-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  font-size: var(--text-md);
  font-weight: var(--weight-body);
}

.fact-list li span:last-child {
  font-weight: var(--weight-label);
  white-space: nowrap;
}

.profile-weight { margin-bottom: 12px; }

.profile-weight-value {
  margin: 0 0 4px;
  font-size: var(--text-2xl);
  font-weight: var(--weight-display);
  color: var(--ink);
}

.profile-weight .note { margin: 0 0 4px; }

.sub-title {
  margin: 8px 0 10px;
  font-size: var(--text-md);
  font-weight: var(--weight-label);
}

.restriction-list {
  list-style: none;
  margin: 0 0 10px;
  padding: 0;
  display: grid;
  gap: 8px;
}

.restriction-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.restriction-row input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: var(--r-md);
  padding: 10px 12px;
  font-size: var(--text-md);
  font-weight: var(--weight-body);
  color: var(--ink);
}

.restriction-note { margin-top: 10px; }

.path-total {
  margin: 0 0 4px;
  font-size: var(--text-3xl);
  font-weight: var(--weight-display);
  letter-spacing: -0.04em;
}

.path-total small {
  font-size: var(--text-lg);
  font-weight: var(--weight-label);
  letter-spacing: 0;
  color: var(--muted);
}

.path-compare {
  margin: 0 0 10px;
  font-size: var(--text-md);
  font-weight: var(--weight-label);
  color: var(--green);
}

.path-bar {
  height: 10px;
  margin: 4px 0 8px;
  background: var(--line);
  border-radius: var(--r-pill);
  overflow: hidden;
}

.path-bar span {
  display: block;
  height: 100%;
  background: var(--green);
  border-radius: inherit;
}

.milestones {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
}

.milestones li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0 8px 26px;
  border-top: 1px solid var(--line);
  position: relative;
  font-size: var(--text-sm);
  font-weight: var(--weight-label);
  color: var(--muted);
}

.milestones li::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 50%;
  width: 12px;
  height: 12px;
  margin-top: -6px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--card);
}

.milestones li.is-passed { color: var(--ink); }

.milestones li.is-passed::before {
  border-color: var(--green);
  background: var(--green);
}

.badge-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.badge {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 4px;
  padding: 10px 6px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg);
  opacity: 0.8;
}

.badge.is-earned {
  opacity: 1;
  background: var(--card);
}

.badge-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--miss);
  color: var(--card);
  font-size: var(--text-sm);
  font-weight: var(--weight-display);
}

.badge.is-earned .badge-mark {
  background: var(--orange);
  box-shadow: 0 0 0 4px var(--orange-soft);
}

.badge strong {
  font-size: var(--text-xs);
  font-weight: var(--weight-label);
  line-height: 1.25;
}

.badge-hint {
  font-size: 11px;
  font-weight: var(--weight-body);
  color: var(--muted);
  line-height: 1.3;
}

.compare-list { display: grid; gap: 8px; }

.compare-item {
  padding: 12px;
  border-radius: var(--r-md);
  background: var(--purple-soft);
}

.compare-value {
  margin: 0;
  font-size: var(--text-xl);
  font-weight: var(--weight-display);
  color: var(--purple);
}

.compare-value small {
  font-size: var(--text-sm);
  font-weight: var(--weight-label);
}

.compare-text {
  margin: 2px 0 0;
  font-size: var(--text-sm);
  font-weight: var(--weight-body);
  color: var(--ink);
}

.day-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 0 0;
}

.fill-progress {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--muted);
}

.day-section > summary {
  display: flex;
  align-items: baseline;
  gap: 10px;
  cursor: pointer;
  list-style: none;
}

.day-section > summary::-webkit-details-marker { display: none; }

.day-section > summary h2 { margin: 0; flex: none; }

.section-sum {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--text-sm);
  color: var(--muted);
}

.day-section > summary::after {
  content: "";
  flex: none;
  align-self: center;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.15s;
}

.day-section[open] > summary { margin-bottom: 12px; }
.day-section[open] > summary::after { transform: rotate(-135deg); }

.backup-actions {
  display: grid;
  gap: 8px;
}

.account-form {
  display: grid;
  gap: 10px;
}

.account .fact-list { margin-bottom: 10px; }

#account-user { overflow-wrap: anywhere; text-align: right; }

.file-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.chart-tip {
  min-height: 1.4em;
  margin: 6px 0 0;
  font-size: var(--text-sm);
  color: var(--ink);
}

.week-card .fact-list li span:last-child { text-align: right; }

.trend {
  margin-left: 6px;
  font-size: var(--text-xs);
  color: var(--muted);
}

.heatmap {
  display: grid;
  grid-template-rows: repeat(7, 1fr);
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 3px;
  margin-top: 8px;
}

.heat {
  aspect-ratio: 1;
  border-radius: 3px;
  background: var(--miss);
}

.heat.is-none { background: transparent; border: 1px dashed var(--line); }
.heat.is-l1 { background: #dfe8d6; }
.heat.is-l2 { background: #b9cca8; }
.heat.is-l3 { background: var(--green); }

.heat-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  font-size: var(--text-xs);
  color: var(--muted);
}

.heat-legend .heat { width: 10px; height: 10px; aspect-ratio: auto; }

.chart-svg .line-avg {
  fill: none;
  stroke: var(--orange);
  stroke-width: 2;
  stroke-dasharray: 4 3;
}

.chart-svg [data-tip] { cursor: pointer; }

.quest-title {
  margin: 0 0 4px;
  font-size: var(--text-lg);
  font-weight: var(--weight-label);
}

.quest-stars {
  margin: 10px 0 0;
  font-size: var(--text-sm);
  font-weight: var(--weight-label);
  color: var(--muted);
}

.quest-stars span {
  color: var(--orange);
  letter-spacing: 2px;
}

#rewards-quest .template-list { margin-top: 10px; }

.habit-card.is-celebrate { animation: celebrate 1.2s ease-out; }

@keyframes celebrate {
  0% { box-shadow: 0 0 0 0 var(--green-soft); transform: scale(1); }
  20% { box-shadow: 0 0 0 10px var(--green-soft); transform: scale(1.015); background: var(--green-soft); }
  100% { box-shadow: 0 0 0 0 transparent; transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .habit-card.is-celebrate { animation-duration: 0.01s; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 20;
  transform: translateX(-50%);
  width: min(420px, calc(100% - 32px));
  padding: 12px 14px;
  border-radius: var(--r-md);
  background: var(--ink);
  color: white;
  box-shadow: 0 14px 35px rgba(41, 38, 45, 0.25);
}

.toast p {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: var(--weight-label);
}

.toast p + p { margin-top: 4px; }

.chart-svg .line {
  fill: none;
  stroke: var(--orange);
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart-svg .dot {
  fill: var(--card);
  stroke: var(--orange);
  stroke-width: 2;
}

.chart-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: var(--text-xs);
  font-weight: var(--weight-body);
  color: var(--muted);
}

.habit-grid-row { margin-bottom: 12px; }

.habit-grid-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  font-size: var(--text-sm);
  font-weight: var(--weight-label);
}

.habit-grid-title span { white-space: nowrap; }

.habit-cells { display: grid; gap: 3px; }

.cell {
  aspect-ratio: 1;
  border-radius: 4px;
  background: var(--miss);
}

.cell.is-done { background: var(--green); }

.cell.is-empty { background: var(--line); opacity: 0.5; }

.cell.is-before { background: transparent; }

.cell.is-off {
  background: transparent;
  border: 1px dashed var(--line);
}

.export-status { margin: 8px 0 0; text-align: center; }

/* TrackBeat 2.0 — warm minimal / subtle wabi-sabi */

body {
  min-width: 320px;
  background: var(--bg);
  font-size: var(--text-md);
  font-weight: var(--weight-body);
  line-height: 1.5;
}

.app {
  width: min(480px, 100%);
  padding: 16px 16px calc(112px + env(safe-area-inset-bottom));
}

.top {
  margin: -16px -16px 24px;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom-color: var(--line);
}

.brand {
  gap: 10px;
  font-size: 18px;
  font-weight: var(--weight-label);
  letter-spacing: -0.01em;
}

.brand img {
  width: 32px;
  height: 32px;
}

h1 {
  font-size: 24px;
  font-weight: var(--weight-display);
  letter-spacing: -0.02em;
}

h2 {
  margin-bottom: 16px;
  font-size: 20px;
  font-weight: var(--weight-display);
}

h3 { font-size: 18px; }

.view > .muted {
  margin-bottom: 20px;
  line-height: 1.45;
}

.day-nav {
  gap: 8px;
  margin: 12px 0 20px;
}

.day-picker,
.nav-btn,
.choice-row button,
.pair-row button,
.scale-row button,
.period-row button,
.weekday-row button,
.template-chip,
.counter-btn {
  border-color: var(--line);
  background: var(--card);
  border-radius: var(--r-md);
  font-weight: var(--weight-label);
}

.nav-btn:active,
.choice-row button:active,
.period-row button:active,
.template-chip:active,
.counter-btn:active {
  background: var(--surface-secondary);
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--orange);
  outline-offset: 2px;
}

.block,
.habit-card,
.habit-item,
.history-item {
  background: var(--card);
  border-color: var(--line);
  border-radius: var(--r-lg);
  box-shadow: none;
}

.block {
  padding: 16px;
  margin-bottom: 16px;
}

.habit-card {
  margin: 20px 0;
  padding: 16px;
}

.field,
legend {
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-label);
}

.field input,
.field textarea,
.habit-editor select,
.meal-note,
.restriction-row input {
  min-height: var(--control);
  border-color: transparent;
  background: var(--surface-secondary);
  border-radius: var(--r-md);
  font-size: var(--text-md);
  font-weight: var(--weight-body);
}

.field textarea { line-height: 1.5; }

.field input::placeholder,
.field textarea::placeholder,
.meal-note::placeholder,
.restriction-row input::placeholder {
  color: #a9aca5;
  opacity: 1;
}

.field input:focus,
.field textarea:focus,
.habit-editor select:focus,
.meal-note:focus,
.restriction-row input:focus {
  border-color: var(--green);
  background: var(--card);
}

.check {
  font-size: var(--text-md);
  font-weight: var(--weight-label);
}

.check input,
.habit-check input { accent-color: var(--green); }

.star::before { color: var(--miss); }
.star.is-full::before { color: var(--orange); }
.star.is-half::before {
  background: linear-gradient(90deg, var(--orange) 50%, var(--miss) 50%);
  -webkit-background-clip: text;
  background-clip: text;
}

.scale-row button[aria-pressed="true"],
.choice-row button[aria-pressed="true"],
.pair-row button[aria-pressed="true"],
.weekday-row button[aria-pressed="true"],
.period-row button[aria-pressed="true"] {
  border-color: #dfe2d2;
  background: var(--purple-soft);
  color: var(--ink);
}

.choice-row button[data-value="moved"][aria-pressed="true"] {
  border-color: #ecd8ca;
  background: var(--orange-soft);
  color: var(--ink);
}

.primary-btn {
  min-height: 48px;
  border-radius: var(--r-md);
  background: var(--accent);
  font-size: 16px;
  font-weight: var(--weight-label);
  box-shadow: none;
}

.primary-btn:hover { background: var(--accent-hover); }

.save-bar {
  bottom: calc(72px + env(safe-area-inset-bottom));
  margin: 8px -16px 0;
  padding: 12px 16px 14px;
  background: linear-gradient(to top, var(--bg) 78%, rgba(250, 248, 243, 0));
}

.tabs {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 30;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns:
    minmax(0, 0.75fr)
    minmax(0, 1.12fr)
    minmax(0, 1.18fr)
    minmax(0, 1fr)
    minmax(0, 1fr)
    minmax(0, 0.95fr);
  width: min(480px, 100%);
  min-height: 68px;
  margin: 0;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  gap: 2px;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: var(--card);
}

.tabs button {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  min-width: 0;
  min-height: 54px;
  padding: 4px 1px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: clamp(10px, 2.8vw, 11px);
  font-weight: var(--weight-label);
  line-height: 1.1;
  letter-spacing: -0.01em;
  overflow: visible;
}

.tabs button svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tabs button span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tabs button[aria-pressed="true"] {
  background: var(--green-soft);
  color: var(--accent);
}

.tabs button[aria-pressed="true"] svg { stroke-width: 2.2; }

.empty {
  border-color: #ddd8cc;
  border-radius: var(--r-md);
  background: transparent;
  line-height: 1.45;
}

.habit-row,
.detail-stat,
.cal-cell.is-empty {
  border-color: transparent;
  background: var(--surface-secondary);
}

.habit-row { border-radius: var(--r-md); }

.habit-row.is-done {
  border-color: #dfe5d6;
  background: var(--green-soft);
}

.habit-row.is-done .habit-text strong {
  color: var(--ink);
  text-decoration: none;
}

.history-score,
.habit-goal {
  background: var(--purple-soft);
  color: var(--ink);
}

.habit-streak {
  background: var(--orange-soft);
  color: var(--ink);
}

.history-group h3 {
  color: var(--muted);
  letter-spacing: 0.06em;
}

.stat-grid {
  gap: 12px;
  margin-bottom: 16px;
}

.stat-tile {
  padding: 16px;
  border-color: var(--line);
  border-radius: var(--r-lg);
  background: var(--card);
  box-shadow: none;
}

.stat-value { font-size: 28px; }

.chart-svg .bar { fill: var(--purple); }
.chart-svg .bar-score { fill: var(--blue); }
.chart-svg .bar-mood { fill: var(--orange); }
.chart-svg .line { stroke: var(--orange); }
.chart-svg .dot { fill: var(--card); stroke: var(--orange); }

.badge {
  border-color: var(--line);
  border-radius: var(--r-md);
  background: var(--surface-secondary);
  opacity: 0.72;
}

.badge.is-earned { background: var(--card); }

.badge.is-earned .badge-mark {
  background: var(--orange);
  box-shadow: 0 0 0 3px var(--orange-soft);
}

.compare-item {
  border: 1px solid var(--line);
  background: var(--surface-secondary);
}

.compare-value { color: var(--brand-ink); }

.path-bar { background: var(--surface-secondary); }
.path-bar span { background: var(--green); }

.toast {
  bottom: calc(82px + env(safe-area-inset-bottom));
  border: 1px solid #4a5550;
  border-radius: var(--r-md);
  background: var(--ink);
  box-shadow: 0 8px 24px rgba(40, 48, 44, 0.16);
}

.foot {
  margin: 24px 0 0;
  font-size: var(--text-xs);
}

.danger-btn {
  border-color: var(--danger-line);
  background: var(--danger-soft);
  color: var(--danger);
}

@media (max-width: 360px) {
  .app { padding-inline: 12px; }
  .top { margin-inline: -12px; padding-inline: 12px; }
  .save-bar { margin-inline: -12px; padding-inline: 12px; }
  .grid-3 { gap: 8px; }
  .grid-3 .field { font-size: 12px; }
  .grid-3 .field input { padding-inline: 9px; }
}
