/* ========================================
   Markdown to WeChat Converter - Sketch & Book Style
   Version 1.5.2
   Theme: Parchment & Ink / Sketchy
======================================== */

:root {
  /* Book/Parchment Palette */
  --bg-color: #Fdfbf7;
  /* Warm Parchment */
  --paper-color: #fcfaf2;
  /* Lighter parchment for panels */
  --primary-color: #5D4037;
  /* Ink Brown */
  --primary-hover: #3E2723;
  /* Darker Ink */
  --secondary-color: #8D6E63;
  /* Lighter Ink */
  --text-primary: #3E2723;
  /* Dark Ink text */
  --text-secondary: #5D4037;
  /* Lighter Ink text */
  --accent-color: #A1887F;
  --border-color: #8D6E63;
  /* Ink border */
  --white: #fffefb;

  /* Dimensions & Spacing */
  --header-height: 64px;
  --toolbar-height: 52px;

  /* Sketchy Borders */
  --border-radius-base: 255px 15px 225px 15px / 15px 225px 15px 255px;
  --border-radius-small: 2px 2px 2px 2px / 2px 2px 2px 2px;
  /* More subtle for small items */
  --border-width: 2px;
}

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

body {
  font-family: 'Source Serif 4', 'Georgia', serif;
  background-color: var(--bg-color);
  background-image:
    linear-gradient(to right, rgba(93, 64, 55, 0.05) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(93, 64, 55, 0.05) 1px, transparent 1px);
  background-size: 20px 20px;
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

/* App Layout */
.app-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Navbar */
.navbar {
  height: var(--header-height);
  background: var(--paper-color);
  border-bottom: var(--border-width) solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  box-shadow: 0 2px 10px rgba(62, 39, 35, 0.05);
  font-family: 'Patrick Hand', cursive;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  font-size: 20px;
  color: var(--primary-color);
  letter-spacing: 0.5px;
}

.brand-icon {
  background: var(--primary-color);
  color: #fff;
  /* Paper white text on ink */
  width: 36px;
  height: 36px;
  border-radius: 40% 60% 70% 30% / 40% 50% 60% 50%;
  /* Blob shape */
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 20px;
  font-family: 'Patrick Hand', cursive;
  box-shadow: 2px 3px 0px rgba(62, 39, 35, 0.2);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Word Count */
.word-count {
  font-size: 14px;
  color: var(--text-secondary);
  padding: 6px 14px;
  background: rgba(141, 110, 99, 0.1);
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  white-space: nowrap;
  font-family: 'Patrick Hand', cursive;
  border: 1px dashed var(--border-color);
}

.theme-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  color: var(--text-primary);
  font-family: 'Patrick Hand', cursive;
}

.nav-select {
  padding: 4px 12px;
  border: 2px solid var(--border-color);
  background-color: var(--white);
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  font-size: 15px;
  outline: none;
  font-family: 'Patrick Hand', cursive;
  color: var(--primary-color);
  cursor: pointer;
}

.nav-select:focus {
  border-color: var(--primary-hover);
}

/* Buttons */
.btn {
  border: 2px solid var(--border-color);
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  padding: 8px 18px;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 600;
  font-family: 'Patrick Hand', cursive;
  position: relative;
  overflow: visible;
}

.btn-primary {
  background-color: var(--primary-color);
  color: #fff;
  border-color: var(--primary-color);
  box-shadow: 2px 2px 0px rgba(62, 39, 35, 0.3);
}

.btn-primary:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0px rgba(62, 39, 35, 0.3);
}

.btn-secondary {
  background-color: var(--white);
  color: var(--primary-color);
  border-color: var(--border-color);
  box-shadow: 2px 2px 0px rgba(141, 110, 99, 0.2);
}

.btn-secondary:hover {
  background-color: rgba(141, 110, 99, 0.1);
  transform: rotate(-1deg);
}

.btn-secondary:active {
  transform: translate(1px, 1px) rotate(-1deg);
  box-shadow: 1px 1px 0px rgba(141, 110, 99, 0.2);
}

