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

/* ── Day v1 — Pure White ─────────────────────────────────────────────────── */
[data-theme="day1"] {
  --color-bg:              #ffffff;
  --color-text:            #1a1a1a;
  --color-text-muted:      #999999;
  --color-accent:          #1a1a1a;
  --color-link:            #2c5fa8;
  --color-selection:       #b3d4ff;
  --color-bar-bg:          rgba(255, 255, 255, 0.92);
  --color-bar-border:      rgba(0, 0, 0, 0.08);
  --color-btn-hover:       rgba(0, 0, 0, 0.06);
  --color-btn-active:      #1a1a1a;
  --color-btn-active-text: #ffffff;
  --shadow-toolbar:        0 2px 14px rgba(0, 0, 0, 0.12);
  --shadow-modal:          0 4px 24px rgba(0, 0, 0, 0.14);
}

/* ── Day v2 — Warm Paper ─────────────────────────────────────────────────── */
[data-theme="day2"] {
  --color-bg:              #f5f0ec;
  --color-text:            #1a1a1a;
  --color-text-muted:      #8a7d70;
  --color-accent:          #1a1a1a;
  --color-link:            #7a4e2a;
  --color-selection:       #ffe4b5;
  --color-bar-bg:          rgba(245, 240, 236, 0.93);
  --color-bar-border:      rgba(0, 0, 0, 0.07);
  --color-btn-hover:       rgba(0, 0, 0, 0.05);
  --color-btn-active:      #1a1a1a;
  --color-btn-active-text: #f5f0ec;
  --shadow-toolbar:        0 2px 14px rgba(0, 0, 0, 0.10);
  --shadow-modal:          0 4px 24px rgba(0, 0, 0, 0.12);
}

/* ── Day v3 — Nordic Slate ───────────────────────────────────────────────── */
[data-theme="day3"] {
  --color-bg:              #f4f6f8;
  --color-text:            #1d2a3a;
  --color-text-muted:      #6f7e8a;
  --color-accent:          #1d2a3a;
  --color-link:            #2e7ba8;
  --color-selection:       #bfd4e6;
  --color-bar-bg:          rgba(244, 246, 248, 0.93);
  --color-bar-border:      rgba(29, 42, 58, 0.08);
  --color-btn-hover:       rgba(29, 42, 58, 0.06);
  --color-btn-active:      #1d2a3a;
  --color-btn-active-text: #f4f6f8;
  --shadow-toolbar:        0 2px 14px rgba(29, 42, 58, 0.12);
  --shadow-modal:          0 4px 24px rgba(29, 42, 58, 0.14);
}

/* ── Night v1 — Warm Dark ────────────────────────────────────────────────── */
[data-theme="night1"] {
  --color-bg:              #1a1814;
  --color-text:            #e8dfc8;
  --color-text-muted:      #6a6050;
  --color-accent:          #e8dfc8;
  --color-link:            #9ab8e0;
  --color-selection:       #3d4f6b;
  --color-bar-bg:          rgba(26, 24, 20, 0.94);
  --color-bar-border:      rgba(255, 255, 255, 0.07);
  --color-btn-hover:       rgba(255, 255, 255, 0.07);
  --color-btn-active:      #e8dfc8;
  --color-btn-active-text: #1a1814;
  --shadow-toolbar:        0 2px 14px rgba(0, 0, 0, 0.55);
  --shadow-modal:          0 4px 24px rgba(0, 0, 0, 0.60);
}

/* ── Night v2 — Midnight Blue ────────────────────────────────────────────── */
[data-theme="night2"] {
  --color-bg:              #0f1621;
  --color-text:            #e8ecef;
  --color-text-muted:      #4a6070;
  --color-accent:          #e8ecef;
  --color-link:            #64b5f6;
  --color-selection:       #1a3a52;
  --color-bar-bg:          rgba(15, 22, 33, 0.95);
  --color-bar-border:      rgba(232, 236, 239, 0.07);
  --color-btn-hover:       rgba(232, 236, 239, 0.07);
  --color-btn-active:      #e8ecef;
  --color-btn-active-text: #0f1621;
  --shadow-toolbar:        0 2px 14px rgba(0, 0, 0, 0.70);
  --shadow-modal:          0 4px 24px rgba(0, 0, 0, 0.75);
}

