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

:root {
  --bg: #1a1a2e;
  --sidebar-bg: #16213e;
  --card-bg: #0f3460;
  --accent: #e94560;
  --text: #e0e0e0;
  --muted: #888;
  --border: #2a2a4a;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  position: relative; /* contains the absolutely-positioned sky overlay */
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Sky overlay and its siblings must sit above it via z-index: 1 */
.sidebar-header {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.logo {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.5px;
}

.header-btns {
  display: flex;
  align-items: center;
  gap: 6px;
}

#new-note-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
}
#new-note-btn:hover { transform: scale(1.1); opacity: 0.9; }

#settings-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.05rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}
#settings-btn:hover { color: var(--text); background: var(--border); }

#new-note-fab { display: none; }

#search {
  position: relative;
  z-index: 1;
  margin: 12px;
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
}
#search:focus { border-color: var(--accent); }

#note-list {
  position: relative;
  z-index: 1;
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 4px 8px 16px;
}

#note-list li {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  margin-bottom: 4px;
}

/* ── Swipe action buttons (revealed behind content) ── */
.swipe-actions {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  display: flex;
  z-index: 0;
}

.action-btn {
  border: none;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0 18px;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 70px;
}
.action-pin   { background: #4a6fa5; }
.action-delete { background: var(--accent); }

/* ── Slideable content layer ── */
.note-item-content {
  position: relative;
  z-index: 1;
  background: var(--sidebar-bg);
  border-radius: var(--radius);
  padding: 10px 12px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s;
  will-change: transform;
  touch-action: manipulation;
}
.note-item-content:hover { background: var(--card-bg); }
#note-list li.active .note-item-content {
  background: var(--card-bg);
  border-color: var(--accent);
}

.pin-badge {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 700;
  color: #4a6fa5;
  background: rgba(74, 111, 165, 0.18);
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 6px;
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.note-item-title {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-item-preview {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.note-item-date {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 4px;
}

/* ── Editor ── */
.editor {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.editor-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}

#note-title {
  flex: 1;
  background: transparent;
  border: none;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  outline: none;
}
#note-title::placeholder { color: var(--muted); }

#last-saved {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}

#delete-btn {
  padding: 6px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
#delete-btn:hover { background: var(--accent); color: #fff; }

#note-body {
  flex: 1;
  padding: 24px;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.7;
  resize: none;
  outline: none;
  font-family: inherit;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.95rem;
  pointer-events: none;
}
.empty-state.hidden { display: none; }

/* ── Back button (hidden on desktop) ── */
#back-btn {
  display: none;
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0 8px 0 0;
  line-height: 1;
  flex-shrink: 0;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Welcome screen ── */
#welcome {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 100;
}

#welcome.hidden { display: none; }

#welcome.exit {
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  transform: translateX(-100%);
}

@keyframes welcomeFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
#welcome.fade-in { animation: welcomeFadeIn 0.3s ease forwards; }

.welcome-logo {
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 1px;
}

.welcome-tagline {
  font-size: 1rem;
  color: var(--muted);
}

#start-btn {
  margin-top: 8px;
  padding: 14px 40px;
  border: none;
  border-radius: 30px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
}
#start-btn:hover { transform: scale(1.05); opacity: 0.9; }

/* ── Sky overlay — sits inside .sidebar below all content (z-index: 0) ── */
#sky-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  display: none;
}
#stars-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
}

/* ── Settings panel ── */
.settings-panel {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.settings-panel.hidden { display: none; }

.settings-sheet {
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 520px;
  padding: 0 20px 36px;
  max-height: 85vh;
  overflow-y: auto;
  animation: sheetUp 0.26s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes sheetUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.settings-drag-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px auto 18px;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}
.settings-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}
.settings-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 0.95rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
.settings-close:hover { color: var(--text); background: var(--border); }

.settings-section { margin-bottom: 26px; }

.settings-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.9px;
  margin-bottom: 12px;
}

