:root {
  --bg: #f7f3ec;
  --card: #ffffff;
  --ink: #26242c;
  --muted: #7a7684;
  --line: #e7e1d6;
  --accent: #2f7f79;
  --accent-dark: #25665f;
  --danger: #c0392b;
  --radius: 16px;
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.spacer { flex: 1; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 600;
  min-height: 44px; padding: 0 18px;
  border-radius: 999px; border: 1.5px solid var(--line);
  background: var(--card); color: var(--ink);
  cursor: pointer;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-dark); }
.btn.danger { color: var(--danger); border-color: #efc7c2; }
.btn.big { min-height: 54px; font-size: 1.1rem; padding: 0 28px; }
.icon-btn {
  font: inherit; font-size: 2rem; line-height: 1;
  width: 48px; height: 48px; border-radius: 50%;
  border: none; background: transparent; color: var(--ink); cursor: pointer;
}
.icon-btn:active { background: rgba(0,0,0,0.06); }

/* ---------- login ---------- */
.login {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center; padding: 24px;
}
.login-card {
  background: var(--card); border-radius: 28px; padding: 36px 28px;
  max-width: 420px; width: 100%; text-align: center;
  box-shadow: 0 8px 30px rgba(60, 50, 30, 0.10);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.login-card img { border-radius: 22px; }
.login-card h1 { font-size: 1.7rem; }
.login-card p { margin: 0; }
.login-card .btn { margin-top: 10px; }
.login-msg { color: var(--danger); min-height: 1.3em; font-size: 0.95rem; }

/* ---------- main shell ---------- */
#main { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

.banner {
  background: #fdecea; color: #7a2018; padding: 10px 16px;
  font-size: 0.95rem; text-align: center;
}

#panels {
  flex: 1; min-height: 0;
  display: flex; overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
#panels::-webkit-scrollbar { display: none; }

.panel {
  flex: 0 0 100%; width: 100%;
  scroll-snap-align: start; scroll-snap-stop: always;
  overflow-y: auto; overflow-x: hidden;
  padding: 16px 16px 24px;
  padding-top: max(16px, env(safe-area-inset-top));
}

/* tab bar */
#tabbar {
  flex: none; display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
#tabbar button {
  position: relative; flex: 1; max-width: 140px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: none; font: inherit; font-size: 0.72rem; font-weight: 600;
  color: var(--muted); padding: 6px 4px; border-radius: 12px; cursor: pointer;
}
#tabbar svg {
  width: 26px; height: 26px; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
#tabbar button.active { color: var(--accent); }
.badge {
  position: absolute; top: 4px; left: calc(50% + 8px);
  width: 12px; height: 12px; border-radius: 50%;
  background: #ff5a4f; border: 2px solid var(--card);
}

/* ---------- home / photos placeholder ---------- */
.panel-home { display: flex; flex-direction: column; justify-content: space-between; }
.home-center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 4px; }
.home-clock { font-size: clamp(4rem, 16vw, 9rem); font-weight: 700; letter-spacing: -0.03em; line-height: 1; }
.home-date { font-size: clamp(1.1rem, 3.5vw, 2rem); color: var(--muted); }
.home-note { margin-top: 24px; max-width: 28ch; }
.home-footer { display: flex; flex-direction: column; align-items: center; gap: 10px; padding-top: 16px; }
.switch { display: flex; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; }
.switch input { width: 22px; height: 22px; accent-color: var(--accent); }

/* ---------- placeholders ---------- */
.panel-soon { display: grid; place-items: center; }
.soon { text-align: center; }
.soon-icon { font-size: 4rem; margin-bottom: 8px; }

/* ---------- calendar ---------- */
.cal-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.cal-nav { display: flex; align-items: center; gap: 2px; }
.cal-nav h2 { font-size: 1.4rem; min-width: 9.5ch; text-align: center; }
.cal-actions { display: flex; gap: 8px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 10px; font-size: 0.85rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); display: inline-block; }

