:root {
  --bg: #F4EFE6;
  --ink: #1E2626;
  --teal: #2B4A4A;
  --teal-dark: #1E3434;
  --amber: #FFC43D;
  --card: #FFFFFF;
  --muted: #6B7676;
  --error: #B4432F;
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

#app {
  min-height: 100vh;
  min-height: 100dvh;
}

.view {
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- login ---------- */

#view-login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: 20px;
  padding-right: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 32px 24px;
  box-shadow: 0 8px 30px rgba(30, 38, 38, 0.08);
  text-align: center;
}

.brand { display: flex; align-items: center; justify-content: center; gap: 10px; }
.brand-icon { font-size: 2rem; }
.brand h1 { font-size: 1.6rem; margin: 0; color: var(--teal-dark); }

.tagline { color: var(--muted); margin: 8px 0 28px; font-size: 0.95rem; }

#login-form { display: flex; flex-direction: column; gap: 12px; text-align: left; }
#login-form label { font-size: 0.85rem; font-weight: 600; color: var(--teal-dark); }

input[type="email"], input[type="text"] {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid rgba(30, 38, 38, 0.15);
  border-radius: 12px;
  font-size: 1rem;
  background: var(--bg);
  color: var(--ink);
}
input:focus { outline: 2px solid var(--teal); outline-offset: 1px; }

button {
  font-family: inherit;
  cursor: pointer;
}

#login-form button,
.fab-full {
  margin-top: 8px;
  padding: 14px;
  border: none;
  border-radius: 12px;
  background: var(--teal);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
}
#login-form button:active { background: var(--teal-dark); }

.link-btn {
  background: none;
  border: none;
  color: var(--teal);
  text-decoration: underline;
  font-size: 0.9rem;
  padding: 8px;
}

.error { color: var(--error); font-size: 0.9rem; margin-top: 14px; }

#login-sent p { color: var(--muted); line-height: 1.5; }

/* ---------- home ---------- */

.home-header, .detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 8px;
}
.home-header h1, .detail-header h1 {
  font-size: 1.3rem;
  margin: 0;
  color: var(--teal-dark);
}
.detail-header h1 { font-size: 1.1rem; text-align: center; flex: 1; }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(30, 38, 38, 0.06);
  font-size: 1.1rem;
  color: var(--teal-dark);
  display: flex;
  align-items: center;
  justify-content: center;
}

.routines-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 4px 20px 4px;
  -webkit-overflow-scrolling: touch;
}
.routines-row:empty { display: none; }

.routine-pill {
  position: relative;
  flex: 0 0 auto;
  display: flex;
}
.routine-pill-main {
  border: none;
  background: var(--card);
  border-radius: 14px;
  padding: 10px 16px;
  box-shadow: 0 3px 12px rgba(30, 38, 38, 0.06);
  text-align: left;
  display: flex;
  flex-direction: column;
  min-width: 120px;
}
.routine-pill-name { font-weight: 700; font-size: 0.88rem; color: var(--ink); }
.routine-pill-count { font-size: 0.72rem; color: var(--muted); margin-top: 2px; }
.routine-pill-delete {
  position: absolute;
  top: -6px;
  right: -6px;
  background: rgba(180, 67, 47, 0.9);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 0.7rem;
  line-height: 1;
  z-index: 1;
}
.routine-pill-add {
  border: 1.5px dashed rgba(30, 38, 38, 0.25);
  background: none;
  color: var(--teal);
  font-weight: 700;
  font-size: 0.85rem;
  border-radius: 14px;
  padding: 10px 16px;
  white-space: nowrap;
}

.items-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  padding: 12px 20px 100px;
}

.item-card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(30, 38, 38, 0.06);
  border: none;
  padding: 0;
  text-align: left;
  display: flex;
  flex-direction: column;
}

.item-thumb {
  width: 100%;
  aspect-ratio: 1;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  position: relative;
  overflow: hidden;
}
.item-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.check-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(30, 38, 38, 0.75);
  color: #fff;
  font-size: 0.65rem;
  padding: 3px 7px;
  border-radius: 20px;
}

.photo-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 16px 10px 8px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0.35) 60%, rgba(0, 0, 0, 0));
  display: flex;
  flex-direction: column;
  pointer-events: none;
}
.overlay-time {
  color: #fff;
  font-size: 1.3rem;
  font-weight: 800;
  line-height: 1.1;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}
