:root {
  --bg: #f3efe8;
  --bg-deep: #e6dfd4;
  --card: #fffcf8;
  --ink: #1f1a17;
  --muted: #7d746c;
  --line: #e3dbd1;
  --accent: #8c3a32;
  --accent-soft: #f8e8e3;
  --soon: #8a5a22;
  --soon-soft: #f8efdf;
  --ok: #3f6b56;
  --shadow: 0 12px 40px rgba(70, 48, 28, 0.06);
  --serif: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", serif;
  --sans: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Source Han Sans SC", sans-serif;
  --tab: calc(68px + env(safe-area-inset-bottom));
}

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

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--sans);
  background:
    radial-gradient(900px 420px at 50% -80px, #fffaf4 0%, transparent 60%),
    var(--bg);
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; display: block; }

.phone {
  width: min(520px, 100%);
  min-height: 100%;
  margin: 0 auto;
  padding-bottom: var(--tab);
}

.phone.no-tabs { padding-bottom: env(safe-area-inset-bottom); }

#topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(14px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(243, 239, 232, 0.9);
  backdrop-filter: blur(16px);
}

.topbar-row {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  gap: 8px;
  align-items: center;
}

.topbar-copy { min-width: 0; }

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.14em;
}

h1 {
  margin: 2px 0 0;
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.15;
}

h1.compact { font-size: 24px; }

.icon-btn, .text-btn, .text-toggle, .primary, .ghost, .row, .tile, .effect-card, .chip, .banner {
  border: 0;
  background: transparent;
}

.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--card);
  border: 1px solid var(--line);
}

.icon-btn svg, .tab svg { width: 22px; height: 22px; }

.icon-btn.invisible { visibility: hidden; }

#view { padding: 6px 16px 28px; }

.boot, .empty p, .explain, .settings p, .fine {
  color: var(--muted);
  line-height: 1.65;
}

.empty {
  margin-top: 28px;
  padding: 28px 8px 12px;
  text-align: center;
}

.empty h2 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 600;
}

.empty p { margin: 0 auto 18px; max-width: 28em; }

.jar {
  width: 72px;
  height: 86px;
  margin: 0 auto 16px;
  color: #b9aa9b;
}

.primary, .ghost, .danger {
  min-height: 48px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid transparent;
}

