:root {
  --primary: #0066cc;
  --primary-focus: #0071e3;
  --primary-on-dark: #2997ff;
  --ink: #1d1d1f;
  --ink-80: #333333;
  --ink-48: #7a7a7a;
  --body-muted: #cccccc;
  --hairline: #e0e0e0;
  --canvas: #ffffff;
  --parchment: #f5f5f7;
  --tile-dark: #272729;
  --black: #000000;
  --chip: rgba(210, 210, 215, 0.64);
  --r-sm: 8px;
  --r-lg: 18px;
  --r-pill: 9999px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--parchment);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 17px;
  font-weight: 400;
  line-height: 1.47;
  letter-spacing: -0.374px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

/* global nav */
.gnav {
  position: sticky; top: 0; z-index: 20;
  height: calc(44px + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  background: var(--black); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; letter-spacing: -0.12px;
}

main {
  max-width: 680px; margin: 0 auto;
  padding: 0 16px calc(120px + env(safe-area-inset-bottom));
}

.hero { text-align: center; padding: 48px 8px 32px; }
.hero h1 {
  margin: 0 0 12px;
  font-size: 34px; font-weight: 600; line-height: 1.1; letter-spacing: -0.28px;
  text-wrap: balance;
}
.hero p { margin: 0; color: var(--ink-80); }
@media (min-width: 641px) { .hero h1 { font-size: 40px; } .hero { padding-top: 80px; } }
@media (max-width: 419px) { .hero h1 { font-size: 28px; } }

/* cards */
.card {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  padding: 24px;
  margin-bottom: 17px;
}

.composer { display: flex; flex-direction: column; gap: 17px; align-items: center; }
.field { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.field-label { font-weight: 600; }

.date-pill {
  position: relative;
  display: inline-flex; align-items: center;
  min-height: 44px; padding: 8px 20px;
  border: 1px solid rgba(0, 0, 0, 0.08); border-radius: var(--r-pill);
  background: var(--canvas); color: var(--primary);
  font-variant-numeric: tabular-nums;
}
.date-pill input, .chip input {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; border: 0; padding: 0; margin: 0;
  font-size: 17px; cursor: pointer;
}
.date-pill:focus-within, .chip:focus-within { outline: 2px solid var(--primary-focus); outline-offset: 2px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 11px 22px;
  border: 1px solid transparent; border-radius: var(--r-pill);
  font: inherit; letter-spacing: inherit; text-decoration: none; text-align: center;
  cursor: pointer; user-select: none; -webkit-user-select: none;
  transition: transform 0.12s ease;
}
.btn:active { transform: scale(0.95); }
.btn:focus-visible { outline: 2px solid var(--primary-focus); outline-offset: 2px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-ghost { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-ghost-dark { background: transparent; color: var(--primary-on-dark); border-color: var(--primary-on-dark); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.4; pointer-events: none; }

.text-link {
  background: none; border: 0; padding: 8px; margin: 0;
  font: inherit; letter-spacing: inherit; color: var(--primary);
  text-decoration: none; cursor: pointer; text-align: center;
}
.text-link.on-dark { color: var(--primary-on-dark); }
.text-link:active { transform: scale(0.95); }

/* date groups */
.group-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 17px; }
.group-head h2 { margin: 0; font-size: 21px; font-weight: 600; line-height: 1.19; letter-spacing: 0.231px; }
.group-head p { margin: 4px 0 0; font-size: 14px; letter-spacing: -0.224px; color: var(--ink-48); }
.chip {
  position: relative; flex: none;
  display: inline-flex; align-items: center; min-height: 44px; padding: 8px 16px;
  border: 1px solid var(--hairline); border-radius: var(--r-pill);
  font-size: 14px; letter-spacing: -0.224px; color: var(--ink);
}

.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 641px) { .grid { grid-template-columns: repeat(3, 1fr); } }
.shot {
  position: relative; margin: 0;
  aspect-ratio: 3 / 2; /* 12cm × 8cm の枠 */
  background: var(--parchment); border-radius: var(--r-sm); overflow: hidden;
}
.shot img { width: 100%; height: 100%; object-fit: contain; display: block; }
.shot button {
  position: absolute; top: 0; right: 0; width: 44px; height: 44px;
  border: 0; background: none; padding: 0; cursor: pointer;
}
.shot button::after {
  content: "×"; display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; margin: 6px 6px auto auto;
  border-radius: 50%; background: var(--chip); color: var(--ink);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  font-size: 18px; line-height: 1;
}
.shot button:active { transform: scale(0.95); }
.add {
  aspect-ratio: 3 / 2; border-radius: var(--r-sm);
  border: 1px dashed #c7c7cc; color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; letter-spacing: -0.224px; cursor: pointer;
}
.add:active { transform: scale(0.95); }

.notes { padding: 24px 8px 0; color: var(--ink-48); font-size: 12px; line-height: 1.5; letter-spacing: -0.12px; text-align: center; }
.notes p { margin: 0 0 4px; text-wrap: balance; }

/* floating sticky bar */
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: rgba(245, 245, 247, 0.8);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}
.bar-inner { max-width: 680px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.bar-summary { display: flex; flex-direction: column; min-width: 0; line-height: 1.24; }
.bar-summary strong { font-weight: 600; }
.bar-summary span { font-size: 12px; letter-spacing: -0.12px; color: var(--ink-48); margin-top: 4px; }
.bar .btn { flex: none; }

/* busy overlay */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(245, 245, 247, 0.8);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  display: flex; align-items: center; justify-content: center;
}
.busy-box { text-align: center; padding: 24px; }
.busy-box p { margin: 17px 0 0; }
.spinner {
  width: 32px; height: 32px; margin: 0 auto; border-radius: 50%;
  border: 3px solid var(--hairline); border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } .btn { transition: none; } }

