/* =========================================
   MyNote — 治愈手账  Theme
   ========================================= */

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --cream-bg:       #EDE8DC;
  --paper-bg:       #FBFAF5;
  --paper-shadow:   rgba(60, 45, 30, 0.08);
  --text-primary:   #3D3226;
  --text-secondary: #6B5B4F;
  --text-muted:     #B8A590;
  --accent-line:    #D4C8B5;
  --accent-brown:   #8B7355;
  --editor-bg:      #2B2318;
  --editor-border:  #3D3226;
  --editor-text:    #D4C8B5;
  --editor-placeholder: #5C4F3F;
  --export-btn-bg:  #6B5B4F;
  --export-btn-hover: #4A3D30;
  --line-color:     rgba(139, 115, 85, 0.06);
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Noto Serif SC', 'Lora', Georgia, serif;
  background: var(--cream-bg);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- App Container ---------- */
.app-container {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
}

/* =========================================
   Left: Editor Panel
   ========================================= */
.editor-panel {
  width: 42%;
  min-width: 360px;
  display: flex;
  flex-direction: column;
  background: var(--editor-bg);
  border-right: 1px solid var(--editor-border);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 22px;
  border-bottom: 1px solid var(--editor-border);
  flex-shrink: 0;
}

.panel-title {
  font-family: 'Quicksand', sans-serif;
  font-size: 12px;
  font-weight: 500;
  color: var(--accent-brown);
  letter-spacing: 3px;
  text-transform: uppercase;
}

.toolbar-mini {
  display: flex;
  gap: 3px;
}

.tb-btn {
  background: none;
  border: 1px solid var(--editor-border);
  color: #A09080;
  font-family: 'Quicksand', sans-serif;
  font-size: 11px;
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.2s ease;
  line-height: 1;
}

.tb-btn:hover {
  background: var(--editor-border);
  color: var(--editor-text);
  border-color: #5C4F3F;
}

.tb-btn:active {
  transform: scale(0.95);
}

.editor-textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--editor-text);
  font-family: 'Noto Serif SC', 'Lora', Georgia, serif;
  font-size: 15px;
  line-height: 1.85;
  padding: 28px 24px;
  resize: none;
  outline: none;
  tab-size: 2;
}

.editor-textarea::placeholder {
  color: var(--editor-placeholder);
  font-style: italic;
}

/* Editor scrollbar */
.editor-textarea::-webkit-scrollbar {
  width: 5px;
}
.editor-textarea::-webkit-scrollbar-track {
  background: transparent;
}
.editor-textarea::-webkit-scrollbar-thumb {
  background: var(--editor-border);
  border-radius: 3px;
}
.editor-textarea::-webkit-scrollbar-thumb:hover {
  background: #5C4F3F;
}

/* =========================================
   Right: Preview Panel
   ========================================= */
.preview-panel {
  width: 58%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 36px 20px 120px;
  background: var(--cream-bg);
  text-align: center;
}

/* Preview scrollbar */
.preview-panel::-webkit-scrollbar {
  width: 5px;
}
.preview-panel::-webkit-scrollbar-track {
  background: transparent;
}
.preview-panel::-webkit-scrollbar-thumb {
  background: var(--accent-line);
  border-radius: 3px;
}

/* =========================================
   Journal Page (Paper)
   ========================================= */
.journal-page {
  display: inline-block;
  width: 100%;
  max-width: 620px;
  height: auto;
  overflow: visible;
  text-align: left;
  background: var(--paper-bg);
  /* Subtle notebook ruling */
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 27px,
      var(--line-color) 27px,
      var(--line-color) 28px
    );
  box-shadow:
    0 2px 20px var(--paper-shadow),
    0 0 0 1px rgba(139, 115, 85, 0.08);
  border-radius: 4px;
  padding: 52px 60px 64px;
  position: relative;
  min-height: 60vh;
}

/* =========================================
   Journal Header
   ========================================= */
.journal-header {
  position: relative;
  text-align: center;
  padding-bottom: 12px;
}

/* Vertical marginal text — rotated for symmetry (bottoms face inward) */
.margin-text {
  position: absolute;
  top: 50%;
  font-family: 'Quicksand', sans-serif;
  font-size: 10px;
  font-weight: 300;
  letter-spacing: 4px;
  color: var(--text-muted);
  user-select: none;
  white-space: nowrap;
}

.margin-left {
  left: -34px;
  transform: translateY(-50%) rotate(-90deg);
}

