:root {
  color-scheme: light;
  --cream: #f5efe6;
  --ink: #1b1a18;
  --copper: #c36f4d;
  --sand: #f2dcc7;
  --shadow: 0 22px 40px rgba(15, 11, 8, 0.18);
  --soft-shadow: 0 12px 30px rgba(27, 26, 24, 0.1);
  --glow: linear-gradient(135deg, rgba(243, 197, 162, 0.9), rgba(250, 235, 220, 0.2));
  --font-display: "Fraunces", "Times New Roman", serif;
  --font-body: "Space Grotesk", "Trebuchet MS", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--ink);
  background: radial-gradient(circle at top left, #f8e3cf 0%, #f5efe6 40%, #f0e1d1 100%);
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 6vw;
  position: sticky;
  top: 0;
  backdrop-filter: blur(18px);
  background: rgba(245, 239, 230, 0.8);
  border-bottom: 1px solid rgba(27, 26, 24, 0.08);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--ink);
  overflow: hidden;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand-title {
  font-family: var(--font-display);
  font-size: 20px;
  margin: 0;
}

.brand-subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.24em;
}

.top-actions {
  display: flex;
  gap: 12px;
}

button {
  border: none;
  font-family: var(--font-body);
  cursor: pointer;
  border-radius: 999px;
  padding: 10px 22px;
  font-weight: 600;
  font-size: 14px;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

button.primary {
  background: var(--ink);
  color: var(--cream);
  box-shadow: var(--soft-shadow);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
  box-shadow: none;
}

button.primary:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

button.ghost {
  background: transparent;
  border: 1px solid rgba(27, 26, 24, 0.25);
  color: var(--ink);
}

.shell {
  flex: 1;
  padding: 30px 6vw 60px;
}

.panel {
  background: var(--glow);
  border-radius: 32px;
  padding: 40px;
  box-shadow: var(--shadow);
  animation: fadeUp 0.6s ease;
}

.hidden {
  display: none;
}

.panel-inner {
  display: grid;
  gap: 32px;
}

.hero h1 {
  font-family: var(--font-display);
  font-size: clamp(32px, 4vw, 48px);
  margin: 0 0 12px;
}

.hero p {
  margin: 0;
  font-size: 18px;
  max-width: 680px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
}

.card {
  padding: 24px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: var(--soft-shadow);
  border: 1px solid rgba(27, 26, 24, 0.06);
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 10px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow);
}

.card-title {
  font-weight: 600;
  font-size: 18px;
}

.card-body {
  font-size: 14px;
  color: rgba(27, 26, 24, 0.72);
}

.tips {
  font-size: 13px;
  color: rgba(27, 26, 24, 0.7);
}

.tips ul {
  margin: 8px 0 0 18px;
  padding: 0;
}

.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
  margin-bottom: 20px;
}

.mode-select {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mode-btn {
  border-radius: 999px;
  border: 1px solid rgba(27, 26, 24, 0.2);
  background: rgba(255, 255, 255, 0.75);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
}

.mode-btn.is-active {
  background: var(--ink);
  color: var(--cream);
  border-color: var(--ink);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.field label {
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.field input {
  border: 1px solid rgba(27, 26, 24, 0.2);
  border-radius: 12px;
  padding: 12px 14px;
  font-family: var(--font-body);
  font-size: 16px;
  background: rgba(255, 255, 255, 0.85);
}

.status {
  font-size: 14px;
  color: rgba(27, 26, 24, 0.6);
}

.editor-body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px;
}

.editor-pane,
.preview-pane {
  background: rgba(255, 255, 255, 0.9);
  border-radius: 22px;
  padding: 18px;
  box-shadow: var(--soft-shadow);
  border: 1px solid rgba(27, 26, 24, 0.06);
  display: flex;
  flex-direction: column;
  min-height: 380px;
}

.pane-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.24em;
  margin-bottom: 12px;
}

textarea {
  border: none;
  resize: vertical;
  min-height: 320px;
  font-family: "Courier New", Courier, monospace;
  font-size: 15px;
  line-height: 1.6;
  outline: none;
  background: transparent;
  color: var(--ink);
}

.rich-editor {
  border: none;
  min-height: 320px;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  outline: none;
  background: transparent;
}

.rich-editor:empty:before {
  content: attr(data-placeholder);
  color: rgba(27, 26, 24, 0.4);
}

.preview {
  font-size: 15px;
  line-height: 1.7;
  overflow-y: auto;
}

.preview h1,
.preview h2,
.preview h3 {
  font-family: var(--font-display);
}

.preview pre {
  padding: 14px;
  background: #1b1a18;
  color: #f5efe6;
  border-radius: 12px;
  overflow-x: auto;
}

.preview code {
  font-family: "Courier New", Courier, monospace;
  font-size: 0.92em;
}

.preview blockquote {
  border-left: 3px solid var(--copper);
  padding-left: 14px;
  margin-left: 0;
  color: rgba(27, 26, 24, 0.7);
}

.preview.latex-only {
  font-size: 18px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(27, 26, 24, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 30;
}

.modal.hidden {
  display: none;
}


.modal-card {
  background: rgba(255, 255, 255, 0.94);
  border-radius: 28px;
  padding: 28px;
  max-width: 620px;
  width: min(92vw, 620px);
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-card h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 26px;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 720px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 18px;
  }

  .editor-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* History Section */
.history-section {
  margin-top: 32px;
  border-top: 1px solid rgba(27, 26, 24, 0.1);
  padding-top: 24px;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.history-header h2 {
  font-family: var(--font-display);
  font-size: 20px;
  margin: 0;
}

.history-list {
  display: grid;
  gap: 12px;
}

.history-item {
  background: rgba(255, 255, 255, 0.6);
  padding: 16px;
  border-radius: 16px;
  border: 1px solid rgba(27, 26, 24, 0.05);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-item:hover {
  background: rgba(255, 255, 255, 0.95);
  transform: translateX(4px);
  box-shadow: var(--soft-shadow);
}

.history-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-name {
  font-weight: 600;
  font-size: 15px;
}

.history-meta {
  font-size: 12px;
  color: rgba(27, 26, 24, 0.6);
}

button.ghost.small {
  padding: 6px 14px;
  font-size: 12px;
}
