/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:            #F2F2F7;
  --card:          #FFFFFF;
  --primary:       #007AFF;
  --excited:       #34C759;
  --uncomfortable: #FF3B30;
  --text:          #1C1C1E;
  --text2:         #8E8E93;
  --sep:           #E5E5EA;
  --tab-h:         83px;
  --hdr-h:         56px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── App Shell ───────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 430px;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
}

/* ── Header ──────────────────────────────────────── */
header {
  height: var(--hdr-h);
  background: var(--card);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 20px 12px;
  border-bottom: 0.5px solid var(--sep);
  flex-shrink: 0;
  z-index: 10;
}
header h1 { font-size: 22px; font-weight: 700; }

/* ── App content (post-login shell) ─────────────── */
#app-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* ── Main content ────────────────────────────────── */
#main-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-bottom: calc(var(--tab-h) + 8px);
}
.tab-pane { display: none; padding: 16px; }
.tab-pane.active { display: block; }

/* ── Generic card ────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
  overflow: hidden;
}

/* ── Tab bar ─────────────────────────────────────── */
#tab-bar {
  position: fixed;
  bottom: 0;
  left: max(0px, calc(50% - 215px));
  width: min(100%, 430px);
  height: var(--tab-h);
  background: rgba(249,249,249,0.92);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--sep);
  display: flex;
  padding-top: 8px;
  z-index: 100;
}
.tab-btn {
  flex: 1;
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--text2);
  padding: 4px 0;
}
.tab-btn.active { color: var(--primary); }
.tab-icon  { font-size: 22px; }
.tab-label { font-size: 10px; font-weight: 500; }

/* ── FAB ─────────────────────────────────────────── */
#fab {
  position: fixed;
  right: max(16px, calc(50% - 215px + 16px));
  bottom: calc(var(--tab-h) + 16px);
  width: 56px;
  height: 56px;
  border-radius: 28px;
  background: var(--primary);
  color: #fff;
  font-size: 30px;
  font-weight: 300;
  line-height: 1;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0,122,255,0.45);
  z-index: 50;
  transition: transform 0.15s;
}
#fab:active { transform: scale(0.94); }

/* ── Score card ──────────────────────────────────── */
.score-card {
  background: var(--card);
  border-radius: 20px;
  padding: 28px 20px;
  text-align: center;
  margin-bottom: 16px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.07);
}
.score-emoji { font-size: 72px; margin-bottom: 8px; line-height: 1.1; }
.score-num   { font-size: 32px; font-weight: 800; }
.score-date  { font-size: 14px; color: var(--text2); margin-top: 6px; }

/* ── Empty state ─────────────────────────────────── */
.empty-state { text-align: center; padding: 56px 24px; color: var(--text2); }
.empty-icon  { font-size: 52px; margin-bottom: 14px; }
.empty-title { font-size: 20px; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.empty-sub   { font-size: 15px; }
.empty-state-sm { padding: 24px; text-align: center; color: var(--text2); font-size: 15px; }

/* ── Section label ───────────────────────────────── */
.section-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text2);
  margin: 16px 4px 8px;
}

/* ── Moment list ─────────────────────────────────── */
.list-card { background: var(--card); border-radius: 16px; overflow: hidden; }
.moment-row {
  display: flex;
  align-items: center;
  padding: 13px 16px;
  gap: 10px;
  border-bottom: 0.5px solid var(--sep);
}
.moment-row:last-child { border-bottom: none; }
.moment-type-icon   { font-size: 22px; flex-shrink: 0; }
.moment-info        { flex: 1; min-width: 0; }
.moment-tags-text   { font-size: 15px; font-weight: 500; }
.moment-note-text   { font-size: 13px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.moment-score-badge { font-size: 16px; font-weight: 700; flex-shrink: 0; }
.moment-score-badge.excited       { color: var(--excited); }
.moment-score-badge.uncomfortable { color: var(--uncomfortable); }
.del-btn {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 22px;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
  padding: 0 2px;
}
.del-btn:hover { color: var(--uncomfortable); }

/* ── Calendar ────────────────────────────────────── */
.cal-nav-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  margin-bottom: 8px;
}
.cal-month-label { font-size: 18px; font-weight: 600; }
.nav-btn {
  background: none;
  border: none;
  font-size: 26px;
  color: var(--primary);
  cursor: pointer;
  padding: 2px 10px;
  line-height: 1;
}
.cal-grid-card { padding: 12px; }
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.cal-dow {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text2);
  padding: 4px 0 8px;
}
.cal-cell {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
  padding: 1px;
}
.cal-cell:hover { background: var(--bg); }
.cal-cell.empty { cursor: default; }
.cal-cell.empty:hover { background: none; }
.cal-day-num {
  font-size: 13px;
  font-weight: 400;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
.today-num { background: var(--primary); color: #fff; font-weight: 600; }
.cal-emoji { font-size: 13px; line-height: 1; margin-top: 1px; }

/* ── Year view ───────────────────────────────────── */
.year-heading { font-size: 22px; font-weight: 700; text-align: center; margin-bottom: 12px; }
.year-legend  { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-bottom: 14px; }
.legend-item  { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text2); }
.legend-dot   { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.year-card    { padding: 14px 16px; }
.year-month-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.year-month-row:last-child { margin-bottom: 0; }
.year-month-name  { font-size: 11px; font-weight: 600; color: var(--text2); width: 24px; flex-shrink: 0; }
.year-month-cells { display: flex; gap: 2px; flex: 1; }
.year-cell {
  flex: 0 0 calc((100% - 30 * 2px) / 31);
  aspect-ratio: 1;
  border-radius: 2px;
  min-width: 0;
}

/* ── My Focus card ───────────────────────────────── */
.focus-card {
  background: var(--card);
  border-radius: 16px;
  overflow: hidden;
  margin-bottom: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}
.focus-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 0.5px solid var(--sep);
}
.focus-card-title { font-size: 15px; font-weight: 600; }
.focus-edit-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 15px;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
}
.focus-section {
  padding: 10px 16px;
  border-bottom: 0.5px solid var(--sep);
}
.focus-section:last-of-type { border-bottom: none; }
.focus-section-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text2);
  margin-bottom: 6px;
}
.focus-item  { font-size: 15px; padding: 2px 0; color: var(--text); line-height: 1.4; }
.focus-empty { font-size: 14px; color: var(--text2); font-style: italic; padding: 2px 0; }
.focus-updated {
  font-size: 11px;
  color: var(--text2);
  padding: 7px 16px;
  text-align: right;
  border-top: 0.5px solid var(--sep);
}
.reflect-textarea {
  width: 100%;
  min-height: 110px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--sep);
  background: var(--bg);
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
  outline: none;
  color: var(--text);
}
.reflect-textarea:focus { border-color: var(--primary); }
.reflect-hint { font-size: 12px; color: var(--text2); margin-top: 6px; }