.margin-right {
  right: -34px;
  transform: translateY(-50%) rotate(90deg);
}

/* Center header content */
.header-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.butterfly-icon {
  opacity: 0.65;
  line-height: 0;
}

.butterfly-icon svg {
  width: 28px;
  height: 28px;
  display: block;
}

.date-text {
  font-family: 'Quicksand', sans-serif;
  font-size: 13px;
  font-weight: 400;
  color: var(--text-secondary);
  letter-spacing: 1.8px;
  text-transform: uppercase;
  margin-top: 2px;
}

.mascot-area {
  margin-top: 6px;
  line-height: 0;
}

.mascot-img {
  width: 80px;
  height: auto;
  opacity: 0.72;
  display: block;
  margin: 0 auto;
}

/* Header divider */
.header-divider {
  border: none;
  border-top: 1px solid var(--accent-line);
  margin: 18px 0 32px;
  opacity: 0.7;
}

/* =========================================
   Journal Content (Rendered Markdown)
   ========================================= */
.journal-content {
  font-family: 'Noto Serif SC', 'Lora', Georgia, serif;
  font-size: 15px;
  line-height: 1.9;
  color: var(--text-primary);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* ---------- Headings ---------- */
.journal-content h1 {
  font-size: 1.55em;
  font-weight: 600;
  margin: 0.7em 0 0.35em;
  color: #2C2416;
  border-bottom: 1px solid rgba(139, 115, 85, 0.15);
  padding-bottom: 5px;
}

.journal-content h2 {
  font-size: 1.25em;
  font-weight: 600;
  margin: 0.65em 0 0.3em;
  color: #2C2416;
}

.journal-content h3 {
  font-size: 1.08em;
  font-weight: 500;
  margin: 0.5em 0 0.25em;
  color: #4A3D30;
}

/* ---------- Paragraphs ---------- */
.journal-content p {
  margin: 0.45em 0;
}

/* ---------- Lists ---------- */
.journal-content ul,
.journal-content ol {
  padding-left: 1.6em;
  margin: 0.35em 0;
}

.journal-content li {
  margin: 0.15em 0;
}

.journal-content li::marker {
  color: var(--accent-brown);
}

/* ---------- Blockquote ---------- */
.journal-content blockquote {
  border-left: 3px solid #C8B89A;
  margin: 0.7em 0;
  padding: 0.3em 0 0.3em 1em;
  color: var(--text-secondary);
  font-style: italic;
  background: rgba(200, 184, 154, 0.12);
  border-radius: 0 3px 3px 0;
}

.journal-content blockquote p {
  margin: 0.2em 0;
}

/* ---------- Code ---------- */
.journal-content code {
  font-family: 'SF Mono', 'Consolas', 'Monaco', 'Courier New', monospace;
  background: rgba(139, 115, 85, 0.1);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.88em;
  color: #5C4F3F;
}

.journal-content pre {
  background: rgba(139, 115, 85, 0.06);
  border: 1px solid rgba(139, 115, 85, 0.1);
  padding: 16px 18px;
  border-radius: 4px;
  overflow-x: auto;
  margin: 0.55em 0;
  line-height: 1.6;
}

.journal-content pre code {
  background: none;
  padding: 0;
  border: none;
  font-size: 0.85em;
  color: #4A3D30;
}

/* ---------- Links ---------- */
.journal-content a {
  color: #8B6C42;
  text-decoration: none;
  border-bottom: 1px dashed rgba(139, 108, 66, 0.35);
  transition: all 0.2s;
}

.journal-content a:hover {
  color: #6B4F2E;
  border-bottom-style: solid;
}

/* ---------- Images ---------- */
.journal-content img {
  max-width: 100%;
  border-radius: 3px;
  margin: 0.3em 0;
}

/* ---------- Bold / Italic ---------- */
.journal-content strong {
  font-weight: 700;
  color: #2C2416;
}

.journal-content em {
  font-style: italic;
  color: #5C4F3F;
}

/* ---------- Horizontal rule ---------- */
.journal-content hr {
  border: none;
  border-top: 1px dashed var(--accent-line);
  margin: 1.1em 0;
}

/* ---------- Tables ---------- */
.journal-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.5em 0;
  font-size: 0.92em;
}

.journal-content th,
.journal-content td {
  border: 1px solid var(--accent-line);
  padding: 6px 12px;
  text-align: left;
}

