/* ================================================================
   INK & PAPER — Handwritten Notebook App
   ================================================================ */

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

:root {
  --sidebar-w: 260px;
  --toolbar-h: 62px;
  --paper-cream: #f5efe0;
  --paper-warm: #ede0c4;
  --paper-aged: #e8d5b0;
  --line-color: rgba(100, 149, 200, 0.35);
  --line-gap: 32px;
  --margin-color: rgba(220, 80, 80, 0.25);
  --margin-x: 72px;
  --ink: #1a1a2e;
  --spiral: #888;
  --sidebar-bg: #2c2416;
  --sidebar-text: #d4c4a0;
  --sidebar-hover: rgba(212, 196, 160, 0.1);
  --sidebar-active: rgba(212, 196, 160, 0.18);
  --toolbar-bg: rgba(44, 36, 22, 0.97);
  --shadow-page: 6px 8px 30px rgba(0, 0, 0, 0.35), 2px 3px 10px rgba(0, 0, 0, 0.2);
  --font-hand: 'Caveat', cursive;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
  font-size: 16px;
  height: 100%;
}

body {
  height: 100%;
  overflow: hidden;
  background-color: #1a1208;
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(80, 50, 10, 0.6) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(60, 30, 5, 0.5) 0%, transparent 55%),
    radial-gradient(ellipse at 60% 80%, rgba(90, 60, 15, 0.4) 0%, transparent 50%);
  font-family: var(--font-hand);
  user-select: text;
}

/* Ink canvas */
#inkCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.7;
}

/* ================================================================
   LAYOUT
   ================================================================ */

.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ================================================================
   SIDEBAR
   ================================================================ */

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(212, 196, 160, 0.12);
  transition: transform var(--transition), width var(--transition), min-width var(--transition), border-color var(--transition);
  z-index: 100;
  position: relative;
  overflow: hidden;
}

.sidebar::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(to bottom,
      transparent 0px,
      transparent 23px,
      rgba(255, 255, 255, 0.015) 23px,
      rgba(255, 255, 255, 0.015) 24px);
  pointer-events: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(212, 196, 160, 0.1);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-text {
  font-family: 'Dancing Script', cursive;
  font-size: 20px;
  color: #d4c4a0;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--sidebar-text);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  opacity: 0.6;
  transition: opacity var(--transition), background var(--transition);
}

.sidebar-toggle:hover {
  opacity: 1;
  background: var(--sidebar-hover);
}

.btn-new-note {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 14px 10px;
  padding: 10px 16px;
  background: linear-gradient(135deg, #6b4c2a, #4a3018);
  border: 1px solid rgba(212, 196, 160, 0.2);
  border-radius: 10px;
  color: #f0e0c0;
  font-family: 'Caveat', cursive;
  font-size: 16px;
  cursor: pointer;
  transition: all var(--transition);
  letter-spacing: 0.3px;
}

.btn-new-note:hover {
  background: linear-gradient(135deg, #7d5a34, #5c3d20);
  border-color: rgba(212, 196, 160, 0.35);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 14px 10px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(212, 196, 160, 0.1);
  border-radius: 8px;
}

.search-box svg {
  color: rgba(212, 196, 160, 0.4);
  flex-shrink: 0;
}

.search-box input {
  background: none;
  border: none;
  outline: none;
  color: var(--sidebar-text);
  font-family: 'Caveat', cursive;
  font-size: 15px;
  width: 100%;
  opacity: 0.7;
}

.search-box input::placeholder {
  color: rgba(212, 196, 160, 0.35);
}

.notes-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(212, 196, 160, 0.15) transparent;
}

.notes-list::-webkit-scrollbar {
  width: 4px;
}

.notes-list::-webkit-scrollbar-thumb {
  background: rgba(212, 196, 160, 0.15);
  border-radius: 4px;
}

.note-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--sidebar-text);
  transition: background var(--transition);
  border: 1px solid transparent;
  margin-bottom: 3px;
  position: relative;
  overflow: hidden;
}

.note-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 0;
  background: #d4c4a0;
  border-radius: 2px;
  transition: height var(--transition);
}

.note-item:hover {
  background: var(--sidebar-hover);
}

.note-item.active {
  background: var(--sidebar-active);
  border-color: rgba(212, 196, 160, 0.12);
}

.note-item.active::before {
  height: 65%;
}

.note-item-icon {
  font-size: 18px;
  flex-shrink: 0;
  opacity: 0.8;
}

.note-item-info {
  flex: 1;
  min-width: 0;
}

.note-item-title {
  font-family: 'Caveat', cursive;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #e8d8b0;
}

