* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #F7F6F3;
  --surface: #FFFFFF;
  --border: rgba(0,0,0,0.09);
  --border-light: rgba(0,0,0,0.055);
  --text: #1A1A1A;
  --text-2: #555552;
  --text-3: #9A9994;
  --purple: #534AB7;
  --purple-bg: #EEEDFE;
  --purple-text: #3C3489;
}

html, body {
  height: 100%;
  background: #E8E6DF;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.app {
  width: 100%;
  max-width: 390px;
  min-height: 100vh;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ── Tab bar ── */
.tab-bar {
  display: flex;
  border-bottom: 0.5px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 0 4px;
}

.tab-item {
  flex: 1;
  padding: 13px 4px 11px;
  font-size: 12px;
  text-align: center;
  color: var(--text-3);
  cursor: pointer;
  border: none;
  background: none;
  transition: color 0.15s;
  font-family: inherit;
  font-weight: 400;
  letter-spacing: 0.01em;
}

.tab-item.active {
  color: var(--purple);
  font-weight: 500;
  box-shadow: inset 0 -1.5px 0 var(--purple);
}

/* ── Views ── */
.view { display: none; flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.view.active { display: block; }

/* ── Log tab ── */
.log-header {
  padding: 22px 20px 16px;
}

.log-title {
  font-size: 21px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
  letter-spacing: -0.3px;
}

.log-date {
  font-size: 13px;
  color: var(--text-3);
}

.mood-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 12px 4px;
}

.mood-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  flex: 1;
  padding: 8px 2px;
  border-radius: 12px;
  transition: background 0.12s;
  border: none;
  background: none;
  font-family: inherit;
}

.mood-btn:hover { background: var(--bg); }
.mood-btn.selected { background: var(--bg); }

.mood-dot {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s cubic-bezier(.34,1.56,.64,1);
}

.mood-btn.selected .mood-dot { transform: scale(1.18); }
.mood-dot i { font-size: 19px; }

.mood-label {
  font-size: 10px;
  color: var(--text-3);
  letter-spacing: 0.01em;
}

.mood-btn.selected .mood-label {
  color: var(--text);
  font-weight: 500;
}

.section-label {
  padding: 14px 20px 7px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.section-opt {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  font-size: 10px;
  color: var(--text-3);
}

.tags-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 0 20px 4px;
}

.tag {
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 99px;
  border: 0.5px solid var(--border);
  color: var(--text-2);
  cursor: pointer;
  transition: all 0.12s;
  background: none;
  font-family: inherit;
  line-height: 1;
}

.tag.on {
  border-color: var(--purple);
  background: var(--purple-bg);
  color: var(--purple-text);
  font-weight: 500;
}

.note-wrap { margin: 0 20px 16px; }

.note-area {
  width: 100%;
  background: var(--bg);
  border-radius: 10px;
  border: 0.5px solid var(--border);
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-2);
  min-height: 64px;
  line-height: 1.5;
  resize: none;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.note-area:focus { border-color: rgba(83,74,183,0.4); }
.note-area::placeholder { color: var(--text-3); }

.save-btn {
  margin: 0 20px 20px;
  width: calc(100% - 40px);
  padding: 13px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 12px;
  background: var(--purple);
  color: #fff;
  border: none;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: 0.01em;
  transition: opacity 0.15s, transform 0.1s;
}
.save-btn:active { opacity: 0.85; transform: scale(0.99); }

.divider { height: 0.5px; background: var(--border-light); }

.recent-header {
  padding: 16px 20px 8px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

/* ── Entry row (shared) ── */
.entry-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 20px;
}

.entry-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-top: 4px;
  flex-shrink: 0;
}

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