/* done: dark tile */
.done {
  position: fixed; inset: 0; z-index: 40; overflow-y: auto;
  background: var(--tile-dark); color: #fff;
  display: flex; align-items: center; justify-content: center;
  padding: calc(48px + env(safe-area-inset-top)) 24px calc(48px + env(safe-area-inset-bottom));
}
.done-inner { width: 100%; max-width: 360px; text-align: center; display: flex; flex-direction: column; align-items: center; }
.done h2 { margin: 0 0 12px; font-size: 34px; font-weight: 600; line-height: 1.1; letter-spacing: -0.28px; }
.done p { margin: 0; color: var(--body-muted); overflow-wrap: anywhere; }
.done-actions { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; margin: 32px 0 24px; }
.done-tip { font-size: 12px; letter-spacing: -0.12px; margin-bottom: 24px !important; }

/* passcode dialog */
dialog {
  border: 1px solid var(--hairline); border-radius: var(--r-lg);
  padding: 24px; width: min(360px, calc(100vw - 32px)); color: var(--ink);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog h3 { margin: 0 0 8px; font-size: 21px; font-weight: 600; line-height: 1.19; letter-spacing: 0.231px; }
dialog p { margin: 0 0 17px; font-size: 14px; letter-spacing: -0.224px; color: var(--ink-80); }
dialog input {
  width: 100%; height: 44px; padding: 12px 20px;
  border: 1px solid rgba(0, 0, 0, 0.08); border-radius: var(--r-pill);
  font: inherit; color: var(--ink); background: var(--canvas);
}
dialog input:focus { outline: 2px solid var(--primary-focus); outline-offset: 2px; }
.dlg-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; }

/* 小さいスマホ */
.group-head > div { min-width: 0; }
.group-head h2 { white-space: nowrap; }
@media (max-width: 419px) {
  main { padding-left: 12px; padding-right: 12px; }
  .card { padding: 20px 17px; }
  .hero { padding: 32px 4px 24px; }
  .grid { gap: 8px; }
  .bar { padding-left: 12px; padding-right: 12px; }
}

/* 日付ボタン */
.date-pill, .chip { font: inherit; letter-spacing: inherit; cursor: pointer; transition: transform 0.12s ease; }
.date-pill { font-size: 17px; gap: 8px; }
.date-pill:active, .chip:active { transform: scale(0.95); }
.date-pill:focus-visible, .chip:focus-visible { outline: 2px solid var(--primary-focus); outline-offset: 2px; }
.chip { background: var(--canvas); }
.date-icon { width: 18px; height: 18px; flex: none; }

