/* ── Variables ── */
:root {
  --bg:      #0f0f0f;
  --surface: #161616;
  --border:  #2a2a2a;
  --text:    #e8e8e0;
  --muted:   #666660;
  --accent:  #d4a843;
  --danger:  #d94f4f;
  --accent2: #5cb890;
  --mono:    ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --sans:    system-ui, -apple-system, sans-serif;
  --anim:    0.18s cubic-bezier(0.4,0,0.2,1);
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ════════════════ AUTH ════════════════ */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100dvh;
}

.auth-box {
  width: 360px;
  background: var(--surface);
  border: 2px solid var(--border);
  padding: 40px 36px 36px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.auth-box h1 {
  font-family: var(--sans);
  font-size: 28px;
  color: var(--accent);
  letter-spacing: -0.04em;
  line-height: 1;
  font-weight: 800;
  text-transform: uppercase;
}

.auth-box .auth-sub {
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-top: -10px;
}

.auth-field { display: flex; flex-direction: column; gap: 5px; }

.auth-field label {
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.auth-field input {
  background: #0f0f0f;
  border: 2px solid var(--border);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  padding: 9px 12px;
  outline: none;
  transition: border-color var(--anim);
  caret-color: var(--accent);
}
.auth-field input:focus { border-color: var(--accent); }

.auth-btn {
  padding: 11px;
  background: var(--accent);
  color: #0f0f0f;
  border: none;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: opacity var(--anim);
}
.auth-btn:hover { opacity: 0.85; }

.auth-error { font-size: 11px; color: var(--danger); text-align: center; min-height: 14px; }

.auth-switch { font-size: 11px; color: var(--muted); text-align: center; }
.auth-switch a { color: var(--accent2); cursor: pointer; text-decoration: underline; }

/* ════════════════ APP SHELL ════════════════ */
#app-screen { display: none; }
#app-screen.visible { display: block; height: 100dvh; }

#app {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: 100dvh;
  max-width: 1400px;
  margin: 0 auto;
}

/* ════════════════ SIDEBAR ════════════════ */
#sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-right: 2px solid var(--border);
  overflow: hidden;
}

#sidebar-header {
  padding: 16px 14px 12px;
  border-bottom: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

#sidebar-header h1 {
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--accent);
  text-transform: uppercase;
}

#logout-btn {
  background: transparent;
  border: 2px solid transparent;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 7px;
  cursor: pointer;
  transition: all var(--anim);
}
#logout-btn:hover { border-color: var(--border); color: var(--text); }

/* ── Stack area: fills all space between header and add-btn ── */
#stack-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Scrollable container for the cards */
#stack-inner {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
}

/* ── Note card ── */
/* 7 brutal accent colours, high-contrast on dark bg */
.note-card {
  /* flex: 1;           each card shares available space equally */
  min-height: 0;
  position: relative;
  cursor: pointer;
  overflow: hidden;
  border-bottom: 2px solid rgba(0,0,0,0.25);
  transition: filter var(--anim);
  display: flex;
  flex-direction: column;
  padding: 12px 14px 10px;
}

.note-card:last-child { border-bottom: none; }

.note-card:hover { filter: brightness(1.06); }
.note-card.active { filter: brightness(1.12); outline: 2px solid rgba(255,255,255,0.25); outline-offset: -2px; z-index: 1; }

