/* ============================================================
   Journal — "Nocturne." A dim, lamp-lit writing room.
   Spectral for writing, Hanken Grotesk for furniture,
   one restrained brass. The canvas warms with the hour
   (see --canvas, set by app.js).
   ============================================================ */

:root {
  --canvas:   #16130E;   /* page bg — overridden by time of day in JS */
  --paper:    var(--canvas);
  --surface:  #1F1B14;   /* lifted card / active / input */
  --surface-2:#120F0A;   /* recessed sidebar */
  --ink:      #ECE6D9;   /* warm off-white — primary text */
  --ink-soft: #B4AB99;
  --ink-faint:#7C7565;   /* placeholders */
  --muted:    #8C8473;
  --hairline: #2B261D;
  --hairline-2:#211D16;
  --accent:   #C49A5E;   /* muted brass — used sparingly */
  --accent-2: rgba(196, 154, 94, 0.14);  /* brass wash */
  --danger:   #CF6E55;

  --serif: "Spectral", Georgia, "Times New Roman", serif;
  --sans: "Hanken Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --measure: 38rem;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); }

button {
  font-family: var(--sans);
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.kicker {
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}

.hidden { display: none !important; }

/* small utilities (kept out of inline styles so the CSP can stay strict) */
.kicker-muted { color: var(--muted); }
.signin-back { width: 100%; margin-top: 1.2rem; }
.lock-label { vertical-align: 2px; }

/* ---- buttons ---- */

.btn {
  font-family: var(--sans);
  font-size: 0.92rem;
  font-weight: 500;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  padding: 0.7rem 1.25rem;
  border-radius: var(--radius);
  transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.btn:hover { opacity: 0.88; }
.btn:disabled { opacity: 0.45; cursor: default; }

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--hairline);
}
.btn-ghost:hover { background: var(--surface-2); opacity: 1; color: var(--ink); }

.btn-text {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 0.85rem;
  padding: 0.35rem 0.5rem;
}
.btn-text:hover { color: var(--ink); }
.btn-text.danger:hover { color: var(--danger); }

/* ============================================================
   Sign-in
   ============================================================ */

.signin {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 2rem 1.5rem;
}

.signin-inner {
  width: 100%;
  max-width: 26rem;
  animation: rise 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.signin h1 {
  font-family: var(--serif);
  font-optical-sizing: auto;
  font-weight: 500;
  font-size: clamp(2.3rem, 7vw, 3.1rem);
  line-height: 1.04;
  letter-spacing: -0.01em;
  margin: 0.75rem 0 0.85rem;
}
.signin h1 em {
  font-style: italic;
  color: var(--accent);
}

.signin .lead {
  color: var(--ink-soft);
  font-size: 1.02rem;
  margin: 0 0 2rem;
  max-width: 24rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.field label {
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
}

.input {
  font-family: var(--sans);
  font-size: 1rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 0.8rem 0.95rem;
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input::placeholder { color: var(--ink-faint); }
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-2);
}

.signin .btn { width: 100%; margin-top: 1.1rem; }

.note {
  margin-top: 1.6rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--hairline);
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.5;
}
.note svg { flex-shrink: 0; margin-top: 0.1rem; color: var(--accent); }

.sent {
  border: 1px solid var(--hairline);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.4rem 1.5rem;
  margin-top: 1.2rem;
  box-shadow: var(--shadow);
}
.sent h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.3rem;
  margin: 0.3rem 0 0.5rem;
}
.sent p { color: var(--ink-soft); margin: 0 0 0.4rem; font-size: 0.92rem; }
.sent code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  padding: 0.1rem 0.4rem;
  border-radius: 5px;
}
.form-error { color: var(--danger); font-size: 0.85rem; margin-top: 0.7rem; min-height: 1rem; }

/* ============================================================
   App shell
   ============================================================ */

.app {
  display: grid;
  grid-template-columns: 19rem 1fr;
  height: 100%;
}

/* ---- sidebar ---- */

.sidebar {
  border-right: 1px solid var(--hairline);
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.brand {
  padding: 1.4rem 1.4rem 1.1rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}
.brand .mark {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.35rem;
  letter-spacing: -0.01em;
}
.brand .mark .dot { color: var(--accent); }

.sidebar-actions {
  padding: 0 1.4rem 1rem;
}
.new-entry {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  justify-content: center;
  font-size: 0.9rem;
}
.new-entry svg { width: 16px; height: 16px; }

.entry-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.3rem 0.8rem 1rem;
  min-height: 0;
}

.list-empty {
  color: var(--muted);
  font-size: 0.88rem;
  padding: 1.5rem 0.6rem;
  text-align: center;
  line-height: 1.6;
}

.entry-item {
  position: relative;
  border-radius: 8px;
  margin-bottom: 0.1rem;
  transition: background 0.12s ease;
}
.entry-item:hover { background: var(--surface); }
.entry-item.active { background: var(--surface); box-shadow: inset 2px 0 0 var(--accent); }