/* ── Insights ────────────────────────────────────── */
.stats-card { padding: 20px; margin-bottom: 0; }
.stat-trio  { display: flex; justify-content: space-around; }
.stat-block { text-align: center; }
.stat-val   { font-size: 30px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--text2); margin-top: 4px; }
.tag-stat-row {
  display: flex;
  align-items: center;
  padding: 11px 16px;
  border-bottom: 0.5px solid var(--sep);
  gap: 8px;
}
.tag-stat-row:last-child { border-bottom: none; }
.tag-stat-name  { flex: 1; font-size: 15px; font-weight: 500; }
.tag-stat-count { font-size: 13px; color: var(--text2); }
.tag-stat-avg   { font-size: 15px; font-weight: 700; min-width: 44px; text-align: right; }
.tag-stat-avg.pos { color: var(--excited); }
.tag-stat-avg.neg { color: var(--uncomfortable); }
.overall-vibe-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
}
.overall-vibe-emoji { font-size: 40px; line-height: 1; }
.overall-vibe-meta  { margin-left: auto; text-align: right; }
.overall-vibe-label { font-size: 12px; color: var(--text2); }
.overall-vibe-value { font-size: 22px; font-weight: 700; margin-top: 2px; }
.overall-vibe-value.pos { color: var(--excited); }
.overall-vibe-value.neg { color: var(--uncomfortable); }

/* ── Overlay / Sheet ─────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.hidden { display: none !important; }
.overlay.hidden { display: none; }
.sheet {
  background: var(--card);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 430px;
  max-height: 88vh;
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom, 16px);
  overscroll-behavior: contain;
}
.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 0.5px solid var(--sep);
  position: sticky;
  top: 0;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  z-index: 1;
}
.sheet-header-title { font-size: 17px; font-weight: 600; }
.sheet-header-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 17px;
  cursor: pointer;
  padding: 2px 0;
  min-width: 56px;
}
.sheet-header-btn:first-child { text-align: left; }
.sheet-header-btn:last-child  { text-align: right; }
.sheet-header-btn.primary     { font-weight: 600; }
.sheet-body { padding: 0; }

/* ── Form sections ───────────────────────────────── */
.form-section {
  padding: 14px 20px;
  border-bottom: 0.5px solid var(--sep);
}
.form-section:last-child { border-bottom: none; }
.form-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text2);
  margin-bottom: 10px;
}

