/* ===== CSS Variables / M3 Tokens ===== */
:root {
  /* Light theme */
  --md-primary: #1a73e8;
  --md-on-primary: #ffffff;
  --md-primary-container: #d3e3fd;
  --md-on-primary-container: #041e49;
  --md-secondary: #5f6368;
  --md-surface: #ffffff;
  --md-surface-dim: #f8f9fa;
  --md-surface-container: #f1f3f4;
  --md-surface-container-high: #e8eaed;
  --md-surface-container-highest: #dadce0;
  --md-on-surface: #1f1f1f;
  --md-on-surface-variant: #444746;
  --md-outline: #c4c7c9;
  --md-outline-variant: #dde0e3;
  --md-error: #d93025;
  --md-on-error: #ffffff;
  --md-error-container: #fce8e6;
  --md-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --md-shadow-lg: 0 4px 12px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06);
  --md-radius-sm: 8px;
  --md-radius-md: 12px;
  --md-radius-lg: 16px;
  --md-radius-xl: 28px;
  --md-transition: 200ms cubic-bezier(0.2, 0, 0, 1);
  --md-font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --md-mono: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
  --md-success: #1e8e3e;
  --md-success-container: #e6f4ea;
}

[data-theme="dark"] {
  --md-primary: #8ab4f8;
  --md-on-primary: #062e6f;
  --md-primary-container: #0842a0;
  --md-on-primary-container: #d3e3fd;
  --md-secondary: #9aa0a6;
  --md-surface: #1e1e1e;
  --md-surface-dim: #141414;
  --md-surface-container: #252525;
  --md-surface-container-high: #2d2d2d;
  --md-surface-container-highest: #383838;
  --md-on-surface: #e8eaed;
  --md-on-surface-variant: #9aa0a6;
  --md-outline: #3c4043;
  --md-outline-variant: #2d2d2d;
  --md-error: #f28b82;
  --md-on-error: #601410;
  --md-error-container: #442726;
  --md-shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --md-shadow-lg: 0 4px 12px rgba(0,0,0,0.4), 0 2px 4px rgba(0,0,0,0.3);
  --md-success: #81c995;
  --md-success-container: #1b3626;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--md-font);
  background: var(--md-surface-dim);
  color: var(--md-on-surface);
  min-height: 100vh;
  transition: background var(--md-transition), color var(--md-transition);
  line-height: 1.5;
}

a {
  color: var(--md-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

a.logo,
a.logo:hover {
  text-decoration: none;
}

/* ===== Header Row ===== */
.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--md-on-surface);
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}

.logo a {
  color: var(--md-on-surface);
  text-decoration: none;
  font-weight: 700;
}

.logo a:hover {
  text-decoration: none;
  opacity: 0.85;
}

.logo .separator {
  color: var(--md-on-surface-variant);
  font-weight: 300;
}

.logo .note-id {
  color: var(--md-on-surface);
  font-weight: 400;
  font-size: 1rem;
}

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

/* ===== Buttons ===== */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--md-radius-xl);
  background: transparent;
  color: var(--md-on-surface-variant);
  cursor: pointer;
  transition: background var(--md-transition), color var(--md-transition);
  font-size: 0.9rem;
}

.icon-btn:hover {
  background: var(--md-surface-container-high);
  color: var(--md-on-surface);
}

.icon-btn.small {
  width: 36px;
  height: 36px;
  font-size: 0.8rem;
}

.icon-btn span {
  font-size: 0.8rem;
  font-weight: 500;
}

#lang-toggle {
  width: auto;
  padding: 0 12px;
  gap: 6px;
}

.m3-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 24px;
  border: none;
  border-radius: var(--md-radius-xl);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: var(--md-font);
  cursor: pointer;
  transition: all var(--md-transition);
  letter-spacing: 0.02em;
  min-height: 40px;
}

.m3-btn.filled {
  background: var(--md-primary);
  color: var(--md-on-primary);
  box-shadow: var(--md-shadow);
}

.m3-btn.filled:hover {
  box-shadow: var(--md-shadow-lg);
  filter: brightness(1.08);
}

.m3-btn.tonal {
  background: var(--md-primary-container);
  color: var(--md-on-primary-container);
}

.m3-btn.tonal:hover {
  box-shadow: var(--md-shadow);
  filter: brightness(0.96);
}

