:root {
  --bg: #0a0a0a;
  --text: #eaeaea;
  --muted: #9a9a9a;
  --accent: #ffffff;
  --paper: #111;
}

html.light-theme {
  --bg: #ffffff;
  --text: #1a1a1a;
  --muted: #666666;
  --accent: #000000;
  --paper: #f5f5f5;
}

html.rubber-ducky-theme {
  --bg: #d09421;
  --text: #ffffff;
  --muted: #9d6b15;
  --accent: #0669ed;
  --paper: #e0a530;
}

html.pinetop-theme {
  --bg: #344f1f;
  --text: #e8f5e9;
  --muted: #9cbb8f;
  --accent: #00e091;
  --paper: #3d5a28;
}

html.ocean-breeze-theme {
  --bg: #001b3d;
  --text: #d4e8f7;
  --muted: #5ab5d4;
  --accent: #148aa8;
  --paper: #002851;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--paper);
  border: 1px solid var(--muted);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 4px;
  font-size: 13px;
  z-index: 300;
  animation: slideUp 0.3s ease, slideDown 0.3s ease 2.7s forwards;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

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

@keyframes slideDown {
  to {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Times New Roman", Georgia, serif;
  transition: background 0.3s, color 0.3s;
}

.page {
  max-width: 780px;
  margin: 0 auto;
  padding: 80px 24px;
}

.title-section {
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--muted);
}

.document-title {
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  font-size: 28px;
  font-weight: bold;
  font-family: "Times New Roman", Georgia, serif;
  padding: 0;
  margin: 0 0 10px 0;
  outline: none;
  cursor: text;
}

.document-title::placeholder {
  color: var(--muted);
}

.stats-bar {
  display: flex;
  gap: 20px;
  font-size: 12px;
  color: var(--muted);
}

.stat-item {
  display: flex;
  gap: 4px;
}

.stat-item span:first-child {
  font-weight: bold;
}

.controls {
  display: flex;
  gap: 20px;
  align-items: center;
  margin-bottom: 40px;
  font-size: 13px;
  color: var(--muted);
  flex-wrap: wrap;
}

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

.control-group label {
  cursor: pointer;
}

.control-group input {
  background: none;
  border: none;
  color: var(--text);
  padding: 4px 6px;
  font-size: 13px;
  width: 40px;
  font-family: "Times New Roman", Georgia, serif;
  cursor: text;
}

.control-group input:focus {
  outline: 1px solid var(--muted);
}

.control-group select {
  background: none;
  border: none;
  color: var(--text);
  padding: 4px 6px;
  font-size: 13px;
  font-family: "Times New Roman", Georgia, serif;
  cursor: pointer;
}

.control-group select:focus {
  outline: 1px solid var(--muted);
}

.source-input {
  display: flex;
  gap: 6px;
  align-items: center;
}

.source-input input {
  width: 150px;
}

.source-list {
  margin-top: 8px;
  padding-left: 16px;
  font-size: 12px;
  color: var(--muted);
  max-height: 100px;
  overflow-y: auto;
}

.source-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2px 0;
  word-break: break-all;
}

.source-item button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  padding: 0 4px;
  margin-left: 8px;
}

.source-item button:hover {
  color: var(--text);
}

.control-button {
  background: none;
  border: 1px solid var(--muted);
  color: var(--muted);
  padding: 4px 10px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: "Times New Roman", Georgia, serif;
}

.control-button:hover {
  color: var(--text);
  border-color: var(--text);
}

.settings-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  background: none;
  border: 1px solid var(--muted);
  color: var(--muted);
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
  z-index: 100;
  font-weight: 500;
}

.settings-toggle:hover {
  color: var(--text);
  border-color: var(--text);
}

.settings-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 200;
  align-items: center;
  justify-content: center;
  transition: background 0.3s;
}

html.light-theme .settings-modal {
  background: rgba(255, 255, 255, 0.9);
}

.settings-modal.open {
  display: flex;
}

.settings-content {
  background: var(--paper);
  border: 1px solid var(--muted);
  padding: 0;
  border-radius: 8px;
  max-width: 500px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background 0.3s;
}

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

.settings-header h2 {
  margin: 0;
  font-size: 18px;
  color: var(--text);
  font-weight: 600;
}

.close-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  padding: 0;
  transition: color 0.2s;
}

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

