:root {
  --bg: #f4f1ea;
  --card: #ffffff;
  --ink: #2b2a27;
  --ink-soft: #6b6860;
  --accent: #6f8f6f;
  --accent-dark: #4f6b4f;
  --negative: #b9694f;
  --positive: #4f7a5a;
  --border: #e7e2d6;
  --danger: #b4463a;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(72px + var(--safe-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 18px 12px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}

.brand {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
  padding-right: 10px;
}

.streak-badge {
  font-size: 14px;
  font-weight: 600;
  background: var(--card);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 999px;
  flex-shrink: 0;
}

.view {
  display: none;
  padding: 4px 16px 24px;
  flex: 1;
}

.view.active {
  display: block;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

.card h2 {
  margin: 0 0 10px;
  font-size: 17px;
  font-weight: 700;
}

.sub {
  margin: -4px 0 12px;
  font-size: 13px;
  color: var(--ink-soft);
}

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  margin: 12px 0 6px;
}

.field-label:first-of-type {
  margin-top: 0;
}

textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
  background: #fbfaf7;
  color: var(--ink);
}

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

.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn.primary {
  background: var(--accent);
  color: white;
  width: 100%;
  margin-top: 14px;
}

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

.btn.ghost {
  background: transparent;
  color: var(--accent-dark);
  border: 1px solid var(--border);
}

.btn.small {
  padding: 6px 10px;
  font-size: 13px;
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.generate-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.generate-status {
  font-size: 12px;
  color: var(--ink-soft);
}

.ai-note {
  font-weight: 400;
  color: var(--ink-soft);
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0;
}

.btn.danger {
  background: var(--danger);
  color: white;
  width: 100%;
}

.file-btn {
  width: 100%;
  margin-top: 10px;
  text-align: center;
}

.hint {
  font-size: 12px;
  color: var(--ink-soft);
  margin: 8px 0 0;
  line-height: 1.4;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-header h2 { margin: 0; }

.entry-list, .positive-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.entry-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fbfaf7;
}

.entry-time {
  font-size: 11px;
  color: var(--ink-soft);
  margin-bottom: 4px;
}

.entry-negative-wrap {
  margin-bottom: 8px;
}

.reveal-btn {
  background: none;
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--ink-soft);
  cursor: pointer;
  width: 100%;
  text-align: left;
}

.negative-text {
  font-size: 14px;
  color: var(--negative);
  padding: 6px 2px;
  border-left: 3px solid var(--negative);
  padding-left: 8px;
  margin: 4px 0;
}

.positive-text {
  font-size: 14px;
  color: var(--positive);
  padding: 6px 2px;
  border-left: 3px solid var(--positive);
  padding-left: 8px;
}

.positive-list .positive-text {
  font-size: 15px;
}

.empty-state {
  font-size: 13px;
  color: var(--ink-soft);
  text-align: center;
  padding: 18px 8px;
  display: none;
}

.review-card {
  position: relative;
}

.back-btn {
  margin-bottom: 10px;
}

.day-group {
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 10px;
  overflow: hidden;
}

.day-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  cursor: pointer;
  background: #fbfaf7;
}

.day-header .date-label {
  font-weight: 700;
  font-size: 14px;
}

.day-header .day-count {
  font-size: 12px;
  color: var(--ink-soft);
}

.day-body {
  display: none;
  padding: 10px 14px 14px;
}

.day-body.open {
  display: block;
}

.reveal-negatives-btn {
  margin-bottom: 10px;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}

.row label {
  font-size: 15px;
}

.row input[type="time"] {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 15px;
}

.danger-zone h2 { color: var(--danger); }

.contact-card a {
  color: var(--accent-dark);
}

.contact-tagline {
  font-weight: 700;
  font-size: 14px;
  margin: 0 0 8px;
}

.app-copyright {
  text-align: center;
  font-size: 11px;
  color: var(--ink-soft);
  margin: 4px 0 24px;
  line-height: 1.6;
}

.app-copyright a {
  color: var(--ink-soft);
  text-decoration: underline;
}

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  max-width: 480px;
  margin: 0 auto;
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  padding: 10px 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  color: var(--ink-soft);
  cursor: pointer;
}

.tab-btn.active {
  color: var(--accent-dark);
  font-weight: 700;
}

.tab-icon {
  font-size: 18px;
}

.toast {
  position: fixed;
  bottom: calc(84px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--ink);
  color: white;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 90%;
  text-align: center;
  z-index: 20;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.crisis-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 28, 24, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}

.crisis-overlay[hidden] {
  display: none;
}

.crisis-card {
  background: var(--card);
  border-radius: 20px;
  padding: 26px 22px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}

.crisis-card h2 {
  margin: 0 0 10px;
  font-size: 19px;
}

.crisis-card p {
  font-size: 14px;
  color: var(--ink);
  line-height: 1.5;
  margin: 0 0 16px;
}

.crisis-call {
  width: 100%;
  margin-top: 10px;
  font-size: 15px;
}

.crisis-note {
  font-size: 11px !important;
  color: var(--ink-soft) !important;
  margin: 12px 0 0 !important;
}

.crisis-dismiss {
  margin-top: 16px;
  width: 100%;
}
