:root {
  --font-ui: "Pyidaungsu", "Noto Sans Myanmar", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --bg: #fff8fa;
  --surface: #ffffff;
  --surface-soft: #fce7f3;
  --primary: #db2777;
  --accent: #0f766e;
  --text: #18181b;
  --muted: #64748b;
  --border: rgba(24, 24, 27, 0.11);
  --shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
  --radius: 14px;
}

body[data-theme="warm"] {
  --bg: #fbf8f1;
  --surface: #ffffff;
  --surface-soft: #f4ecdc;
  --primary: #b45309;
  --accent: #0f766e;
  --text: #1f2937;
  --muted: #6b6458;
  --border: rgba(31, 41, 55, 0.12);
}

body[data-theme="matcha"] {
  --bg: #f4faf6;
  --surface: #ffffff;
  --surface-soft: #dcfce7;
  --primary: #047857;
  --accent: #db2777;
  --text: #132a1e;
  --muted: #4b6356;
  --border: rgba(19, 42, 30, 0.12);
}

body[data-theme="sky"] {
  --bg: #f3f8fd;
  --surface: #ffffff;
  --surface-soft: #e0f2fe;
  --primary: #0369a1;
  --accent: #7c3aed;
  --text: #0f172a;
  --muted: #475569;
  --border: rgba(15, 23, 42, 0.12);
}

body[data-theme="night"] {
  --bg: #0f141f;
  --surface: #182032;
  --surface-soft: #232e47;
  --primary: #f472b6;
  --accent: #2dd4bf;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --border: rgba(255, 255, 255, 0.12);
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.45);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.note-app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* ==================== TOP BAR ==================== */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.9rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.top-left, .top-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.app-logo {
  border-radius: 9px;
  object-fit: cover;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.brand-text {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.brand-text strong {
  font-size: 1rem;
}

.nightly-pill {
  font-size: 0.7rem;
  font-weight: 800;
  padding: 0.16rem 0.55rem;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--primary);
}

.btn, .icon-pill, .fmt-btn {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.12s ease, background 0.15s ease;
}

.btn {
  padding: 0.42rem 0.85rem;
  font-size: 0.82rem;
}

.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.76rem; }
.btn-full { width: 100%; text-align: center; }

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.btn-soft {
  background: var(--surface-soft);
  color: var(--text);
  border-color: transparent;
}

.btn[aria-pressed="true"], .fmt-btn.is-active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.icon-pill {
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.45rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.88rem;
}

.fmt-btn {
  border-radius: 8px;
  padding: 0.3rem 0.58rem;
  font-size: 0.79rem;
  background: var(--surface-soft);
  border-color: transparent;
}

/* ==================== TRI-PANE WORKSPACE ==================== */
.workspace-grid {
  display: grid;
  grid-template-columns: 224px 290px minmax(0, 1fr);
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.workspace-grid.sidebar-collapsed {
  grid-template-columns: 0 290px minmax(0, 1fr);
}

.workspace-grid.sidebar-collapsed .sidebar-pane {
  overflow: hidden;
  border-right: 0;
}

.sidebar-pane {
  background: var(--surface);
  border-right: 1px solid var(--border);
  min-height: 0;
  overflow-y: auto;
}

.sidebar-scroll {
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.rail-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.65rem;
}

.rail-heading {
  margin: 0.55rem 0 0.2rem;
  font-size: 0.69rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.mini-plus {
  border: 0;
  background: var(--surface-soft);
  color: var(--primary);
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 999px;
  font-weight: 900;
  cursor: pointer;
}

.rail-list {
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
}

.rail-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.83rem;
  font-weight: 600;
  padding: 0.45rem 0.65rem;
  border-radius: 10px;
  cursor: pointer;
  text-align: start;
}

.rail-btn.is-active {
  background: var(--surface-soft);
  color: var(--primary);
  font-weight: 800;
}

.rail-count {
  font-size: 0.72rem;
  color: var(--muted);
}

.tags-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.tag-chip {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--accent);
  font: inherit;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  cursor: pointer;
}

.tag-chip.is-active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.rail-footer {
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

/* ==================== LIST PANE ==================== */
.list-pane {
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.list-controls {
  display: flex;
  gap: 0.45rem;
  padding: 0.65rem;
  border-bottom: 1px solid var(--border);
}

.search-input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 0.84rem;
  padding: 0.46rem 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.notes-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.notes-scroll.is-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
}

.note-card {
  padding: 0.78rem;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.note-card.is-selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 22%, transparent);
}

