/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3248;
  --accent: #6c7cf8;
  --accent-hover: #5a6ae6;
  --accent-light: rgba(108, 124, 248, 0.12);
  --text: #e4e6f0;
  --text-muted: #7c81a0;
  --danger: #f87171;
  --success: #4ade80;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --font-ui: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

html, body {
  height: 100%;
}

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== Header ===== */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  flex-shrink: 0;
  box-shadow: 0 2px 12px rgba(0,0,0,0.3);
  z-index: 10;
}

.header-inner {
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  gap: 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 22px;
}

.logo-text {
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(135deg, #6c7cf8, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ===== Mode Toggle ===== */
.mode-toggle {
  display: flex;
  align-items: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}

.mode-btn {
  padding: 5px 14px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
  background: transparent;
  transition: all 0.18s ease;
  white-space: nowrap;
}

.mode-btn:hover {
  color: var(--text);
}

.mode-btn.is-active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(108,124,248,0.35);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 16px rgba(108,124,248,0.4);
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  color: var(--text);
  border-color: var(--accent);
}

.btn-outline {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-outline:hover {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-light);
}

.btn-icon {
  font-size: 15px;
}

/* ===== Main Layout ===== */
.main {
  flex: 1;
  display: flex;
  overflow: hidden;
  gap: 0;
}

/* ===== Panels ===== */
.panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.panel:first-child {
  border-right: 1px solid var(--border);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
  flex-wrap: wrap;
}

.panel-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.panel-footer {
  padding: 6px 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.char-count {
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== File Input Label ===== */
.file-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.18s;
}

.file-label:hover {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-light);
}

/* ===== Drop Zone ===== */
.drop-zone {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.drop-zone.drag-over .drop-overlay {
  opacity: 1;
  pointer-events: all;
}

.drop-zone.drag-over .editor {
  opacity: 0.3;
}

.drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(108, 124, 248, 0.15);
  border: 3px dashed var(--accent);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 5;
  margin: 8px;
  border-radius: var(--radius);
}

.drop-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--accent);
  font-size: 16px;
  font-weight: 700;
}

.drop-icon {
  font-size: 48px;
}

/* ===== Editor (Textarea) ===== */
.editor {
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  border: none;
  outline: none;
  resize: none;
  padding: 20px 24px;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.7;
  tab-size: 2;
  transition: opacity 0.2s;
}

.editor::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

/* ===== PDF Options ===== */
.pdf-options {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.option-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.option-label select {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 12px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.18s;
}

.option-label select:focus {
  border-color: var(--accent);
}

/* ===== Preview ===== */
.preview-scroll {
  flex: 1;
  overflow-y: auto;
  background: #2a2a2a;
  padding: 24px;
}

.preview-scroll::-webkit-scrollbar {
  width: 6px;
}

.preview-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.preview-scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.preview-page {
  background: #fff;
  color: #1a1a1a;
  max-width: 794px;
  margin: 0 auto;
  padding: 48px 60px;
  border-radius: 4px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
  min-height: 1123px;
}

/* ===== Empty State ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 80px 20px;
  color: #9ca3af;
}

.empty-icon {
  font-size: 52px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 15px;
}

/* ===== Markdown Body Styles ===== */
.markdown-body {
  font-family: 'Helvetica Neue', Arial, 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', Meiryo, sans-serif;
  font-size: 15px;
  line-height: 1.8;
  color: #1a1a1a;
  word-break: break-word;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  font-weight: 700;
  line-height: 1.3;
  color: #111;
}

.markdown-body h1 { font-size: 2em; border-bottom: 2px solid #e5e7eb; padding-bottom: 0.3em; }
.markdown-body h2 { font-size: 1.5em; border-bottom: 1px solid #e5e7eb; padding-bottom: 0.25em; }
.markdown-body h3 { font-size: 1.25em; }
.markdown-body h4 { font-size: 1.1em; }
.markdown-body h5 { font-size: 1em; }
.markdown-body h6 { font-size: 0.9em; color: #6b7280; }

.markdown-body p {
  margin-bottom: 1em;
}

.markdown-body a {
  color: #4f46e5;
  text-decoration: underline;
}

.markdown-body strong { font-weight: 700; }
.markdown-body em { font-style: italic; }

.markdown-body ul,
.markdown-body ol {
  margin: 0.5em 0 1em 0;
  padding-left: 2em;
}

.markdown-body li {
  margin-bottom: 0.3em;
}

.markdown-body li > ul,
.markdown-body li > ol {
  margin-top: 0.3em;
  margin-bottom: 0.3em;
}

.markdown-body blockquote {
  margin: 1em 0;
  padding: 0.5em 1.2em;
  border-left: 4px solid #6c7cf8;
  background: #f5f5ff;
  color: #555;
  border-radius: 0 4px 4px 0;
}

.markdown-body code {
  font-family: 'Cascadia Code', 'Fira Code', Consolas, monospace;
  font-size: 0.875em;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  padding: 0.1em 0.4em;
  color: #c0392b;
}

.markdown-body pre {
  margin: 1em 0;
  padding: 16px;
  background: #1e1e2e;
  border-radius: 8px;
  overflow-x: auto;
}

.markdown-body pre code {
  background: none;
  border: none;
  padding: 0;
  color: #cdd6f4;
  font-size: 0.875em;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
  font-size: 0.9em;
}

.markdown-body th {
  background: #f3f4f6;
  font-weight: 700;
  padding: 10px 14px;
  border: 1px solid #d1d5db;
  text-align: left;
}

.markdown-body td {
  padding: 8px 14px;
  border: 1px solid #d1d5db;
}

.markdown-body tr:nth-child(even) {
  background: #f9fafb;
}

.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

.markdown-body hr {
  border: none;
  border-top: 2px solid #e5e7eb;
  margin: 1.5em 0;
}

.markdown-body input[type="checkbox"] {
  margin-right: 6px;
  accent-color: #6c7cf8;
}

/* GFM task list: marked がネイティブ出力する <li class="task-list-item"> */
.markdown-body .task-list-item {
  list-style: none;
  margin-left: -1.5em;
}

/* ===== Converting Overlay ===== */
.converting-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.converting-overlay[hidden] {
  display: none;
}

.converting-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  box-shadow: var(--shadow);
}

.converting-box p {
  font-size: 15px;
  color: var(--text-muted);
  font-weight: 500;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 28px;
  right: 28px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 200;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.success { border-color: var(--success); color: var(--success); }
.toast.error   { border-color: var(--danger);  color: var(--danger);  }

/* ===== Preview only mode ===== */
.preview-only .editor-panel {
  display: none;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .main {
    flex-direction: column;
  }

  .panel:first-child {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 40vh;
  }

  .preview-page {
    padding: 24px 20px;
  }

  .pdf-options {
    display: none;
  }
}
