:root {
  --bg: #f7f5ef;
  --card: #ffffff;
  --ink: #2b2a26;
  --muted: #8a857a;
  --line: #e7e3d8;
  --accent: #c8743a;
  --accent-ink: #ffffff;
  --danger: #c0473b;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 6px 18px rgba(0, 0, 0, 0.05);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.4;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 0.9rem; }

/* ---------- Login ---------- */
.login {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 22px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-emoji { font-size: 44px; }
.login-card h1 { margin: 6px 0 2px; font-size: 1.5rem; }
.login-card input {
  width: 100%;
  margin: 18px 0 12px;
  padding: 14px;
  font-size: 1.1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfaf6;
}
.login-card button {
  width: 100%;
  padding: 14px;
  font-size: 1.05rem;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
}

/* ---------- App shell ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 18px 12px;
  background: rgba(247, 245, 239, 0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.15rem; }
.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.95rem;
  padding: 6px;
}

.feed {
  max-width: 640px;
  margin: 0 auto;
  padding: 14px 14px calc(100px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.empty {
  text-align: center;
  color: var(--muted);
  margin-top: 18vh;
  padding: 0 30px;
}

/* ---------- Note card ---------- */
.note {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.note-body { white-space: pre-wrap; word-break: break-word; }
.note-body.empty-body { display: none; }

.note-photos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 8px;
  margin-top: 10px;
}
.note-photos img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 10px;
  background: #eee;
}

.note-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
}
.note-date { font-size: 0.78rem; color: var(--muted); }
.note-tools button {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 6px 8px;
}
.note-tools .del { color: var(--danger); }

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 32px;
  line-height: 1;
  box-shadow: 0 6px 16px rgba(200, 116, 58, 0.45);
  z-index: 6;
}

/* ---------- Sheet ---------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
}
.sheet-card {
  width: 100%;
  max-width: 640px;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow);
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-weight: 600;
}
#noteBody {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  font: inherit;
  background: #fbfaf6;
  resize: vertical;
  min-height: 96px;
}
.thumb-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.thumb-row:empty { display: none; }
.thumb {
  position: relative;
  width: 72px;
  height: 72px;
}
.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 10px;
}
.thumb .x {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: var(--danger);
  color: #fff;
  font-size: 14px;
  line-height: 22px;
  padding: 0;
}
.sheet-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
}
.photo-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
  font-weight: 600;
  padding: 10px 4px;
}
.primary {
  padding: 12px 24px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  font-size: 1rem;
}
.primary:disabled { opacity: 0.5; }

/* ---------- Viewer ---------- */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.92);
  display: grid;
  place-items: center;
  padding: 16px;
}
.viewer img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