.entry-open {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: 8px;
  padding: 0.7rem 2rem 0.7rem 0.7rem; /* room for the trash icon */
}

.entry-del {
  position: absolute;
  top: 50%;
  right: 0.45rem;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.12s ease, color 0.12s ease, background 0.12s ease;
}
.entry-item:hover .entry-del,
.entry-del:focus-visible { opacity: 1; }
.entry-del:hover { color: var(--danger); background: rgba(207, 110, 85, 0.13); }

.entry-item .it-title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1rem;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.entry-item .it-meta {
  font-family: var(--sans);
  font-size: 0.74rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.sidebar-foot {
  border-top: 1px solid var(--hairline);
  padding: 0.9rem 1.4rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.45rem;
}
.sidebar-foot .who {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.foot-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.foot-actions .btn-text { text-decoration: none; }

/* ---- editor ---- */

.editor {
  min-height: 0;
  overflow-y: auto;
  /* a faint lamp casting from above the page */
  background:
    radial-gradient(130% 55% at 50% -8%, rgba(196, 154, 94, 0.06), transparent 62%),
    var(--paper);
  display: flex;
  flex-direction: column;
}

.editor-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(6px);
  z-index: 2;
}
.editor-bar .back { display: none; }
.save-state {
  font-family: var(--sans);
  font-size: 0.76rem;
  letter-spacing: 0.04em;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.save-state .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted); transition: background 0.2s ease;
}
.save-state.saved .dot { background: #6f9c6a; }
.save-state.saving .dot { background: var(--accent); }

.editor-body {
  flex: 1;
  width: 100%;
  max-width: calc(var(--measure) + 4rem);
  margin: 0 auto;
  padding: 1.5rem 2rem 5rem;
}

.entry-date {
  margin-bottom: 1rem;
}

.title-input {
  font-family: var(--serif);
  font-optical-sizing: auto;
  font-weight: 500;
  font-size: clamp(1.9rem, 4.5vw, 2.6rem);
  line-height: 1.1;
  letter-spacing: -0.015em;
  color: var(--ink);
  width: 100%;
  border: none;
  background: none;
  resize: none;
  padding: 0;
  margin-bottom: 1.1rem;
}
.title-input:focus { outline: none; }
.title-input::placeholder { color: var(--ink-faint); }

.divider {
  border: none;
  border-top: 1px solid var(--hairline);
  margin: 0 0 1.4rem;
  width: 3rem;
  border-top-color: var(--accent);
  opacity: 0.7;
}

.body-input {
  font-family: var(--serif);
  font-optical-sizing: auto;
  font-weight: 400;
  font-size: 1.18rem;
  line-height: 1.72;
  color: var(--ink);
  width: 100%;
  min-height: 50vh;
  border: none;
  background: none;
  resize: none;
  padding: 0;
}
.body-input:focus { outline: none; }
.body-input::placeholder { color: var(--ink-faint); font-style: italic; }

.editor-foot {
  max-width: calc(var(--measure) + 4rem);
  margin: 0 auto;
  width: 100%;
  padding: 0 2rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.78rem;
}

/* ---- reflection agent ---- */

.reflect {
  margin-top: 2.75rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--hairline);
}
.reflect-btn { padding-left: 0; }
.reflect-btn:disabled { opacity: 0.4; cursor: default; }
.reflect-hint {
  font-family: var(--sans);
  font-size: 0.76rem;
  color: var(--muted);
  margin-left: 0.55rem;
}

.reflect-note {
  margin-top: 1.3rem;
  padding-left: 1.1rem;
  border-left: 2px solid var(--accent);
  animation: rise 0.45s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
.reflect-note .kicker { display: block; margin-bottom: 0.5rem; }
.reflect-q {
  font-family: var(--serif);
  font-optical-sizing: auto;
  font-style: italic;
  font-weight: 400;
  font-size: 1.3rem;
  line-height: 1.5;
  color: var(--ink);
  margin: 0;
}
.reflect-loading {
  font-family: var(--sans);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0;
}
.reflect-error {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0;
}

/* ---- empty editor state ---- */
.editor-empty {
  flex: 1;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 2rem;
}
.editor-empty .inner { max-width: 22rem; }
.editor-empty h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.7rem;
  margin: 0.6rem 0 0.5rem;
}
.editor-empty p { color: var(--ink-soft); margin: 0 0 1.3rem; }

/* ============================================================
   Motion / responsive
   ============================================================ */

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .app[data-view="editor"] .sidebar { display: none; }
  .app[data-view="list"] .editor { display: none; }
  .editor-bar .back { display: inline-flex; }
  /* No hover on touch — keep the delete affordance visible. */
  .entry-del { opacity: 0.55; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