.m3-btn.text {
  background: transparent;
  color: var(--md-primary);
}

.m3-btn.text:hover {
  background: var(--md-primary-container);
}

.m3-btn.text.danger {
  color: var(--md-error);
  background: var(--md-error-container);
}

.m3-btn.text.danger:hover {
  filter: brightness(0.95);
}

.m3-btn.filled.danger {
  background: var(--md-error);
  color: var(--md-on-error);
  box-shadow: var(--md-shadow);
}

.m3-btn.filled.danger:hover {
  box-shadow: var(--md-shadow-lg);
  filter: brightness(1.08);
}

/* ===== Inputs ===== */
.m3-input {
  padding: 10px 14px;
  border: 1px solid var(--md-outline);
  border-radius: var(--md-radius-sm);
  background: var(--md-surface);
  color: var(--md-on-surface);
  font-size: 0.875rem;
  font-family: var(--md-font);
  outline: none;
  transition: border-color var(--md-transition), box-shadow var(--md-transition), background var(--md-transition);
  width: 100%;
}

.m3-input:focus {
  border-color: var(--md-primary);
  box-shadow: 0 0 0 1px var(--md-primary);
}

.m3-input::placeholder {
  color: var(--md-on-surface-variant);
  opacity: 0.7;
}

.m3-input[readonly] {
  background: var(--md-surface-container);
  cursor: default;
}

.m3-select {
  padding: 10px 32px 10px 14px;
  border: 1px solid var(--md-outline);
  border-radius: var(--md-radius-sm);
  background: var(--md-surface);
  color: var(--md-on-surface);
  font-size: 0.875rem;
  font-family: var(--md-font);
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%235f6368' d='M3 4.5L6 7.5L9 4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border-color var(--md-transition), background var(--md-transition);
}

.m3-select:focus {
  border-color: var(--md-primary);
  box-shadow: 0 0 0 1px var(--md-primary);
}

/* Number input — hide spinner */
.m3-input[type="number"] {
  -moz-appearance: textfield;
}

.m3-input[type="number"]::-webkit-outer-spin-button,
.m3-input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Select — dark mode arrow fix */
[data-theme="dark"] .m3-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239aa0a6' d='M3 4.5L6 7.5L9 4.5'/%3E%3C/svg%3E");
}

/* ===== Container ===== */
.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.surface {
  background: var(--md-surface);
  border-radius: var(--md-radius-lg);
  border: 1px solid var(--md-outline-variant);
  padding: 20px;
  transition: background var(--md-transition), border-color var(--md-transition);
}

/* ===== Editor Section ===== */
.title-row {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.title-row .m3-input {
  flex: 1;
}

.title-row .m3-select {
  width: 160px;
  flex-shrink: 0;
}

.editor-wrapper {
  display: flex;
  border: 1px solid var(--md-outline);
  border-radius: var(--md-radius-md);
  overflow: hidden;
  min-height: 360px;
  max-height: 600px;
  background: var(--md-surface-container);
  transition: border-color var(--md-transition), background var(--md-transition);
}

.editor-wrapper:focus-within {
  border-color: var(--md-primary);
  box-shadow: 0 0 0 1px var(--md-primary);
}

.line-numbers {
  padding: 14px 0;
  min-width: 48px;
  text-align: right;
  font-family: var(--md-mono);
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--md-on-surface-variant);
  background: var(--md-surface-container);
  border-right: 1px solid var(--md-outline-variant);
  user-select: none;
  overflow: hidden;
  padding-right: 12px;
  transition: background var(--md-transition), border-color var(--md-transition);
}

.editor-textarea {
  flex: 1;
  padding: 14px 16px;
  border: none;
  outline: none;
  background: transparent;
  color: var(--md-on-surface);
  font-family: var(--md-mono);
  font-size: 0.875rem;
  line-height: 1.6;
  resize: none;
  overflow-y: auto;
  tab-size: 4;
  white-space: pre;
  transition: color var(--md-transition);
}

.editor-textarea::placeholder {
  color: var(--md-on-surface-variant);
  opacity: 0.5;
}

/* ===== Settings Section ===== */
.settings-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--md-on-surface);
}

.setting-item {
  margin-bottom: 16px;
}

.setting-item > label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--md-on-surface-variant);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.setting-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.setting-input-row .m3-input,
.setting-input-row .m3-select {
  flex: 1;
}

