:root {
  --bg: #f5f3ec;
  --surface: #fffdf8;
  --surface-2: #edf2ee;
  --text: #203129;
  --muted: #6b7a72;
  --line: #d6ddd8;
  --primary: #355c4d;
  --primary-2: #527766;
  --danger: #a34242;
  --shadow: 0 8px 26px rgba(36, 60, 49, 0.08);
  --radius: 18px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { -webkit-tap-highlight-color: transparent; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100dvh; padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(53,92,77,.08);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-icon { width: 38px; height: 38px; border-radius: 12px; background: var(--primary); display: grid; place-items: center; color: white; font-size: 21px; }
.brand h1 { font-size: 18px; margin: 0; letter-spacing: .03em; }
.brand small { display: block; color: var(--muted); font-size: 11px; margin-top: 1px; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }

main { width: min(760px, 100%); margin: 0 auto; padding: 18px 14px 28px; }
.section-head { display: flex; align-items: end; gap: 12px; margin-bottom: 14px; }
.section-head h2 { margin: 0; font-size: 24px; line-height: 1.25; }
.section-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.section-head .spacer { flex: 1; }

.btn {
  border: 0; border-radius: 13px; padding: 11px 14px;
  background: var(--surface-2); color: var(--text); font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
}
.btn:hover { filter: brightness(.98); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: white; }
.btn-danger { background: #f5e6e6; color: var(--danger); }
.btn-ghost { background: transparent; padding: 9px; }
.btn-small { padding: 8px 10px; border-radius: 11px; font-size: 12px; }
.icon-btn { width: 40px; height: 40px; border: 0; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); color: var(--text); font-size: 18px; }

.toolbar { display: grid; grid-template-columns: 1fr auto; gap: 9px; margin-bottom: 14px; }
.search { width: 100%; border: 1px solid var(--line); border-radius: 14px; padding: 12px 13px; background: var(--surface); color: var(--text); outline: none; }
.search:focus { border-color: var(--primary-2); box-shadow: 0 0 0 3px rgba(82,119,102,.12); }
.filter { border: 1px solid var(--line); border-radius: 14px; padding: 0 11px; background: var(--surface); color: var(--text); }

.card-list { display: grid; gap: 11px; }
.card {
  background: var(--surface); border: 1px solid rgba(53,92,77,.09); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 15px;
}
.question-card { display: grid; gap: 9px; }
.question-card[data-open] { cursor: pointer; }
.question-card h3 { margin: 0; font-size: 17px; line-height: 1.45; }
.question-card p { margin: 0; color: var(--muted); line-height: 1.6; font-size: 13px; }
.card-meta { display: flex; gap: 7px; flex-wrap: wrap; align-items: center; }
.badge { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 5px 9px; font-size: 11px; font-weight: 700; background: var(--surface-2); color: var(--primary); }
.badge.type { background: #ece8f4; color: #5e4d79; }
.badge.muted { color: var(--muted); }
.card-actions { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 4px; }

.hero-card { padding: 18px; margin-bottom: 14px; }
.hero-card h2 { margin: 0 0 8px; font-size: 23px; line-height: 1.45; }
.hero-card p { color: var(--muted); line-height: 1.7; margin: 0 0 12px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

.tree { display: grid; gap: 10px; }
.tree-node { position: relative; margin-left: min(calc(var(--depth, 0) * 14px), 56px); }
.tree-node.depth-1::before, .tree-node.deep::before {
  content: ""; position: absolute; left: -10px; top: 0; bottom: -10px; width: 2px; border-radius: 2px; background: #cbd8d1;
}
.thought-card { padding: 13px 13px 11px; }
.thought-card .thought-content { white-space: pre-wrap; line-height: 1.65; font-size: 15px; margin: 7px 0 8px; }
.thought-head { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.thought-date { margin-left: auto; color: var(--muted); font-size: 10px; }
.children { margin-top: 9px; display: grid; gap: 9px; }

.empty { text-align: center; padding: 36px 20px; color: var(--muted); background: var(--surface); border-radius: var(--radius); border: 1px dashed var(--line); }
.empty strong { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }

.fragment-card p { white-space: pre-wrap; line-height: 1.65; margin: 0 0 10px; }

.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255,253,248,.94); backdrop-filter: blur(14px);
  border-top: 1px solid rgba(53,92,77,.12);
}
.nav-btn { border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; gap: 2px; font-size: 11px; padding: 4px; }
.nav-btn .nav-icon { font-size: 21px; line-height: 1; }
.nav-btn.active { color: var(--primary); font-weight: 800; }

.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(18,30,24,.42); display: flex; align-items: flex-end; justify-content: center; }
.modal { width: min(680px, 100%); max-height: 91dvh; overflow: auto; background: var(--surface); border-radius: 24px 24px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); box-shadow: 0 -16px 44px rgba(0,0,0,.16); }
.modal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 15px; }
.modal-head h3 { margin: 0; font-size: 20px; }
.modal-head .spacer { flex: 1; }
.form-grid { display: grid; gap: 13px; }
.field { display: grid; gap: 6px; }
.field label { font-weight: 800; font-size: 13px; }
.field small { color: var(--muted); }
.field input, .field textarea, .field select {
  width: 100%; border: 1px solid var(--line); border-radius: 13px; padding: 12px; background: white; color: var(--text); outline: none;
}
.field textarea { min-height: 110px; resize: vertical; line-height: 1.6; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--primary-2); box-shadow: 0 0 0 3px rgba(82,119,102,.12); }
.form-actions { display: grid; grid-template-columns: 1fr 1.7fr; gap: 9px; margin-top: 7px; }

.settings-grid { display: grid; gap: 12px; }
.setting-row { display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.setting-row .text strong { display: block; margin-bottom: 4px; }
.setting-row .text small { color: var(--muted); line-height: 1.5; }
.notice { padding: 13px; border-radius: 14px; background: #fff3d9; color: #6f561d; font-size: 13px; line-height: 1.6; }
.file-input { display: none; }

.toast { position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); z-index: 80; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: #1f3028; color: white; padding: 11px 14px; border-radius: 999px; font-size: 13px; box-shadow: var(--shadow); transition: .22s ease; white-space: nowrap; max-width: 90vw; overflow: hidden; text-overflow: ellipsis; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 720px) {
  .modal-backdrop { align-items: center; padding: 24px; }
  .modal { border-radius: 24px; max-height: 88dvh; }
  main { padding-top: 24px; }
}
