*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #F9F8F6;
  --ink: #111111;
  --muted: #888888;
  --border: #E2E0DC;
  --surface: #FFFFFF;
  --radius: 10px;
  --max-w: 660px;
  --sidebar-w: 220px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Satoshi', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden; /* page-level scroll disabled; scroll lives inside .main-inner */
}

/* ── Screens ─────────────────────────────────────────── */
.screen {
  display: none;
  height: 100vh;
  height: 100dvh;
}
.screen.active { display: flex; }

/* ── Lock screen ──────────────────────────────────────── */
#lock-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.card-sub {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 28px;
  line-height: 1.5;
}

label {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 7px;
}

input[type="password"],
input[type="text"] {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s;
  margin-bottom: 20px;
}
input:focus { border-color: var(--ink); }
input.error { border-color: #c0392b; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 20px;
  border: 1px solid var(--ink);
  border-radius: 7px;
  background: var(--ink);
  color: #fff;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
  width: 100%;
}
.btn:hover { opacity: 0.82; }
.btn:disabled { opacity: 0.4; cursor: default; }

.error-msg {
  font-size: 0.82rem;
  color: #c0392b;
  margin-top: -14px;
  margin-bottom: 16px;
  display: none;
}
.error-msg.visible { display: block; }

.file-warn {
  font-size: 0.82rem;
  color: #7a5c00;
  background: #fffbe6;
  border: 1px solid #f0d060;
  border-radius: 7px;
  padding: 14px 16px;
  margin-bottom: 24px;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.file-warn svg { flex-shrink: 0; margin-bottom: 4px; }
.file-warn code {
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 0.8rem;
  background: rgba(0,0,0,0.06);
  padding: 2px 5px;
  border-radius: 4px;
}

/* ── Journal screen ───────────────────────────────────── */
#journal-screen {
  flex-direction: row;
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sidebar-logo {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.lock-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 8px;
  margin: -8px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  min-height: 36px;
  transition: color 0.15s, background 0.15s;
}
.lock-btn:hover { color: var(--ink); background: var(--bg); }

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
  min-height: 0;
}
.sidebar-list::-webkit-scrollbar { width: 4px; }
.sidebar-list::-webkit-scrollbar-track { background: transparent; }
.sidebar-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.date-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--muted);
  transition: background 0.1s, color 0.1s;
  border-left: 2px solid transparent;
  user-select: none;
}
.date-item:hover { background: var(--bg); color: var(--ink); }
.date-item.active {
  background: var(--bg);
  color: var(--ink);
  border-left-color: var(--ink);
  font-weight: 500;
}
.date-item .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
}
.date-item.has-content .dot { background: var(--ink); }

.new-entry-btn {
  margin: 12px 16px 16px;
  padding: 10px 14px;
  border: 1px dashed var(--border);
  border-radius: 7px;
  background: none;
  font-family: inherit;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  text-align: center;
  flex-shrink: 0;
}
.new-entry-btn:hover { border-color: var(--ink); color: var(--ink); }

/* ── Main ─────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;      /* prevent flex blowout on narrow screens */
  min-height: 0;
  overflow: hidden;
}

.main-inner {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  max-width: var(--max-w);
  width: 100%;
  margin: 0 auto;
  padding: 52px 40px 40px;
  /* scroll padding so focused textarea isn't hidden under toolbar */
  scroll-padding-bottom: 80px;
}

.main-inner::-webkit-scrollbar { width: 4px; }
.main-inner::-webkit-scrollbar-track { background: transparent; }
.main-inner::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.entry-date {
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.entry-heading {
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 44px;
  line-height: 1.2;
}

.section { margin-bottom: 36px; }

.section-label {
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

.section textarea {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.75;
  color: var(--ink);
  resize: none;
  outline: none;
  overflow: hidden;
  padding: 0 0 10px;
  transition: border-color 0.15s;
  min-height: 44px;
  /* prevent iOS zoom on focus */
  font-size: max(1rem, 16px);
}
.section textarea:focus { border-bottom-color: var(--ink); }
.section textarea::placeholder { color: var(--border); }

/* ── Toolbar ──────────────────────────────────────────── */
.toolbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 40px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.toolbar-status {
  font-size: 0.8rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.toolbar-status .dot-status {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.toolbar-status.saved .dot-status { background: #2ecc71; }
.toolbar-status.saving .dot-status { background: #f39c12; }
.toolbar-status.error .dot-status { background: #e74c3c; }

.save-btn { padding: 9px 20px; font-size: 0.85rem; width: auto; flex-shrink: 0; }

/* ── Mobile header (hidden on desktop) ───────────────── */
.mobile-header { display: none; }

/* ── Overlay ──────────────────────────────────────────── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 90;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.overlay.visible { display: block; }

/* ── Spinner ──────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* ── Dirty / autosave pulse ───────────────────────────── */
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.35; transform: scale(0.7); }
}
.toolbar-status.dirty .dot-status {
  background: var(--muted);
  animation: pulse-dot 1.4s ease-in-out infinite;
}

/* ── Search ───────────────────────────────────────────── */
.search-wrap {
  position: relative;
  margin: 12px 16px 6px;
  flex-shrink: 0;
}
.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.search-wrap input {
  width: 100%;
  padding: 8px 10px 8px 30px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  font-family: inherit;
  font-size: 0.82rem;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s;
  margin-bottom: 0;
}
.search-wrap input:focus { border-color: var(--ink); }
.search-wrap input::placeholder { color: var(--muted); }

.search-status {
  padding: 12px 20px;
  font-size: 0.82rem;
  color: var(--muted);
}

.search-result-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.search-result-date {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-result-snippet {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.search-result-snippet mark {
  background: #f5e642;
  color: var(--ink);
  border-radius: 2px;
  padding: 0 1px;
}

/* ── Tablet (≤ 900px) ─────────────────────────────────── */
@media (max-width: 900px) {
  :root { --sidebar-w: 190px; }
  .main-inner { padding: 40px 28px 40px; }
  .toolbar { padding: 12px 28px; }
}

/* ── Mobile (≤ 640px) ─────────────────────────────────── */
@media (max-width: 640px) {
  body { overflow: hidden; }

  /* Sidebar becomes a full-screen drawer */
  .sidebar {
    position: fixed;
    inset: 0;
    width: 100%;
    min-width: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex; /* always in DOM, just off-screen */
  }
  .sidebar.open { transform: translateX(0); }

  #journal-screen { flex-direction: column; }

  /* Mobile top bar */
  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: 52px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
    position: relative;
    z-index: 10;
  }

  .mobile-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .menu-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--ink);
    padding: 8px;
    margin: -8px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    border-radius: 6px;
  }

  .mobile-logo {
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: -0.02em;
  }

  /* Increase lock-btn touch target on mobile */
  .lock-btn {
    min-width: 44px;
    min-height: 44px;
    margin: -10px;
    padding: 10px;
  }

  .main-inner {
    padding: 24px 20px 24px;
    /* prevent content from scrolling under toolbar */
    scroll-padding-bottom: 70px;
  }

  .entry-heading { font-size: 1.45rem; margin-bottom: 32px; }

  .toolbar {
    padding: 10px 16px;
    gap: 10px;
  }

  .card { padding: 28px 20px; }

  /* Remove double scrollbar: only main-inner scrolls */
  .main { overflow: hidden; }
}

/* ── Very small screens (≤ 380px) ────────────────────── */
@media (max-width: 380px) {
  .card { padding: 24px 16px; }
  .main-inner { padding: 20px 16px 20px; }
  .entry-heading { font-size: 1.25rem; }
  .toolbar { padding: 10px 12px; }
}