.setting-input-row .m3-input.small {
  width: 80px;
  flex: 0 0 80px;
}

.setting-input-row .m3-select.small {
  width: 120px;
  flex: 0 0 120px;
}

.hint {
  display: block;
  font-size: 0.75rem;
  color: var(--md-on-surface-variant);
  margin-top: 4px;
  min-height: 18px;
}

.hint.error {
  color: var(--md-error);
}

.hint.success {
  color: var(--md-success);
}

/* ===== Action Buttons ===== */
.action-buttons {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--md-outline-variant);
}

/* ===== Result Panel ===== */
.result-panel {
  margin-top: 16px;
  padding: 16px;
  background: var(--md-surface-container);
  border-radius: var(--md-radius-md);
  border: 1px solid var(--md-outline-variant);
  animation: slideDown 300ms cubic-bezier(0.2, 0, 0, 1);
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.result-item {
  margin-bottom: 12px;
}

.result-item:last-child {
  margin-bottom: 0;
}

.result-item > label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--md-on-surface-variant);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.copy-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.copy-row .m3-input {
  flex: 1;
  font-family: var(--md-mono);
  font-size: 0.8rem;
}

.expires-value {
  font-size: 0.875rem;
  color: var(--md-on-surface);
  font-family: var(--md-mono);
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 150ms ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  width: 340px;
  max-width: 90vw;
  padding: 24px;
  animation: scaleIn 200ms cubic-bezier(0.2, 0, 0, 1);
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.modal h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--md-on-surface);
}

.modal .m3-input {
  margin-bottom: 20px;
}

.modal-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: var(--md-radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 2000;
  animation: toastIn 300ms cubic-bezier(0.2, 0, 0, 1);
  box-shadow: var(--md-shadow-lg);
  white-space: nowrap;
}

.toast.success {
  background: var(--md-success-container);
  color: var(--md-success);
}

.toast.error {
  background: var(--md-error-container);
  color: var(--md-error);
}

.toast.info {
  background: var(--md-primary-container);
  color: var(--md-on-primary-container);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.hidden {
  display: none !important;
}

/* ===== Note View Page ===== */
.note-view {
  max-width: 1000px;
}

.note-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.note-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--md-on-surface);
  word-break: break-word;
}

.note-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--md-on-surface-variant);
}

.language-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: var(--md-radius-xl);
  background: var(--md-primary-container);
  color: var(--md-on-primary-container);
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: capitalize;
}

.meta-separator {
  color: var(--md-outline);
}

.created-time {
  font-family: var(--md-mono);
  font-size: 0.8rem;
}

/* Note content */
.note-content-wrapper {
  position: relative;
  overflow: hidden;
}

.note-content {
  line-height: 1.7;
  word-break: break-word;
  overflow-x: auto;
}

/* Markdown rendered content */
.note-content.markdown-body h1,
.note-content.markdown-body h2,
.note-content.markdown-body h3,
.note-content.markdown-body h4,
.note-content.markdown-body h5,
.note-content.markdown-body h6 {
  margin-top: 1.2em;
  margin-bottom: 0.6em;
  font-weight: 600;
  color: var(--md-on-surface);
}

/* Must appear after heading rules to win specificity tie (both 0,2,1) */
.note-content.markdown-body > :first-child {
  margin-top: 0;
}

.note-content.markdown-body h1 { font-size: 1.8rem; }
.note-content.markdown-body h2 { font-size: 1.5rem; border-bottom: 1px solid var(--md-outline-variant); padding-bottom: 6px; }
.note-content.markdown-body h3 { font-size: 1.25rem; }

.note-content.markdown-body p {
  margin-bottom: 0.8em;
}

.note-content.markdown-body a {
  color: var(--md-primary);
}

.note-content.markdown-body code {
  font-family: var(--md-mono);
  font-size: 0.85em;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--md-surface-container-high);
  color: var(--md-on-surface);
}

.note-content.markdown-body pre {
  margin: 1em 0;
  border-radius: var(--md-radius-md);
  overflow-x: auto;
  position: relative;
}

.note-content.markdown-body pre code {
  display: block;
  padding: 16px;
  background: var(--md-surface-container);
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-radius-md);
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--md-on-surface);
}

/* Override prism-tomorrow base color for all code blocks */
.note-content code[class*="language-"],
.note-content pre[class*="language-"] {
  color: var(--md-on-surface);
  background: none;
}