/* ── Night v3 — Pure Noir ────────────────────────────────────────────────── */
[data-theme="night3"] {
  --color-bg:              #121212;
  --color-text:            #ebebeb;
  --color-text-muted:      #606060;
  --color-accent:          #ebebeb;
  --color-link:            #9ab8cc;
  --color-selection:       #2d2d2d;
  --color-bar-bg:          rgba(18, 18, 18, 0.96);
  --color-bar-border:      rgba(255, 255, 255, 0.05);
  --color-btn-hover:       rgba(255, 255, 255, 0.06);
  --color-btn-active:      #ebebeb;
  --color-btn-active-text: #121212;
  --shadow-toolbar:        0 2px 14px rgba(0, 0, 0, 0.80);
  --shadow-modal:          0 4px 24px rgba(0, 0, 0, 0.85);
}

/* ── Root Variables ──────────────────────────────────────────────────────── */
:root {
  --font-active:         'Lora', Georgia, serif;
  --font-size-base:      18px;
  --line-height-body:    1.78;
  --letter-spacing-body: 0.012em;
  --content-max-width:   700px;
  --bar-height:          54px;
}

/* ── Base ────────────────────────────────────────────────────────────────── */
html, body {
  height: 100%;
  background-color: var(--color-bg);
  color: var(--color-text);
  transition: background-color 0.3s ease, color 0.3s ease;
}

::selection {
  background: var(--color-selection);
  color: var(--color-text);
}

/* ── Editor Wrapper ──────────────────────────────────────────────────────── */
#editor-wrapper {
  min-height: 100vh;
  padding-bottom: var(--bar-height);
  display: flex;
  justify-content: center;
  background-color: var(--color-bg);
  transition: background-color 0.3s ease;
}

/* ── Editor Surface ──────────────────────────────────────────────────────── */
#editor {
  width: 100%;
  max-width: var(--content-max-width);
  padding: 5rem 2rem 5rem;
  font-family: var(--font-active);
  font-size: var(--font-size-base);
  line-height: var(--line-height-body);
  letter-spacing: var(--letter-spacing-body);
  color: var(--color-text);
  background: transparent;
  outline: none;
  min-height: calc(100vh - var(--bar-height));
  caret-color: var(--color-accent);
  word-break: break-word;
  overflow-wrap: break-word;
  transition: color 0.3s ease, font-size 0.12s ease;
}

#editor:empty::before,
#editor > h1:first-child:empty::before {
  content: attr(data-placeholder);
  color: var(--color-text-muted);
  pointer-events: none;
  font-style: italic;
  opacity: 0.6;
}

#editor > h1:first-child:empty::before {
  content: 'Title…';
  font-style: normal;
}

/* Typography */
#editor p          { margin-bottom: 1.45em; }
#editor div        { margin-bottom: 0.4em; }

#editor h1 {
  font-size: 2.1em;
  font-weight: 700;
  line-height: 1.18;
  letter-spacing: -0.015em;
  margin: 0.1em 0 0.55em;
}
#editor h2 {
  font-size: 1.55em;
  font-weight: 600;
  line-height: 1.28;
  letter-spacing: -0.008em;
  margin: 0.1em 0 0.55em;
}
#editor h3 {
  font-size: 1.22em;
  font-weight: 600;
  line-height: 1.35;
  margin: 0.1em 0 0.45em;
}
/* Lists — tight rhythm matching paragraph line-height, not paragraph spacing */
#editor ul,
#editor ol {
  margin: 0 0 1.45em 0;
  padding-left: 1.4em;
}

#editor li {
  margin-bottom: 0.35em;
  line-height: var(--line-height-body);
}

#editor li:last-child {
  margin-bottom: 0;
}

/* Nested lists */
#editor li ul,
#editor li ol {
  margin: 0.25em 0 0.25em;
}

/* Images — constrain to column, never overflow */
#editor img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.6em 0;
  border-radius: 2px;
}

#editor strong     { font-weight: 700; }
#editor em         { font-style: italic; }
#editor a {
  color: var(--color-link);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  cursor: pointer;
  transition: opacity 0.12s;
}
#editor a:hover    { opacity: 0.65; text-decoration: none; }
#editor blockquote {
  border-left: 2px solid var(--color-text-muted);
  padding-left: 1.2em;
  margin: 1.6em 0;
  color: var(--color-text-muted);
  font-style: italic;
}