.cal-body { display: grid; grid-template-columns: 1fr; gap: 16px; }
.weekdays, .cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.weekdays { text-align: center; font-size: 0.78rem; font-weight: 700; color: var(--muted); padding-bottom: 6px; }
.cal-grid {
  background: var(--line); gap: 1px;
  border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
}
.cell {
  background: var(--card); min-height: 62px; padding: 6px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  cursor: pointer; outline-offset: -3px;
}
.cell.other { background: #faf8f4; color: #b2adbb; }
.cell .num { font-size: 0.9rem; font-weight: 600; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; }
.cell.today .num { background: var(--accent); color: #fff; }
.cell.sel { outline: 3px solid var(--accent); z-index: 1; }
.dots { display: flex; flex-wrap: wrap; gap: 3px; justify-content: center; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.chips { display: none; width: 100%; flex-direction: column; gap: 2px; }
.chip {
  display: block; width: 100%; font-size: 0.72rem; font-weight: 600; line-height: 1.35;
  padding: 1px 5px; border-radius: 5px; color: #fff; background: var(--c);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left;
}
.more { font-size: 0.7rem; color: var(--muted); text-align: left; padding-left: 4px; }

.day-panel { background: var(--card); border-radius: var(--radius); padding: 16px; border: 1px solid var(--line); align-self: start; }
.day-panel h3 { font-size: 1.15rem; margin-bottom: 10px; }
.day-list { display: flex; flex-direction: column; gap: 10px; }
.day-empty { color: var(--muted); padding: 8px 0; }
.ev {
  display: flex; gap: 12px; align-items: stretch; text-align: left; width: 100%;
  background: #fbfaf7; border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; font: inherit; color: inherit; cursor: pointer;
}
.ev:active { background: #f1ede4; }
.ev-bar { width: 6px; border-radius: 3px; background: var(--c); flex: none; }
.ev-main { min-width: 0; }
.ev-time { font-size: 0.8rem; font-weight: 700; color: var(--muted); }
.ev-title { font-size: 1.05rem; font-weight: 700; overflow-wrap: anywhere; }
.ev-meta { font-size: 0.85rem; color: var(--muted); overflow-wrap: anywhere; }

/* tablet and up: show event names in the grid */
@media (min-width: 700px) {
  .cell { min-height: 92px; align-items: stretch; padding: 6px; }
  .cell .num { align-self: flex-start; }
  .dots { display: none; }
  .chips { display: flex; }
}
/* wide screens (landscape iPad, TV): grid + day list side by side */
@media (min-width: 1000px) {
  .cal-body { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
  .cell { min-height: 104px; }
  .day-panel { position: sticky; top: 0; }
}
@media (min-width: 1600px) {
  html { font-size: 20px; }
}

/* ---------- dialog ---------- */
dialog {
  border: none; border-radius: 22px; padding: 0;
  width: min(94vw, 460px); max-height: 92dvh; color: var(--ink);
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
dialog::backdrop { background: rgba(30, 25, 20, 0.45); }
#event-form { padding: 22px 20px 18px; display: flex; flex-direction: column; gap: 14px; }
#event-form h3 { font-size: 1.3rem; }
.field { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 0; }
.field > span { font-size: 0.82rem; font-weight: 700; color: var(--muted); }
.field input, .field textarea {
  font: inherit; font-size: 16px; /* 16px stops iOS zooming in */
  padding: 11px 12px; border-radius: 12px; border: 1.5px solid var(--line);
  background: #fff; color: var(--ink); width: 100%; min-height: 46px;
}
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.field-row { display: flex; gap: 12px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.who-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.who-picker label { cursor: pointer; position: relative; }
.who-picker input { position: absolute; opacity: 0; pointer-events: none; }
.who-picker span {
  display: inline-flex; align-items: center; gap: 7px; padding: 9px 14px;
  border-radius: 999px; border: 2px solid var(--line); font-weight: 600;
}
.who-picker span::before { content: ""; width: 12px; height: 12px; border-radius: 50%; background: var(--c); }
.who-picker input:checked + span { border-color: var(--c); background: color-mix(in srgb, var(--c) 14%, #fff); }
.who-picker input:focus-visible + span { outline: 2px solid var(--accent); }
.form-error { color: var(--danger); margin: 0; min-height: 1.2em; font-size: 0.9rem; }
.dlg-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #26242c; color: #fff; padding: 11px 18px; border-radius: 999px;
  font-weight: 600; font-size: 0.95rem; z-index: 50; max-width: 90vw; text-align: center;
}

/* ---------- photos: slideshow ---------- */
.panel-photos { padding: 0; position: relative; background: #111; }
.slideshow { position: relative; width: 100%; height: 100%; min-height: 100%; overflow: hidden; background: #111; cursor: pointer; }
.slide {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; opacity: 0; transition: opacity 1.4s ease;
}
.slide.on { opacity: 1; }
.slide-shade {
  position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(to top, rgba(0,0,0,0.55), rgba(0,0,0,0) 45%);
}
.overlay {
  position: absolute; left: 0; right: 0; bottom: 0; pointer-events: none;
  padding: 20px 24px calc(18px + env(safe-area-inset-bottom) * 0);
  color: #fff; text-shadow: 0 2px 12px rgba(0,0,0,0.55);
  display: grid; gap: 2px;
}
.ov-clock { font-size: clamp(3.2rem, 11vw, 7rem); font-weight: 700; letter-spacing: -0.03em; line-height: 1; }
.ov-date { font-size: clamp(1rem, 2.6vw, 1.7rem); opacity: 0.95; }
.ov-weather { font-size: clamp(1rem, 2.6vw, 1.7rem); opacity: 0.95; min-height: 1.3em; }
.empty-photos {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; color: #fff; text-align: center;
  background: linear-gradient(135deg, #2f7f79, #25506b);
}
.empty-photos p { margin: 0; font-size: 1.2rem; }
.manage-btn {
  position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px;
  width: 46px; height: 46px; border-radius: 50%; border: none; cursor: pointer;
  background: rgba(0,0,0,0.38); color: #fff; display: grid; place-items: center;
  opacity: 0.55;
}
.manage-btn:active { opacity: 1; }
.manage-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; }

/* ---------- photos: gallery ---------- */
.gallery {
  background: var(--bg); min-height: 100%; padding: 16px 16px 28px;
  padding-top: max(16px, env(safe-area-inset-top));
}
.gal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
#upload-status { min-height: 1.3em; margin-bottom: 8px; }
.gal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; }
.gal-grid button { padding: 0; border: none; background: #ddd; border-radius: 10px; overflow: hidden; aspect-ratio: 1; cursor: pointer; }
.gal-grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.settings { margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--line); display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.settings h3 { font-size: 1.05rem; }

.photo-dialog { padding: 14px; width: min(96vw, 720px); }
.photo-dialog img { width: 100%; max-height: 68dvh; object-fit: contain; border-radius: 12px; background: #111; display: block; }
.photo-dialog #pv-meta { margin: 8px 2px 12px; }

/* ---------- groceries ---------- */
.panel-gro { max-width: 760px; margin: 0 auto; }
.panel-gro { flex-basis: 100%; }
.gro-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.gro-head h2 { font-size: 1.4rem; }
.gro-form { display: flex; gap: 8px; margin-bottom: 14px; }
.gro-form input {
  flex: 1; min-width: 0; font: inherit; font-size: 16px; padding: 0 14px; min-height: 48px;
  border-radius: 14px; border: 1.5px solid var(--line); background: #fff; color: var(--ink);
}
.gro-form input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.btn.icon-only { padding: 0; width: 48px; min-height: 48px; display: grid; place-items: center; border-radius: 14px; }
.btn.icon-only svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.gro-form .btn.primary { border-radius: 14px; min-height: 48px; }

.gro-list { display: flex; flex-direction: column; gap: 6px; }
.gro-empty { color: var(--muted); padding: 14px 4px; }
.gro-sub { margin: 14px 2px 2px; font-size: 0.8rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.gro-row {
  display: flex; align-items: center; gap: 10px; background: var(--card);
  border: 1px solid var(--line); border-radius: 14px; padding: 4px 6px 4px 4px;
}
.gro-check {
  flex: none; width: 48px; height: 48px; border: none; background: none; cursor: pointer;
  display: grid; place-items: center; padding: 0;
}
.gro-check i { width: 26px; height: 26px; border-radius: 50%; border: 2.5px solid #b9b3c2; display: grid; place-items: center; }
.gro-row.done .gro-check i { background: var(--accent); border-color: var(--accent); }
.gro-row.done .gro-check i::after { content: ""; width: 7px; height: 12px; border: solid #fff; border-width: 0 3px 3px 0; transform: rotate(45deg) translate(-1px, -1px); }
.gro-name { flex: 1; min-width: 0; font-size: 1.1rem; font-weight: 600; overflow-wrap: anywhere; }
.gro-row.done .gro-name { text-decoration: line-through; color: var(--muted); font-weight: 500; }
.gro-who { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.gro-del { flex: none; width: 44px; height: 44px; border: none; background: none; font-size: 1.5rem; color: #b9b3c2; cursor: pointer; border-radius: 50%; }
.gro-del:active { background: rgba(0,0,0,0.06); }

.gro-again { margin-top: 26px; }
.gro-again-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.gro-again-head h3 { font-size: 1.05rem; }
.linkish { font: inherit; font-weight: 700; color: var(--accent); background: none; border: none; padding: 10px 6px; cursor: pointer; }
.again-wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.again-chip {
  display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 600; font-size: 0.98rem;
  min-height: 42px; padding: 0 14px; border-radius: 999px; cursor: pointer;
  background: #fff; border: 1.5px solid var(--line); color: var(--ink);
}
.again-chip:active { background: #eef6f5; border-color: var(--accent); }
.again-chip .x { color: var(--danger); font-size: 1.2rem; line-height: 1; }
.again-empty { color: var(--muted); }

/* ---------- scanner ---------- */
.scan-dialog { width: min(94vw, 460px); padding: 14px; }
.scan-view { position: relative; border-radius: 14px; overflow: hidden; background: #111; aspect-ratio: 4 / 3; }
.scan-view video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame {
  position: absolute; left: 12%; right: 12%; top: 30%; bottom: 30%;
  border: 3px solid rgba(255,255,255,0.9); border-radius: 12px; box-shadow: 0 0 0 999px rgba(0,0,0,0.28);
}
.scan-msg { margin: 12px 2px; font-weight: 600; }
.scan-form { display: flex; flex-direction: column; gap: 12px; }
