:root {
  --bg: #f6f6f4; --panel: #ffffff; --panel-2: #f0f0ee; --text: #1c1c1e; --muted: #8a8a8e;
  --line: #e2e2df; --accent: #d9a441; --accent-soft: #fbeecb; --danger: #d9534f;
  --list-w: 340px; --side-w: 250px; --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN",
          "Noto Sans JP", "Yu Gothic", Meiryo, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg:#0f1114; --panel:#171a1f; --panel-2:#1e2228; --text:#e8e8ea; --muted:#8b9099;
    --line:#272b31; --accent:#e0b458; --accent-soft:#2a2a20; --danger:#e06b67; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text);
  font-size: 15px; line-height: 1.6; overscroll-behavior: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; color: var(--text); }

/* ---------- Auth gate ---------- */
.gate { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 50; padding: 1rem; }
.gate-card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 2rem 1.6rem; width: 100%; max-width: 340px; text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,.12); display: flex; flex-direction: column; gap: .7rem; }
.gate-logo { font-size: 2.4rem; }
.gate-card h1 { margin: 0; font-size: 1.3rem; }
.gate-card input { padding: .7rem .8rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel-2); font-size: 1rem; }
.gate-card button { padding: .7rem; border: none; border-radius: 10px; background: var(--accent);
  color: #1c1400; font-weight: 700; font-size: 1rem; }
.gate-err { color: var(--danger); font-size: .85rem; min-height: 1.1em; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: var(--side-w) var(--list-w) 1fr; height: 100dvh; }
.sidebar { background: var(--panel-2); border-right: 1px solid var(--line); display: flex;
  flex-direction: column; min-height: 0; padding-top: env(safe-area-inset-top); }
.list-pane { background: var(--panel); border-right: 1px solid var(--line); display: flex;
  flex-direction: column; min-height: 0; }
.editor-pane { background: var(--panel); display: flex; flex-direction: column; min-height: 0; }

/* ---------- Sidebar ---------- */
.side-head { display: flex; align-items: center; justify-content: space-between; padding: .9rem 1rem .4rem; }
.brand { font-weight: 700; font-size: 1.05rem; }
.search-wrap { padding: .3rem 1rem .6rem; }
#search { width: 100%; padding: .5rem .7rem; border: 1px solid var(--line); border-radius: 9px;
  background: var(--panel); font-size: .95rem; }
.views { display: flex; flex-direction: column; padding: .2rem .6rem; gap: 1px; }
.view-btn { text-align: left; background: none; border: none; color: var(--text);
  padding: .5rem .6rem; border-radius: 8px; font-size: .95rem; }
.view-btn.active { background: var(--accent-soft); font-weight: 600; }
.view-btn:hover { background: var(--panel); }
.side-section { padding: .5rem .6rem; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.side-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  padding: .3rem .6rem; }
.chips-col { overflow-y: auto; display: flex; flex-direction: column; gap: 1px; }
.chip { text-align: left; background: none; border: none; color: var(--text); padding: .35rem .6rem;
  border-radius: 7px; font-size: .88rem; display: flex; justify-content: space-between; gap: .5rem; }
.chip:hover { background: var(--panel); }
.chip.active { background: var(--accent-soft); font-weight: 600; }
.chip .c { color: var(--muted); font-size: .78rem; }
.side-foot { margin-top: auto; padding: .6rem 1rem; border-top: 1px solid var(--line); display: flex; gap: 1rem; }
.text-btn { background: none; border: none; color: var(--muted); font-size: .82rem; padding: .2rem 0; }
.text-btn:hover { color: var(--text); }

/* ---------- Panes ---------- */
.pane-head { display: flex; align-items: center; gap: .5rem; padding: .7rem .9rem; border-bottom: 1px solid var(--line);
  min-height: 52px; padding-top: max(.7rem, env(safe-area-inset-top)); }
.pane-title { font-weight: 700; }
.count { color: var(--muted); font-size: .8rem; }
.icon-btn { background: none; border: none; font-size: 1.15rem; color: var(--text); width: 34px; height: 34px;
  border-radius: 8px; display: grid; place-items: center; }
.icon-btn:hover { background: var(--panel-2); }

/* ---------- List ---------- */
.list { overflow-y: auto; flex: 1; }
.item { padding: .7rem .9rem; border-bottom: 1px solid var(--line); cursor: pointer; }
.item:hover { background: var(--panel-2); }
.item.active { background: var(--accent-soft); }
.item-title { font-weight: 600; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { color: var(--muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.item-meta { display: flex; gap: .5rem; align-items: center; margin-top: 4px; font-size: .72rem; color: var(--muted); }
.item-folder { background: var(--panel-2); padding: 0 .4rem; border-radius: 5px; }
.empty-note { padding: 2rem 1rem; text-align: center; color: var(--muted); }

/* ---------- Editor ---------- */
.ed-actions { display: flex; gap: .1rem; align-items: center; margin-left: auto; }
.save-state { font-size: .74rem; color: var(--muted); min-width: 3.4em; text-align: right; }
.editor { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: .8rem 1.1rem 0; }
.editor-empty { flex: 1; display: grid; place-items: center; color: var(--muted); }
.ed-title { border: none; background: none; font-size: 1.3rem; font-weight: 700; padding: .3rem 0; outline: none; }
.ed-meta { display: flex; gap: .5rem; padding: .3rem 0 .5rem; border-bottom: 1px solid var(--line); }
.ed-folder { border: 1px solid var(--line); background: var(--panel-2); border-radius: 7px; padding: .25rem .4rem; font-size: .82rem; max-width: 50%; }
.ed-tags { flex: 1; border: none; background: none; font-size: .85rem; outline: none; color: var(--accent); }
.ed-body { flex: 1; border: none; background: none; resize: none; outline: none; font-size: 1rem;
  line-height: 1.75; padding: .8rem 0; min-height: 0; }
.ed-preview { flex: 1; overflow-y: auto; padding: .8rem 0; min-height: 0; }

/* Markdown preview */
.ed-preview h1,.ed-preview h2,.ed-preview h3 { line-height: 1.35; margin: 1rem 0 .4rem; }
.ed-preview h1 { font-size: 1.4rem; } .ed-preview h2 { font-size: 1.2rem; } .ed-preview h3 { font-size: 1.05rem; }
.ed-preview p { margin: .5rem 0; } .ed-preview ul,.ed-preview ol { padding-left: 1.3rem; margin: .4rem 0; }
.ed-preview code { background: var(--panel-2); padding: .1rem .35rem; border-radius: 5px; font-size: .9em; }
.ed-preview pre { background: var(--panel-2); padding: .7rem; border-radius: 8px; overflow-x: auto; }
.ed-preview blockquote { border-left: 3px solid var(--accent); margin: .5rem 0; padding: .1rem .8rem; color: var(--muted); }
.ed-preview a { color: var(--accent); }
.ed-preview .task { list-style: none; margin-left: -1.3rem; }
.ed-preview hr { border: none; border-top: 1px solid var(--line); margin: 1rem 0; }

/* ---------- Responsive ---------- */
.only-mobile { display: none; }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 30; width: 82%; max-width: 300px; height: 100dvh;
    transform: translateX(-100%); transition: transform .22s ease; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .app.show-side .sidebar { transform: translateX(0); }
  .app.show-side::after { content: ''; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; }
  .list-pane { grid-column: 1; }
  .editor-pane { position: fixed; inset: 0; z-index: 25; transform: translateX(100%);
    transition: transform .22s ease; }
  .app.show-editor .editor-pane { transform: translateX(0); }
  .only-mobile { display: grid; }
}