/* ── Bottom Control Bar ──────────────────────────────────────────────────── */
#control-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  height: var(--bar-height);
  padding: 0 1.5rem;
  background: var(--color-bar-bg);
  border-top: 1px solid var(--color-bar-border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  opacity: 0.45;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  /* transition covers both auto-hide and hover opacity */
  transition: transform 0.35s ease, opacity 0.35s ease,
              background-color 0.3s, border-color 0.3s;
}

#control-bar::-webkit-scrollbar { display: none; }

#control-bar:hover,
#control-bar:focus-within {
  opacity: 1;
}

/* Auto-hide state */
#control-bar.bar-hidden {
  transform: translateY(100%);
  opacity: 0 !important;
  pointer-events: none;
}

/* ── Bar Trigger Zone ────────────────────────────────────────────────────── */
/* Always at very bottom. When bar is hidden (slid away), this is the only
   hoverable target at the bottom edge. When bar is visible, bar (z-index 100)
   sits above it so bar hover fires instead. */
#bar-trigger {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 10px;
  z-index: 99;
}

/* ── Control Groups ──────────────────────────────────────────────────────── */
.control-group {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  padding: 0 0.8rem;
}

.control-group:first-child { padding-left: 0; }

.control-group + .control-group {
  border-left: 1px solid var(--color-bar-border);
}

#control-bar button {
  font-size: 0.65rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 0.28rem 0.48rem;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  border-radius: 3px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
  font-family: system-ui, -apple-system, sans-serif;
  line-height: 1;
}

#control-bar button:hover  { background: var(--color-btn-hover); color: var(--color-text); }
#control-bar button.active { background: var(--color-btn-active); color: var(--color-btn-active-text); }

.font-btn {
  font-size: 0.75rem !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
}

/* Theme picker two-row layout */
#theme-picker {
  align-items: stretch;
  gap: 0;
  padding: 5px 0.8rem;
}

.theme-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 0.7rem 0 0;
}

.theme-group + .theme-group {
  padding-left: 0.7rem;
  border-left: 1px solid var(--color-bar-border);
  padding-right: 0;
}

.theme-group-label {
  font-size: 0.5rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  opacity: 0.5;
  line-height: 1;
  user-select: none;
  font-family: system-ui, -apple-system, sans-serif;
  padding-left: 0.1rem;
}

.theme-group-btns {
  display: flex;
  align-items: center;
  gap: 2px;
}

#font-size-display {
  font-size: 0.65rem;
  letter-spacing: 0.07em;
  color: var(--color-text-muted);
  min-width: 2.8rem;
  text-align: center;
  user-select: none;
  font-variant-numeric: tabular-nums;
  font-family: system-ui, -apple-system, sans-serif;
}

#copy-btn {
  border: 1px solid var(--color-bar-border) !important;
  padding: 0.28rem 0.8rem !important;
}

#stats-display {
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  white-space: nowrap;
  user-select: none;
  font-family: system-ui, -apple-system, sans-serif;
}

/* ── Floating Format Toolbar ─────────────────────────────────────────────── */
#format-toolbar {
  position: fixed;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 6px;
  background: var(--color-bar-bg);
  border: 1px solid var(--color-bar-border);
  border-radius: 6px;
  box-shadow: var(--shadow-toolbar);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 200;
  opacity: 0;
  transform: translateY(5px);
  transition: opacity 0.14s ease, transform 0.14s ease,
              background-color 0.3s, border-color 0.3s;
  pointer-events: none;
}

#format-toolbar.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

#format-toolbar button {
  font-size: 0.76rem;
  padding: 0.22rem 0.5rem;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  min-width: 1.8rem;
  text-align: center;
  font-family: system-ui, -apple-system, sans-serif;
  line-height: 1.4;
}

#format-toolbar button:hover  { background: var(--color-btn-hover); color: var(--color-text); }
#format-toolbar button.active { color: var(--color-accent); background: var(--color-btn-hover); }
#fmt-bold   { font-weight: 700; }
#fmt-italic { font-style: italic; }