/* カレンダー: スマホでは下から出るシート、広い画面では中央のカード */
dialog.cal {
  padding: 0; border: 0; background: transparent; color: var(--ink);
  width: 100%; max-width: 100%; max-height: 100%;
  margin: auto 0 0; overflow: visible;
}
dialog.cal::backdrop { background: rgba(0, 0, 0, 0.4); }
.cal-sheet {
  background: var(--canvas);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 8px 20px calc(12px + env(safe-area-inset-bottom));
  max-width: 420px; margin: 0 auto;
}
.cal-grabber { width: 36px; height: 5px; border-radius: var(--r-pill); background: var(--hairline); margin: 0 auto 12px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 12px; }
.cal-head h3 { margin: 0; font-size: 21px; font-weight: 600; line-height: 1.19; letter-spacing: 0.231px; font-variant-numeric: tabular-nums; }
.cal-nav { display: flex; gap: 8px; }
.cal-arrow {
  width: 44px; height: 44px; border: 0; border-radius: 50%; padding: 0;
  background: var(--parchment); color: var(--ink); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.12s ease;
}
.cal-arrow svg { width: 20px; height: 20px; }
.cal-arrow:active { transform: scale(0.95); }
.cal-arrow:disabled { color: #c7c7cc; pointer-events: none; }
.cal-arrow:focus-visible { outline: 2px solid var(--primary-focus); outline-offset: 2px; }

.cal-week, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); justify-items: center; }
.cal-week { padding-bottom: 4px; font-size: 12px; letter-spacing: -0.12px; color: var(--ink-48); }
.cal-grid { row-gap: 2px; min-height: 286px; align-content: start; }
.cal-day {
  position: relative; width: 46px; height: 46px; max-width: 100%;
  border: 0; border-radius: 50%; padding: 0; background: none;
  font: inherit; font-size: 19px; letter-spacing: 0; color: var(--ink);
  font-variant-numeric: tabular-nums; cursor: pointer;
  transition: transform 0.12s ease;
}
.cal-day:active { transform: scale(0.95); }
.cal-day:disabled { color: #c7c7cc; pointer-events: none; }
.cal-day.is-today { color: var(--primary); font-weight: 600; }
.cal-day[aria-pressed="true"] { background: var(--primary); color: #fff; font-weight: 600; }
.cal-day:focus-visible { outline: 2px solid var(--primary-focus); outline-offset: 2px; }
.cal-day.has-photos::after {
  content: ""; position: absolute; left: 50%; bottom: 5px; width: 5px; height: 5px;
  margin-left: -2.5px; border-radius: 50%; background: var(--primary);
}
.cal-day[aria-pressed="true"].has-photos::after { background: #fff; }

.cal-foot { display: flex; align-items: center; justify-content: space-between; padding-top: 8px; margin: 8px -8px 0; border-top: 1px solid var(--divider, #f0f0f0); }
.cal-foot .text-link { min-height: 44px; padding: 8px 12px; }
.cal-legend { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; letter-spacing: -0.12px; color: var(--ink-48); }
.cal-legend i { width: 5px; height: 5px; border-radius: 50%; background: var(--primary); }

dialog.cal[open] .cal-sheet { animation: sheet-up 0.28s cubic-bezier(0.2, 0.8, 0.2, 1); }
dialog.cal[open]::backdrop { animation: fade-in 0.2s ease; }
@keyframes sheet-up { from { transform: translateY(100%); } }
@keyframes fade-in { from { opacity: 0; } }

@media (min-width: 641px) {
  dialog.cal { margin: auto; width: 420px; }
  .cal-sheet { border-radius: var(--r-lg); padding: 20px 24px 12px; }
  .cal-grabber { display: none; }
  dialog.cal[open] .cal-sheet { animation: pop-in 0.18s ease; }
  @keyframes pop-in { from { opacity: 0; transform: scale(0.97); } }
}
@media (prefers-reduced-motion: reduce) {
  dialog.cal[open] .cal-sheet, dialog.cal[open]::backdrop { animation: none; }
  .cal-day, .cal-arrow, .date-pill, .chip { transition: none; }
}
