:root {
  --bg: #0f1115;
  --fg: #e8e8ea;
  --muted: #7a7f8a;
  --accent: #ff4d4d;
  --panel: #171a21;
  --border: #262a33;

  --font-ui:     'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-editor: 'Literata', Georgia, 'Times New Roman', serif;

  --editor-width: 680px;
  --active-line-top: 65vh;
  --topbar-h: 56px;

  --fade-dur: 300ms;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

/* ---------- Top bar ---------- */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: rgba(15, 17, 21, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 30;
  opacity: 1;
  transition: opacity var(--fade-dur) ease;
}
body.writing .topbar { opacity: 0; pointer-events: none; }
.topbar-spacer { flex: 1; }

#sidebar-toggle {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
#sidebar-toggle:hover { background: var(--panel); border-color: #3a4050; }
#sidebar-toggle .hamburger,
#sidebar-toggle .hamburger::before,
#sidebar-toggle .hamburger::after {
  display: block;
  width: 16px;
  height: 2px;
  background: var(--fg);
  border-radius: 1px;
  position: relative;
}
#sidebar-toggle .hamburger::before,
#sidebar-toggle .hamburger::after {
  content: '';
  position: absolute;
  left: 0;
}
#sidebar-toggle .hamburger::before { top: -5px; }
#sidebar-toggle .hamburger::after  { top:  5px; }

.nav-switcher {
  display: flex;
  gap: 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 2px;
}
.nav-link {
  color: var(--muted);
  text-decoration: none;
  transition: color .15s;
}
.nav-link:hover { color: var(--fg); }
.nav-link.nav-current { color: var(--fg); }
.nav-sep { color: var(--border); }

/* ---------- Sidebar ---------- */
#sidebar {
  position: fixed;
  top: var(--topbar-h);
  bottom: 0;
  left: 0;
  width: 300px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 20px;
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform .22s ease;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
body.sidebar-open #sidebar { transform: translateX(0); }
body.writing #sidebar { transform: translateX(-100%); }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.sidebar-header h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
  font-weight: 600;
  margin: 0;
}
.sidebar-empty {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  text-align: center;
  margin: 20px 0 0;
}

.session-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: var(--font-ui);
  font-size: 13px;
}
.session-list li {
  padding: 10px 14px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.session-list li:hover { border-color: #3a4050; background: var(--panel); }
.session-list .session-preview {
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-list .session-meta {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-variant-numeric: tabular-nums;
}

/* ---------- Editor layout ---------- */
#editor-main {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

/*
 * The wrapper pins its bottom edge so that #active (the typing area)
 * sits at --active-line-top from the top of the viewport.
 * Committed paragraphs stack above it via flex-direction: column +
 * justify-content: flex-end.
 */
#editor-wrapper {
  position: absolute;
  bottom: calc(100vh - var(--active-line-top));
  left: 50%;
  transform: translateX(-50%);
  max-width: var(--editor-width);
  width: 100%;
  padding: 0 40px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

#committed .para {
  font-family: var(--font-editor);
  font-size: 21px;
  line-height: 1.8;
  color: var(--fg);
  white-space: pre-wrap;
  word-wrap: break-word;
  transition: opacity var(--fade-dur) ease;
}

#active {
  font-family: var(--font-editor);
  font-size: 21px;
  line-height: 1.8;
  color: var(--fg);
  outline: none;
  caret-color: var(--accent);
  white-space: pre-wrap;
  word-wrap: break-word;
  min-height: 1.8em;
}

/* Paragraph fade classes */
.fade-0, .fade-1 { opacity: 1; }
.fade-2 { opacity: 0.40; }
.fade-3 { opacity: 0.15; }
.fade-4 { opacity: 0; }

/* ---------- Placeholder ---------- */
.editor-placeholder {
  position: fixed;
  top: var(--active-line-top);
  left: 50%;
  transform: translate(-50%, -100%);
  max-width: var(--editor-width);
  width: 100%;
  padding: 0 40px;
  color: var(--muted);
  font-family: var(--font-editor);
  font-size: 21px;
  line-height: 1.8;
  pointer-events: none;
  opacity: 1;
  transition: opacity var(--fade-dur) ease;
  display: flex;
  align-items: center;
  z-index: 10;
}
body.writing .editor-placeholder { opacity: 0; }

.placeholder-cursor {
  display: inline-block;
  width: 2px;
  height: 1.2em;
  background: var(--accent);
  margin-right: 2px;
  animation: blink 1s step-end infinite;
}
@keyframes blink {
  50% { opacity: 0; }
}

/* ---------- Done button ---------- */
#done-btn {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  background: transparent;
  border: none;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 2px;
  cursor: pointer;
  padding: 8px 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 400ms ease, color .15s;
}
#done-btn.visible { opacity: 0.6; pointer-events: auto; }
#done-btn.visible:hover { color: var(--fg); opacity: 1 !important; }
body.done #done-btn { display: none; }

/* ---------- Done view ---------- */
#done-view {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 30;
}
.done-actions {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  background: rgba(15, 17, 21, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  pointer-events: auto;
}
.done-actions button {
  background: transparent;
  border: none;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  padding: 8px 14px;
  cursor: pointer;
  border-radius: 4px;
  transition: color .15s, background .15s;
}
.done-actions button:hover {
  color: var(--fg);
  background: var(--panel);
}

/* ---------- Brand logo ---------- */
.brand-logo {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 50;
  opacity: 0.3;
  transition: opacity .2s;
}
.brand-logo:hover { opacity: 0.7; }
.brand-logo img { display: block; }

/* ---------- Done state ---------- */
body.done #editor-main { overflow-y: auto; }
body.done #editor-wrapper {
  position: relative;
  bottom: auto;
  left: auto;
  transform: none;
  margin: 0 auto;
  padding: 80px 40px 200px;
}
body.done #committed .para { opacity: 1 !important; }
body.done #active { display: none; }
body.done .editor-placeholder { display: none; }