/* Toolbar */
.toolbar {
  height: var(--toolbar-height);
  background: var(--bg-color);
  border-bottom: var(--border-width) solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  font-family: 'Patrick Hand', cursive;
}

.toolbar-group {
  display: flex;
  gap: 6px;
  background: rgba(255, 255, 255, 0.5);
  padding: 4px;
  border-radius: 10px;
  border: 1px dashed rgba(141, 110, 99, 0.3);
}

.tool-btn {
  background: transparent;
  border: 1px solid transparent;
  min-width: 32px;
  padding: 0 8px;
  height: 32px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
  transition: all 0.2s;
  font-family: 'Patrick Hand', cursive;
}

.tool-btn:hover {
  background: rgba(141, 110, 99, 0.1);
  color: var(--primary-color);
  transform: scale(1.1) rotate(2deg);
}

.tool-btn:active {
  background: rgba(141, 110, 99, 0.2);
  transform: scale(0.95);
}

.toolbar-divider {
  width: 2px;
  height: 24px;
  background: var(--border-color);
  margin: 0 4px;
  border-radius: 2px;
  opacity: 0.5;
  transform: rotate(5deg);
}

/* Workspace (Split View) */
.workspace {
  flex: 1;
  display: flex;
  overflow: hidden;
  background-color: var(--bg-color);
}

.pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.editor-pane {
  background: var(--paper-color);
  border-right: var(--border-width) solid var(--border-color);
  position: relative;
}

/* Paper texture or lines for editor */
.editor-pane::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  background: linear-gradient(rgba(141, 110, 99, 0.05) 1px, transparent 1px);
  background-size: 100% 28.8px;
  /* Match line height approx */
  opacity: 0.5;
  z-index: 0;
}

.preview-pane {
  background: var(--bg-color);
  /* Patterned bg from body shows through or explicitly set */
  padding: 40px;
  align-items: center;
  overflow-y: auto;
  border-left: 1px solid rgba(255, 255, 255, 0.5);
  /* Highlight */
}

/* Editor */
#markdown-editor {
  flex: 1;
  width: 100%;
  padding: 24px 30px;
  border: none;
  resize: none;
  outline: none;
  font-size: 16px;
  line-height: 1.8;
  font-family: 'Courier Prime', 'Courier New', monospace;
  /* Monospace for code/markdown editing */
  color: var(--text-primary);
  background: transparent;
  z-index: 1;
}

/* Mobile Preview Mockup - Sketchy Phone */
.mobile-mockup {
  width: 375px;
  min-width: 375px;
  height: 812px;
  min-height: 812px;
  background: #fff;
  border-radius: 40px;
  box-shadow:
    10px 15px 0px rgba(62, 39, 35, 0.1),
    /* Hard sketched shadow */
    0 0 0 4px var(--primary-color) inset,
    /* Inner Ink Line */
    0 0 0 8px var(--bg-color) inset;
  /* Gap */
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 4px solid var(--primary-color);
  transform: rotate(-0.5deg);
}

.mobile-header {
  height: 48px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary-color);
  background: #fff;
  z-index: 10;
  border-bottom: 2px dashed rgba(141, 110, 99, 0.2);
  font-family: 'Patrick Hand', cursive;
}

.mobile-notch {
  width: 140px;
  height: 28px;
  background: var(--primary-color);
  border-radius: 0 0 15px 15px;
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
}

/* Sketchy reflection on notch */
.mobile-notch::after {
  content: '';
  position: absolute;
  top: 6px;
  right: 12px;
  width: 8px;
  height: 8px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 50%;
}

.mobile-bar {
  height: 48px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
  font-size: 17px;
  font-weight: 600;
  border-bottom: 1px solid rgba(141, 110, 99, 0.1);
  background: #fff;
  z-index: 10;
  color: var(--primary-color);
  font-family: 'Source Serif 4', serif;
}

.mobile-content-wrapper {
  flex: 1;
  overflow-y: auto;
  background: #fff;
  padding: 16px;
}