/* Code block copy button */
.note-content.markdown-body pre .code-copy-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-radius-md);
  background: var(--md-surface-container-high);
  color: var(--md-on-surface-variant);
  cursor: pointer;
  font-size: 0.8rem;
  opacity: 0;
  transition: opacity var(--md-transition), background var(--md-transition);
  z-index: 1;
}

.note-content.markdown-body pre:hover .code-copy-btn {
  opacity: 1;
}

.note-content.markdown-body pre .code-copy-btn:hover {
  background: var(--md-surface-container-highest);
  color: var(--md-on-surface);
}

.note-content.markdown-body blockquote {
  border-left: 3px solid var(--md-primary);
  padding: 8px 16px;
  margin: 1em 0;
  background: var(--md-surface-container);
  border-radius: 0 var(--md-radius-sm) var(--md-radius-sm) 0;
  color: var(--md-on-surface-variant);
}

.note-content.markdown-body ul,
.note-content.markdown-body ol {
  padding-left: 1.5em;
  margin-bottom: 0.8em;
}

.note-content.markdown-body li {
  margin-bottom: 0.3em;
}

.note-content.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
}

.note-content.markdown-body th,
.note-content.markdown-body td {
  padding: 8px 12px;
  border: 1px solid var(--md-outline);
  text-align: left;
}

.note-content.markdown-body th {
  background: var(--md-surface-container);
  font-weight: 600;
}

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

.note-content.markdown-body hr {
  border: none;
  border-top: 1px solid var(--md-outline-variant);
  margin: 1.5em 0;
}

/* Code view (non-markdown) */
.note-content.code-view {
  font-family: var(--md-mono);
  font-size: 0.875rem;
  white-space: pre;
  overflow-x: auto;
  line-height: 1.6;
}

.note-content.code-view pre {
  margin: 0;
}

.note-content.code-view code {
  font-family: var(--md-mono);
}

.copy-float {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  background: var(--md-surface-container-high);
  border: 1px solid var(--md-outline);
  box-shadow: var(--md-shadow);
}

.copy-float:hover {
  background: var(--md-surface-container-highest);
}

/* Source section */
.source-section {
  margin-top: 0;
}

.source-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 12px 20px;
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-radius-lg);
  background: var(--md-surface);
  color: var(--md-on-surface-variant);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--md-transition);
}

.source-toggle:hover {
  background: var(--md-surface-container);
}

.source-toggle .toggle-arrow {
  margin-left: auto;
  transition: transform var(--md-transition);
}

.source-toggle.open .toggle-arrow {
  transform: rotate(180deg);
}

.source-content {
  margin-top: 8px;
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-radius-lg);
  overflow: hidden;
  background: var(--md-surface);
}

.source-header {
  display: flex;
  justify-content: flex-end;
  padding: 8px 12px;
  border-bottom: 1px solid var(--md-outline-variant);
  background: var(--md-surface-container);
}

.source-header .icon-btn {
  width: auto;
  padding: 0 12px;
  gap: 6px;
  font-size: 0.8rem;
}

.source-header .icon-btn span {
  font-weight: 500;
}

.source-pre {
  margin: 0;
  padding: 16px;
  overflow-x: auto;
  font-family: var(--md-mono);
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--md-on-surface);
}

.source-pre code {
  font-family: var(--md-mono);
}

/* ===== Footer ===== */
.site-footer {
  text-align: center;
  padding: 16px 24px;
  font-size: 0.8rem;
  color: var(--md-on-surface-variant);
}

.site-footer a {
  color: var(--md-on-surface-variant);
  text-decoration: none;
  font-weight: 500;
}

.site-footer a:hover {
  color: var(--md-on-surface);
  text-decoration: underline;
}

/* ===== Scroll to top ===== */
.scroll-top-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--md-primary);
  color: var(--md-on-primary);
  font-size: 1rem;
  cursor: pointer;
  box-shadow: var(--md-shadow-lg);
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 300ms ease, transform 300ms ease;
  opacity: 0;
  pointer-events: none;
}

.scroll-top-btn.visible {
  opacity: 1;
  pointer-events: auto;
}