/* Theme swatches */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
.theme-swatch {
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}
.swatch-preview {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  outline: 2px solid transparent;
  outline-offset: 2px;
  transition: outline-color 0.15s, transform 0.15s;
}
.theme-swatch:hover .swatch-preview { transform: scale(1.06); }
.theme-swatch.active .swatch-preview { outline-color: var(--accent); }
.swatch-name {
  font-size: 0.62rem;
  color: var(--muted);
  text-align: center;
}
.theme-swatch.active .swatch-name { color: var(--text); font-weight: 600; }

/* Color pickers */
.color-rows { display: flex; flex-direction: column; gap: 14px; }
.color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.color-row span { font-size: 0.88rem; color: var(--text); }
.color-row input[type="color"] {
  width: 44px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  padding: 2px 3px;
}

/* Toggle switches */
.toggle-rows { display: flex; flex-direction: column; gap: 10px; }
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.toggle-row span { font-size: 0.88rem; color: var(--text); }
.toggle-row.disabled { opacity: 0.38; pointer-events: none; }

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
  cursor: pointer;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 12px;
  transition: background 0.2s;
}
.toggle-track::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.35);
}
.toggle-switch input:checked + .toggle-track { background: var(--accent); }
.toggle-switch input:checked + .toggle-track::before { transform: translateX(18px); }

/* Desktop: centered modal instead of bottom sheet */
@media (min-width: 641px) {
  .settings-panel { align-items: center; }
  .settings-sheet {
    border-radius: 14px;
    max-width: 360px;
    animation: modalPop 0.2s ease;
  }
  @keyframes modalPop {
    from { transform: scale(0.95); opacity: 0; }
    to   { transform: scale(1);    opacity: 1; }
  }
  .settings-drag-handle { display: none; }
}

/* ── Mobile ── */
@media (max-width: 640px) {
  /* Prevent horizontal overscroll / rubber-band revealing off-screen panels */
  html, body { overscroll-behavior-x: none; overflow-x: hidden; }

  body { height: 100dvh; }

  .app {
    position: relative; /* makes .app the containing block for .editor,
                           so overflow:hidden actually clips it */
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    height: 100dvh;
    overflow: hidden;
  }

  /* Both panels fill the viewport and slide horizontally */
  .sidebar,
  .editor {
    grid-column: 1;
    grid-row: 1;
    width: 100%;
    height: 100dvh;
    transition: transform 0.25s ease;
  }

  /* Default: sidebar visible, editor off-screen to the right */
  /* touch-action: pan-y prevents the browser from interpreting horizontal
     drags on the sidebar as page navigation — JS swipe handlers still fire */
  .sidebar  { transform: translateX(0); touch-action: manipulation; }
  .editor   { transform: translateX(100%); position: absolute; inset: 0; background: var(--bg); }

  /* When a note is open, slide sidebar left and editor in */
  .app.show-editor .sidebar { transform: translateX(-100%); }
  .app.show-editor .editor  { transform: translateX(0); }

  /* Show back button on mobile */
  #back-btn { display: block; }

  /* Larger touch targets */
  .note-item-content { padding: 14px 12px; }

  /* Hide inline + button; FAB takes over */
  #new-note-btn { display: none; }
  #settings-btn { width: 38px; height: 38px; font-size: 1.15rem; }

  /* Floating action button */
  #new-note-fab {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    bottom: 28px;
    right: 24px;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #fff;
    font-size: 2rem;
    cursor: pointer;
    z-index: 10;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
    transition: transform 0.15s, opacity 0.15s;
  }
  #new-note-fab:active { transform: scale(0.93); }

  /* Hide FAB when editor is open */
  .app.show-editor ~ #new-note-fab { display: none; }

  /* Compact editor header */
  .editor-header { padding: 12px 16px; gap: 8px; }
  #note-title { font-size: 1.1rem; }
  #last-saved { display: none; }
  #note-body  { padding: 16px; font-size: 1rem; } /* 1rem = 16px; below 16px iOS auto-zooms on focus */

  /* Slightly larger search bar */
  #search { font-size: 1rem; padding: 10px 12px; }

  /* Welcome exit: slide down on mobile instead of left */
  #welcome.exit { transform: translateY(100%); }
}