/* Hide scrollbar in mockup but allow scroll */
.mobile-content-wrapper::-webkit-scrollbar {
  width: 6px;
}

.mobile-content-wrapper::-webkit-scrollbar-thumb {
  background: rgba(141, 110, 99, 0.3);
  border-radius: 4px;
}

/* Notification */
.notification {
  position: fixed;
  top: 80px;
  right: 20px;
  padding: 14px 28px;
  background: var(--primary-color);
  color: #fff;
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.2);
  transform: translateX(120%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1000;
  font-size: 16px;
  font-family: 'Patrick Hand', cursive;
}

.notification.show {
  transform: translateX(0) rotate(-2deg);
}

.notification.error {
  background: #C62828;
  border: 2px solid #8E0000;
}

.notification.success {
  background: #2E7D32;
  /* Sketchy Green */
  border: 2px solid #1B5E20;
}

/* Mermaid SVG Responsiveness */
.mermaid svg {
  max-width: 100%;
  height: auto;
}

/* View Controls */
.view-controls {
  display: flex;
  background: transparent;
  padding: 2px;
  border-radius: 8px;
  gap: 6px;
}

.btn-icon {
  background: transparent;
  border: 2px solid transparent;
  padding: 6px;
  border-radius: 8px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: rgba(141, 110, 99, 0.1);
  color: var(--primary-color);
  transform: scale(1.1);
}

.btn-icon.active {
  background: var(--white);
  color: var(--primary-color);
  border: 2px solid var(--border-color);
  box-shadow: 1px 1px 0 rgba(141, 110, 99, 0.2);
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
}

.btn-icon svg {
  display: block;
  stroke-width: 0.5px;
  /* Make icons look a bit daintier */
}

/* PC Preview Mode (Sketchy Monitor) */
.mobile-mockup.pc-view {
  width: 900px;
  height: 600px;
  max-width: 95%;
  max-height: 90vh;
  min-width: unset;
  min-height: unset;
  border: 12px solid var(--primary-color);
  border-bottom-width: 20px;
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  background: #fff;
  box-shadow:
    6px 8px 0 rgba(62, 39, 35, 0.2),
    inset 0 0 20px rgba(0, 0, 0, 0.05);
  margin: 0 auto;
  position: relative;
  transform: rotate(0.5deg);
}

/* Monitor Stand */
.mobile-mockup.pc-view::after {
  content: '';
  position: absolute;
  bottom: -50px;
  left: 50%;
  transform: translateX(-50%);
  width: 140px;
  height: 40px;
  background: var(--primary-color);
  z-index: -1;
  clip-path: polygon(15% 0, 85% 0, 100% 100%, 0% 100%);
  border-radius: 4px;
}

.mobile-mockup.pc-view::before {
  content: '';
  position: absolute;
  bottom: -60px;
  left: 50%;
  transform: translateX(-50%) skewX(-10deg);
  width: 200px;
  height: 12px;
  background: var(--primary-color);
  border-radius: 10px;
  z-index: -1;
  box-shadow: 4px 4px 0 rgba(62, 39, 35, 0.2);
}

/* Hide Mobile Elements in PC View */
.mobile-mockup.pc-view .mobile-header,
.mobile-mockup.pc-view .mobile-bar,
.mobile-mockup.pc-view .mobile-notch {
  display: none;
}

.mobile-mockup.pc-view .mobile-content-wrapper {
  padding: 0;
  height: 100%;
  overflow-y: auto;
  border-radius: 4px;
}

.mobile-mockup.pc-view .preview-content {
  padding: 40px 60px;
  max-width: 800px;
  margin: 0 auto;
  min-height: 100%;
}

/* Scrollbar for PC view */
.mobile-mockup.pc-view .mobile-content-wrapper::-webkit-scrollbar {
  width: 8px;
}

.mobile-mockup.pc-view .mobile-content-wrapper::-webkit-scrollbar-track {
  background: transparent;
}

.mobile-mockup.pc-view .mobile-content-wrapper::-webkit-scrollbar-thumb {
  background: var(--secondary-color);
  border-radius: 10px;
  border: 2px solid #fff;
}

