/* --- App shell --- */
:root {
  --bg: #f5f2ed;
  --surface: #fffef9;
  --ink: #1a1814;
  --muted: #5c564c;
  --accent: #8b4513;
  --accent-hover: #6d3410;
  --border: #e5e0d8;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(26, 24, 20, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.5;
}

.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  text-align: center;
  margin-bottom: 2rem;
}

.app-header h1 {
  font-size: 1.75rem;
  font-weight: 600;
  margin: 0 0 0.25rem;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.app-header .btn-ghost {
  margin-top: 0.75rem;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
}

.app-header .btn-ghost:hover {
  background: rgba(139, 69, 19, 0.06);
  border-color: var(--accent);
}

/* --- How it works modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 24, 20, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1.5rem;
}

.modal-overlay[hidden] {
  display: none !important;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(26, 24, 20, 0.2);
  max-width: 560px;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0.25rem;
}

.modal-close:hover {
  color: var(--ink);
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
}

.speech-content p {
  margin: 0 0 1rem;
  font-size: 0.95rem;
  line-height: 1.6;
}

.speech-content p:last-child {
  margin-bottom: 0;
}

.main-content {
  flex: 1;
}

/* --- Upload --- */
.upload-section {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.upload-card {
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
}

.upload-card.drag-over {
  border-color: var(--accent);
  background: rgba(139, 69, 19, 0.04);
}

.upload-content .upload-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 1rem;
  color: var(--muted);
}

.upload-text {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
}

.browse-link {
  color: var(--accent);
  font-weight: 500;
  cursor: pointer;
  text-decoration: underline;
}

.browse-link:hover {
  color: var(--accent-hover);
}

.upload-hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.upload-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* --- MLA meta fields --- */
.mla-meta {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.mla-meta h3 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
  font-weight: 600;
}

.meta-hint {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.meta-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1rem;
}

.meta-fields label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.meta-fields label span {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
}

.meta-fields input {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.95rem;
}

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

@media (max-width: 500px) {
  .meta-fields {
    grid-template-columns: 1fr;
  }
}

/* --- Sources section --- */
.sources-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.sources-section h3 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
  font-weight: 600;
}

.sources-hint {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.source-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.source-type-label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.source-type-label span {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
}

.source-form select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.95rem;
  max-width: 14rem;
}

.source-field-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 1rem;
}

.source-field-group label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.source-field-group label span {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
}

.source-field-group input {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.9rem;
}

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

.btn-add {
  background: var(--accent);
  color: var(--surface);
  align-self: flex-start;
}

.btn-add:hover {
  background: var(--accent-hover);
}