/* Card colour palette – assigned by index */
.note-card[data-ci="0"] { background: #1a2f1a; color: #b8e8b8; }
.note-card[data-ci="1"] { background: #2a1a0e; color: #f0c88a; }
.note-card[data-ci="2"] { background: #1a1a2f; color: #a8b8f0; }
.note-card[data-ci="3"] { background: #2f1a1a; color: #f0a8a8; }
.note-card[data-ci="4"] { background: #1f2a1a; color: #c8e890; }
.note-card[data-ci="5"] { background: #2a2a14; color: #e8e090; }
.note-card[data-ci="6"] { background: #1a2a2a; color: #90d8d8; }

/* ── Card content ── */
.card-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-shrink: 0;
  margin-bottom: 6px;
}

.card-time {
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.5;
  white-space: nowrap;
  margin-left: auto;
  flex-shrink: 0;
}

.card-md-badge {
  font-size: 8px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.5;
  flex-shrink: 0;
}

/* Rendered markdown inside the card */
.card-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  font-size: 11px;
  line-height: 1.5;
  /* fade out at bottom */
  -webkit-mask-image: linear-gradient(to bottom, black 50%, transparent 100%);
  mask-image: linear-gradient(to bottom, black 50%, transparent 100%);
}

.card-body p       { margin: 0 0 4px; }

.card-body h1,
.card-body h2,
.card-body h3 {
  font-family: var(--sans);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.card-body h1 {
  font-size: 2rem;
  margin: 0 0 4px;
  line-height: 1.2;  
}

.card-body h2 {
  font-size: 1.5rem;
  margin: 0 0 4px;
  line-height: 1.1;  
}

.card-body h3 {
  font-size: 1.125rem;
  margin: 0 0 4px;
  line-height: 1;  
}

.card-body strong  { font-weight: 700; }
.card-body em      { font-style: italic; opacity: 0.8; }
.card-body code    { font-family: var(--mono); font-size: 10px; opacity: 0.7; }
.card-body pre     { font-size: 10px; opacity: 0.6; white-space: pre-wrap; }
.card-body ul,.card-body ol { padding-left: 14px; margin-bottom: 4px; }
.card-body li      { margin-bottom: 2px; font-size: 11px; }
.card-body blockquote { opacity: 0.65; padding-left: 8px; border-left: 2px solid currentColor; }
.card-body a       { text-decoration: underline; opacity: 0.8; }

/* ── Empty stack ── */
#stack-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  pointer-events: none;
}
#stack-empty .empty-glyph { font-size: 26px; opacity: 0.15; }

/* ── LRU confirm overlay ── */
#lru-confirm {
  position: absolute;
  inset: 0;
  background: rgba(10,10,10,0.92);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 18px;
  gap: 16px;
}
#lru-confirm.show { display: flex; }

#lru-confirm-text {
  font-size: 12px;
  color: var(--text);
  text-align: center;
  line-height: 1.6;
  font-family: var(--sans);
}
#lru-confirm-text .lru-label { color: var(--danger); font-weight: 700; }
#lru-confirm-text .lru-note-title {
  display: block;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted);
  font-style: italic;
  word-break: break-word;
  line-height: 1.45;
}

.lru-btn-row { display: flex; gap: 8px; width: 100%; }

.lru-btn {
  flex: 1;
  padding: 9px 0;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  border: 2px solid var(--border);
  transition: all var(--anim);
}
.lru-btn-ok { background: var(--danger); border-color: var(--danger); color: #fff; }
.lru-btn-ok:hover { opacity: 0.85; }
.lru-btn-cancel { background: transparent; color: var(--muted); }
.lru-btn-cancel:hover { border-color: var(--muted); color: var(--text); }

/* ── Add button ── */
#add-btn {
  flex-shrink: 0;
  height: 44px;
  border: none;
  border-top: 2px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  transition: all var(--anim);
  display: flex;
  align-items: center;
  justify-content: center;
}
#add-btn:hover { background: var(--border); color: var(--accent); }

/* ════════════════ MAIN (right panel) ════════════════ */
#main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  position: relative;  /* anchor for overlay */
}

/* Passive right panel: just shows a hint */
#main-idle {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  pointer-events: none;
}
#main-idle .idle-glyph { font-size: 30px; opacity: 0.1; }

/* ════════════════ EDITOR OVERLAY ════════════════ */
#editor-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#editor-overlay.open { display: flex; }

#editor-panel {
  width: 100%;
  max-width: 760px;
  max-height: calc(100dvh - 48px);
  background: #131313;
  border: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#editor-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
}

#editor-close-btn {
  background: transparent;
  border: 2px solid transparent;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 16px;
  line-height: 1;
  padding: 2px 6px;
  cursor: pointer;
  transition: all var(--anim);
  margin-left: auto;
}
#editor-close-btn:hover { border-color: var(--border); color: var(--text); }

#md-indicator {
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 2px 7px;
  border: 1px solid #2a3a30;
  color: var(--accent2);
  opacity: 0;
  transition: opacity var(--anim);
  pointer-events: none;
}
#md-indicator.show { opacity: 1; }