.note-card[data-color="sakura"] { background: color-mix(in srgb, #ec4899 8%, var(--surface)); }
.note-card[data-color="gold"] { background: color-mix(in srgb, #f59e0b 10%, var(--surface)); }
.note-card[data-color="matcha"] { background: color-mix(in srgb, #10b981 9%, var(--surface)); }
.note-card[data-color="sky"] { background: color-mix(in srgb, #0ea5e9 9%, var(--surface)); }
.note-card[data-color="lavender"] { background: color-mix(in srgb, #8b5cf6 9%, var(--surface)); }

.note-card h4 {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.35;
}

.note-card p {
  margin: 0;
  font-size: 0.77rem;
  color: var(--muted);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-card-meta {
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 700;
}

/* ==================== EDITOR PANE ==================== */
.editor-pane {
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.editor-active {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.editor-empty {
  margin: auto;
  text-align: center;
  padding: 2rem;
  color: var(--muted);
}

.editor-meta-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.5rem 0.85rem;
  border-bottom: 1px solid var(--border);
}

.meta-left, .meta-right {
  display: flex;
  align-items: center;
  gap: 0.42rem;
  flex-wrap: wrap;
}

.meta-select, .meta-date {
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.3rem 0.55rem;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.meta-stat {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--muted);
}

.color-dots {
  display: inline-flex;
  gap: 0.3rem;
}

.color-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}

.color-dot.is-active {
  border-color: var(--text);
  transform: scale(1.12);
}

.format-bar {
  display: flex;
  align-items: center;
  gap: 0.32rem;
  padding: 0.45rem 0.85rem;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
}

.fmt-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 0.2rem;
}

.editor-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.editor-split.has-sketch {
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
}

.writing-column {
  overflow-y: auto;
  padding: 1rem 1.25rem 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.note-title-input {
  font: inherit;
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: none;
  width: 100%;
}

.tags-editor-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.inline-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.tag-add-input {
  font: inherit;
  font-size: 0.76rem;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 999px;
  padding: 0.16rem 0.6rem;
  width: 7.5rem;
}

.checklist-widget {
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius);
  background: var(--bg);
  border: 1px solid var(--border);
}

.checklist-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  font-size: 0.8rem;
  color: var(--accent);
}

.progress-bar-bg {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: var(--surface);
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--primary));
  transition: width 0.2s ease;
}

.checklist-items {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.chk-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.86rem;
  cursor: pointer;
}

.chk-row.is-done span {
  text-decoration: line-through;
  color: var(--muted);
}

.note-body-editor {
  min-height: 220px;
  font-size: var(--editor-font-size, 16px);
  line-height: 1.75;
  outline: none;
  white-space: pre-wrap;
}

.note-body-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
}

.note-body-editor blockquote {
  margin: 0.5rem 0;
  padding: 0.45rem 0.9rem;
  border-left: 4px solid var(--primary);
  background: var(--surface-soft);
  border-radius: 0 10px 10px 0;
}

.note-body-editor code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--surface-soft);
  padding: 0.1rem 0.35rem;
  border-radius: 5px;
}

.locked-panel {
  padding: 2rem 1rem;
  display: flex;
  justify-content: center;
}

.locked-card {
  max-width: 24rem;
  padding: 1.5rem;
  border-radius: 18px;
  background: var(--bg);
  border: 1px solid var(--border);
  text-align: center;
}

.lock-icon { font-size: 2.2rem; }

.sketch-thumb-card {
  padding: 0.65rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.sketch-thumb-card img {
  max-width: 100%;
  max-height: 200px;
  border-radius: 10px;
}

.links-panel {
  margin-top: 0.75rem;
  padding: 0.85rem;
  border-radius: var(--radius);
  background: var(--bg);
  border: 1px solid var(--border);
}

.links-panel h4 {
  margin: 0 0 0.5rem;
  font-size: 0.82rem;
  color: var(--accent);
}

.link-chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.35rem;
}

/* ==================== SKETCH COLUMN ==================== */
.sketch-column {
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
}

.sketch-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.5rem 0.7rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.ink-palette {
  display: inline-flex;
  gap: 0.28rem;
}

.ink-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
}

.ink-swatch.is-active {
  border-color: var(--primary);
  transform: scale(1.15);
}

.sketch-stage {
  flex: 1;
  min-height: 260px;
  position: relative;
  overflow: hidden;
}

#sketchCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

/* ==================== DIALOGS & TOAST ==================== */
.neko-dialog {
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  width: min(92vw, 32rem);
  max-height: 82dvh;
  box-shadow: var(--shadow);
}

.neko-dialog::backdrop {
  background: rgba(10, 14, 24, 0.52);
  backdrop-filter: blur(4px);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--border);
}

.dialog-head h3 { margin: 0; font-size: 1rem; }

.dialog-list, .dialog-body {
  padding: 0.9rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  max-height: 62dvh;
  overflow-y: auto;
}

.tpl-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  font-size: 0.86rem;
  cursor: pointer;
  text-align: start;
}

.theme-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.setting-label {
  margin: 0.4rem 0 0.2rem;
  font-size: 0.86rem;
  font-weight: 700;
}

.range-slider { width: 100%; accent-color: var(--primary); }
.muted-small { font-size: 0.78rem; color: var(--muted); margin: 0; }

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  padding: 0.55rem 1.1rem;
  border-radius: 999px;
  background: var(--text);
  color: var(--surface);
  font-size: 0.84rem;
  font-weight: 700;
  box-shadow: var(--shadow);
}

.mobile-only { display: none; }

/* ==================== RESPONSIVE ADAPTATION (iPad Split View & Phones) ==================== */
@media (max-width: 960px) {
  .workspace-grid {
    grid-template-columns: 200px 245px minmax(0, 1fr);
  }
  .editor-split.has-sketch {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(0, 0.9fr);
  }
  .sketch-column {
    border-left: 0;
    border-top: 1px solid var(--border);
  }
}

@media (max-width: 720px) {
  .mobile-only { display: inline-flex; }
  .workspace-grid {
    grid-template-columns: 1fr;
  }
  .sidebar-pane {
    position: fixed;
    inset: 3.4rem auto 0 0;
    width: min(82vw, 270px);
    z-index: 80;
    box-shadow: var(--shadow);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }
  .workspace-grid.mobile-sidebar-open .sidebar-pane {
    transform: translateX(0);
  }
  .workspace-grid.mobile-editor-open .list-pane { display: none; }
  .workspace-grid:not(.mobile-editor-open) .editor-pane { display: none; }
}