/* Type picker */
.type-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.type-btn {
  padding: 13px 8px;
  border-radius: 12px;
  border: 1.5px solid var(--sep);
  background: var(--bg);
  font-size: 15px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.type-btn.active {
  border-color: var(--primary);
  background: rgba(0,122,255,0.09);
  color: var(--primary);
  font-weight: 600;
}

/* Score preview */
.score-preview { font-size: 24px; font-weight: 800; text-align: center; padding: 2px 0; }
.score-preview.excited       { color: var(--excited); }
.score-preview.uncomfortable { color: var(--uncomfortable); }

/* Intensity scroll picker */
.intensity-picker {
  position: relative;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  cursor: grab;
  padding: 4px 0;
}
.intensity-picker:active { cursor: grabbing; }
.intensity-picker::-webkit-scrollbar { display: none; }
.int-track {
  display: flex;
  gap: 8px;
  /* paddingLeft / paddingRight set dynamically in JS */
}
.int-item {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: 1.5px solid var(--sep);
  background: var(--bg);
  font-size: 15px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  scroll-snap-align: center;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s, border-color 0.15s, transform 0.15s, color 0.15s;
}
.int-item.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 700;
  transform: scale(1.13);
}
.int-center-mark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 52px;
  height: 52px;
  border: 2px solid var(--primary);
  border-radius: 13px;
  pointer-events: none;
  opacity: 0.35;
  z-index: 2;
}
.int-fade {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 52px;
  pointer-events: none;
  z-index: 1;
}
.int-fade-l { left:  0; background: linear-gradient(to right, #fff, transparent); }
.int-fade-r { right: 0; background: linear-gradient(to left,  #fff, transparent); }

/* Tags */
.tags-picker { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.tag-chip {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--sep);
  background: var(--bg);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.tag-chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.tag-chip-remove {
  font-size: 11px;
  line-height: 1;
  opacity: 0.55;
  cursor: pointer;
  padding: 0 1px;
  border-radius: 50%;
}
.tag-chip-remove:hover { opacity: 1; }
.tag-chip.active .tag-chip-remove { opacity: 0.75; }
.tag-chip.active .tag-chip-remove:hover { opacity: 1; }

/* Custom tag row */
.custom-tag-row { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
#custom-tag-input {
  flex: 1;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--sep);
  background: var(--bg);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  color: var(--text);
}
#custom-tag-input:focus { border-color: var(--primary); }
.custom-tag-row button {
  padding: 9px 16px;
  border-radius: 10px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
}

/* Note */
#note-input {
  width: 100%;
  height: 80px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--sep);
  background: var(--bg);
  font-size: 15px;
  font-family: inherit;
  resize: none;
  outline: none;
  color: var(--text);
}
#note-input:focus { border-color: var(--primary); }

/* Day detail */
.day-score {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  padding: 18px 20px;
  border-bottom: 0.5px solid var(--sep);
}

/* ── Login screen ────────────────────────────────── */
#login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 24px;
}
.login-card {
  background: var(--card);
  border-radius: 24px;
  padding: 40px 28px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 4px 24px rgba(0,0,0,0.09);
}
.login-emoji  { font-size: 64px; margin-bottom: 16px; }
.login-title  { font-size: 26px; font-weight: 800; margin-bottom: 8px; }
.login-sub    { font-size: 15px; color: var(--text2); margin-bottom: 28px; }
#login-form input {
  width: 100%;
  padding: 13px 16px;
  border-radius: 12px;
  border: 1.5px solid var(--sep);
  background: var(--bg);
  font-size: 16px;
  font-family: inherit;
  outline: none;
  color: var(--text);
  margin-bottom: 12px;
}
#login-form input:focus { border-color: var(--primary); }
#login-form button {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  margin-bottom: 10px;
}
#login-form button.secondary {
  background: var(--bg);
  color: var(--primary);
  border: 1.5px solid var(--primary);
}
#login-form button:disabled { opacity: 0.6; cursor: default; }
.auth-error {
  color: var(--uncomfortable);
  font-size: 14px;
  text-align: center;
  margin-top: 4px;
}

/* ── Sign-out button ─────────────────────────────── */
#signout-btn {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 0;
  margin-left: auto;
}
#signout-btn:hover { color: var(--uncomfortable); }

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}
.header-link {
  color: var(--text2);
  font-size: 13px;
  text-decoration: none;
}
.header-link:hover { color: var(--primary); }
.header-danger {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 0;
}
.header-danger:hover { color: var(--uncomfortable); }
.header-danger:disabled { opacity: 0.5; cursor: default; }

/* Profile menu (dropdown) ─────────────────────────── */
.profile-menu { position: relative; margin-left: auto; }
.profile-btn {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 8px;
}
.profile-btn:hover { background: rgba(0, 0, 0, 0.05); }
.profile-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  background: #fff;
  border: 1px solid var(--sep);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  padding: 6px 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
}
.profile-email {
  padding: 8px 14px 4px;
  font-size: 12px;
  color: var(--text2);
  word-break: break-all;
}
.profile-item {
  display: block;
  background: none;
  border: none;
  text-align: left;
  width: 100%;
  padding: 10px 14px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}
.profile-item:hover { background: rgba(0, 0, 0, 0.05); }
.profile-item.danger { color: var(--uncomfortable); }
.profile-sep {
  border: none;
  border-top: 1px solid var(--sep);
  margin: 4px 0;
}

.login-foot {
  margin-top: 18px;
  text-align: center;
  font-size: 12px;
}
.login-foot a {
  color: var(--text2);
  text-decoration: none;
}
.login-foot a:hover { color: var(--primary); }

/* ── Desktop ─────────────────────────────────────── */
@media (min-width: 500px) {
  #app {
    box-shadow: 0 8px 40px rgba(0,0,0,0.14);
    border-radius: 20px;
    margin: 16px auto;
    height: calc(100dvh - 32px);
  }
  #tab-bar { border-radius: 0 0 20px 20px; }
}