.settings-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--muted);
  padding: 0;
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  padding: 12px 16px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.tab-content {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

.tab-content.active {
  display: block;
}

.settings-group {
  margin-bottom: 20px;
}

.settings-group:last-child {
  margin-bottom: 0;
}

.settings-group label {
  display: block;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 8px;
  font-weight: 500;
}

.settings-group input[type="range"] {
  width: 100%;
  margin-bottom: 12px;
  cursor: pointer;
}

.settings-group select,
.settings-group input[type="text"] {
  width: 100%;
  background: none;
  border: 1px solid var(--muted);
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  font-family: "Times New Roman", Georgia, serif;
  cursor: pointer;
  transition: all 0.3s;
  border-radius: 4px;
  margin-bottom: 8px;
}

.settings-group select:focus,
.settings-group input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

.group-description {
  margin: 0 0 12px 0;
  font-size: 12px;
  color: var(--muted);
}

.button-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.action-btn {
  background: none;
  border: 1px solid var(--muted);
  color: var(--muted);
  padding: 10px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: "Times New Roman", Georgia, serif;
  border-radius: 4px;
  font-weight: 500;
}

.action-btn:hover {
  color: var(--text);
  border-color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.subsection {
  padding: 12px 0;
  border-top: 1px solid var(--muted);
}

.subsection:first-child {
  border-top: none;
  padding-top: 0;
}

.subsection h4 {
  margin: 0 0 8px 0;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.citation-btn {
  background: none;
  border: 1px solid var(--muted);
  color: var(--muted);
  padding: 8px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: "Times New Roman", Georgia, serif;
  border-radius: 4px;
  font-weight: 500;
}

.citation-btn:hover {
  color: var(--text);
  border-color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.source-input-group {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.source-input-group input {
  flex: 1;
  background: none;
  border: 1px solid var(--muted);
  color: var(--text);
  padding: 8px 10px;
  font-size: 12px;
  font-family: "Times New Roman", Georgia, serif;
  transition: all 0.3s;
  border-radius: 4px;
}

.source-input-group input:focus {
  outline: none;
  border-color: var(--accent);
}

.btn-add {
  background: none;
  border: 1px solid var(--muted);
  color: var(--muted);
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s;
  border-radius: 4px;
  font-weight: bold;
}

.btn-add:hover {
  color: var(--text);
  border-color: var(--text);
}

.settings-source-list {
  margin-bottom: 12px;
  padding: 8px 0;
  font-size: 12px;
  color: var(--muted);
  max-height: 150px;
  overflow-y: auto;
}

.settings-source-input input:focus {
  outline: 1px solid var(--text);
}

.settings-source-input button {
  background: none;
  border: 1px solid var(--muted);
  color: var(--muted);
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.settings-source-input button:hover {
  color: var(--text);
  border-color: var(--text);
}

.settings-source-list {
  font-size: 12px;
  color: var(--muted);
  max-height: 120px;
  overflow-y: auto;
}

.settings-source-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  word-break: break-all;
}

.settings-source-item button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  padding: 0 4px;
  margin-left: 8px;
  transition: all 0.2s;
}

.settings-source-item button:hover {
  color: var(--text);
}

.theme-toggle {
  display: flex;
  gap: 4px;
}

.theme-btn {
  background: none;
  border: 1px solid var(--muted);
  color: var(--muted);
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: "Times New Roman", Georgia, serif;
}

.theme-btn.active {
  color: var(--text);
  border-color: var(--text);
}

.theme-btn:hover {
  color: var(--text);
  border-color: var(--text);
}

.editor {
  outline: none;
  min-height: 70vh;
  font-size: 18px;
  line-height: 1.8;
}

.editor p {
  margin: 0 0 1.2em 0;
  text-indent: 2em;
}

.editor p:first-child,
.editor p:nth-child(2) {
  text-indent: 0;
  margin-bottom: 0.5em;
}

.placeholder {
  color: var(--muted);
}

.image-wrapper {
  position: relative;
  margin: 16px 0;
  padding: 8px;
  border: 1px solid transparent;
  transition: border-color 0.2s;
}

.image-wrapper:hover {
  border: 1px solid var(--muted);
  border-radius: 4px;
}

.image-wrapper img {
  max-width: 100%;
  height: auto;
  display: block;
}

.image-controls {
  display: none;
  position: absolute;
  top: 8px;
  right: 8px;
  gap: 4px;
  background: var(--paper);
  border: 1px solid var(--muted);
  border-radius: 4px;
  padding: 4px;
}

.image-wrapper:hover .image-controls {
  display: flex;
}

.img-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  transition: color 0.2s;
  font-weight: bold;
}

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

.autocomplete-popup {
  position: fixed;
  display: none;
  background: var(--paper);
  border: 1px solid var(--muted);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  min-width: 200px;
  z-index: 1000;
}

.autocomplete-popup.visible {
  display: block;
}

.autocomplete-item {
  padding: 8px 12px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 13px;
  color: var(--text);
  border-bottom: 1px solid var(--muted);
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

.autocomplete-match {
  color: var(--text);
  font-weight: 600;
}

.autocomplete-remaining {
  color: var(--muted);
  margin-left: 2px;
}

footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin-top: 60px;
}

@media print {
  body {
    background: white;
    color: black;
  }

  .page {
    padding: 1in;
    max-width: 100%;
  }

  .title-section {
    border-bottom: 2px solid black;
    margin-bottom: 0.5in;
  }

  .document-title {
    font-size: 24px;
    margin-bottom: 0.25in;
  }

  .stats-bar {
    display: none;
  }

  .settings-toggle {
    display: none;
  }

  footer {
    display: none;
  }

  .editor * {
    color: black !important;
  }

  .editor p {
    page-break-inside: avoid;
  }
}