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

/* ── CSS variables ── */
:root {
  --bg: #111111;
  --surface: #1c1c1c;
  --border: #7c3aed;
  --border-focus: #a855f7;
  --text: #e5e5e5;
  --text-muted: #888888;
  --title-text: #e5e5e5;
  --editor-placeholder: #666666;
  --blockquote-border: #444444;
  --blockquote-text: #999999;
  --pre-bg: #161616;
  --code-bg: #222222;
  --link: #a855f7;
  --btn-secondary-bg: #2a2a2a;
  --btn-secondary-text: #cccccc;
  --btn-secondary-hover: #333333;
  --toast-bg: #222222;
  --toast-border: #444444;
  --shadow-focus: rgba(168, 85, 247, 0.25);
}

[data-theme="light"] {
  --bg: #f0f0f0;
  --surface: #ffffff;
  --border: #a855f7;
  --border-focus: #7c3aed;
  --text: #1a1a1a;
  --text-muted: #666666;
  --title-text: #333333;
  --editor-placeholder: #999999;
  --blockquote-border: #cccccc;
  --blockquote-text: #666666;
  --pre-bg: #f5f5f5;
  --code-bg: #eeeeee;
  --link: #7c3aed;
  --btn-secondary-bg: #e8e8e8;
  --btn-secondary-text: #333333;
  --btn-secondary-hover: #dedede;
  --toast-bg: #222222;
  --toast-border: #555555;
  --shadow-focus: rgba(124, 58, 237, 0.2);
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 16px;
  transition: background 0.3s, color 0.3s;
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin-bottom: 20px;
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: -0.02em;
  color: #888888;
}

[data-theme="light"] h1 {
  color: #393939;
}

/* ── Theme toggle ── */
.theme-toggle {
  position: absolute;
  right: 0;
  background: var(--btn-secondary-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  padding: 6px 12px;
  line-height: 1;
  transition: background 0.2s, border-color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.theme-toggle:hover {
  background: var(--btn-secondary-hover);
  border-color: var(--border-focus);
}

/* ── Container ── */
.container {
  max-width: 800px;
  margin: 0 auto;
}

/* ── Title preview ── */
.title-preview {
  font-size: 0.875rem;
  color: var(--text-muted);
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 12px 12px 0 0;
  min-height: 36px;
  line-height: 1.4;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  transition: background 0.3s, border-color 0.3s, color 0.3s;
}

.title-preview.has-title {
  color: var(--title-text);
  font-weight: 500;
}

/* ── Editor ── */
.editor {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 0 12px 12px;
  padding: 16px;
  min-height: 50vh;
  max-height: 70vh;
  overflow-y: auto;
  outline: none;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text);
  -webkit-overflow-scrolling: touch;
  transition: background 0.3s, border-color 0.3s, color 0.3s;
}

.editor:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--shadow-focus);
}

.editor:empty::before {
  content: attr(data-placeholder);
  color: var(--editor-placeholder);
  pointer-events: none;
}

.editor h1, .editor h2, .editor h3,
.editor h4, .editor h5, .editor h6 {
  margin-top: 0.8em;
  margin-bottom: 0.4em;
}

.editor p {
  margin-bottom: 0.5em;
}

.editor ul, .editor ol {
  margin-left: 1.5em;
  margin-bottom: 0.5em;
}

.editor blockquote {
  border-left: 3px solid var(--blockquote-border);
  padding-left: 12px;
  color: var(--blockquote-text);
  margin-bottom: 0.5em;
}

.editor pre {
  background: var(--pre-bg);
  padding: 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin-bottom: 0.5em;
}

.editor code {
  background: var(--code-bg);
  padding: 2px 4px;
  border-radius: 3px;
  font-size: 0.9em;
}

.editor a {
  color: var(--link);
}

/* ── Buttons ── */
.actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.btn {
  flex: 1;
  padding: 14px 20px;
  font-size: 1rem;
  font-weight: 500;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s, box-shadow 0.2s;
  -webkit-tap-highlight-color: transparent;
  min-height: 48px;
}

.btn:active {
  opacity: 0.75;
}

.btn-secondary {
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--btn-secondary-hover);
  border-color: var(--border-focus);
}

.btn-primary {
  background: linear-gradient(135deg, #7c3aed, #a855f7);
  color: #fff;
  box-shadow: 0 2px 12px rgba(168, 85, 247, 0.35);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #6d28d9, #9333ea);
  box-shadow: 0 4px 18px rgba(168, 85, 247, 0.5);
}

.btn-kindle {
  background: linear-gradient(135deg, #c2410c, #f97316);
  color: #fff;
  box-shadow: 0 2px 12px rgba(249, 115, 22, 0.35);
}

.btn-kindle:hover {
  background: linear-gradient(135deg, #9a3412, #ea580c);
  box-shadow: 0 4px 18px rgba(249, 115, 22, 0.5);
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--toast-bg);
  color: #fff;
  border: 1px solid var(--toast-border);
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 0.875rem;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  pointer-events: none;
  z-index: 100;
  max-width: calc(100% - 32px);
  text-align: center;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ── Mobile ── */
@media (max-width: 480px) {
  h1 {
    font-size: 1.25rem;
  }

  .actions {
    flex-direction: column;
  }

  .editor {
    min-height: 40vh;
  }

  .theme-toggle {
    font-size: 0.875rem;
    padding: 5px 10px;
  }
}
