:root {
  --bg1: #0f0c29;
  --bg2: #302b63;
  --bg3: #24243e;
  --glass: rgba(255,255,255,0.08);
  --glass-border: rgba(255,255,255,0.15);
  --glass-hover: rgba(255,255,255,0.13);
  --accent: #a78bfa;
  --text: #f1f5f9;
  --text-muted: rgba(241,245,249,0.55);
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
  --radius: 18px;
}

body.dark {
  --bg1: #09090b;
  --bg2: #18181b;
  --bg3: #09090b;
  --glass: rgba(255,255,255,0.04);
  --glass-border: rgba(255,255,255,0.08);
  --glass-hover: rgba(255,255,255,0.08);
}

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

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: 'DM Sans', sans-serif;
  background: linear-gradient(135deg, var(--bg1) 0%, var(--bg2) 50%, var(--bg3) 100%);
  background-attachment: fixed;
  color: var(--text);
  transition: background 0.4s;
  overflow-x: hidden;
}

/* Ambient blobs */
body::before, body::after {
  content: '';
  position: fixed;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.18;
  pointer-events: none;
  z-index: 0;
}
body::before {
  width: 420px; height: 420px;
  background: radial-gradient(circle, #a78bfa, transparent);
  top: -100px; left: -100px;
}
body::after {
  width: 350px; height: 350px;
  background: radial-gradient(circle, #f472b6, transparent);
  bottom: -80px; right: -80px;
}

/* LAYOUT */
.container {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 40px 16px 24px;
  position: relative;
  z-index: 1;
}

/* CARD */
.notes-app {
  background: var(--glass);
  backdrop-filter: blur(24px) saturate(1.5);
  -webkit-backdrop-filter: blur(24px) saturate(1.5);
  border: 1px solid var(--glass-border);
  border-radius: 28px;
  padding: 30px 28px 28px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,0.1);
  transition: background 0.4s;
}

/* HEADER */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 22px;
}
.header h2 {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 1.55rem;
  letter-spacing: -0.5px;
  background: linear-gradient(90deg, #a78bfa, #f472b6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.header-actions {
  display: flex;
  gap: 8px;
}
.icon-btn {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text);
  transition: background 0.2s, transform 0.15s;
  backdrop-filter: blur(8px);
}
.icon-btn:hover {
  background: var(--glass-hover);
  transform: scale(1.08);
}

/* SEARCH */
.search-wrap {
  position: relative;
  margin-bottom: 14px;
}
.search-wrap span {
  position: absolute;
  left: 13px; top: 50%;
  transform: translateY(-50%);
  font-size: 0.95rem;
  opacity: 0.5;
}
#search {
  width: 100%;
  padding: 11px 14px 11px 36px;
  border-radius: 12px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.92rem;
  outline: none;
  backdrop-filter: blur(8px);
  transition: border 0.2s, background 0.2s;
}
#search::placeholder { color: var(--text-muted); }
#search:focus {
  border-color: var(--accent);
  background: rgba(167,139,250,0.07);
}

/* TEXTAREA */
#noteInput {
  width: 100%;
  height: 90px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.93rem;
  resize: none;
  outline: none;
  backdrop-filter: blur(8px);
  transition: border 0.2s, background 0.2s;
  margin-bottom: 12px;
}
#noteInput::placeholder { color: var(--text-muted); }
#noteInput:focus {
  border-color: var(--accent);
  background: rgba(167,139,250,0.07);
}

/* COLOR ROW */
.color-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.color-row span {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.3px;
}
.color-dot {
  width: 22px; height: 22px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.18s, border 0.18s;
  flex-shrink: 0;
}
.color-dot:hover { transform: scale(1.2); }
.color-dot.active {
  border-color: white;
  transform: scale(1.25);
}