.scroll-top-btn:hover {
  filter: brightness(1.1);
  transform: scale(1.05);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .container {
    padding: 16px;
  }


  .title-row {
    flex-direction: column;
    gap: 8px;
  }

  .title-row .m3-select {
    width: 100%;
  }

  .editor-wrapper {
    min-height: 280px;
  }

  .action-buttons {
    flex-wrap: wrap;
  }

  .setting-input-row {
    flex-wrap: wrap;
  }

  .setting-input-row .m3-input.small,
  .setting-input-row .m3-select.small {
    flex: 1 1 auto;
    width: auto;
  }

  .note-title {
    font-size: 1.25rem;
  }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

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

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

::-webkit-scrollbar-thumb:hover {
  background: var(--md-on-surface-variant);
}

/* ===== Prism overrides for light theme ===== */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
  color: #008000;
}

.token.punctuation {
  color: #393a34;
}

.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol {
  color: #098658;
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin {
  color: #a31515;
}

.token.operator,
.token.entity,
.token.url {
  color: #393a34;
}

.token.atrule,
.token.attr-value,
.token.keyword {
  color: #0000ff;
}

.token.function,
.token.class-name {
  color: #795e26;
}

.token.regex,
.token.important,
.token.variable {
  color: #811f3f;
}

/* ===== Prism overrides for dark theme ===== */
[data-theme="dark"] .token.comment,
[data-theme="dark"] .token.prolog,
[data-theme="dark"] .token.doctype,
[data-theme="dark"] .token.cdata {
  color: #6a9955;
}

[data-theme="dark"] .token.punctuation {
  color: #d4d4d4;
}

[data-theme="dark"] .token.property,
[data-theme="dark"] .token.tag,
[data-theme="dark"] .token.boolean,
[data-theme="dark"] .token.number,
[data-theme="dark"] .token.constant,
[data-theme="dark"] .token.symbol {
  color: #b5cea8;
}

[data-theme="dark"] .token.selector,
[data-theme="dark"] .token.attr-name,
[data-theme="dark"] .token.string,
[data-theme="dark"] .token.char,
[data-theme="dark"] .token.builtin {
  color: #ce9178;
}

[data-theme="dark"] .token.operator,
[data-theme="dark"] .token.entity,
[data-theme="dark"] .token.url {
  color: #d4d4d4;
}

[data-theme="dark"] .token.atrule,
[data-theme="dark"] .token.attr-value,
[data-theme="dark"] .token.keyword {
  color: #569cd6;
}

[data-theme="dark"] .token.function,
[data-theme="dark"] .token.class-name {
  color: #dcdcaa;
}

[data-theme="dark"] .token.regex,
[data-theme="dark"] .token.important,
[data-theme="dark"] .token.variable {
  color: #d16969;
}

/* ===== Button Loading State ===== */
.m3-btn.loading {
  pointer-events: none;
  opacity: 0.7;
  position: relative;
}

.m3-btn.loading::after {
  content: '';
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-left: 8px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: btnSpin 600ms linear infinite;
}

@keyframes btnSpin {
  to { transform: rotate(360deg); }
}

/* ===== Editor Syntax Highlight Overlay ===== */
.editor-stack {
  position: relative;
  flex: 1;
  overflow: hidden;
  display: flex;
}

.editor-highlight {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 14px 16px;
  margin: 0;
  font-family: var(--md-mono);
  font-size: 0.875rem;
  line-height: 1.6;
  white-space: pre;
  overflow: hidden;
  pointer-events: none;
  color: var(--md-on-surface);
  background: transparent;
  tab-size: 4;
  word-wrap: normal;
  border: none;
}

.editor-highlight code {
  font-family: var(--md-mono);
  font-size: inherit;
  line-height: inherit;
  background: transparent !important;
  padding: 0;
  white-space: pre;
  tab-size: 4;
}

.editor-textarea.highlight-active {
  color: transparent;
  caret-color: var(--md-on-surface);
  -webkit-text-fill-color: transparent;
  background: transparent;
}

/* ===== Markdown Live Preview ===== */
.editor-preview-split {
  display: flex;
  gap: 16px;
}

.editor-preview-split .editor-section {
  flex: 1;
  min-width: 0;
}

.preview-pane {
  overflow-y: auto;
  max-height: 600px;
  min-height: 360px;
}

.preview-pane .preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--md-outline-variant);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--md-on-surface-variant);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.preview-pane .preview-content {
  line-height: 1.7;
  word-break: break-word;
}