/* Task List Checkbox Styles (for preview) */
.task-checkbox {
  display: inline-block;
  width: 18px;
  height: 18px;
  margin-right: 8px;
  vertical-align: middle;
  border: 2px solid var(--primary-color);
  border-radius: 6px 3px 6px 4px / 4px 6px 3px 6px;
  /* Sketchy */
  background: #fff;
  cursor: pointer;
}

.task-checkbox.checked {
  background: var(--primary-color);
  position: relative;
}

.task-checkbox.checked::after {
  content: '✓';
  color: #fff;
  position: absolute;
  top: -2px;
  left: 1px;
  font-size: 14px;
  font-family: 'Patrick Hand', cursive;
  font-weight: bold;
}

/* ========================================
   Responsive & Mobile Styles
   ======================================== */

/* --- Mobile Tab Bar --- */
.mobile-tab-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--paper-color);
  border-top: 2px solid var(--border-color);
  z-index: 1000;
  box-shadow: 0 -2px 10px rgba(62, 39, 35, 0.08);
  font-family: 'Patrick Hand', cursive;
}

.mobile-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 100%;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.2s;
  font-family: 'Patrick Hand', cursive;
  padding: 0;
}

.mobile-tab svg {
  width: 22px;
  height: 22px;
}

.mobile-tab.active {
  color: var(--primary-color);
  position: relative;
}

.mobile-tab.active::after {
  content: '';
  position: absolute;
  top: 0;
  left: 20%;
  right: 20%;
  height: 3px;
  background: var(--primary-color);
  border-radius: 0 0 3px 3px;
}

.mobile-tab:active {
  opacity: 0.7;
}

/* --- Mobile Overlay --- */
.mobile-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 2000;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.mobile-overlay.open {
  display: block;
  opacity: 1;
}

/* --- Mobile Drawer --- */
.mobile-drawer {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--paper-color);
  border-top: 2px solid var(--border-color);
  border-radius: 20px 20px 0 0;
  z-index: 2001;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 -8px 30px rgba(62, 39, 35, 0.15);
  font-family: 'Patrick Hand', cursive;
  max-height: 70vh;
  overflow-y: auto;
}

.mobile-drawer.open {
  display: block;
  transform: translateY(0);
}

.mobile-drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px 12px;
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 1px solid rgba(141, 110, 99, 0.15);
}

.mobile-drawer-header .btn-icon {
  font-size: 20px;
  padding: 4px 8px;
  color: var(--text-secondary);
}

.mobile-drawer-content {
  padding: 8px 0 24px;
}

.mobile-drawer-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  color: var(--text-primary);
  font-size: 16px;
  width: 100%;
  border: none;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s;
}

.mobile-drawer-item:active {
  background: rgba(141, 110, 99, 0.08);
}

.mobile-drawer-item svg {
  flex-shrink: 0;
  color: var(--secondary-color);
}

.drawer-item-label {
  flex-shrink: 0;
  min-width: 80px;
  color: var(--text-secondary);
}

.mobile-drawer-item .nav-select {
  flex: 1;
  padding: 8px 12px;
  font-size: 16px;
}

.btn-drawer {
  font-family: 'Patrick Hand', cursive;
  font-weight: 500;
  justify-content: flex-start;
}

/* --- Utility: Desktop/Mobile Visibility --- */
.nav-mobile {
  display: none !important;
}

/* --- Responsive: Tablet & Below --- */
@media (max-width: 1024px) {
  .mobile-mockup.pc-view {
    width: 100%;
    max-width: 100%;
  }

  .mobile-mockup.pc-view .preview-content {
    padding: 30px 24px;
  }
}

