@font-face {
  font-family: 'Euclid Circular A';
  src: url('fonts/EuclidCircularA-Light.otf') format('opentype');
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Euclid Circular A';
  src: url('fonts/EuclidCircularA-Regular.otf') format('opentype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Euclid Circular A';
  src: url('fonts/EuclidCircularA-Medium.otf') format('opentype');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Euclid Circular A';
  src: url('fonts/EuclidCircularA-Semibold.otf') format('opentype');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Euclid Circular A';
  src: url('fonts/EuclidCircularA-Bold.otf') format('opentype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

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

:root {
  --font: 'Euclid Circular A', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'SF Mono', 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  --bg: #ffffff;
  --bg-surface: #f8f9fa;
  --bg-elevated: #ffffff;
  --bg-hover: #f1f3f5;
  --bg-active: #e9ecef;
  --border: #e9ecef;
  --border-subtle: #f1f3f5;
  --text: #212529;
  --text-secondary: #868e96;
  --text-tertiary: #adb5bd;
  --accent: #228be6;
  --accent-hover: #1c7ed6;
  --accent-subtle: #e7f5ff;
  --accent-text: #1971c2;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04), 0 1px 3px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.04);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.1), 0 4px 12px rgba(0,0,0,0.04);
  --transition: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-surface);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Toolbar ── */

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  min-height: 52px;
  flex-shrink: 0;
  z-index: 10;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.toolbar-group.file-actions {
  gap: 6px;
  padding-right: 12px;
  border-right: 1px solid var(--border);
  margin-right: 6px;
}

.toolbar-group.format-actions {
  flex: 1;
  flex-wrap: wrap;
  gap: 1px;
}

.toolbar-group.view-actions {
  margin-left: auto;
  padding-left: 12px;
  border-left: 1px solid var(--border);
}

.toolbar button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
  position: relative;
}

.toolbar button:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.toolbar button:active {
  background: var(--bg-active);
  transform: scale(0.97);
}

.toolbar button svg {
  flex-shrink: 0;
  opacity: 0.7;
  transition: opacity var(--transition);
}

.toolbar button:hover svg {
  opacity: 1;
}

.file-actions button {
  height: 34px;
  padding: 0 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 500;
}

.file-actions button:hover {
  background: var(--bg-hover);
  border-color: var(--text-tertiary);
}

.separator {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
  flex-shrink: 0;
}

.filename {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-tertiary);
  margin-left: 4px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: -0.01em;
}

.modified-indicator {
  font-size: 20px;
  font-weight: 600;
  color: var(--accent);
  line-height: 1;
}

.hidden {
  display: none !important;
}

/* ── Editor Container ── */

.editor-container {
  flex: 1;
  display: flex;
  overflow: hidden;
  background: var(--bg-surface);
  gap: 1px;
}

.editor-pane {
  flex: 1;
  display: flex;
  min-width: 0;
  background: var(--bg-elevated);
}

#editor {
  flex: 1;
  padding: 32px 36px;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font-mono);
  font-size: 13.5px;
  font-weight: 400;
  line-height: 1.8;
  color: var(--text);
  background: var(--bg-elevated);
  tab-size: 2;
  letter-spacing: -0.01em;
}

#editor::placeholder {
  color: var(--text-tertiary);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 300;
}

.preview-pane {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-elevated);
  min-width: 0;
}

#preview {
  padding: 32px 40px;
  max-width: 780px;
}

.editor-container:not(.split-view) .preview-pane {
  display: none;
}

.editor-container:not(.split-view) .editor-pane {
  max-width: 100%;
}

/* ── Markdown Preview ── */

.markdown-body {
  font-family: var(--font);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.75;
  color: var(--text);
  letter-spacing: -0.01em;
}

.markdown-body h1 {
  font-size: 1.875em;
  font-weight: 600;
  margin: 1.2em 0 0.5em;
  padding-bottom: 0.35em;
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.025em;
  color: var(--text);
}

.markdown-body h2 {
  font-size: 1.4em;
  font-weight: 600;
  margin: 1.2em 0 0.4em;
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--border-subtle);
  letter-spacing: -0.02em;
}

.markdown-body h3 {
  font-size: 1.15em;
  font-weight: 600;
  margin: 1em 0 0.4em;
  letter-spacing: -0.015em;
}

.markdown-body h4, .markdown-body h5, .markdown-body h6 {
  font-weight: 600;
  margin: 0.8em 0 0.4em;
}

.markdown-body p {
  margin: 0.65em 0;
}

.markdown-body strong {
  font-weight: 600;
}

.markdown-body a {
  color: var(--accent-text);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color var(--transition);
}

.markdown-body a:hover {
  border-bottom-color: var(--accent-text);
}

