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

:root {
  --bg: #f0eff4;
  --surface: #ffffff;
  --border: #e2e1de;
  --text: #1c1b1f;
  --text-2: #706e6b;
  --primary: #A5AA77;
  --primary-h: #8D9265;
  --primary-bg: #F2F2EB;
  --danger: #e03131;
  --radius: 10px;
  --header-h: 56px;
  --left-w: 340px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans TC', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}

/* ==========================================
   Overlay
   ========================================== */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 100;
  animation: fadeIn .2s ease;
}
.overlay.open { display: block; }

/* ==========================================
   Drawer
   ========================================== */
.drawer {
  position: fixed;
  top: 0;
  left: -320px;
  width: 300px;
  height: 100vh;
  background: var(--surface);
  z-index: 200;
  transition: left .25s cubic-bezier(.4, 0, .2, 1);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}
.drawer.open {
  left: 0;
  box-shadow: 4px 0 20px rgba(0,0,0,.12);
}

.drawer-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.drawer-heading { font-weight: 700; font-size: 15px; }

.drawer-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.drawer-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 11px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s;
}
.drawer-item:hover { background: var(--bg); }
.drawer-item.active { background: var(--primary-bg); }

.drawer-item-info { flex: 1; min-width: 0; }
.drawer-item-title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}
.drawer-item-date {
  font-size: 11px;
  color: var(--text-2);
  margin-top: 3px;
}

.drawer-del {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-2);
  font-size: 14px;
  padding: 2px 5px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity .15s, color .15s;
  flex-shrink: 0;
  line-height: 1;
}
.drawer-item:hover .drawer-del { opacity: 1; }
.drawer-del:hover { color: var(--danger); }

.empty-state {
  text-align: center;
  color: var(--text-2);
  font-size: 13px;
  padding: 48px 20px;
  line-height: 1.7;
}

/* ==========================================
   Header
   ========================================== */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 50;
  gap: 12px;
}

.app-logo {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.3px;
  white-space: nowrap;
}

.header-actions { display: flex; align-items: center; gap: 8px; }

.ghost-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background .15s;
  white-space: nowrap;
}
.ghost-btn:hover { background: var(--bg); }

.save-btn {
  background: var(--text);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
  white-space: nowrap;
}
.save-btn:hover { opacity: .82; }

/* ==========================================
   App Layout
   ========================================== */
.app-layout {
  display: flex;
  margin-top: var(--header-h);
  height: calc(100vh - var(--header-h));
}

/* ==========================================
   Left Panel
   ========================================== */
.left-panel {
  width: var(--left-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.panel-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.section-label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.1px;
}

.hint-text {
  font-size: 11px;
  color: var(--text-2);
  line-height: 1.5;
}

.sm-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: var(--primary);
  white-space: nowrap;
  transition: background .15s, border-color .15s;
  flex-shrink: 0;
}
.sm-btn:hover { background: var(--primary-bg); border-color: var(--primary); }

/* ==========================================
   Textarea & Input
   ========================================== */
.textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  resize: vertical;
  background: var(--bg);
  transition: border-color .15s, background .15s;
  line-height: 1.6;
}
.textarea:focus { outline: none; border-color: var(--primary); background: #fff; }

.inp {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  transition: border-color .15s, background .15s;
}
.inp:focus { outline: none; border-color: var(--primary); background: #fff; }
.inp + .inp { margin-top: 8px; }

/* ==========================================
   Reference Details
   ========================================== */
.ref-details { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.ref-summary {
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  cursor: pointer;
  list-style: none;
  user-select: none;
  background: var(--primary-bg);
  transition: background .15s;
}
.ref-summary::-webkit-details-marker { display: none; }
.ref-details[open] .ref-summary { background: #e0e7ff; }
.ref-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--border);
}

/* ==========================================
   Source URLs
   ========================================== */
#urlList { display: flex; flex-direction: column; gap: 6px; }

.url-row { display: flex; gap: 6px; align-items: center; }
.url-row .inp { flex: 1; min-width: 0; }

.del-btn {
  background: none;
  border: none;
  color: var(--text-2);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 5px;
  flex-shrink: 0;
  transition: color .15s, background .15s;
}
.del-btn:hover { color: var(--danger); background: #fff0f0; }

/* ==========================================
   Slider
   ========================================== */
.slider { width: 100%; accent-color: var(--primary); cursor: pointer; }
.slider-hints { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-2); }
.level-badge { font-size: 14px; font-weight: 700; color: var(--primary); }

/* ==========================================
   Length Cards
   ========================================== */
.length-group { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

.length-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  padding: 10px 8px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  text-align: center;
}
.length-card input { position: absolute; opacity: 0; width: 0; height: 0; }
.length-card:has(input:checked) { border-color: var(--primary); background: var(--primary-bg); }
.length-name { font-size: 13px; font-weight: 600; }
.length-words { font-size: 11px; color: var(--text-2); }

/* ==========================================
   Generate Button
   ========================================== */
.gen-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 13px 20px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  margin-top: 4px;
  transition: background .15s, transform .1s;
}
.gen-btn:hover { background: var(--primary-h); }
.gen-btn:active { transform: scale(.98); }
.gen-btn.full { margin-top: 0; border-radius: 8px; font-size: 14px; }

/* ==========================================
   Right Panel
   ========================================== */
.right-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fafaf8;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.tool-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  transition: background .15s;
  white-space: nowrap;
}
.tool-btn:hover { background: var(--bg); }

.emoji-tool-btn { font-size: 13px; }

.toolbar-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 2px;
  flex-shrink: 0;
}

.toolbar-spacer { flex: 1; }