/* --- Import citations --- */
.import-citations {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.import-citations h4 {
  margin: 0 0 0.25rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.import-citations .import-hint {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.import-format-label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
}

.import-format-label span {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
}

.import-citations select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.9rem;
  max-width: 12rem;
}

.import-citations textarea {
  width: 100%;
  min-height: 120px;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.5;
  resize: vertical;
  margin-bottom: 0.75rem;
}

.import-citations textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.import-result {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.import-result.success {
  color: #2d6a2d;
}

.import-result.error {
  color: #a52a2a;
}

.sources-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sources-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border-radius: 8px;
  font-size: 0.85rem;
  line-height: 1.4;
}

.sources-list .citation-preview {
  flex: 1;
  min-width: 0;
}

.sources-list .citation-actions {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

.sources-list .btn-remove {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}

.sources-list .btn-remove:hover {
  color: var(--ink);
  border-color: var(--muted);
}

@media (max-width: 600px) {
  .source-field-group {
    grid-template-columns: 1fr;
  }
}

/* --- MLA Works Cited (in paper) --- */
.mla-works-cited {
  margin-top: 2em;
  page-break-before: always;
}

.mla-works-cited-heading {
  text-align: center;
  font-size: 12pt;
  font-weight: 400;
  margin: 0 0 1em;
  line-height: 2;
}

.mla-works-cited-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.mla-works-cited-list li {
  margin-bottom: 0.5em;
  padding-left: 0.5in;
  text-indent: -0.5in;
  hanging-punctuation: hang;
}

.mla-works-cited-list li .mla-citation {
  font-style: normal;
}

.mla-works-cited-list li .mla-citation em {
  font-style: italic;
}

/* --- Output section --- */
.output-section {
  margin-top: 2rem;
}

.output-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.output-toolbar h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.print-tip {
  margin: 0.75rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
  max-width: 520px;
}

.print-tip strong {
  color: var(--ink);
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.toolbar-spellcheck {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
}

.toolbar-spellcheck input {
  margin: 0;
  cursor: pointer;
}

/* --- Search in document --- */
.search-in-doc {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.search-in-doc input {
  width: 140px;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.85rem;
}

.search-in-doc input:focus {
  outline: none;
  border-color: var(--accent);
}

.btn-search-nav {
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
  min-width: auto;
}

.mla-body mark.search-highlight {
  background: rgba(255, 220, 100, 0.6);
  padding: 0 1px;
  border-radius: 2px;
}

.mla-body mark.search-highlight.current {
  background: rgba(255, 180, 0, 0.8);
}

/* --- Plagiarism panel --- */
.plagiarism-panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.plagiarism-panel[hidden] {
  display: none;
}

.plagiarism-panel h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
}

.plagiarism-intro {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.5;
}

.plagiarism-list {
  margin: 0 0 1rem;
  padding-left: 1.25rem;
  font-size: 0.9rem;
  line-height: 1.5;
}

.plagiarism-list li {
  margin-bottom: 0.5rem;
}

.plagiarism-list .passage {
  font-style: italic;
  color: var(--ink);
}

.plagiarism-list .advice {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.plagiarism-tips {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.5;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

/* --- Writing grader panel --- */
.grader-panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.grader-panel[hidden] {
  display: none;
}

.grader-panel h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
}

.grader-score {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.grader-details {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
  line-height: 1.5;
}

.grader-tips {
  margin: 0;
  padding-left: 1.25rem;
  font-size: 0.9rem;
  line-height: 1.5;
}

.grader-tips li {
  margin-bottom: 0.25rem;
}

.grader-breakdown {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Spell check mode: editable body */
.mla-body[contenteditable="true"] {
  outline: 1px dashed var(--accent);
  outline-offset: 2px;
  min-height: 4em;
}

.btn {
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background 0.2s, color 0.2s;
}

.btn-secondary {
  background: var(--ink);
  color: var(--surface);
}

.btn-secondary:hover {
  background: var(--muted);
}

.btn-fix {
  background: var(--accent);
  color: var(--surface);
}

.btn-fix:hover {
  background: var(--accent-hover);
}

/* --- MLA paper (print-style) --- */
.mla-paper-wrapper {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  overflow-x: auto;
}

.mla-paper {
  position: relative;
  max-width: 21cm;
  margin: 0 auto;
  padding: 1in;
  font-family: 'Crimson Pro', 'Times New Roman', Times, serif;
  font-size: 12pt;
  line-height: 2; /* double space */
  color: #000;
}

/* Running header: last name + page number, 0.5" from top, right */
.mla-header {
  position: absolute;
  top: 0.5in;
  right: 1in;
  font-size: 12pt;
  font-family: inherit;
}

.mla-heading-block {
  margin-bottom: 1em;
}

.mla-heading-block p {
  margin: 0;
  font-size: 12pt;
  line-height: 2;
}

.mla-title {
  text-align: center;
  font-size: 12pt;
  font-weight: 400;
  margin: 0 0 1em;
  line-height: 2;
}

.mla-body {
  text-indent: 0.5in;
}

.mla-body p {
  margin: 0 0 1em;
}

.mla-body p:last-child {
  margin-bottom: 0;
}

.mla-body h1, .mla-body h2, .mla-body h3 {
  font-size: 12pt;
  font-weight: 600;
  margin: 1em 0 0.5em;
  text-indent: 0;
}

.mla-body ul, .mla-body ol {
  margin: 0.5em 0 1em;
  padding-left: 1.5em;
}

.mla-body li {
  margin-bottom: 0.25em;
}

.mla-body blockquote {
  margin: 1em 0;
  padding-left: 0.5in;
  border-left: none;
}

/* Print styles */
@media print {
  body {
    background: #fff;
  }

  .app-header,
  .upload-section,
  .sources-section,
  .output-toolbar,
  .grader-panel,
  .plagiarism-panel,
  .app-footer {
    display: none !important;
  }

  .mla-paper-wrapper {
    box-shadow: none;
    padding: 0;
  }

  .mla-paper {
    padding: 1in;
    max-width: none;
  }

  .mla-header {
    position: fixed;
    top: 0.5in;
    right: 1in;
  }
}

.app-footer {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

.app-footer p {
  margin: 0;
}