.entry-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.entry-mood {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.entry-time {
  font-size: 10px;
  color: var(--text-3);
  text-align: right;
  line-height: 1.5;
  flex-shrink: 0;
}

.entry-tags {
  font-size: 11px;
  color: var(--text-2);
  margin-top: 2px;
}

.entry-note {
  font-size: 12px;
  color: var(--text-2);
  margin-top: 3px;
  line-height: 1.45;
  word-break: break-word;
}

.entry-del-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  padding: 4px;
  margin-top: 1px;
  color: var(--text-3);
  cursor: pointer;
  border-radius: 6px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  font-size: 14px;
  line-height: 1;
}
.entry-row:hover .entry-del-btn { opacity: 1; }
.entry-del-btn:hover { color: #E05555; }

/* ── History tab ── */
.hist-header {
  padding: 22px 20px 14px;
}

.hist-title {
  font-size: 21px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.3px;
}

.hist-list {
  padding: 0 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.hist-entry {
  background: var(--bg);
  border-radius: 12px;
  border: 0.5px solid var(--border);
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
}

.hist-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-top: 4px;
  flex-shrink: 0;
}

.hist-body { flex: 1; min-width: 0; }

.hist-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.hist-mood {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.hist-time {
  font-size: 10px;
  color: var(--text-3);
  text-align: right;
  line-height: 1.5;
  flex-shrink: 0;
}

.hist-tags {
  font-size: 11px;
  color: var(--text-2);
  margin-top: 3px;
}

.hist-note {
  font-size: 11px;
  color: var(--text-2);
  margin-top: 3px;
  line-height: 1.45;
  word-break: break-word;
}

.stats-section {
  margin: 0 16px 14px;
  padding-top: 4px;
}

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

.stat-card {
  background: var(--bg);
  border-radius: 11px;
  border: 0.5px solid var(--border-light);
  padding: 12px 12px 10px;
}

.stat-label {
  font-size: 10px;
  color: var(--text-3);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}

.stat-val {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.5px;
}

.empty {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-3);
  font-size: 14px;
  line-height: 1.6;
}

/* ── Heatmap tab ── */
.hm-header {
  padding: 22px 20px 14px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.hm-title {
  font-size: 21px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.3px;
}

.hm-toggle {
  display: flex;
  gap: 6px;
  padding-top: 4px;
}

.hm-toggle-btn {
  font-size: 12px;
  padding: 5px 14px;
  border-radius: 99px;
  border: 0.5px solid var(--border);
  cursor: pointer;
  color: var(--text-3);
  background: transparent;
  font-family: inherit;
  transition: all 0.15s;
}

.hm-toggle-btn.active {
  background: var(--bg);
  color: var(--text);
  border-color: rgba(0,0,0,0.14);
  font-weight: 500;
}

.hm-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px 14px;
}

.hm-nav-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 0.5px solid var(--border);
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  font-family: inherit;
  transition: background 0.12s;
}
.hm-nav-btn:hover { background: var(--bg); }
.hm-nav-btn i { font-size: 15px; }

.hm-period {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.2px;
}

/* Month grid */
.hm-month-wrap { padding: 0 16px 8px; }

.hm-day-labels {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
  margin-bottom: 3px;
}

.hm-day-label {
  font-size: 10px;
  color: var(--text-3);
  text-align: center;
  padding: 2px 0;
}

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

.hm-cell {
  aspect-ratio: 1;
  border-radius: 5px;
  cursor: default;
  transition: transform 0.1s;
}
.hm-cell:hover { transform: scale(1.12); }

/* Year grid */
.hm-year-wrap { padding: 0 16px 8px; }

.hm-months-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.hm-month-name {
  font-size: 9px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}

.hm-mini-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.hm-mini-cell {
  aspect-ratio: 1;
  border-radius: 2px;
}

.hm-legend {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 16px 24px;
  font-size: 11px;
  color: var(--text-3);
  flex-wrap: wrap;
}

.hm-legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

.hm-legend-sep { width: 8px; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: #1A1A1A;
  color: #fff;
  padding: 9px 18px;
  border-radius: 99px;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.22s, transform 0.22s;
  pointer-events: none;
  z-index: 100;
  white-space: nowrap;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', sans-serif;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Dark mode ── */
html[data-theme="dark"] {
  --bg: #1C1C1E;
  --surface: #2C2C2E;
  --border: rgba(255,255,255,0.1);
  --border-light: rgba(255,255,255,0.06);
  --text: #F2F2F7;
  --text-2: rgba(235,235,245,0.8);
  --text-3: #636366;
  --purple-bg: rgba(83,74,183,0.22);
  --purple-text: #B0ACEE;
}

html[data-theme="dark"] body { background: #000; }
html[data-theme="dark"] .save-btn { background: #6B62D4; }
html[data-theme="dark"] .toast { background: #3A3A3C; }

/* ── Tab logo ── */
.tab-logo {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  margin-left: 12px;
  flex-shrink: 0;
  align-self: center;
}

/* ── Gear button ── */
.gear-btn {
  width: 44px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: color 0.15s;
  flex-shrink: 0;
}
.gear-btn:hover { color: var(--text-2); }


/* ── Settings overlay ── */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.settings-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.settings-sheet {
  width: 100%;
  max-width: 390px;
  max-height: 88vh;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform: translateY(100%);
  transition: transform 0.32s cubic-bezier(.32,0,.67,0);
}
.settings-overlay.open .settings-sheet {
  transform: translateY(0);
  transition: transform 0.32s cubic-bezier(.33,1,.68,1);
}

.settings-drag-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 99px;
  margin: 12px auto 0;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 12px;
}

.settings-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.3px;
}

.settings-close-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--bg);
  cursor: pointer;
  color: var(--text-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-family: inherit;
}

.settings-body { padding: 0 16px; }

.settings-group-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 14px 4px 6px;
}

.settings-card {
  background: var(--bg);
  border-radius: 12px;
  border: 0.5px solid var(--border-light);
}