.snapshot-btn { color: #2f9e44; border-color: #b2f2bb; }
.snapshot-btn:hover { background: #ebfbee; border-color: #69db7c; }

.diff-btn { color: var(--primary); border-color: #bac8ff; }
.diff-btn:hover:not(:disabled) { background: var(--primary-bg); border-color: #91a7ff; }
.diff-btn:disabled { opacity: 0.38; cursor: not-allowed; }

.saved-indicator { font-size: 12px; color: var(--text-2); }

.share-btn { color: #2f9e44; border-color: #b2f2bb; }
.share-btn:hover:not(:disabled) { background: #ebfbee; border-color: #69db7c; }
.share-btn:disabled { opacity: 0.38; cursor: not-allowed; }

/* ==========================================
   Editor
   ========================================== */
.editor-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 48px 64px;
}

@media (max-width: 900px) {
  .editor-wrap { padding: 32px 28px; }
}

[contenteditable].empty::before {
  content: attr(data-ph);
  color: #b8b6b2;
  pointer-events: none;
}

.editor-title {
  font-size: 30px;
  font-weight: 800;
  line-height: 1.3;
  margin-bottom: 28px;
  outline: none;
  min-height: 44px;
  max-width: 760px;
  letter-spacing: -0.4px;
}

.editor-body {
  font-size: 16px;
  line-height: 1.8;
  outline: none;
  min-height: 400px;
  max-width: 760px;
}

.editor-body h1, .editor-body h2, .editor-body h3 {
  font-weight: 700;
  line-height: 1.35;
  margin: 28px 0 12px;
}
.editor-body h1 { font-size: 26px; }
.editor-body h2 { font-size: 22px; }
.editor-body h3 { font-size: 18px; }
.editor-body p { margin-bottom: 18px; }
.editor-body strong { font-weight: 700; }
.editor-body em { font-style: italic; }
.editor-body ul, .editor-body ol { padding-left: 26px; margin-bottom: 18px; }
.editor-body li { margin-bottom: 8px; }
.editor-body blockquote {
  border-left: 3px solid var(--border);
  margin: 20px 0;
  padding: 10px 20px;
  color: var(--text-2);
  font-style: italic;
}
.editor-body a { color: var(--primary); text-decoration: underline; }
.editor-body hr { border: none; border-top: 1px solid var(--border); margin: 28px 0; }

/* Figure / Caption / Image / Video */
.editor-body figure {
  margin: 24px 0;
  display: block;
}
.editor-body figure img,
.editor-body figure video {
  max-width: 100%;
  border-radius: 10px;
  display: block;
}
.editor-body figcaption {
  font-size: 13px;
  color: var(--text-2);
  text-align: center;
  margin-top: 8px;
  font-style: italic;
}
.editor-body img {
  max-width: 100%;
  border-radius: 10px;
  margin: 20px 0;
  display: block;
}
.editor-body video {
  max-width: 100%;
  border-radius: 10px;
  margin: 20px 0;
  display: block;
}

/* ==========================================
   Emoji Picker
   ========================================== */
.emoji-picker {
  display: none;
  position: fixed;
  z-index: 500;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  width: 300px;
  padding: 10px;
  animation: slideUp .15s ease;
}
.emoji-picker.open { display: block; }

.emoji-search-wrap { margin-bottom: 8px; }

.emoji-search {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
  background: var(--bg);
}
.emoji-search:focus { outline: none; border-color: var(--primary); background: #fff; }

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  max-height: 220px;
  overflow-y: auto;
}

.emoji-btn {
  background: none;
  border: none;
  border-radius: 6px;
  padding: 5px;
  font-size: 20px;
  cursor: pointer;
  text-align: center;
  line-height: 1;
  transition: background .1s;
}
.emoji-btn:hover { background: var(--bg); }

/* ==========================================
   Modals
   ========================================== */
.modal-bg {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.48);
  z-index: 400;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn .2s ease;
}
.modal-bg.open { display: flex; }

.modal-box {
  background: var(--surface);
  border-radius: 14px;
  width: 640px;
  max-width: 100%;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.22);
  animation: slideUp .2s ease;
}
.modal-box.sm { width: 440px; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-head strong { font-size: 15px; font-weight: 700; }

.modal-sub {
  font-size: 13px;
  color: var(--text-2);
  padding: 12px 22px 6px;
  line-height: 1.6;
  flex-shrink: 0;
}

.prompt-display {
  flex: 1;
  overflow-y: auto;
  margin: 8px 22px;
  padding: 14px 16px;
  background: #f7f6f3;
  border-radius: 8px;
  font-size: 12.5px;
  line-height: 1.7;
  white-space: pre-wrap;
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  color: var(--text);
  border: 1px solid var(--border);
}

.modal-footer {
  padding: 14px 22px;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
}

/* Tabs */
.tab-row {
  display: flex;
  padding: 0 22px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 14px 11px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  color: var(--text-2);
  margin-bottom: -1px;
  font-weight: 500;
  transition: color .15s, border-color .15s;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 700; }

.modal-inner {
  padding: 16px 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.upload-area {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 32px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-2);
  transition: border-color .15s, background .15s;
  text-align: center;
}
.upload-area:hover { border-color: var(--primary); background: var(--primary-bg); color: var(--primary); }
.upload-area input { display: none; }

/* Diff Modal */
.diff-modal { width: 900px; max-width: 96vw; }

.diff-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 8px 22px;
  overflow: hidden;
}

.diff-col { display: flex; flex-direction: column; min-height: 0; }

.diff-col-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-2);
  margin-bottom: 6px;
}

.diff-text {
  overflow-y: auto;
  background: #f7f6f3;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  color: var(--text);
  max-height: 360px;
}

.diff-footer { border-top: 1px solid var(--border); }

/* ==========================================
   Media Selection & Delete
   ========================================== */
.editor-body img.media-selected,
.editor-body video.media-selected,
.editor-body figure.media-selected {
  outline: 2.5px solid var(--primary);
  outline-offset: 3px;
  border-radius: 10px;
  cursor: pointer;
}

.media-delete-btn {
  display: none;
  position: fixed;
  z-index: 300;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
  transition: background .15s;
  font-family: inherit;
}
.media-delete-btn.visible { display: block; }
.media-delete-btn:hover { background: #c92a2a; }

/* ==========================================
   Shared Utilities
   ========================================== */
.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-2);
  font-size: 18px;
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--bg); color: var(--text); }

.hidden { display: none !important; }

/* ==========================================
   Animations
   ========================================== */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
