:root {
  --bg: #f4f6f2;
  --surface: #ffffff;
  --text: #1c2a21;
  --muted: #637268;
  --line: #dde4dc;
  --accent: #3f8f5a;
  --accent-ink: #ffffff;
  --ok: #3f8f5a;
  --soon: #d49a1a;
  --over: #d2483f;
  --skip: #6b8fc7;
  --radius: 16px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111613;
    --surface: #1b231e;
    --text: #e8efe9;
    --muted: #94a69a;
    --line: #2b372f;
    --accent: #56b176;
    --accent-ink: #0c1a11;
    --ok: #56b176;
    --soon: #e6b13a;
    --over: #ee6a60;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 16px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; min-height: 100dvh; }
button, input, select, textarea { font: inherit; color: inherit; }
.ico { display: inline-flex; width: 1.25em; height: 1.25em; }
.ico svg { width: 100%; height: 100%; }
.hidden { display: none !important; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  padding: calc(var(--safe-t) + 10px) 16px 8px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
}
.bar { display: flex; align-items: center; gap: 8px; }
.bar h1 { flex: 1; margin: 0; font-size: 1.35rem; }
.iconbtn {
  width: 40px; height: 40px; border: 0; border-radius: 12px; cursor: pointer;
  display: grid; place-items: center; background: var(--surface); box-shadow: 0 0 0 1px var(--line);
}
.iconbtn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: none; }
.chips { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip-btn {
  flex: none; border: 0; border-radius: 999px; padding: 6px 14px; cursor: pointer;
  background: var(--surface); box-shadow: 0 0 0 1px var(--line); color: var(--muted);
}
.chip-btn.on { background: var(--accent); color: var(--accent-ink); box-shadow: none; font-weight: 600; }
.banner {
  margin: 8px 16px 0; padding: 10px 12px; border-radius: 12px; font-size: .9rem;
  background: color-mix(in srgb, var(--soon) 18%, var(--surface)); box-shadow: 0 0 0 1px var(--line);
}
.banner button { margin-left: 8px; }

/* ---------- grid + tiles ---------- */
.grid {
  display: grid; gap: 12px; padding: 8px 16px calc(var(--safe-b) + 40px);
  grid-template-columns: repeat(2, 1fr); /* two big tiles across a phone */
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 48px 0; }
.cell { position: relative; border-radius: var(--radius); overflow: hidden; background: var(--skip); aspect-ratio: 1; }
.skip-hint {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  gap: 2px; padding-left: 14px; color: #fff; font-size: .8rem; font-weight: 600;
}
.cell.armed .skip-hint { filter: brightness(1.15); }
.tile {
  position: relative; display: block; width: 100%; height: 100%; padding: 0; border: 0; cursor: pointer;
  border-radius: var(--radius); overflow: hidden; background: var(--surface); text-align: left;
  touch-action: pan-y; transition: transform .18s ease;
  box-shadow: inset 0 0 0 3px var(--tone, var(--line));
}
.tile.dragging { transition: none; }
.tile.ok { --tone: var(--ok); }
.tile.soon { --tone: var(--soon); }
.tile.over { --tone: var(--over); }
.tile img, .tile .ph { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.tile .ph { display: grid; place-items: center; color: var(--muted); background: color-mix(in srgb, var(--tone) 12%, var(--surface)); }
.tile .ph .ico { width: 44%; height: 44%; opacity: .55; }
.tile::after { /* readable text over photos */
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(to top, rgba(0,0,0,.72) 0%, rgba(0,0,0,.25) 45%, rgba(0,0,0,0) 70%);
}
.tile .info { position: absolute; left: 0; right: 0; bottom: 0; z-index: 1; padding: 8px 10px 9px; color: #fff; pointer-events: none; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); } }
.tile .name { font-weight: 650; font-size: 1.05rem; line-height: 1.15; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile .due { display: inline-block; max-width: 100%; margin-top: 6px; padding: 2px 10px; border-radius: 999px; background: var(--tone); color: #fff; font-size: .86rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.soon .due { color: #20180a; }
.tile .badge {
  position: absolute; top: 9px; right: 9px; z-index: 1; display: inline-flex; align-items: center; gap: 3px;
  padding: 3px 9px 3px 7px; border-radius: 999px; font-size: .82rem; font-weight: 600; color: #fff; background: rgba(20, 60, 35, .78);
}
.tile .badge.left { right: auto; left: 9px; background: rgba(30, 60, 100, .78); }
.tile .badge.left.skip { background: color-mix(in srgb, var(--skip) 85%, #000); }
.tile .badge .ico { width: 1em; height: 1em; }
.tile.pop { animation: pop .35s ease; }
@keyframes pop { 40% { transform: scale(.94); } }

/* ---------- layers: sheets, screens, toast ---------- */
.backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } }
.backdrop { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.sheet {
  width: min(100%, 520px); max-height: 85dvh; overflow: auto; background: var(--surface);
  border-radius: 20px 20px 0 0; padding: 14px 16px calc(var(--safe-b) + 16px); animation: rise .2s ease;
}
@keyframes rise { from { transform: translateY(24px); opacity: .6; } }
.sheet h2 { margin: 2px 0 10px; font-size: 1.05rem; }
.sheet .opt {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 13px 8px; border: 0; background: none;
  cursor: pointer; text-align: left; border-top: 1px solid var(--line); font-size: 1rem;
}
.sheet .opt:first-of-type { border-top: 0; }
.sheet .opt .ico { color: var(--accent); }
.sheet .opt.danger { color: var(--over); }
.sheet .chips { flex-wrap: wrap; margin: 4px 0 12px; }

.screen { position: fixed; inset: 0; z-index: 30; background: var(--bg); overflow-y: auto; animation: fade .15s ease; }
.screen .head {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-t) + 10px) 16px 10px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.screen .head h2 { flex: 1; margin: 0; font-size: 1.15rem; }
.screen .body { padding: 16px 16px calc(var(--safe-b) + 40px); max-width: 560px; margin: 0 auto; display: grid; gap: 16px; }
.field { display: grid; gap: 6px; }
.field > label, .label { font-size: .82rem; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
}
.field textarea { min-height: 76px; resize: vertical; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }
.btn {
  border: 0; border-radius: 12px; padding: 11px 16px; cursor: pointer; font-weight: 600;
  background: var(--accent); color: var(--accent-ink);
}
.btn.ghost { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--line); }
.btn.danger { background: none; color: var(--over); box-shadow: 0 0 0 1px var(--over); }
.btn:disabled { opacity: .5; }
.hint { color: var(--muted); font-size: .85rem; margin: 0; }
.error { color: var(--over); font-size: .9rem; margin: 0; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: 0 0 0 1px var(--line); padding: 14px; display: grid; gap: 12px; }
.photo { position: relative; aspect-ratio: 16 / 10; border-radius: var(--radius); overflow: hidden; background: color-mix(in srgb, var(--accent) 12%, var(--surface)); display: grid; place-items: center; color: var(--muted); }
.photo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.photo .acts { position: absolute; right: 8px; bottom: 8px; display: flex; gap: 8px; }
.photo .acts .iconbtn { width: 36px; height: 36px; background: rgba(0, 0, 0, .55); color: #fff; box-shadow: none; }
.season { display: grid; grid-template-columns: 1fr 1fr 78px 36px; gap: 6px; align-items: center; }
.season input, .season select { padding: 9px 8px; }
.hist { display: grid; gap: 0; }
.hist .item { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); font-size: .92rem; }
.hist .item:first-child { border-top: 0; }
.hist .item .who { flex: 1; color: var(--muted); font-size: .82rem; }
.hist .item button { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 4px; }
.kind { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.kind.water { color: var(--skip); } .kind.fertilize { color: var(--ok); } .kind.skip { color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 18px); transform: translateX(-50%); z-index: 40;
  display: flex; align-items: center; gap: 14px; max-width: min(92vw, 480px); padding: 11px 14px;
  border-radius: 14px; background: #222b25; color: #fff; box-shadow: 0 6px 24px rgba(0, 0, 0, .35); animation: rise .2s ease;
}
.toast button { border: 0; background: none; color: #8fe0a8; font-weight: 700; cursor: pointer; padding: 2px 4px; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login form { width: min(100%, 360px); display: grid; gap: 14px; }
.login h1 { margin: 0; text-align: center; }
.login .logo { width: 72px; height: 72px; margin: 0 auto; border-radius: 18px; }