.note-item-date {
  font-family: 'Caveat', cursive;
  font-size: 12px;
  color: rgba(212, 196, 160, 0.45);
  margin-top: 1px;
}

.note-item-preview {
  font-family: 'Caveat', cursive;
  font-size: 12px;
  color: rgba(212, 196, 160, 0.4);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.sidebar-footer {
  padding: 10px 16px 14px;
  border-top: 1px solid rgba(212, 196, 160, 0.08);
  font-family: 'Caveat', cursive;
  font-size: 13px;
  color: rgba(212, 196, 160, 0.35);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* Credit line */
.credit-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin-top: 2px;
  opacity: 0.55;
  transition: opacity var(--transition);
}

.credit-line:hover {
  opacity: 1;
}

.credit-quill {
  color: rgba(212, 196, 160, 0.6);
  flex-shrink: 0;
  transition: transform 0.4s ease, color var(--transition);
}

.credit-line:hover .credit-quill {
  transform: rotate(-20deg) translateY(-1px);
  color: #d4c4a0;
}

.credit-text {
  font-family: 'Dancing Script', cursive;
  font-size: 12px;
  color: rgba(212, 196, 160, 0.5);
  white-space: nowrap;
  letter-spacing: 0.2px;
}

.credit-link {
  font-family: 'Dancing Script', cursive;
  font-size: 14px;
  font-weight: 600;
  color: #c8a86a;
  text-decoration: none;
  letter-spacing: 0.4px;
  position: relative;
  transition: color var(--transition), text-shadow var(--transition);
}

.credit-link::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 0;
  height: 1px;
  background: #c8a86a;
  transition: width 0.3s ease;
}

.credit-link:hover {
  color: #e8c880;
  text-shadow: 0 0 12px rgba(200, 168, 106, 0.45);
}

.credit-link:hover::after {
  width: 100%;
}

/* ================================================================
   MAIN AREA
   ================================================================ */

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ================================================================
   TOOLBAR
   ================================================================ */

.toolbar {
  background: var(--toolbar-bg);
  height: var(--toolbar-h);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  border-bottom: 1px solid rgba(212, 196, 160, 0.08);
  backdrop-filter: blur(10px);
  z-index: 50;
  flex-shrink: 0;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}

.toolbar-center {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  justify-content: center;
  flex-wrap: wrap;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.tool-btn {
  background: none;
  border: 1px solid rgba(212, 196, 160, 0.15);
  border-radius: 8px;
  color: rgba(212, 196, 160, 0.7);
  padding: 7px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.tool-btn:hover {
  background: rgba(212, 196, 160, 0.08);
  color: rgba(212, 196, 160, 0.95);
  border-color: rgba(212, 196, 160, 0.3);
}

.tool-btn.danger:hover {
  background: rgba(200, 50, 50, 0.15);
  border-color: rgba(200, 80, 80, 0.4);
  color: #e07070;
}

#mobileSidebarBtn {
  display: none;
}

#mobileFormatToggle {
  display: none;
}

#mobileFormatToggle {
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
}

#mobileFormatToggleLabel {
  font-family: 'Caveat', cursive;
  font-size: 15px;
  line-height: 1;
}

.note-title-input {
  background: none;
  border: none;
  border-bottom: 1px solid rgba(212, 196, 160, 0.2);
  outline: none;
  color: #e8d8b0;
  font-family: 'Caveat', cursive;
  font-size: 20px;
  font-weight: 600;
  width: 200px;
  padding: 4px 0;
  letter-spacing: 0.3px;
  transition: border-color var(--transition);
}

.note-title-input:focus {
  border-bottom-color: rgba(212, 196, 160, 0.5);
}

.note-title-input::placeholder {
  color: rgba(212, 196, 160, 0.3);
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tool-label {
  font-family: 'Caveat', cursive;
  font-size: 13px;
  color: rgba(212, 196, 160, 0.45);
  white-space: nowrap;
}

.tool-select {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(212, 196, 160, 0.18);
  border-radius: 7px;
  color: rgba(212, 196, 160, 0.85);
  font-family: 'Caveat', cursive;
  font-size: 14px;
  padding: 5px 8px;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition);
}

.tool-select:hover,
.tool-select:focus {
  border-color: rgba(212, 196, 160, 0.4);
}

.tool-select option {
  background: #2c2416;
  color: #d4c4a0;
}

.ink-colors {
  display: flex;
  align-items: center;
  gap: 5px;
}

.ink-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ink-dot:hover {
  transform: scale(1.2);
  border-color: rgba(255, 255, 255, 0.4);
}

.ink-dot.active {
  border-color: #fff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2), 0 2px 6px rgba(0, 0, 0, 0.4);
  transform: scale(1.15);
}

