:root {
  --bg: #0f1f0f;
  --surface: #1a3a1a;
  --border: #2d5a2d;
  --text: #f4ead5;
  --text-secondary: #a8b89a;
  --green: #7a9b6a;
  --amber: #d4a056;
  --blue: #7ab0c4;
  --lavender: #a89bc4;
  --moss: #5a7a3a;
  --terracotta: #c4926a;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 16px;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

/* Noise texture overlay */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-top: var(--safe-top);
}

main#view {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* ── Bottom nav ── */
#bottom-nav {
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 0 calc(6px + var(--safe-bottom));
  flex-shrink: 0;
}

.nav-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px 20px;
  border-radius: 12px;
  transition: color 0.2s, background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-btn svg { width: 24px; height: 24px; }

.nav-btn.active { color: var(--green); }
.nav-btn:not(.active):active { background: var(--border); }

/* ── HOME VIEW ── */
.home-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100%;
  padding-bottom: 24px;
}

.tree-hero {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding: 32px 0 0;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none; /* let JS handle swipe; prevents iOS scroll interception */
}

.tree-hero svg {
  width: min(280px, 78vw);
  height: auto;
  animation: sway 4s ease-in-out infinite;
  transform-origin: 50% 100%;
  filter: drop-shadow(0 8px 24px rgba(0,0,0,0.5));
}

@keyframes sway {
  0%, 100% { transform: rotate(-1.5deg); }
  50%       { transform: rotate(1.5deg); }
}

/* ── Next task card ── */
.next-task-card {
  width: calc(100% - 32px);
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 22px 22px 20px;
  margin-top: 20px;
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, transform 0.1s;
}

.next-task-card:active {
  transform: scale(0.97);
  border-color: var(--green);
}

.next-task-label {
  font-family: 'DM Sans', sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.next-task-text {
  font-size: 20px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.35;
}

.next-task-text.overdue {
  color: var(--amber);
}

.next-task-loading {
  height: 24px;
  background: var(--border);
  border-radius: 6px;
  width: 60%;
  margin: 0 auto;
  animation: pulse 1.5s ease infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50%       { opacity: 1; }
}

/* ── ACTION SHEET ── */
#sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

#action-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 101;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 24px 24px 0 0;
  padding: 12px 20px calc(24px + var(--safe-bottom));
  transform: translateY(0);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#action-sheet.hidden,
#sheet-backdrop.hidden {
  display: none;
}

#action-sheet.entering {
  transform: translateY(100%);
}

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 16px;
}

.sheet-label {
  font-family: 'Playfair Display', serif;
  font-style: italic;
  color: var(--text-secondary);
  font-size: 14px;
  text-align: center;
  margin-bottom: 16px;
  letter-spacing: 0.04em;
}

.sheet-actions {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.care-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  transition: transform 0.12s, background 0.12s, border-color 0.12s;
  -webkit-tap-highlight-color: transparent;
}

.care-btn:active {
  transform: scale(0.94);
  background: var(--border);
  border-color: var(--green);
}

.care-icon { font-size: 22px; line-height: 1; }
.care-name { font-size: 11px; font-weight: 400; color: var(--text-secondary); }

/* ── TOAST ── */
#toast {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  white-space: nowrap;
  pointer-events: none;
}

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

#toast.hidden { display: none; }

/* ── CALENDAR VIEW ── */
.calendar-view {
  padding: 24px 16px 32px;
  max-width: 480px;
  margin: 0 auto;
}

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

.calendar-month-title {
  font-family: 'Playfair Display', serif;
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
}

.cal-nav-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 36px; height: 36px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s;
  font-size: 18px;
  line-height: 1;
}

.cal-nav-btn:hover { color: var(--text); border-color: var(--green); }

.calendar-dow-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 6px;
}

.dow-label {
  text-align: center;
  font-size: 11px;
  color: var(--text-secondary);
  letter-spacing: 0.06em;
  padding: 4px 0;
}

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

.cal-day {
  aspect-ratio: 1;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 6px;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
  min-height: 44px;
}

.cal-day:empty { cursor: default; }

.cal-day:not(:empty):hover { background: var(--surface); }
.cal-day:not(:empty):active { background: var(--border); }

.cal-day.today {
  box-shadow: 0 0 0 1.5px var(--green);
}

.cal-day.today .day-num { color: var(--green); font-weight: 500; }

.cal-day.future { opacity: 0.5; cursor: default; }