.overlay-timer {
  color: rgba(255, 255, 255, 0.88);
  font-size: 0.75rem;
  font-weight: 600;
  margin-top: 2px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.item-info { padding: 10px 12px 12px; }
.item-name { font-weight: 700; font-size: 0.95rem; display: flex; align-items: center; gap: 6px; }
.item-status { font-size: 0.78rem; color: var(--muted); margin-top: 4px; }

.item-delete {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(180, 67, 47, 0.85);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-size: 0.8rem;
  line-height: 1;
}

.fab {
  position: fixed;
  right: 24px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--amber);
  color: var(--teal-dark);
  font-size: 1.8rem;
  font-weight: 700;
  box-shadow: 0 6px 20px rgba(30, 38, 38, 0.25);
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
}

/* ---------- history ---------- */

.history-list {
  padding: 8px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 2px 10px rgba(30, 38, 38, 0.05);
}
.history-row img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 10px;
  flex-shrink: 0;
}
.history-time { font-size: 0.9rem; color: var(--ink); }
.history-time small { display: block; color: var(--muted); font-size: 0.78rem; margin-top: 2px; }

/* ---------- routines ---------- */

.routine-item-picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
  margin-top: 4px;
}

.routine-pick-row {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1.5px solid rgba(30, 38, 38, 0.12);
  background: var(--bg);
  border-radius: 12px;
  padding: 10px 12px;
  text-align: left;
  color: var(--ink);
}
.routine-pick-row.selected {
  border-color: var(--teal);
  background: rgba(111, 191, 191, 0.12);
}
.routine-pick-order {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--teal);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.routine-pick-name { font-weight: 600; font-size: 0.9rem; }

.routine-run {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 24px;
  min-height: 60vh;
}
.routine-progress { color: var(--muted); font-size: 0.85rem; font-weight: 600; margin-bottom: 18px; }
.routine-current-emoji { font-size: 4rem; line-height: 1; margin-bottom: 12px; }
.routine-current-name { font-size: 1.4rem; font-weight: 800; color: var(--teal-dark); margin-bottom: 28px; }
.routine-done-icon {
  font-size: 3.5rem;
  color: var(--teal);
  margin-bottom: 10px;
}
.routine-done p { font-size: 1.05rem; color: var(--ink); margin-bottom: 24px; }
.routine-run .fab-full { width: 100%; max-width: 260px; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--teal-dark);
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 0.9rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  z-index: 10;
}

/* ---------- modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 26, 26, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
}

.modal-card {
  width: 100%;
  max-width: 340px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
}
.modal-card h2 { font-size: 1.1rem; margin: 0 0 16px; color: var(--teal-dark); }
#add-item-form { display: flex; flex-direction: column; gap: 10px; }
#add-item-form label { font-size: 0.82rem; font-weight: 600; color: var(--teal-dark); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}
.modal-actions button[type="submit"] {
  padding: 10px 20px;
  border: none;
  border-radius: 10px;
  background: var(--teal);
  color: #fff;
  font-weight: 600;
}

/* ---------- household ---------- */

.household-name { font-weight: 700; font-size: 1rem; color: var(--teal-dark); margin: 0 0 6px; }
.household-members { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.household-members li { font-size: 0.88rem; color: var(--ink); }
#household-info label,
#household-join-form label { font-size: 0.82rem; font-weight: 600; color: var(--teal-dark); display: block; margin-bottom: 6px; }
.invite-row { display: flex; align-items: center; gap: 10px; }
.invite-row code {
  flex: 1;
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: var(--ink);
}
#household-join-form {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid rgba(30, 38, 38, 0.1);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#household-join-confirm p { font-size: 0.9rem; color: var(--ink); line-height: 1.5; }
#join-confirm-btn {
  padding: 10px 20px;
  border: none;
  border-radius: 10px;
  background: var(--teal);
  color: #fff;
  font-weight: 600;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16201F;
    --ink: #EDEEEA;
    --card: #202B2A;
    --muted: #9AA6A5;
    --teal: #6FBFBF;
    --teal-dark: #A9DADA;
  }
  .icon-btn { background: rgba(255,255,255,0.08); }
  input[type="email"], input[type="text"] { background: #16201F; color: var(--ink); border-color: rgba(255,255,255,0.12); }
  #login-form button, .modal-actions button[type="submit"], .fab-full, #join-confirm-btn { color: #0E1616; }
  .fab { color: #0E1616; }
  .routine-pick-order { color: #0E1616; }
  #household-join-form { border-top-color: rgba(255,255,255,0.12); }
}