.markdown-body ul, .markdown-body ol {
  padding-left: 1.75em;
  margin: 0.5em 0;
}

.markdown-body li {
  margin: 0.3em 0;
}

.markdown-body li::marker {
  color: var(--text-tertiary);
}

.markdown-body blockquote {
  padding: 12px 20px;
  margin: 0.75em 0;
  border-left: 3px solid var(--accent);
  background: var(--accent-subtle);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text);
}

.markdown-body blockquote p {
  margin: 0.25em 0;
}

.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  padding: 2px 7px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--accent-text);
}

.markdown-body pre {
  padding: 20px;
  margin: 1em 0;
  background: #1e1e2e;
  border-radius: var(--radius-md);
  overflow-x: auto;
}

.markdown-body pre code {
  padding: 0;
  background: none;
  border: none;
  color: #cdd6f4;
  font-size: 13px;
  line-height: 1.7;
}

.markdown-body table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 1em 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.markdown-body th, .markdown-body td {
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.markdown-body th {
  background: var(--bg-surface);
  font-weight: 600;
  font-size: 0.875em;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-secondary);
}

.markdown-body td {
  font-size: 0.95em;
}

.markdown-body tr:last-child td {
  border-bottom: none;
}

.markdown-body tr:hover td {
  background: var(--bg-surface);
}

.markdown-body hr {
  border: none;
  height: 1px;
  background: var(--border);
  margin: 2em 0;
}

.markdown-body img {
  max-width: 100%;
  border-radius: var(--radius-md);
}

.markdown-body input[type="checkbox"] {
  margin-right: 8px;
  accent-color: var(--accent);
}

/* ── Modal ── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modal-fade-in 0.2s ease;
}

@keyframes modal-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modal-slide-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 720px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  animation: modal-slide-in 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-family: var(--font);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-tertiary);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

/* ── Table Editor ── */

.table-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.table-controls button {
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.table-controls button:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--text-tertiary);
}

.table-grid {
  overflow-x: auto;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.table-grid table {
  border-collapse: collapse;
  width: 100%;
}

.table-grid th, .table-grid td {
  border: 1px solid var(--border);
  border-top: none;
  border-left: none;
  padding: 0;
}

.table-grid th:first-child, .table-grid td:first-child {
  border-left: none;
}

.table-grid th:last-child, .table-grid td:last-child {
  border-right: none;
}

.table-grid tr:last-child td {
  border-bottom: none;
}

.table-grid input {
  width: 100%;
  min-width: 80px;
  padding: 10px 14px;
  border: none;
  outline: none;
  font-family: var(--font);
  font-size: 13px;
  background: transparent;
  color: var(--text);
  transition: background var(--transition);
}

.table-grid th input {
  font-weight: 600;
  background: var(--bg-surface);
  color: var(--text);
}

.table-grid input:focus {
  background: var(--accent-subtle);
}

.table-alignment {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.table-alignment label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

#table-alignment-controls {
  display: flex;
  gap: 8px;
}

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

.align-group span {
  font-size: 12px;
  color: var(--text-tertiary);
  min-width: 18px;
  text-align: center;
  font-weight: 500;
}

.align-group select {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 12px;
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
}

/* ── Buttons ── */

.btn-primary {
  height: 38px;
  padding: 0 22px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 2px 8px rgba(34, 139, 230, 0.25);
}

.btn-primary:active {
  transform: scale(0.97);
}

.btn-secondary {
  height: 38px;
  padding: 0 22px;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--text-tertiary);
}

/* ── Browser Notice ── */

.browser-notice {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #fff9db;
  color: #5c4813;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 400;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-md);
  border: 1px solid #f0e4b8;
  z-index: 100;
  max-width: 560px;
  animation: notice-slide-up 0.3s ease;
}

@keyframes notice-slide-up {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.browser-notice button {
  border: none;
  background: none;
  font-size: 18px;
  cursor: pointer;
  color: #5c4813;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0.6;
  transition: opacity var(--transition);
}

.browser-notice button:hover {
  opacity: 1;
}

/* ── Scrollbar ── */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--text-tertiary);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* ── Preview Toggle Active State ── */

.toolbar button.preview-active {
  background: var(--accent-subtle);
  color: var(--accent-text);
}

.toolbar button.preview-active svg {
  opacity: 1;
}

/* ── Responsive ── */

@media (max-width: 768px) {
  .toolbar {
    padding: 6px 10px;
    gap: 4px;
    min-height: 46px;
  }

  .toolbar button span {
    display: none;
  }

  .toolbar-group.file-actions {
    padding-right: 8px;
    margin-right: 4px;
  }

  .filename {
    display: none;
  }

  #editor {
    padding: 20px;
    font-size: 13px;
  }

  #preview {
    padding: 20px;
  }
}