#save-indicator {
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.06em;
  opacity: 0;
  transition: opacity 0.3s;
}
#save-indicator.show { opacity: 1; }

#delete-btn {
  padding: 3px 8px;
  background: transparent;
  border: 2px solid transparent;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all var(--anim);
}
#delete-btn:hover { border-color: var(--danger); color: var(--danger); }

#edit-btn {
  padding: 3px 10px;
  background: var(--accent);
  border: 2px solid var(--accent);
  color: #0f0f0f;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: opacity var(--anim);
}
#edit-btn:hover { opacity: 0.85; }

/* ── Note view (rendered markdown in overlay) ── */
#note-view {
  flex: 1;
  padding: 24px 28px;
  overflow-y: auto;
  display: none;
}
#note-view.visible { display: block; }
#note-view::-webkit-scrollbar { width: 4px; }
#note-view::-webkit-scrollbar-thumb { background: var(--border); }

/* Markdown styles inside overlay view */
#note-view .md-body {
  max-width: 100%;
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.8;
}
#note-view .md-body h1,
#note-view .md-body h2,
#note-view .md-body h3,
#note-view .md-body h4 {
  font-family: var(--sans);
  color: var(--accent);
  margin: 1.2em 0 0.4em;
  line-height: 1.2;
  font-weight: 700;
}
#note-view .md-body h1 { font-size: 1.7em; }
#note-view .md-body h2 { font-size: 1.35em; }
#note-view .md-body h3 { font-size: 1.1em; }
#note-view .md-body p  { margin: 0.6em 0; }
#note-view .md-body a  { color: var(--accent2); text-decoration: underline; }
#note-view .md-body strong { color: #f0ece3; font-weight: 600; }
#note-view .md-body em     { color: var(--accent); font-style: italic; }
#note-view .md-body blockquote {
  border-left: 3px solid var(--accent);
  margin: 1em 0; padding: 0.5em 1em;
  color: var(--muted);
  background: #1a1a1a;
}
#note-view .md-body ul,
#note-view .md-body ol  { padding-left: 1.5em; margin: 0.6em 0; }
#note-view .md-body li  { margin: 0.2em 0; }
#note-view .md-body hr  { border: none; border-top: 2px solid var(--border); margin: 1.2em 0; }
#note-view .md-body code:not(pre code) {
  font-family: var(--mono);
  font-size: 12px;
  background: #1a1a1a;
  padding: 2px 6px;
  color: var(--accent2);
  border: 1px solid var(--border);
}
#note-view .md-body pre {
  margin: 1em 0;
  overflow: hidden;
  border: 2px solid var(--border);
  background: #0d1117 !important;
}
#note-view .md-body pre code {
  font-family: var(--mono);
  font-size: 12.5px;
  padding: 14px 16px;
  display: block;
  overflow-x: auto;
  background: transparent !important;
  line-height: 1.6;
}
#note-view .md-body table { border-collapse: collapse; width: 100%; margin: 1em 0; font-size: 13px; }
#note-view .md-body th {
  background: #1a1a1a; padding: 7px 11px;
  border: 1px solid var(--border);
  text-align: left; color: var(--accent); font-weight: 600;
}
#note-view .md-body td { padding: 6px 11px; border: 1px solid var(--border); }
#note-view .md-body tr:nth-child(even) { background: #161616; }

/* ── Textarea ── */
#editor {
  flex: 1;
  padding: 24px 28px;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.75;
  color: var(--text);
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  min-height: 320px;
  max-height: calc(100dvh - 160px);
  caret-color: var(--accent);
  tab-size: 2;
  overflow-y: auto;
}
#editor::placeholder { color: var(--muted); font-style: italic; }
#editor::-webkit-scrollbar { width: 4px; }
#editor::-webkit-scrollbar-thumb { background: var(--border); }

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1a1a1a;
  border: 2px solid var(--border);
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  padding: 8px 16px;
  opacity: 0;
  transition: all 0.25s;
  pointer-events: none;
  white-space: nowrap;
  z-index: 600;
  letter-spacing: 0.04em;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Mobile ── */
@media (max-width: 600px) {
  #app { grid-template-columns: 1fr; }
  #main { display: none; }
  #editor-overlay { padding: 0; }
  #editor-panel { max-width: 100%; max-height: 100dvh; border: none; }
}
