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

:root {
  --footer-h: calc(58px + env(safe-area-inset-bottom, 0px));
  --bg: #eef0f4;
  --card: #ffffff;
  --ink: #1c1c1e;
  --ink-soft: #8e8e93;
  --accent: #0a84ff;
  --hairline: rgba(60, 60, 67, 0.12);
}

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- stage + world ---------- */

#stage {
  position: fixed;
  inset: 0 0 var(--footer-h) 0;
  overflow-x: hidden;
  overflow-y: auto;
  touch-action: pan-y;
}
#stage.zoomed { overflow: hidden; }

#world {
  position: relative;
  transform-origin: 0 0;
  will-change: transform;
  transition: transform 0.5s cubic-bezier(0.22, 0.9, 0.26, 1);
}
#world.pinching, #world.pinching .cell { transition: none; }

/* ---------- cells ---------- */

.cell {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  transition: transform 0.5s cubic-bezier(0.22, 0.9, 0.26, 1);
}

.card {
  position: absolute;
  inset: 10px;
  background: var(--card);
  border-radius: 30px;
  box-shadow: 0 3px 14px rgba(20, 24, 40, 0.07);
  padding: 30px 32px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.cell.empty .card {
  background: transparent;
  box-shadow: none;
  border: 3px dashed rgba(60, 60, 67, 0.16);
  align-items: center;
  justify-content: center;
  color: rgba(60, 60, 67, 0.28);
  font-size: 72px;
  font-weight: 200;
}

/* in grid view the whole cell is one tap target */
.cell .card > * { pointer-events: none; }
#stage.zoomed .cell.focused .card > * { pointer-events: auto; }
#stage.zoomed .cell:not(.focused) { pointer-events: none; }

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex-shrink: 0;
}

.title {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  outline: none;
  min-width: 40px;
}
.title:empty::before { content: "Untitled"; color: var(--ink-soft); }

.close-btn {
  display: none;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: rgba(118, 118, 128, 0.12);
  color: #6c6c70;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}
.cell.focused .close-btn { display: flex; }

/* ---------- todo rows ---------- */

.rows { display: flex; flex-direction: column; overflow: hidden; }

.row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 9px 0;
  min-height: 46px;
}

.check {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border: 2.5px solid #c7c7cc;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  position: relative;
}
.row.done .check {
  background: var(--accent);
  border-color: var(--accent);
}
.row.done .check::after {
  content: "";
  position: absolute;
  left: 8px;
  top: 3.5px;
  width: 6px;
  height: 12px;
  border: solid #fff;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}

.row input {
  flex: 1;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 20px;
  color: var(--ink);
  outline: none;
  min-width: 0;
}
.row.done input { color: var(--ink-soft); text-decoration: line-through; }

.row.ghost { opacity: 0.35; }
.row.ghost input::placeholder { color: var(--ink-soft); }

/* ---------- footer ---------- */

#footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--footer-h);
  padding: 0 18px env(safe-area-inset-bottom, 0px) 18px;
  display: flex;
  align-items: center;
  background: rgba(249, 249, 251, 0.82);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--hairline);
  z-index: 10;
}

#menu-btn {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
#menu-btn:active { background: rgba(118, 118, 128, 0.12); }

/* ---------- card body + sections ---------- */

.card-body { flex: 1; overflow: hidden; }
.cell.focused .card-body { overflow-y: auto; }

.section.optional { display: none; }
.section.optional.has-content, .cell.focused .section.optional { display: block; }

.section-label {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 26px 0 10px;
}

/* ---------- notes ---------- */

.notes {
  width: 100%;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 20px;
  line-height: 1.45;
  color: var(--ink);
  resize: none;
  outline: none;
  min-height: 30px;
  overflow: hidden;
}
.notes::placeholder { color: var(--ink-soft); opacity: 0.5; }

/* ---------- photos ---------- */

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

.photo {
  position: relative;
  aspect-ratio: 1;
  border-radius: 14px;
  overflow: hidden;
  background: rgba(118, 118, 128, 0.08);
}
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }

.photo-del {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
}
.cell.focused .photo-del { display: flex; }

.photo-add {
  aspect-ratio: 1;
  border: 3px dashed rgba(60, 60, 67, 0.18);
  border-radius: 14px;
  background: none;
  color: rgba(60, 60, 67, 0.35);
  font-size: 44px;
  font-weight: 200;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
}
.cell.focused .photo-add { display: flex; }