/* ADD BUTTON */
#addBtn {
  width: 100%;
  padding: 13px;
  border-radius: 14px;
  border: none;
  background: linear-gradient(90deg, #a78bfa, #f472b6);
  color: white;
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 0.97rem;
  letter-spacing: 0.3px;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s, box-shadow 0.2s;
  box-shadow: 0 4px 20px rgba(167,139,250,0.35);
  margin-bottom: 4px;
}
#addBtn:hover {
  opacity: 0.92;
  transform: translateY(-1px);
  box-shadow: 0 6px 28px rgba(167,139,250,0.45);
}
#addBtn:active { transform: scale(0.98); }

/* STATS */
.stats {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 8px 0 16px;
  letter-spacing: 0.2px;
}

/* NOTES CONTAINER */
#notesContainer {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* NOTE CARD */
.note {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 2px 12px rgba(0,0,0,0.18);
  animation: slideIn 0.28s cubic-bezier(.34,1.56,.64,1);
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
  overflow: hidden;
}
.note::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 4px; height: 100%;
  background: var(--note-accent, linear-gradient(180deg, #a78bfa, #f472b6));
  border-radius: 4px 0 0 4px;
}
.note:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 22px rgba(0,0,0,0.28);
}
.note.pinned {
  border-color: rgba(252,211,77,0.45);
}
.note.pinned::before {
  background: linear-gradient(180deg, #fcd34d, #f59e0b);
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* NOTE TOP ROW */
.note-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.pin-badge {
  font-size: 0.75rem;
  background: rgba(252,211,77,0.15);
  border: 1px solid rgba(252,211,77,0.3);
  border-radius: 6px;
  padding: 1px 6px;
  color: #fcd34d;
  white-space: nowrap;
  line-height: 1.6;
}
.note-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.note-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text);
  transition: background 0.18s, transform 0.14s;
}
.note-btn:hover {
  background: rgba(255,255,255,0.15);
  transform: scale(1.12);
}
.note-btn.delete:hover {
  background: rgba(244,63,94,0.25);
  border-color: rgba(244,63,94,0.3);
}
.note-btn.pin-btn.active {
  background: rgba(252,211,77,0.15);
  border-color: rgba(252,211,77,0.3);
}

/* NOTE TEXT */
.note-text {
  font-size: 0.91rem;
  line-height: 1.6;
  color: var(--text);
  word-break: break-word;
  white-space: pre-wrap;
}
.note-text.editing { display: none; }

/* EDIT INPUT */
.note-edit-input {
  display: none;
  width: 100%;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.91rem;
  resize: none;
  outline: none;
  min-height: 60px;
}
.note-edit-input.editing { display: block; }

.note-edit-save {
  display: none;
  margin-top: 8px;
  padding: 6px 14px;
  border-radius: 8px;
  border: none;
  background: linear-gradient(90deg, #a78bfa, #f472b6);
  color: white;
  font-family: 'Syne', sans-serif;
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
  transition: opacity 0.2s;
}
.note-edit-save.editing { display: inline-block; }
.note-edit-save:hover { opacity: 0.88; }

/* NOTE DATE */
.note-date {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 8px;
  letter-spacing: 0.2px;
}

/* EMPTY STATE */
.empty-state {
  text-align: center;
  padding: 30px 0 10px;
  color: var(--text-muted);
}
.empty-state .big {
  font-size: 2.4rem;
  margin-bottom: 8px;
}
.empty-state p {
  font-size: 0.85rem;
  line-height: 1.6;
}

/* FOOTER */
footer {
  text-align: center;
  padding: 18px 16px 20px;
  font-size: 0.78rem;
  color: rgba(241,245,249,0.4);
  border-top: 1px solid rgba(255,255,255,0.07);
  position: relative;
  z-index: 1;
}
.visitor-box { margin-top: 8px; }

/* TOAST */
#toast {
  position: fixed;
  bottom: 30px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(30,30,40,0.92);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 10px 22px;
  font-size: 0.84rem;
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 999;
  white-space: nowrap;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* SCROLLBAR */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 10px;
}

/* MOBILE */
@media (max-width: 480px) {
  .container {
    align-items: flex-start;
    padding: 20px 12px 16px;
  }
  .notes-app {
    padding: 22px 16px 20px;
    border-radius: 22px;
  }
}