/* --- Responsive: Tablet & Mobile (<= 900px) --- */
@media (max-width: 900px) {
  .mobile-tab-bar {
    display: flex;
    height: 32px;
  }

  .mobile-tab {
    font-size: 10px;
    gap: 1px;
  }

  .mobile-tab svg {
    width: 14px;
    height: 14px;
  }

  /* Hide toolbar when previewing */
  .app-layout:has(.workspace[data-view="preview"]) > .toolbar {
    display: none;
  }

  /* Workspace - single pane, account for tab bar */
  .workspace {
    flex-direction: column;
    padding-bottom: 32px;
  }

  .editor-pane {
    border-right: none;
  }

  .preview-pane {
    display: none;
    padding: 0;
    border-left: none;
  }

  /* When in preview mode */
  .workspace[data-view="preview"] .editor-pane {
    display: none;
  }

  .workspace[data-view="preview"] .preview-pane {
    display: flex;
    padding: 16px;
    align-items: stretch;
  }

  /* Flat preview (no phone mockup) */
  .workspace[data-view="preview"] .mobile-mockup {
    width: 100%;
    min-width: unset;
    height: auto;
    min-height: unset;
    border: none;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(62, 39, 35, 0.1);
    transform: none;
    overflow: hidden;
  }

  .workspace[data-view="preview"] .mobile-mockup::before,
  .workspace[data-view="preview"] .mobile-mockup::after {
    display: none;
  }

  .workspace[data-view="preview"] .mobile-header,
  .workspace[data-view="preview"] .mobile-bar,
  .workspace[data-view="preview"] .mobile-notch {
    display: none;
  }

  .workspace[data-view="preview"] .mobile-content-wrapper {
    padding: 16px;
    min-height: calc(100vh - 32px - 32px - var(--toolbar-height));
  }
}

/* --- Responsive: Mobile (< 768px) --- */
@media (max-width: 768px) {
  /* Show mobile elements */
  .nav-mobile {
    display: flex !important;
  }

  .nav-desktop {
    display: none !important;
  }

  /* Compact Navbar */
  .navbar {
    padding: 0 8px;
    height: 32px;
  }

  .brand-text {
    display: none;
  }

  .brand-icon {
    width: 22px;
    height: 22px;
    font-size: 12px;
  }

  .nav-right {
    gap: 4px;
  }

  .word-count {
    display: none;
  }

  .theme-switch {
    display: none;
  }

  .view-controls {
    display: none;
  }

  .nav-select {
    padding: 4px 8px;
    font-size: 14px;
  }

  #copy-btn {
    padding: 6px 14px;
    font-size: 14px;
    white-space: nowrap;
  }

  /* Larger editor text area on mobile */
  #markdown-editor {
    padding: 16px 18px;
    font-size: 15px;
    line-height: 1.7;
  }

  .editor-pane::before {
    background-size: 100% 26px;
  }

  /* Toolbar - compact icons only on mobile */
  .toolbar {
    padding: 0 4px;
    height: 48px;
    gap: 2px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .toolbar::-webkit-scrollbar {
    display: none;
  }

  .toolbar-group {
    flex-shrink: 0;
    background: none;
    border: none;
    padding: 0;
    gap: 1px;
  }

  .tool-btn {
    min-width: 34px;
    height: 34px;
    padding: 0 4px;
  }

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

  .tool-btn svg {
    width: 22px;
    height: 22px;
  }

  .toolbar-divider {
    display: none;
  }

  /* Notification on mobile */
  .notification {
    top: auto;
    bottom: 80px;
    right: 16px;
    left: 16px;
    text-align: center;
    font-size: 15px;
    padding: 12px 20px;
  }

  .notification.show {
    transform: translateX(0);
  }
}

/* --- Responsive: Small Mobile (< 480px) --- */
@media (max-width: 480px) {
  .toolbar {
    padding: 0 2px;
    height: 44px;
    gap: 1px;
  }

  .tool-btn {
    min-width: 32px;
    height: 32px;
    padding: 0 3px;
  }

  .tool-btn svg {
    width: 20px;
    height: 20px;
  }

  #markdown-editor {
    padding: 12px 14px;
    font-size: 14px;
  }

  #copy-btn {
    padding: 5px 10px;
    font-size: 13px;
  }

  .mobile-drawer-item {
    padding: 12px 16px;
    font-size: 15px;
  }
}