.primary { background: var(--ink); color: #fff; }
.ghost { background: transparent; border-color: var(--line); }
.danger { background: var(--accent-soft); color: var(--accent); }
.wide { width: 100%; }

.section-label {
  margin: 20px 4px 8px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.08em;
}

.stack { display: flex; flex-direction: column; gap: 10px; }

.row {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.photo-frame, .hero-photo, .tile-photo {
  display: block;
  position: relative;
  overflow: hidden;
  background: var(--bg-deep);
}

.photo-frame {
  width: 64px;
  height: 64px;
  border-radius: 14px;
}

.photo-frame img, .hero-photo img, .tile-photo img, .photo-pick img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-frame .ph, .hero-photo .ph, .tile-photo .ph { position: absolute; inset: 0; }

.ph {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: #8d8176;
  font-family: var(--serif);
  font-size: 24px;
}

.row-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.35;
}

.name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tag {
  flex: none;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--bg-deep);
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.row-sub {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.remain {
  font-size: 12px;
  line-height: 1.35;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.remain.overdue, .hero-remain.overdue { color: var(--accent); }
.remain.soon, .hero-remain.soon { color: var(--soon); }
.remain.ok, .hero-remain.ok { color: var(--ok); }
.remain.unknown, .hero-remain.unknown { color: var(--muted); }

.later-note, .banner, .linkish {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 12px 14px;
  text-align: left;
  color: var(--muted);
  background: transparent;
  border: 1px dashed var(--line);
  border-radius: 14px;
  line-height: 1.5;
}

.banner { color: var(--soon); border-style: solid; border-color: #ead7bc; background: var(--soon-soft); }

.effect-grid, .photo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.effect-card, .tile {
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.effect-card { padding: 14px 14px 12px; min-height: 118px; }
.effect-name { display: block; font-size: 16px; }
.effect-count {
  display: block;
  margin-top: 8px;
  font-family: var(--serif);
  font-size: 34px;
  line-height: 1;
}
.effect-next { display: block; margin-top: 8px; color: var(--muted); font-size: 12px; }
.effect-card.is-empty .effect-count { color: #c4b8ac; }

.toolbar { margin-bottom: 12px; }
.scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.scroll::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
}

.chip.is-on, .tab.is-on {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.text-toggle {
  margin-top: 10px;
  padding: 0;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.tile {
  display: block;
  width: 100%;
  padding: 0 0 10px;
  overflow: hidden;
}
.tile-photo {
  height: 0;
  padding-top: 100%;
}
.tile-photo .ph {
  font-size: 28px;
  line-height: 1;
}
.tile-name, .tile-meta { display: block; padding: 0 10px; }
.tile-name { margin-top: 8px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-meta { margin-top: 2px; color: var(--muted); font-size: 12px; }

.hero-photo {
  aspect-ratio: 1;
  max-height: 280px;
  border-radius: 22px;
}
.hero-photo .ph { font-size: 72px; }
.hero-remain {
  margin: 14px 2px 0;
  font-family: var(--serif);
  font-size: 32px;
}

.meta-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.pill {
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 13px;
}

.date-card, .field, .settings-card, .explain {
  margin-top: 14px;
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.date-row, .settings-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}
.date-row:last-of-type, .settings-row:last-child { border-bottom: 0; }
.date-row span, .settings-row span { color: var(--muted); }
.explain { color: var(--ink); }
.explain.overdue { background: var(--accent-soft); border-color: transparent; }
.explain.soon { background: var(--soon-soft); border-color: transparent; }

.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.actions.row-actions { flex-direction: row; }
.actions.row-actions > * { flex: 1; }

.field { display: block; }
.field span, .group-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 48px;
  padding: 12px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 16px;
}
.field textarea { min-height: 84px; resize: vertical; }

.photo-pick {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  max-height: 240px;
  margin-bottom: 8px;
  border-radius: 22px;
  border: 1px dashed #cfc4b6;
  background: var(--card);
  color: var(--muted);
  overflow: hidden;
}
.photo-pick img { position: absolute; inset: 0; }
.photo-pick span { position: relative; z-index: 1; padding: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.group-label { margin: 16px 2px 8px; }

.form-error { min-height: 1.2em; margin: 8px 2px 0; color: var(--accent); }
.form-actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 10px;
  margin-top: 16px;
}

#tabbar {
  position: fixed;
  z-index: 6;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(520px, 100%);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 6px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 252, 248, 0.94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 48px;
  color: var(--muted);
  border-radius: 12px;
  font-size: 11px;
}
.tab.is-on { background: transparent; color: var(--ink); }

.sheet-back, .dialog-back {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(36, 27, 22, 0.38);
}
.sheet-back { display: flex; align-items: flex-end; justify-content: center; }
.sheet, .dialog {
  background: var(--card);
  width: min(520px, 100%);
}
.sheet {
  border-radius: 22px 22px 0 0;
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
}
.sheet h2, .dialog h2 {
  margin: 0 0 6px;
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 600;
}
.dialog-back { display: grid; place-items: center; padding: 24px; z-index: 30; }
.dialog { width: min(360px, 100%); border-radius: 20px; padding: 20px; }
.dialog p { color: var(--muted); line-height: 1.6; }

#toast {
  position: fixed;
  z-index: 40;
  left: 50%;
  top: calc(72px + env(safe-area-inset-top));
  transform: translateX(-50%) translateY(-8px);
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.fine { margin: 18px 4px 0; font-size: 13px; }
#ocr-status { margin: 8px 2px 0; }
#ocr-status .text-toggle { display: inline; margin: 0 0 0 6px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