/* Theme toggle */
.srow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
}
.srow-label {
  font-size: 14px;
  color: var(--text);
}
.theme-btns {
  display: flex;
  gap: 5px;
}
.theme-btn {
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 8px;
  border: 0.5px solid var(--border);
  background: none;
  color: var(--text-3);
  cursor: pointer;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}
.theme-btn.active {
  background: var(--surface);
  color: var(--text);
  border-color: rgba(83,74,183,0.4);
  font-weight: 500;
}

/* Mood settings rows */
.msr-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
}
.msr-divider { height: 0.5px; background: var(--border-light); margin: 0 14px; }
.msr-icon-wrap { position: relative; flex-shrink: 0; }
.msr-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  background: none;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.12s;
  padding: 0;
}
.msr-icon-btn:hover { opacity: 0.75; }
.msr-name {
  flex: 1;
  font-size: 14px;
  color: var(--text);
}
.msr-color-input {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  padding: 0;
  cursor: pointer;
  background: none;
  overflow: hidden;
  flex-shrink: 0;
}
.msr-color-input::-webkit-color-swatch-wrapper { padding: 0; }
.msr-color-input::-webkit-color-swatch { border: none; border-radius: 50%; }

/* Icon picker grid */
.icon-picker-grid {
  position: absolute;
  bottom: 42px;
  left: 0;
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.14);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  padding: 6px;
  z-index: 50;
  opacity: 0;
  transform: scale(0.92) translateY(4px);
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
}
.icon-picker-grid.open {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: all;
}
.icon-pick-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 18px;
  color: var(--text-2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s;
}
.icon-pick-btn:hover { background: var(--bg); }
.icon-pick-btn.picked { background: var(--purple-bg); color: var(--purple); }

/* Tags manager */
.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 14px 8px;
}
.settings-tag-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  padding: 4px 8px 4px 10px;
  border-radius: 99px;
  border: 0.5px solid var(--border);
  color: var(--text-2);
  background: var(--surface);
}
.chip-remove {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: none;
  background: var(--border);
  cursor: pointer;
  color: var(--text-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-family: inherit;
  padding: 0;
  flex-shrink: 0;
}
.chip-remove:hover { background: #F09595; color: #fff; }

.tag-add-row {
  display: flex;
  gap: 8px;
  padding: 8px 14px 12px;
}
.tag-add-input {
  flex: 1;
  font-size: 13px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 0.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.tag-add-input:focus { border-color: rgba(83,74,183,0.4); }
.tag-add-input::placeholder { color: var(--text-3); }
.tag-add-btn {
  font-size: 12px;
  padding: 7px 14px;
  border-radius: 8px;
  border: none;
  background: var(--purple);
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
}

/* Reset button */
.reset-defaults-btn {
  width: 100%;
  margin-top: 14px;
  padding: 12px;
  font-size: 13px;
  border-radius: 12px;
  border: 0.5px solid var(--border);
  background: none;
  color: var(--text-3);
  cursor: pointer;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: color 0.15s, border-color 0.15s;
}
.reset-defaults-btn:hover { color: #E05555; border-color: #E05555; }

/* ── Heatmap tooltip ── */
.hm-tooltip {
  display: none;
  position: fixed;
  z-index: 300;
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.13), 0 2px 8px rgba(0,0,0,0.07);
  padding: 10px 13px;
  min-width: 160px;
  max-width: 240px;
  pointer-events: none;
}

.hmt-date {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.hmt-sep {
  height: 0.5px;
  background: var(--border-light);
  margin: 8px 0;
}

.hmt-mood-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
}

.hmt-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.hmt-mood-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  flex: 1;
}

.hmt-period {
  font-size: 10px;
  color: var(--text-3);
}

.hmt-tags {
  font-size: 11px;
  color: var(--text-2);
  margin-top: 2px;
  padding-left: 14px;
}

.hmt-note {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 3px;
  padding-left: 14px;
  line-height: 1.4;
  font-style: italic;
}

/* ── Log title row & sync button ── */
.log-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sync-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}


.sync-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 0.5px solid var(--border);
  background: none;
  cursor: pointer;
  color: var(--text-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: background 0.12s, color 0.18s;
  flex-shrink: 0;
}
.sync-btn:hover { background: var(--bg); }
.sync-btn.is-saved { color: #1D9E75; }
.sync-btn.is-unsaved { color: #EF9F27; }

/* ── GitHub sync settings ── */
.gh-inputs {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
}

.gh-input {
  font-size: 13px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 0.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.gh-input:focus { border-color: rgba(83,74,183,0.4); }
.gh-input::placeholder { color: var(--text-3); }

.gh-save-btn {
  font-size: 12px;
  padding: 7px 14px;
  border-radius: 8px;
  border: none;
  background: var(--purple);
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  align-self: flex-end;
}
