:root {
  --paper: #f7f1e7;
  --paper-2: #fffaf1;
  --ink: #27231e;
  --muted: #7c7164;
  --line: #ded3c3;
  --accent: #d99228;
  --accent-2: #f2d8a7;
  --soft: rgba(217, 146, 40, 0.12);
  --danger: #a64c3c;
  --shadow: 0 18px 48px rgba(63, 46, 24, 0.12);
  --radius: 22px;
  --font: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Hiragino Sans", "Yu Gothic", "YuGothic", "Meiryo", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 255, 255, 0.86), transparent 34rem),
    linear-gradient(140deg, #f8f0df 0%, #f7f3ea 47%, #eee2cd 100%);
  letter-spacing: 0.02em;
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; border: 0; }
button:disabled { opacity: 0.48; cursor: not-allowed; }

.app-shell {
  width: min(1100px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 72px;
}

.hero {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(125, 101, 69, 0.16);
  border-radius: 30px;
  padding: 36px;
  background:
    linear-gradient(135deg, rgba(255, 252, 244, 0.96), rgba(245, 235, 219, 0.88)),
    repeating-linear-gradient(0deg, transparent 0, transparent 31px, rgba(96, 72, 43, 0.035) 32px);
  box-shadow: var(--shadow);
}
.hero::after {
  content: "";
  position: absolute;
  right: 30px;
  top: 26px;
  width: 130px;
  height: 82px;
  border: 14px solid rgba(217, 146, 40, 0.17);
  transform: rotate(-4deg);
  border-radius: 12px;
  pointer-events: none;
}
.hero__topline, .kicker {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.22em;
}
.hero h1 {
  margin: 0;
  font-size: clamp(34px, 7vw, 64px);
  line-height: 1.02;
  letter-spacing: 0.03em;
}
.hero p {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.8;
}
.hero__actions { display: flex; gap: 12px; margin-top: 24px; flex-wrap: wrap; }

.tabs {
  position: sticky;
  top: 10px;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 16px 0;
  padding: 8px;
  border: 1px solid rgba(125, 101, 69, 0.14);
  border-radius: 24px;
  background: rgba(255, 250, 241, 0.86);
  backdrop-filter: blur(14px);
  box-shadow: 0 8px 24px rgba(63, 46, 24, 0.08);
}
.tab {
  padding: 13px 10px;
  color: var(--muted);
  background: transparent;
  border-radius: 17px;
  font-weight: 700;
}
.tab.is-active {
  color: var(--ink);
  background: var(--soft);
}

.view { display: none; }
.view.is-visible { display: block; }

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin: 30px 4px 14px;
}
.section-head h2 {
  margin: 0;
  font-size: clamp(24px, 4vw, 34px);
  letter-spacing: 0.03em;
}
.muted, .counter { color: var(--muted); }
.counter { font-weight: 800; }

.entry-form, .setup-panel, .backup-panel, .entry-card, .detail-dialog .dialog-card {
  background: rgba(255, 250, 241, 0.92);
  border: 1px solid rgba(125, 101, 69, 0.14);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.entry-form, .setup-panel { padding: 22px; }
.setup-panel { margin-bottom: 14px; }
.setup-panel h3 { margin: 0 0 8px; font-size: 22px; }
.setup-panel p { margin: 0 0 16px; color: var(--muted); line-height: 1.8; }
.setup-panel.is-hidden { display: none; }
.setup-form { display: grid; gap: 12px; }

.form-grid, .comments-grid {
  display: grid;
  gap: 14px;
}
.form-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.comments-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

label { display: block; margin-bottom: 14px; }
label span {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 0 7px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 750;
}
label small { color: #9d9285; font-weight: 500; }

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.76);
  outline: none;
  padding: 14px 14px;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
textarea { resize: vertical; line-height: 1.75; }
input:focus, textarea:focus, select:focus {
  border-color: rgba(217, 146, 40, 0.75);
  box-shadow: 0 0 0 4px rgba(217, 146, 40, 0.14);
  background: #fffdfa;
}

.photo-picker {
  padding: 16px;
  border: 1px dashed rgba(217, 146, 40, 0.55);
  border-radius: 18px;
  background: rgba(217, 146, 40, 0.06);
}
.photo-picker {
  position: relative;
  cursor: pointer;
}
.photo-picker input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
}
.upload-line {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 2px 0 8px;
}
.upload-button {
  min-height: 44px;
  border-radius: 999px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
  color: #fffaf1;
  font-weight: 800;
  letter-spacing: 0.02em;
  box-shadow: 0 10px 24px rgba(63, 46, 24, 0.12);
}
.upload-status {
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}
.photo-picker:focus-within {
  border-color: rgba(217, 146, 40, 0.75);
  box-shadow: 0 0 0 4px rgba(217, 146, 40, 0.14);
}
.photo-picker small { display: block; color: var(--muted); line-height: 1.6; }

.image-preview, .archive-grid, .detail-images {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.preview-item, .archive-item, .detail-image-wrap {
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid rgba(125, 101, 69, 0.14);
  background: #fff;
}
.preview-item { position: relative; }
.preview-item img, .archive-item img, .detail-image-wrap img {
  display: block;
  width: 100%;
  height: 180px;
  object-fit: cover;
}
.preview-item button {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(39, 35, 30, 0.78);
  color: #fff;
}

.form-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-top: 18px;
}
.checkline {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}
.checkline input { width: auto; }
.checkline span { margin: 0; color: inherit; }
.form-actions, .backup-actions, .detail-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.primary, .ghost, .danger, .file-button {
  min-height: 46px;
  border-radius: 999px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  letter-spacing: 0.02em;
}
.primary { background: var(--ink); color: #fffaf1; }
.ghost { background: rgba(39, 35, 30, 0.06); color: var(--ink); }
.danger { background: var(--danger); color: #fff; }
.file-button { background: rgba(39, 35, 30, 0.06); color: var(--ink); cursor: pointer; }
.file-button input { display: none; }

.filters {
  display: grid;
  grid-template-columns: 1.7fr 1fr 0.75fr 0.8fr;
  gap: 10px;
  margin-bottom: 14px;
}

.entry-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
}
.entry-card {
  padding: 18px;
  cursor: pointer;
  position: relative;
  transition: transform 160ms ease, box-shadow 160ms ease;
}
.entry-card:hover { transform: translateY(-2px); box-shadow: 0 24px 52px rgba(63, 46, 24, 0.16); }
.card-date {
  color: var(--accent);
  font-weight: 800;
  font-size: 13px;
}
.card-title {
  margin: 12px 0 14px;
  font-size: 20px;
  line-height: 1.55;
  white-space: pre-wrap;
}
.badges { display: flex; flex-wrap: wrap; gap: 7px; }
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 27px;
  border-radius: 999px;
  padding: 0 10px;
  background: rgba(217, 146, 40, 0.12);
  color: #745018;
  font-size: 12px;
  font-weight: 800;
}
.badge.neutral { background: rgba(39, 35, 30, 0.06); color: var(--muted); }
.favorite-mark {
  position: absolute;
  top: 14px;
  right: 14px;
  color: var(--accent);
  font-size: 19px;
}
.card-thumb {
  width: 100%;
  height: 138px;
  margin-top: 14px;
  object-fit: cover;
  border-radius: 16px;
  border: 1px solid rgba(125, 101, 69, 0.12);
}

.empty-state {
  display: none;
  text-align: center;
  padding: 46px 18px;
  border: 1px dashed rgba(125, 101, 69, 0.24);
  border-radius: var(--radius);
  color: var(--muted);
  background: rgba(255, 250, 241, 0.48);
}
.empty-state.is-visible { display: block; }
.empty-state h3 { margin: 0 0 8px; color: var(--ink); }

.archive-item { cursor: pointer; background: #fffaf1; }
.archive-item__text { padding: 12px; }
.archive-item__text strong { display: block; line-height: 1.4; }
.archive-item__text small { color: var(--muted); }

.backup-panel { padding: 22px; margin-bottom: 14px; }
.backup-panel h3 { margin: 0 0 8px; }
.backup-panel p { margin: 0 0 16px; color: var(--muted); line-height: 1.8; }
.danger-zone { border-color: rgba(166, 76, 60, 0.28); }

.detail-dialog {
  border: 0;
  padding: 18px;
  background: transparent;
  max-width: min(920px, 96vw);
  width: 100%;
}
.detail-dialog::backdrop { background: rgba(29, 24, 18, 0.42); backdrop-filter: blur(4px); }
.dialog-card { position: relative; padding: 24px; max-height: 88vh; overflow: auto; }
.dialog-close {
  position: sticky;
  margin-left: auto;
  top: 0;
  z-index: 2;
  display: block;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(39, 35, 30, 0.08);
  color: var(--ink);
  font-size: 26px;
  line-height: 1;
}
.detail-title {
  margin: 8px 0 10px;
  font-size: clamp(28px, 6vw, 46px);
  line-height: 1.35;
  letter-spacing: 0.02em;
  white-space: pre-wrap;
}
.detail-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.detail-block {
  padding: 16px;
  border-radius: 18px;
  background: rgba(39, 35, 30, 0.04);
  margin: 12px 0;
}
.detail-block h4 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.12em;
}
.detail-block p { margin: 0; white-space: pre-wrap; line-height: 1.8; }
.detail-actions { margin: 18px 0 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%) translateY(30px);
  opacity: 0;
  pointer-events: none;
  padding: 12px 16px;
  border-radius: 999px;
  background: rgba(39, 35, 30, 0.88);
  color: #fffaf1;
  transition: opacity 200ms ease, transform 200ms ease;
  z-index: 20;
  max-width: calc(100vw - 34px);
  text-align: center;
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 820px) {
  .app-shell { width: min(100% - 20px, 1100px); padding-top: 10px; }
  .hero { padding: 26px 20px; border-radius: 26px; }
  .hero::after { right: -18px; top: 24px; }
  .tabs { bottom: 10px; top: auto; position: fixed; left: 10px; right: 10px; margin: 0; }
  main { padding-bottom: 76px; }
  .section-head { align-items: flex-start; flex-direction: column; gap: 4px; }
  .form-grid, .comments-grid, .filters { grid-template-columns: 1fr; }
  .form-row { align-items: stretch; flex-direction: column; }
  .form-actions { justify-content: stretch; }
  .form-actions > * { flex: 1; }
  .entry-form { padding: 16px; }
  .entry-list { grid-template-columns: 1fr; }
  .detail-dialog { padding: 8px; max-width: 100vw; }
  .dialog-card { padding: 18px; }
}
