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

:root {
  --bg-gradient-start: #f5f7ff;
  --bg-gradient-end: #dde3ea;
  --card-bg: #ffffff;
  --border-subtle: rgba(226, 232, 240, 0.9);
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --accent-primary: #4f46e5;
  --accent-primary-alt: #6366f1;
  --accent-muted: #e5e7eb;
  --mode-plain-bg: #ffffff;
  --mode-paper-bg: #f9fafb;
  --mode-code-bg: #f3f4f6;
  --font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --code-font: 'SF Mono', ui-monospace, Menlo, Monaco, Consolas, monospace;
  --font-size-base: 16px;
  --line-height: 1.6;
  --page-padding: 24px;
  --card-padding: 20px;
  --gap-large: 20px;
  --gap-medium: 12px;
  --gap-small: 8px;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: var(--line-height);
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--page-padding);
  position: relative;
}

#background {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
  z-index: -1;
}

#card {
  width: 100%;
  max-width: 1100px;
  min-height: calc(100vh * 0.9);
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
}

/* Header */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--card-padding);
  border-bottom: 1px solid var(--border-subtle);
  gap: var(--gap-medium);
  flex-wrap: wrap;
}

#logo {
  display: flex;
  align-items: center;
  gap: var(--gap-small);
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--accent-primary);
}

#logo svg {
  flex-shrink: 0;
}

#mode-switcher {
  display: flex;
  gap: 4px;
  background: var(--accent-muted);
  padding: 4px;
  border-radius: 8px;
}

.mode-btn {
  padding: 6px 14px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.2s ease;
}

.mode-btn:hover {
  color: var(--text-primary);
}

.mode-btn.active {
  background: var(--card-bg);
  color: var(--accent-primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

#header-toolbar {
  display: flex;
  gap: var(--gap-small);
}

#header-toolbar button {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

#new-tab-btn {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-primary-alt));
  color: #ffffff;
}

#new-tab-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
}

#cleaner-toggle-btn {
  background: var(--accent-muted);
  color: var(--text-primary);
}

#cleaner-toggle-btn:hover {
  background: #d1d5db;
}

#cleaner-toggle-btn.active {
  background: var(--accent-primary);
  color: #ffffff;
}

/* Body */
#body {
  display: flex;
  flex: 1;
  min-height: 0;
}

#sidebar-tabs {
  width: 200px;
  border-right: 1px solid var(--border-subtle);
  padding: var(--gap-medium);
  background: #fafbfc;
  overflow-y: auto;
}

#tabs-list {
  display: flex;
  flex-direction: column;
  gap: var(--gap-small);
}

.tab-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  background: #f3f4f6;
  border: 1px solid transparent;
  gap: var(--gap-small);
}

.tab-item:hover {
  background: var(--card-bg);
}

.tab-item.active {
  background: var(--card-bg);
  border-color: var(--accent-primary);
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.12);
}

.tab-title {
  flex: 1;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
  outline: none;
}

.tab-item.active .tab-title {
  color: var(--text-primary);
}

.tab-title:focus {
  cursor: text;
}

.tab-close {
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  opacity: 0;
  transition: all 0.15s ease;
}

.tab-item:hover .tab-close {
  opacity: 1;
}

.tab-close:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

/* Editor Column */
#editor-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#editor {
  flex: 1;
  width: 100%;
  padding: var(--card-padding);
  border: 1px solid rgba(209, 213, 219, 0.8);
  border-left: none;
  border-right: none;
  outline: none;
  resize: none;
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: var(--line-height);
  color: var(--text-primary);
  background: var(--mode-plain-bg);
  transition: background 0.2s ease;
}

#editor::placeholder {
  color: var(--text-secondary);
}

/* Editor Modes */
#editor.mode-plain {
  background: var(--mode-plain-bg);
  font-family: var(--font-family);
}

#editor.mode-paper {
  background: repeating-linear-gradient(
    to bottom,
    var(--mode-paper-bg),
    var(--mode-paper-bg) 26px,
    #e5e7eb 27px
  );
  background-attachment: local;
  font-family: var(--font-family);
}


/* Text Cleaner Panel */
#text-cleaner-panel {
  padding: var(--card-padding);
  border-top: 1px solid var(--border-subtle);
  background: #fafbfc;
  display: flex;
  align-items: center;
  gap: var(--gap-large);
  flex-wrap: wrap;
}

#text-cleaner-panel.hidden {
  display: none;
}

#text-cleaner-options {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap-medium) var(--gap-large);
}

#text-cleaner-options label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.875rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

#text-cleaner-options input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-primary);
  cursor: pointer;
}

#apply-cleaner-btn {
  padding: 8px 16px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-primary-alt));
  color: #ffffff;
  border: none;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-left: auto;
}

#apply-cleaner-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
}

/* Footer */
#footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--gap-medium) var(--card-padding);
  border-top: 1px solid var(--border-subtle);
  background: #fafbfc;
  gap: var(--gap-medium);
  flex-wrap: wrap;
}

#stats {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
}

#temporary-info {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

#temporary-info svg {
  color: #f59e0b;
}

/* SEO Info Section */
.seo-info-section {
  max-width: 720px;
  margin: 40px auto 40px auto;
  padding: 0 16px;
  text-align: left;
}

.seo-info-section h1 {
  font-size: clamp(1.6rem, 2vw + 1rem, 2.2rem);
  margin-bottom: 12px;
  color: var(--text-primary);
  font-weight: 600;
}

.seo-info-section p {
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

/* Responsive */
@media (max-width: 768px) {
  #header {
    flex-direction: column;
    align-items: stretch;
  }

  #logo {
    justify-content: center;
  }

  #mode-switcher {
    justify-content: center;
  }

  #header-toolbar {
    justify-content: center;
  }

  #body {
    flex-direction: column;
  }

  #sidebar-tabs {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
    padding: var(--gap-small);
  }

  #tabs-list {
    flex-direction: row;
    overflow-x: auto;
    gap: var(--gap-small);
  }

  .tab-item {
    flex-shrink: 0;
  }

  #card {
    min-height: calc(100vh - 48px);
  }
}

