/* ---- Theme tokens (light default; dark via system or [data-theme]) ---- */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1a1d23;
  --muted: #626b7a;
  --border: #e2e6ec;
  --accent: #4f6bed;
  --accent-contrast: #ffffff;
  --danger: #c0392b;
  --warn-bg: #fff6e6;
  --warn-text: #8a6100;
  --shadow: 0 6px 24px rgba(20, 25, 40, 0.10);
  --radius: 14px;
  --maxw: 760px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --text: #e7eaf0;
    --muted: #9aa4b2;
    --border: #2a2f3a;
    --accent: #7f95ff;
    --accent-contrast: #0f1115;
    --danger: #ff6b5e;
    --warn-bg: #2a2410;
    --warn-text: #e8c877;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --text: #e7eaf0;
  --muted: #9aa4b2;
  --border: #2a2f3a;
  --accent: #7f95ff;
  --accent-contrast: #0f1115;
  --danger: #ff6b5e;
  --warn-bg: #2a2410;
  --warn-text: #e8c877;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---- Buttons / inputs ---- */
button { font: inherit; cursor: pointer; }
.primary {
  background: var(--accent); color: var(--accent-contrast);
  border: none; border-radius: 10px; padding: 9px 16px; font-weight: 600;
}
.primary:active { transform: translateY(1px); }
.icon-btn {
  background: transparent; border: none; font-size: 18px; padding: 6px 8px;
  border-radius: 8px; color: var(--text);
}
.icon-btn:hover { background: var(--surface-2); }
.link-btn { background: none; border: none; color: var(--accent); padding: 6px 4px; font-weight: 600; }
.link-btn.danger { color: var(--danger); }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---- Lock screen ---- */
.lock { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.lock-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 28px 24px; box-shadow: var(--shadow);
}
.brand { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.brand-mark { color: var(--accent); }
.lock-form { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.lock-form label { font-size: 13px; color: var(--muted); font-weight: 600; }
.error { color: var(--danger); font-size: 14px; min-height: 1.2em; margin: 4px 0 0; }
.warn { background: var(--warn-bg); color: var(--warn-text); padding: 10px 12px; border-radius: 10px; font-size: 13px; }

/* ---- App bar ---- */
.app { min-height: 100dvh; }
.appbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center;
  justify-content: space-between; gap: 8px; padding: 10px 14px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.appbar-left { display: flex; align-items: center; gap: 8px; font-size: 18px; }
.appbar-right { display: flex; align-items: center; gap: 2px; }
.new-btn { margin-left: 6px; }

.netbanner { text-align: center; padding: 6px; font-size: 13px; background: var(--warn-bg); color: var(--warn-text); }

.filterbar { max-width: var(--maxw); margin: 10px auto 0; padding: 0 14px; display: flex; flex-direction: column; gap: 8px; }
.tag-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 4px 10px; border-radius: 999px; font-size: 13px;
}
.chip.active { background: var(--accent); color: var(--accent-contrast); border-color: transparent; }

/* ---- Timeline ---- */
.main { max-width: var(--maxw); margin: 0 auto; padding: 14px; }
.section-label { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 18px 4px 8px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 12px; box-shadow: var(--shadow); cursor: pointer;
}
.card:hover { border-color: var(--accent); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-date { font-weight: 700; }
.card-time { color: var(--muted); font-size: 13px; }
.card-title { font-weight: 600; margin: 6px 0 2px; }
.card-excerpt { color: var(--muted); font-size: 14px; }
.card-foot { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.card-mood { font-size: 18px; }
.tag { font-size: 12px; color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); padding: 2px 8px; border-radius: 999px; }
.card-thumb { width: 100%; max-height: 220px; object-fit: cover; border-radius: 10px; margin-top: 10px; }
.thumb-count { font-size: 12px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }

/* ---- Calendar heatmap ---- */
.calendar { max-width: var(--maxw); margin: 0 auto; padding: 14px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-cell { aspect-ratio: 1; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; font-size: 12px; color: var(--muted); border: 1px solid transparent; }
.cal-cell.dow { background: transparent; font-weight: 700; }
.cal-cell.has { color: var(--accent-contrast); cursor: pointer; border-color: var(--border); }
.cal-cell.today { outline: 2px solid var(--accent); }

/* ---- Dialogs (editor / viewer / menus) ---- */
dialog { border: none; border-radius: 16px; padding: 0; color: var(--text); background: var(--surface); box-shadow: var(--shadow); max-width: 100%; }
dialog::backdrop { background: rgba(0,0,0,0.5); }
.sheet { width: min(680px, 96vw); max-height: 92dvh; overflow: auto; }
.sheet-head { position: sticky; top: 0; background: var(--surface); display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); font-weight: 600; }
#editor-form { display: flex; flex-direction: column; }
.mood-row { display: flex; gap: 4px; flex-wrap: wrap; padding: 10px 16px 0; }
.mood-btn { font-size: 22px; background: none; border: 1px solid transparent; border-radius: 10px; padding: 4px 6px; }
.mood-btn.active { border-color: var(--accent); background: var(--surface-2); }
.entry-title { border: none; border-bottom: 1px solid var(--border); border-radius: 0; font-size: 18px; font-weight: 700; padding: 14px 16px; background: var(--surface); }
.entry-title:focus { outline: none; border-bottom-color: var(--accent); }
#entry-content { border: none; border-radius: 0; min-height: 36dvh; resize: vertical; padding: 14px 16px; background: var(--surface); }
#entry-content:focus { outline: none; }
.editor-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 0 16px 6px; }
.editor-tags-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.viewer-title { margin: 6px 0 2px; line-height: 1.25; }
.editor-thumbs { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 16px; }
.editor-thumb { position: relative; }
.editor-thumb img { width: 76px; height: 76px; object-fit: cover; border-radius: 10px; }
.editor-thumb button { position: absolute; top: -6px; right: -6px; background: var(--danger); color: #fff; border: none; border-radius: 999px; width: 22px; height: 22px; font-size: 13px; }
.editor-actions { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; }
.file-label { cursor: pointer; }

.viewer-body { padding: 8px 20px 24px; }
.viewer-body img.photo { width: 100%; border-radius: 12px; margin: 10px 0; }
.viewer-body h1, .viewer-body h2, .viewer-body h3 { line-height: 1.25; }
.viewer-body blockquote { border-left: 3px solid var(--accent); margin: 10px 0; padding: 2px 14px; color: var(--muted); }
.viewer-body pre { background: var(--surface-2); padding: 12px; border-radius: 10px; overflow: auto; }
.viewer-body code { background: var(--surface-2); padding: 1px 5px; border-radius: 6px; font-size: .92em; }
.viewer-meta { color: var(--muted); font-size: 13px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 4px 0 10px; }

.menu { width: min(340px, 92vw); }
.menu-list { display: flex; flex-direction: column; padding: 8px; }
.menu-item { text-align: left; background: none; border: none; color: var(--text); padding: 13px 14px; border-radius: 10px; font-size: 15px; }
.menu-item:hover { background: var(--surface-2); }
.menu-item.close { color: var(--muted); border-top: 1px solid var(--border); border-radius: 0; margin-top: 6px; }
.row-gap { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

.trash-body { padding: 8px 16px 20px; }
.trash-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px; border-bottom: 1px solid var(--border); }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 14px; box-shadow: var(--shadow); z-index: 50; max-width: 90vw;
}

@media (max-width: 520px) {
  .new-btn { padding: 8px 12px; }
  .appbar strong { display: none; }
}