/* Reuse markdown-body styles for preview */
.preview-content h1,
.preview-content h2,
.preview-content h3,
.preview-content h4,
.preview-content h5,
.preview-content h6 {
  margin-top: 1.2em;
  margin-bottom: 0.6em;
  font-weight: 600;
  color: var(--md-on-surface);
}

.preview-content > :first-child {
  margin-top: 0;
}

.preview-content h1 { font-size: 1.8rem; }
.preview-content h2 { font-size: 1.5rem; border-bottom: 1px solid var(--md-outline-variant); padding-bottom: 6px; }
.preview-content h3 { font-size: 1.25rem; }

.preview-content p { margin-bottom: 0.8em; }
.preview-content a { color: var(--md-primary); }

.preview-content code {
  font-family: var(--md-mono);
  font-size: 0.85em;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--md-surface-container-high);
  color: var(--md-on-surface);
}

.preview-content pre {
  margin: 1em 0;
  border-radius: var(--md-radius-md);
  overflow-x: auto;
}

.preview-content pre code {
  display: block;
  padding: 16px;
  background: var(--md-surface-container);
  border: 1px solid var(--md-outline-variant);
  border-radius: var(--md-radius-md);
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--md-on-surface);
}

.preview-content blockquote {
  border-left: 3px solid var(--md-primary);
  padding: 8px 16px;
  margin: 1em 0;
  background: var(--md-surface-container);
  border-radius: 0 var(--md-radius-sm) var(--md-radius-sm) 0;
  color: var(--md-on-surface-variant);
}

.preview-content ul,
.preview-content ol {
  padding-left: 1.5em;
  margin-bottom: 0.8em;
}

.preview-content li { margin-bottom: 0.3em; }

.preview-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
}

.preview-content th,
.preview-content td {
  padding: 8px 12px;
  border: 1px solid var(--md-outline);
  text-align: left;
}

.preview-content th {
  background: var(--md-surface-container);
  font-weight: 600;
}

.preview-content img {
  max-width: 100%;
  border-radius: var(--md-radius-sm);
}

.preview-content hr {
  border: none;
  border-top: 1px solid var(--md-outline-variant);
  margin: 1.5em 0;
}

.preview-toggle-btn {
  display: none;
}

.preview-toggle-btn.visible {
  display: inline-flex;
}

/* ===== Drag & Drop Overlay ===== */
.drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(26, 115, 232, 0.08);
  border: 2px dashed var(--md-primary);
  border-radius: var(--md-radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  pointer-events: none;
  opacity: 0;
  transition: opacity 200ms ease;
}

.drop-overlay.active {
  opacity: 1;
}

.drop-overlay span {
  padding: 8px 20px;
  background: var(--md-primary-container);
  color: var(--md-on-primary-container);
  border-radius: var(--md-radius-xl);
  font-size: 0.875rem;
  font-weight: 500;
}

/* ===== Note Error State ===== */
.note-error-state {
  text-align: center;
  padding: 60px 20px;
}

.note-error-state .error-icon {
  font-size: 3rem;
  color: var(--md-on-surface-variant);
  margin-bottom: 16px;
}

.note-error-state h2 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--md-on-surface);
  margin-bottom: 8px;
}

.note-error-state p {
  color: var(--md-on-surface-variant);
  margin-bottom: 24px;
  font-size: 0.9rem;
}

.note-error-state .m3-btn {
  margin-top: 8px;
}

/* ===== Keyboard Shortcut Hint ===== */
.shortcut-hint {
  font-size: 0.7rem;
  color: inherit;
  opacity: 0.6;
  margin-left: 6px;
}

/* ===== Mobile Improvements ===== */
@media (max-width: 768px) {
  .editor-preview-split {
    flex-direction: column;
  }

  .preview-pane {
    max-height: 400px;
    min-height: 200px;
  }

  .m3-btn {
    min-height: 44px;
    padding: 10px 20px;
  }

  .icon-btn {
    width: 44px;
    height: 44px;
  }

  .icon-btn.small {
    width: 40px;
    height: 40px;
  }

  .modal {
    width: 92vw;
    max-width: 92vw;
  }

  .modal .m3-input {
    min-height: 44px;
    font-size: 1rem;
  }

  .setting-item > label {
    font-size: 0.75rem;
  }

  .shortcut-hint {
    display: none;
  }

  .copy-row {
    gap: 4px;
  }

  .header-row {
    padding: 0 0 8px;
  }
}