.day-num {
  font-size: 13px;
  color: var(--text);
  line-height: 1;
  margin-bottom: 3px;
}

.day-dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px;
  max-width: 28px;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.dot.water      { background: radial-gradient(circle, #9dd0e8, #7ab0c4); }
.dot.mist       { background: radial-gradient(circle, #c4b8e0, #a89bc4); }
.dot.rotate     { background: radial-gradient(circle, #9aaf8a, #7a9b6a); }
.dot.fertilize  { background: radial-gradient(circle, #7a9a4a, #5a7a3a); }
.dot.trim       { background: radial-gradient(circle, #d4a88a, #c4926a); }

.dot.scheduled {
  opacity: 0.4;
  border: 1px solid currentColor;
  background: transparent;
}

.dot.scheduled.water     { border-color: #7ab0c4; }
.dot.scheduled.rotate    { border-color: #7a9b6a; }
.dot.scheduled.trim      { border-color: #c4926a; }
.dot.scheduled.fertilize { border-color: #5a7a3a; }

/* Day modal */
.day-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.day-modal {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 101;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 24px 24px 0 0;
  padding: 16px 20px calc(32px + var(--safe-bottom));
}

.day-modal-title {
  font-family: 'Playfair Display', serif;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.day-modal-sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.day-modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.day-modal-care-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  cursor: pointer;
  transition: border-color 0.15s;
  text-align: left;
  width: 100%;
}

.day-modal-care-btn:hover { border-color: var(--green); }
.day-modal-care-btn .care-icon { font-size: 20px; }


/* ── SETTINGS VIEW ── */
.settings-view {
  padding: 24px 16px 48px;
  max-width: 480px;
  margin: 0 auto;
}

.settings-title {
  font-family: 'Playfair Display', serif;
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 28px;
  color: var(--text);
}

.settings-section {
  margin-bottom: 28px;
}

.settings-section-label {
  font-family: 'Playfair Display', serif;
  font-style: italic;
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.settings-row:last-child { border-bottom: none; }

.settings-row-label {
  font-size: 15px;
  color: var(--text);
}

.settings-row-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.time-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  padding: 6px 10px;
  width: 90px;
  text-align: center;
  -webkit-appearance: none;
}

.time-input:focus {
  outline: none;
  border-color: var(--green);
}

.settings-btn {
  width: 100%;
  padding: 14px 18px;
  background: none;
  border: none;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background 0.15s;
}

.settings-btn:hover { background: var(--border); }
.settings-btn-arrow { color: var(--text-secondary); font-size: 18px; }

.settings-btn.primary {
  color: var(--green);
  font-weight: 500;
}

.settings-btn.danger {
  color: var(--amber);
}

/* History list */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  max-height: 280px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.history-item:last-child { border-bottom: none; }

.history-icon { font-size: 18px; width: 24px; text-align: center; }

.history-type {
  flex: 1;
  color: var(--text);
  font-weight: 500;
  text-transform: capitalize;
}

.history-date {
  color: var(--text-secondary);
  font-size: 12px;
}

/* Collapsible section headers */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  margin-bottom: 12px;
}

.section-header .settings-section-label {
  margin-bottom: 0;
}

.section-chevron {
  font-size: 16px;
  color: var(--text-secondary);
  display: inline-block;
  transition: transform 0.2s ease;
}

.section-chevron.open {
  transform: rotate(90deg);
}

.collapsible-body.collapsed {
  display: none;
}

/* Upcoming care list */
.upcoming-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
}

.upcoming-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.upcoming-item:last-child { border-bottom: none; }

.upcoming-label {
  flex: 1;
  color: var(--text);
  font-weight: 500;
}

.upcoming-when {
  color: var(--text-secondary);
  font-size: 12px;
}

.upcoming-item.overdue .upcoming-when {
  color: var(--amber);
}

/* Info card (Watering, Troubleshooting) */
.info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.info-rule {
  margin-bottom: 10px;
}

.info-rule:last-of-type {
  margin-bottom: 0;
}

.info-card strong {
  color: var(--text);
}

.info-contact {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

.info-contact a {
  color: var(--blue);
  text-decoration: none;
}

/* About */
.about-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.7;
}

.about-card strong { color: var(--text); }

/* ── Utility ── */
.hidden { display: none !important; }

/* View transition */
.view-enter {
  animation: view-in 0.25s ease forwards;
}

@keyframes view-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