/* ── Link Edit Modal ─────────────────────────────────────────────────────── */
#link-modal {
  position: fixed;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  background: var(--color-bar-bg);
  border: 1px solid var(--color-bar-border);
  border-radius: 8px;
  box-shadow: var(--shadow-modal);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 300;
  min-width: 300px;
  opacity: 0;
  transform: translateY(5px);
  transition: opacity 0.14s ease, transform 0.14s ease,
              background-color 0.3s, border-color 0.3s;
  pointer-events: none;
}

#link-modal.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

#link-url-input {
  font-size: 0.8rem;
  font-family: system-ui, monospace;
  padding: 0.38rem 0.6rem;
  border: 1px solid var(--color-bar-border);
  border-radius: 4px;
  background: transparent;
  color: var(--color-text);
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}

#link-url-input:focus {
  border-color: var(--color-text-muted);
}

#link-modal-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

#link-modal-actions button {
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.28rem 0.6rem;
  border: 1px solid var(--color-bar-border);
  background: transparent;
  color: var(--color-text-muted);
  border-radius: 3px;
  cursor: pointer;
  font-family: system-ui, -apple-system, sans-serif;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

#link-modal-actions button:hover {
  background: var(--color-btn-hover);
  color: var(--color-text);
}

#link-save-btn {
  background: var(--color-btn-active) !important;
  color: var(--color-btn-active-text) !important;
  border-color: var(--color-btn-active) !important;
}

#link-remove-btn:hover {
  color: #c0392b !important;
  border-color: #c0392b !important;
  background: transparent !important;
}

/* ── Docs Panel ──────────────────────────────────────────────────────────── */
#docs-panel {
  position: fixed;
  bottom: var(--bar-height);
  left: 0;
  right: 0;
  max-height: min(360px, 50vh);
  background: var(--color-bar-bg);
  border-top: 1px solid var(--color-bar-border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 150;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease,
              background-color 0.3s, border-color 0.3s;
}

#docs-panel.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

#docs-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 8px;
  border-bottom: 1px solid var(--color-bar-border);
  flex-shrink: 0;
}

#docs-panel-label {
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  font-family: system-ui, -apple-system, sans-serif;
  user-select: none;
}

#docs-new-btn {
  font-size: 0.65rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 0.22rem 0.5rem;
  border: 1px solid var(--color-bar-border) !important;
  background: transparent;
  color: var(--color-text-muted);
  border-radius: 3px;
  cursor: pointer;
  font-family: system-ui, -apple-system, sans-serif;
  transition: background 0.12s, color 0.12s;
}

#docs-new-btn:hover {
  background: var(--color-btn-hover) !important;
  color: var(--color-text) !important;
}

#docs-list {
  overflow-y: auto;
  flex: 1;
  padding: 6px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--color-bar-border) transparent;
}

.doc-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  cursor: pointer;
  transition: background 0.1s;
  position: relative;
}

.doc-item:hover {
  background: var(--color-btn-hover);
}

.doc-item.active {
  background: var(--color-btn-hover);
  border-left: 2px solid var(--color-accent);
  padding-left: 14px;
  cursor: default;
}

.doc-item-dot {
  font-size: 0.6rem;
  color: var(--color-text-muted);
  flex-shrink: 0;
  width: 10px;
  text-align: center;
}

.doc-item.active .doc-item-dot {
  color: var(--color-accent);
}

.doc-item-title {
  flex: 1;
  font-family: var(--font-active);
  font-size: 0.85rem;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-item-time {
  font-size: 0.62rem;
  color: var(--color-text-muted);
  flex-shrink: 0;
  font-family: system-ui, -apple-system, sans-serif;
  letter-spacing: 0.02em;
}

.doc-item-delete {
  font-size: 0.9rem;
  line-height: 1;
  width: 20px;
  height: 20px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  border-radius: 3px;
  cursor: pointer;
  opacity: 0;
  flex-shrink: 0;
  transition: opacity 0.12s, background 0.12s, color 0.12s;
}

.doc-item:hover .doc-item-delete {
  opacity: 1;
}

.doc-item-delete:hover {
  background: var(--color-btn-hover);
  color: #c0392b;
}

.doc-item-delete:disabled {
  opacity: 0 !important;
  cursor: not-allowed;
}

/* Active doc title shown inline in the control bar */
#docs-active-title {
  font-family: var(--font-active);
  font-size: 0.72rem;
  color: var(--color-text-muted);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  user-select: none;
  margin-left: 4px;
}