.journal-content th {
  background: rgba(139, 115, 85, 0.08);
  font-weight: 600;
}

/* ---------- Placeholder ---------- */
.placeholder-text {
  color: var(--text-muted) !important;
  font-style: italic;
  text-align: center;
  margin-top: 64px !important;
  font-size: 1.05em;
}

/* =========================================
   Journal Footer
   ========================================= */
.journal-footer {
  margin-top: 48px;
  text-align: center;
}

.footer-divider {
  border: none;
  border-top: 1px solid var(--accent-line);
  opacity: 0.6;
  margin-bottom: 12px;
}

.footer-signature {
  font-family: 'Quicksand', sans-serif;
  font-size: 12px;
  font-weight: 300;
  letter-spacing: 5px;
  color: var(--text-muted);
  text-transform: none;
}

/* =========================================
   Export Buttons
   ========================================= */
.export-actions {
  position: fixed;
  bottom: 36px;
  right: 36px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 100;
}

.export-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 22px;
  background: var(--export-btn-bg);
  color: var(--paper-bg);
  border: none;
  border-radius: 24px;
  font-family: 'Quicksand', sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 1px;
  cursor: pointer;
  box-shadow: 0 3px 14px rgba(60, 45, 30, 0.18);
  transition: all 0.25s ease;
  user-select: none;
  white-space: nowrap;
}

.export-btn:hover {
  background: var(--export-btn-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(60, 45, 30, 0.28);
}

.export-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(60, 45, 30, 0.18);
}

.export-icon {
  font-size: 15px;
  line-height: 1;
}

/* =========================================
   Export Loading State
   ========================================= */
.export-btn.loading {
  pointer-events: none;
  opacity: 0.7;
}

.export-btn.loading::after {
  content: "";
}

/* =========================================
   Mobile Tab Bar
   ========================================= */
.mobile-tab-bar {
  display: none;
}

@media (max-width: 900px) {
  .mobile-tab-bar {
    display: flex;
    flex-shrink: 0;
    background: var(--editor-bg);
    border-bottom: 1px solid var(--editor-border);
    position: sticky;
    top: 0;
    z-index: 50;
  }
}

.tab-btn {
  flex: 1;
  padding: 14px 16px 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: 'Quicksand', sans-serif;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 2px;
  cursor: pointer;
  position: relative;
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

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

.tab-btn.active {
  color: var(--editor-text);
}

.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 2px;
  background: var(--accent-brown);
  border-radius: 1px;
}

/* Copy-to-clipboard success feedback */
.copy-btn .copy-done-text {
  display: none;
  color: #A8D5BA;
}

.copy-btn.copied .copy-label {
  display: none;
}

.copy-btn.copied .copy-done-text {
  display: inline;
}

/* =========================================
   Responsive
   ========================================= */
@media (max-width: 900px) {
  .app-container {
    flex-direction: column;
  }

  /* ── Tab-based panel switching ── */
  .editor-panel,
  .preview-panel {
    display: none;
    width: 100%;
    min-width: unset;
    flex: 1;
    min-height: 0;
  }

  .editor-panel.active {
    display: flex;
    flex-direction: column;
    border-right: none;
    border-bottom: none;
    height: auto;
  }

  .preview-panel.active {
    display: block;
    padding: 20px 12px 100px;
    height: auto;
    overflow-y: auto;
  }

  /* ── Editor tweaks ── */
  .editor-textarea {
    padding: 20px 18px;
    font-size: 15px;
  }

  /* Touch-friendly toolbar */
  .toolbar-mini {
    gap: 2px;
  }

  .tb-btn {
    padding: 6px 10px;
    font-size: 12px;
    min-width: 36px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* ── Journal page ── */
  .journal-page {
    padding: 28px 20px 40px;
    min-height: unset;
    max-width: 100%;
  }

  .journal-content {
    font-size: 14px;
    line-height: 1.85;
  }

  .margin-left { left: -16px; }
  .margin-right { right: -16px; }

  .mascot-img {
    width: 60px;
  }

  .butterfly-icon svg {
    width: 22px;
    height: 22px;
  }

  .date-text {
    font-size: 11px;
  }

  .header-divider {
    margin: 14px 0 24px;
  }

  /* ── Export buttons ── */
  .export-actions {
    bottom: 16px;
    right: 16px;
    gap: 8px;
  }

  .export-btn {
    padding: 9px 16px;
    font-size: 12px;
    gap: 6px;
  }
}