.ink-dot.custom-ink {
  background: conic-gradient(red, orange, yellow, green, blue, violet, red);
  color: white;
}

.btn-print {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  background: linear-gradient(135deg, #5c3d1a, #3d2610);
  border: 1px solid rgba(212, 196, 160, 0.25);
  border-radius: 9px;
  color: #f0e0c0;
  font-family: 'Caveat', cursive;
  font-size: 15px;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-print:hover {
  background: linear-gradient(135deg, #7a5226, #52351a);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

/* Formatting button group */
.fmt-group {
  gap: 3px;
}

.fmt-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
  padding: 0 7px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(212, 196, 160, 0.15);
  border-radius: 7px;
  color: rgba(212, 196, 160, 0.75);
  font-family: 'Caveat', cursive;
  font-size: 17px;
  cursor: pointer;
  transition: all var(--transition);
  line-height: 1;
  user-select: none;
}

.fmt-btn strong {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: -0.5px;
}

.fmt-btn em {
  font-style: italic;
  font-size: 17px;
}

.fmt-btn:hover {
  background: rgba(212, 196, 160, 0.1);
  border-color: rgba(212, 196, 160, 0.32);
  color: rgba(212, 196, 160, 0.95);
  transform: translateY(-1px);
}

.fmt-btn.active {
  background: rgba(200, 168, 106, 0.18);
  border-color: rgba(200, 168, 106, 0.45);
  color: #e8c880;
  box-shadow: 0 0 8px rgba(200, 168, 106, 0.2);
}

/* Vertical divider between fmt-group and other controls */
.fmt-divider {
  width: 1px;
  height: 24px;
  background: rgba(212, 196, 160, 0.15);
  border-radius: 1px;
  flex-shrink: 0;
}



/* ================================================================
   NOTEBOOK WRAPPER
   ================================================================ */

.notebook-wrapper {
  flex: 1;
  overflow-y: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 40px 30px 60px;
  scrollbar-width: thin;
  scrollbar-color: rgba(212, 196, 160, 0.2) transparent;
}

.notebook-wrapper::-webkit-scrollbar {
  width: 6px;
}

.notebook-wrapper::-webkit-scrollbar-thumb {
  background: rgba(212, 196, 160, 0.2);
  border-radius: 4px;
}

/* ================================================================
   NOTEBOOK / PAGE
   ================================================================ */

.notebook {
  position: relative;
  width: 720px;
  max-width: 100%;
}

/* Stacked page effect */
.notebook::before,
.notebook::after {
  content: '';
  position: absolute;
  background: linear-gradient(to bottom, #e8d5b0, #dfc9a0);
  border-radius: 2px 6px 6px 2px;
  box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.15);
}

.notebook::before {
  top: 5px;
  left: 52px;
  right: -6px;
  bottom: -5px;
  z-index: 1;
}

.notebook::after {
  top: 10px;
  left: 54px;
  right: -10px;
  bottom: -10px;
  z-index: 0;
  background: linear-gradient(to bottom, #dfc9a0, #d4be96);
  filter: brightness(0.92);
}

/* Spirals */
.spirals {
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 54px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 24px;
  gap: 0;
  pointer-events: none;
}

.spiral-ring {
  width: 32px;
  height: 32px;
  border: 4px solid #8a8a8a;
  border-right: 4px solid transparent;
  border-radius: 50%;
  margin-bottom: 14px;
  position: relative;
  background: linear-gradient(135deg, #aaa 0%, #666 50%, transparent 51%);
  background-clip: padding-box;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
}

.spiral-ring::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 12px;
  height: 12px;
  background: #2c2416;
  border-radius: 50%;
}

.spiral-ring::after {
  content: '';
  position: absolute;
  top: -2px;
  left: 50%;
  transform: translateX(-50%);
  width: 6px;
  height: 4px;
  background: #7a7a7a;
  border-radius: 2px 2px 0 0;
}

/* Page */
.page {
  position: relative;
  z-index: 5;
  margin-left: 54px;
  min-height: 900px;
  background: var(--paper-cream);
  border-radius: 0 4px 4px 0;
  box-shadow: var(--shadow-page);
  overflow: hidden;

  /* Paper texture via CSS */
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3CfeBlend in='SourceGraphic' mode='multiply'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23noise)' opacity='0.06'/%3E%3C/svg%3E"),
    linear-gradient(to bottom, #f8f0de 0%, #f2e8d0 40%, #ede3c8 70%, #e8dcbf 100%);
}

.paper-overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 15% 85%, rgba(139, 100, 50, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 90% 10%, rgba(160, 120, 60, 0.04) 0%, transparent 45%),
    radial-gradient(ellipse at 50% 50%, transparent 60%, rgba(0, 0, 0, 0.03) 100%);
}

/* Page curl */
.page-curl {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 50px;
  height: 50px;
  z-index: 20;
  background: linear-gradient(225deg,
      #d4c8a8 0%,
      #c8bca0 40%,
      rgba(180, 160, 120, 0.4) 70%,
      transparent 100%);
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
  box-shadow: -2px -2px 8px rgba(0, 0, 0, 0.15);
}

.page-curl::before {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(225deg, rgba(0, 0, 0, 0.06) 0%, transparent 60%);
}

/* Margin line */
.page-margin-line {
  position: absolute;
  left: var(--margin-x);
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--margin-color);
  z-index: 4;
  pointer-events: none;
}

/* Content area */
.page-content {
  position: relative;
  padding: 40px 40px 60px var(--margin-x);
  min-height: 900px;
}

/* Horizontal lines */
.page-lines {
  position: absolute;
  inset: 0;
  padding-top: 40px;
  pointer-events: none;
  z-index: 2;
}

/* Lined paper */
.page.lined .page-lines {
  background-image: repeating-linear-gradient(to bottom,
      transparent 0px,
      transparent calc(var(--line-gap) - 1px),
      var(--line-color) calc(var(--line-gap) - 1px),
      var(--line-color) var(--line-gap));
  background-position: 0 40px;
}

/* Grid paper */
.page.grid .page-lines {
  background-image:
    repeating-linear-gradient(to bottom,
      transparent 0px,
      transparent calc(var(--line-gap) - 1px),
      rgba(100, 149, 200, 0.2) calc(var(--line-gap) - 1px),
      rgba(100, 149, 200, 0.2) var(--line-gap)),
    repeating-linear-gradient(to right,
      transparent 0px,
      transparent calc(var(--line-gap) - 1px),
      rgba(100, 149, 200, 0.2) calc(var(--line-gap) - 1px),
      rgba(100, 149, 200, 0.2) var(--line-gap));
  background-position: 0 40px;
}

/* Dotted paper */
.page.dotted .page-lines {
  background-image: radial-gradient(circle, rgba(100, 149, 200, 0.4) 1px, transparent 1px);
  background-size: var(--line-gap) var(--line-gap);
  background-position: 40px 40px;
}

/* Blank */
.page.blank .page-lines {
  background: none;
}

/* ================================================================
   TYPEWRITER PAPER STYLES
   ================================================================ */

/* ── Typewriter ── warm ivory, double-spaced sepia lines ── */
.page.typewriter {
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3CfeBlend in='SourceGraphic' mode='multiply'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.05'/%3E%3C/svg%3E"),
    linear-gradient(175deg, #fdf9f0 0%, #f8f3e4 35%, #f2ebd6 70%, #eee5cc 100%);
}

.page.typewriter {
  --line-gap: 40px;
  --line-color: rgba(130, 100, 55, 0.2);
  --margin-color: rgba(180, 90, 50, 0.22);
}

.page.typewriter .page-lines {
  background-image: repeating-linear-gradient(to bottom,
      transparent 0px,
      transparent calc(var(--line-gap) - 1px),
      var(--line-color) calc(var(--line-gap) - 1px),
      var(--line-color) var(--line-gap));
  background-position: 0 60px;
}

/* Typed-ink stamp look on typewriter paper */
.page.typewriter .editor {
  letter-spacing: 0.05em;
  word-spacing: 3px;
  text-shadow:
    0.4px 0.4px 0 rgba(0, 0, 0, 0.09),
    -0.3px -0.2px 0 rgba(0, 0, 0, 0.05);
  font-variant-ligatures: none;
}

.page.typewriter .paper-overlay {
  background:
    radial-gradient(ellipse at 5% 95%, rgba(120, 80, 30, 0.07) 0%, transparent 50%),
    radial-gradient(ellipse at 95% 5%, rgba(140, 100, 40, 0.05) 0%, transparent 45%),
    radial-gradient(ellipse at 50% 50%, transparent 55%, rgba(0, 0, 0, 0.04) 100%);
}

/* ── Carbon Copy ── pale blue-grey, thin blue lines ── */
.page.carbon {
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3CfeBlend in='SourceGraphic' mode='multiply'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E"),
    linear-gradient(170deg, #f0f4fc 0%, #e8eef9 40%, #e2eaf6 70%, #dce5f4 100%);
}

.page.carbon {
  --line-gap: 28px;
  --line-color: rgba(70, 120, 210, 0.2);
  --margin-color: rgba(60, 100, 210, 0.22);
}

.page.carbon .page-lines {
  background-image: repeating-linear-gradient(to bottom,
      transparent 0px,
      transparent calc(var(--line-gap) - 1px),
      var(--line-color) calc(var(--line-gap) - 1px),
      var(--line-color) var(--line-gap));
  background-position: 0 40px;
}

/* Lighter ink on carbon (faded duplicated look) */
.page.carbon .editor {
  letter-spacing: 0.04em;
  opacity: 0.88;
  text-shadow:
    0.3px 0.5px 0.5px rgba(30, 60, 160, 0.08),
    -0.2px -0.1px 0 rgba(30, 60, 160, 0.04);
  font-variant-ligatures: none;
}

.page.carbon .paper-overlay {
  background:
    radial-gradient(ellipse at 0% 100%, rgba(50, 100, 220, 0.07) 0%, transparent 55%),
    radial-gradient(ellipse at 100% 0%, rgba(40, 90, 200, 0.05) 0%, transparent 50%),
    linear-gradient(to bottom, transparent 80%, rgba(30, 80, 190, 0.04) 100%);
}

/* ── Parchment ── aged amber, rustic no-rule manuscript feel ── */
.page.parchment {
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='5' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3CfeBlend in='SourceGraphic' mode='multiply'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='0.08'/%3E%3C/svg%3E"),
    linear-gradient(160deg, #e8ce80 0%, #d8b85a 30%, #c8a840 60%, #bc9c36 85%, #b09030 100%);
}

.page.parchment {
  --line-gap: 36px;
  --line-color: rgba(100, 70, 20, 0.12);
  --margin-color: rgba(100, 60, 10, 0.18);
}

/* Parchment has very faint ghost-lines */
.page.parchment .page-lines {
  background-image: repeating-linear-gradient(to bottom,
      transparent 0px,
      transparent calc(var(--line-gap) - 1px),
      var(--line-color) calc(var(--line-gap) - 1px),
      var(--line-color) var(--line-gap));
  background-position: 0 50px;
}

/* Rich, dark ink on parchment — like a quill pen */
.page.parchment .editor {
  letter-spacing: 0.03em;
  text-shadow:
    1px 1px 1px rgba(60, 30, 0, 0.12),
    -0.5px -0.5px 0 rgba(40, 20, 0, 0.06);
  word-spacing: 3px;
}

.page.parchment .paper-overlay {
  background:
    radial-gradient(ellipse at 10% 90%, rgba(100, 60, 10, 0.14) 0%, transparent 50%),
    radial-gradient(ellipse at 90% 10%, rgba(120, 80, 15, 0.10) 0%, transparent 45%),
    radial-gradient(ellipse at 30% 60%, rgba(80, 50, 5, 0.06) 0%, transparent 40%),
    radial-gradient(ellipse at 50% 50%, transparent 55%, rgba(70, 40, 5, 0.08) 100%);
}


/* ================================================================
   EDITOR
   ================================================================ */

.editor {
  position: relative;
  z-index: 5;
  outline: none;
  min-height: 820px;
  line-height: var(--line-gap);
  font-family: var(--font-hand);
  font-size: 20px;
  color: var(--ink);
  caret-color: var(--ink);
  word-break: break-word;
  padding-left: 20px;

  /* Subtle letter spacing for handwriting feel */
  letter-spacing: 0.4px;
  word-spacing: 2px;
}

.editor:empty::before {
  content: attr(data-placeholder);
  color: rgba(100, 80, 50, 0.28);
  font-style: italic;
  pointer-events: none;
  position: absolute;
}

/* Selection */
.editor ::selection {
  background: rgba(100, 80, 50, 0.18);
}

/* ================================================================
   EMPTY STATE
   ================================================================ */

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: rgba(212, 196, 160, 0.5);
  gap: 14px;
}

.empty-icon {
  font-size: 72px;
  filter: grayscale(0.3);
  animation: float 4s ease-in-out infinite;
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-10px);
  }
}

.empty-state h2 {
  font-family: 'Dancing Script', cursive;
  font-size: 32px;
  color: rgba(212, 196, 160, 0.6);
  font-weight: 600;
}

.empty-state p {
  font-family: 'Caveat', cursive;
  font-size: 18px;
  color: rgba(212, 196, 160, 0.35);
}

.btn-new-note-empty {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 12px 28px;
  background: linear-gradient(135deg, #6b4c2a, #4a3018);
  border: 1px solid rgba(212, 196, 160, 0.2);
  border-radius: 12px;
  color: #f0e0c0;
  font-family: 'Caveat', cursive;
  font-size: 18px;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-new-note-empty:hover {
  background: linear-gradient(135deg, #7d5a34, #5c3d20);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

/* ================================================================
   MODALS
   ================================================================ */

.print-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease;
}

.print-modal.open {
  display: flex;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.print-modal-content {
  background: linear-gradient(160deg, #f5efe0, #ede0c4);
  border-radius: 16px;
  padding: 32px 36px;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(180, 150, 100, 0.3);
  animation: slideUp 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.print-modal-content::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(to bottom,
      transparent 0px,
      transparent 31px,
      rgba(100, 149, 200, 0.2) 31px,
      rgba(100, 149, 200, 0.2) 32px);
  pointer-events: none;
}

@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.print-modal-content h3 {
  font-family: 'Dancing Script', cursive;
  font-size: 26px;
  color: #3d2810;
  margin-bottom: 10px;
  position: relative;
  z-index: 1;
}

.print-modal-content p {
  font-family: 'Caveat', cursive;
  font-size: 16px;
  color: #5c4030;
  line-height: 1.6;
  position: relative;
  z-index: 1;
}

.print-modal-content strong {
  color: #3d2810;
}

.print-options {
  margin: 16px 0;
  position: relative;
  z-index: 1;
}

.print-option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Caveat', cursive;
  font-size: 16px;
  color: #5c4030;
  cursor: pointer;
}

.print-option input {
  accent-color: #6b4c2a;
  width: 16px;
  height: 16px;
}

.print-modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
  position: relative;
  z-index: 1;
}

.print-modal-actions button {
  padding: 9px 20px;
  border-radius: 9px;
  font-family: 'Caveat', cursive;
  font-size: 16px;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid transparent;
}

.print-modal-actions button:first-child {
  background: rgba(60, 40, 20, 0.08);
  color: #5c4030;
  border-color: rgba(100, 70, 40, 0.2);
}

.print-modal-actions button:first-child:hover {
  background: rgba(60, 40, 20, 0.14);
}

.btn-confirm {
  background: linear-gradient(135deg, #6b4c2a, #4a3018) !important;
  color: #f0e0c0 !important;
  border-color: rgba(212, 196, 160, 0.2) !important;
}

.btn-confirm:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.btn-danger-confirm {
  background: linear-gradient(135deg, #7b2020, #4a1010) !important;
  color: #ffd0d0 !important;
  border-color: rgba(200, 100, 100, 0.2) !important;
}

.btn-danger-confirm:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

/* ================================================================
   PRINT STYLES
   ================================================================ */

@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body {
    background: white !important;
    overflow: visible !important;
  }

  #inkCanvas,
  .sidebar,
  .toolbar,
  .mobile-format-bar,
  .install-toast,
  .update-toast,
  .page-curl,
  .spirals,
  .notebook::before,
  .notebook::after {
    display: none !important;
  }

  .app-shell {
    display: block !important;
    height: auto !important;
  }

  .main-area {
    display: block !important;
    height: auto !important;
    overflow: visible !important;
  }

  .notebook-wrapper {
    padding: 0 !important;
    overflow: visible !important;
    height: auto !important;
    display: block !important;
  }

  .notebook {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
  }

  .page {
    margin: 0 !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    min-height: auto !important;
    page-break-after: always;
    width: 100% !important;
    background: white !important;
    background-image: none !important;
  }

  .page.lined {
    background-image: repeating-linear-gradient(to bottom,
        transparent 0px,
        transparent calc(var(--line-gap) - 1px),
        rgba(100, 149, 200, 0.4) calc(var(--line-gap) - 1px),
        rgba(100, 149, 200, 0.4) var(--line-gap)) !important;
    background-position: 0 40px !important;
  }

  .editor {
    min-height: auto !important;
  }

  .paper-overlay {
    display: none !important;
  }

  .print-modal {
    display: none !important;
  }
}

/* ================================================================
   SIDEBAR — DESKTOP COLLAPSE
   ================================================================ */

/* Collapsed state on desktop: slide the sidebar off-screen */
.sidebar.collapsed {
  transform: translateX(-100%);
  min-width: 0;
  width: 0;
  border-right-color: transparent;
}

/* Reveal tab — only visible when sidebar is collapsed on desktop */
.sidebar-reveal {
  display: none;
  /* hidden by default */
  position: fixed;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 110;
  width: 22px;
  height: 56px;
  background: linear-gradient(180deg, #4a3018, #3a2210);
  border: 1px solid rgba(212, 196, 160, 0.18);
  border-left: none;
  border-radius: 0 8px 8px 0;
  color: rgba(212, 196, 160, 0.7);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.3);
}

.sidebar-reveal.visible {
  display: flex;
}

.sidebar-reveal:hover {
  width: 28px;
  background: linear-gradient(180deg, #6b4c2a, #4a3018);
  color: rgba(212, 196, 160, 1);
  box-shadow: 3px 0 16px rgba(0, 0, 0, 0.4);
}

/* ================================================================
   RESPONSIVE
   ================================================================ */

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    z-index: 200;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 30px rgba(0, 0, 0, 0.5);
  }

  #mobileSidebarBtn {
    display: flex !important;
  }

  .toolbar-center {
    gap: 8px;
  }

  .notebook {
    width: 100%;
  }

  .note-title-input {
    width: 120px;
  }

  /* Never show the desktop reveal tab on mobile */
  .sidebar-reveal {
    display: none !important;
  }
}

@media (max-width: 600px) {
  .toolbar-center {
    display: none;
  }
}

/* ================================================================
   ANIMATIONS
   ================================================================ */

@keyframes inkFade {
  0% {
    opacity: 1;
    transform: scale(1);
  }

  100% {
    opacity: 0;
    transform: scale(0.3);
  }
}

.note-item {
  animation: noteItemIn 0.3s ease;
}

@keyframes noteItemIn {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Scrollbar body */
body::-webkit-scrollbar {
  width: 6px;
}

/* ================================================================
   OFFLINE BADGE
   ================================================================ */

.offline-badge {
  display: none;
  align-items: center;
  gap: 5px;
  background: rgba(200, 80, 40, 0.18);
  border: 1px solid rgba(200, 100, 60, 0.35);
  border-radius: 20px;
  padding: 4px 10px;
  font-family: 'Caveat', cursive;
  font-size: 13px;
  color: #e8a080;
  white-space: nowrap;
}

.offline-badge::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #e07050;
  flex-shrink: 0;
  animation: pulse-offline 1.8s ease-in-out infinite;
}

.offline-badge.visible {
  display: flex;
}

@keyframes pulse-offline {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.3;
  }
}

/* ================================================================
   PWA INSTALL TOAST
   ================================================================ */

.install-toast {
  /* display:none = fully removed from hit-testing when hidden */
  display: none;
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  opacity: 0;
  align-items: center;
  gap: 12px;
  background: linear-gradient(135deg, #3a2810, #2c2010);
  border: 1px solid rgba(200, 168, 106, 0.3);
  border-radius: 16px;
  padding: 14px 18px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3);
  z-index: 2000;
  max-width: 92vw;
  /* transition only runs when display is flex (set by JS) */
  transition: opacity 0.35s ease, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  backdrop-filter: blur(12px);
  pointer-events: auto;
}

/* Shown: display:flex is set by JS first, then this class triggers animation */
.install-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.install-toast-icon {
  font-size: 26px;
  flex-shrink: 0;
}

.install-toast-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.install-toast-body strong {
  font-family: 'Dancing Script', cursive;
  font-size: 17px;
  color: #e8d8b0;
  display: block;
}

.install-toast-body span {
  font-family: 'Caveat', cursive;
  font-size: 13px;
  color: rgba(212, 196, 160, 0.55);
}

.install-btn-accept {
  padding: 8px 18px;
  background: linear-gradient(135deg, #c8a86a, #a08040);
  border: none;
  border-radius: 9px;
  color: #2c2010;
  font-family: 'Caveat', cursive;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.install-btn-accept:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.install-btn-dismiss {
  background: none;
  border: 1px solid rgba(212, 196, 160, 0.15);
  border-radius: 7px;
  color: rgba(212, 196, 160, 0.5);
  padding: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  /* Minimum 44×44 px touch target on all screens */
  min-width: 44px;
  min-height: 44px;
  transition: all var(--transition);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  /* Ensure the element itself (not SVG child) receives touch events */
  pointer-events: auto;
}

.install-btn-dismiss:hover,
.install-btn-dismiss:active {
  color: rgba(212, 196, 160, 0.9);
  border-color: rgba(212, 196, 160, 0.3);
  background: rgba(212, 196, 160, 0.06);
}


/* ================================================================
   SW UPDATE TOAST
   ================================================================ */

.update-toast {
  position: fixed;
  top: 80px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(135deg, #1b4332, #143326);
  border: 1px solid rgba(100, 200, 130, 0.3);
  border-radius: 12px;
  padding: 12px 16px;
  color: #a8e6b8;
  font-family: 'Caveat', cursive;
  font-size: 15px;
  z-index: 2000;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  transform: translateX(160%);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.update-toast.visible {
  transform: translateX(0);
}

.update-toast button {
  background: rgba(100, 200, 130, 0.2);
  border: 1px solid rgba(100, 200, 130, 0.35);
  border-radius: 7px;
  color: #a8e6b8;
  font-family: 'Caveat', cursive;
  font-size: 14px;
  padding: 5px 12px;
  cursor: pointer;
  transition: all var(--transition);
}

.update-toast button:hover {
  background: rgba(100, 200, 130, 0.35);
}

/* ================================================================
   MOBILE BOTTOM FORMAT BAR
   ================================================================ */

.mobile-format-bar {
  display: none;
  position: fixed;
  top: var(--toolbar-h);
  bottom: auto;
  left: 0;
  right: 0;
  z-index: 300;
  background: rgba(36, 28, 16, 0.98);
  border-top: none;
  border-bottom: 1px solid rgba(212, 196, 160, 0.15);
  padding: 10px 16px;
  padding-bottom: 10px;
  gap: 8px;
  align-items: center;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

.mobile-format-bar .fmt-btn {
  min-width: 40px;
  height: 38px;
  font-size: 18px;
  flex-shrink: 0;
}

.mobile-format-close {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(212, 196, 160, 0.12);
  border-radius: 8px;
  color: rgba(212, 196, 160, 0.5);
  padding: 7px;
  cursor: pointer;
  display: flex;
  align-items: center;
  margin-left: auto;
  transition: all var(--transition);
}

.mobile-format-close:hover {
  color: rgba(212, 196, 160, 0.9);
}

.mobile-font-select {
  font-size: 13px;
  padding: 6px 8px;
  max-width: 90px;
  flex-shrink: 0;
}

.mobile-compact-select {
  font-size: 13px;
  padding: 6px 8px;
  max-width: 78px;
  flex-shrink: 0;
}

.mobile-ink-colors {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.mobile-ink-dot {
  width: 26px;
  height: 26px;
  min-width: 26px;
  min-height: 26px;
}

.mobile-format-bar .fmt-divider {
  flex-shrink: 0;
}

/* ================================================================
   MOBILE RESPONSIVE — enhanced
   ================================================================ */

@media (max-width: 900px) {
  body.mobile-bar-open .mobile-format-bar {
    display: flex;
  }

  #mobileFormatToggle {
    display: inline-flex;
  }

  /* When mobile bar visible, add top padding to notebook so it's not hidden */
  body.mobile-bar-open .notebook-wrapper {
    padding-top: 98px;
  }

  /* Toolbar: hide style/size/ink/paper on small screens (in mobile bar instead) */
  .toolbar {
    padding: 0 10px;
    gap: 8px;
  }

  .note-title-input {
    width: clamp(100px, 30vw, 200px);
    font-size: 16px;
  }

  .btn-print-label {
    display: none;
  }

  .btn-print {
    padding: 8px 10px;
    gap: 0;
  }

  /* Make notebook wrapper fill properly */
  .notebook-wrapper {
    padding: 20px 12px 50px;
  }

  /* Scale down notebook spirals on mobile */
  .spirals {
    width: 38px;
  }

  .spiral-ring {
    width: 24px;
    height: 24px;
  }

  .page {
    margin-left: 38px;
  }

  .page-content {
    padding: 28px 20px 40px 58px;
  }

  :root {
    --margin-x: 54px;
  }

  /* Sidebar full-width on mobile */
  .sidebar {
    width: 100vw;
    max-width: 320px;
  }

  /* Better touch targets throughout */
  .tool-btn,
  .fmt-btn,
  .btn-new-note,
  .note-item {
    min-height: 44px;
  }

  .note-item {
    padding: 12px 14px;
  }

  .install-toast {
    /* On mobile: full-width, above format bar, same display:none base state */
    bottom: 80px;
    left: 12px;
    right: 12px;
    max-width: none;
    transform: translateY(16px);
    /* no translateX centering needed since left/right set */
  }

  .install-toast.visible {
    transform: translateY(0);
  }
}

@media (max-width: 480px) {

  /* Hide ink color dots and divider on very small screens */
  .tool-group:has(#ink-midnight),
  .fmt-divider {
    display: none;
  }

  .toolbar-center {
    display: none;
  }

  /* Larger text on mobile for readability */
  .editor {
    font-size: 20px !important;
    line-height: 34px !important;
  }

  /* Notebook fills screen width better */
  .notebook-wrapper {
    padding: 16px 8px 80px;
  }

  .spirals {
    width: 32px;
  }

  .spiral-ring {
    width: 20px;
    height: 20px;
    margin-bottom: 10px;
  }

  .page {
    margin-left: 32px;
  }
}

/* Safe area padding for notch / home bar devices */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .notebook-wrapper {
    padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px));
  }
}
