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

:root {
  --ink: #1a1a2e;
  --ink-light: #4a4a6a;
  --ink-faint: #8888aa;
  --cream: #faf9f6;
  --cream-dark: #f2f0eb;
  --gold: #c9a96e;
  --gold-light: #e8d5b0;
  --green: #2d7a5a;
  --shadow-soft: 0 4px 24px rgba(26,26,46,0.08);
  --shadow-lift: 0 12px 48px rgba(26,26,46,0.14);
  --surface: #ffffff;
  --surface-alt: var(--cream);
  --border: var(--cream-dark);
}

[data-theme="dark"] {
  --ink: #e8e4dc;
  --ink-light: #b0aaA0;
  --ink-faint: #6a6560;
  --cream: #1a1814;
  --cream-dark: #252219;
  --gold: #c9a96e;
  --gold-light: #4a3a20;
  --green: #4aad7a;
  --shadow-soft: 0 4px 24px rgba(0,0,0,0.3);
  --shadow-lift: 0 12px 48px rgba(0,0,0,0.5);
  --surface: #201e1a;
  --surface-alt: #1a1814;
  --border: #2e2b24;
}

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--cream);
  color: var(--ink);
  transition: background 0.3s, color 0.3s;
}

.screen {
  width: 100%;
  height: 100vh;
}

/* ───────────────────────────────────────
   Auth Screen
─────────────────────────────────────── */
#authScreen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cream);
  position: relative;
  overflow: hidden;
}

.auth-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 380px;
  text-align: center;
  padding: 0 24px;
}

.auth-logo {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 42px;
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin-bottom: 6px;
  line-height: 1;
}

.subtitle {
  font-family: 'Lora', Georgia, serif;
  font-style: italic;
  color: var(--ink-faint);
  font-size: 14px;
  margin-bottom: 32px;
  letter-spacing: 0.02em;
}

.auth-divider {
  width: 32px;
  height: 1px;
  background: var(--gold);
  margin: 0 auto 40px;
}

.form {
  text-align: left;
}

.form h2 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 16px;
  font-weight: 400;
  margin-bottom: 20px;
  color: var(--ink-faint);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-style: normal;
  text-align: center;
}

.form input {
  display: block;
  width: 100%;
  padding: 14px 0;
  margin-bottom: 0;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  font-size: 15px;
  font-family: 'Lora', Georgia, serif;
  font-weight: 400;
  color: var(--ink);
  background: transparent;
  transition: border-color 0.25s;
  letter-spacing: 0.01em;
}

.form input + input {
  margin-top: 4px;
}

.form input::placeholder {
  color: var(--ink-faint);
  font-style: italic;
}

.form input:focus {
  outline: none;
  border-bottom-color: var(--gold);
}

.form button {
  display: block;
  width: 100%;
  padding: 14px;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 0;
  font-size: 11px;
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
  margin-bottom: 20px;
  margin-top: 28px;
}

.form button:hover {
  background: var(--gold);
  border-color: var(--gold);
  color: white;
}

.toggle-text {
  font-size: 12px;
  color: var(--ink-faint);
  text-align: center;
  font-family: 'Lora', Georgia, serif;
  font-style: italic;
}

.toggle-text a {
  color: var(--ink-light);
  text-decoration: none;
  border-bottom: 1px solid var(--gold-light);
  transition: border-color 0.2s, color 0.2s;
}

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

.error {
  color: #c0392b;
  font-size: 12px;
  margin-top: 8px;
  display: none;
  font-family: 'Lora', serif;
  font-style: italic;
}

.error:not(:empty) {
  display: block;
}

/* ───────────────────────────────────────
   Writing Screen
─────────────────────────────────────── */
#writingScreen {
  flex-direction: column;
  background: var(--surface);
}

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

.header h1 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 26px;
  font-weight: 400;
  letter-spacing: 0.01em;
  color: var(--ink);
  margin: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 28px;
}

.word-count-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--ink-faint);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.4s;
  position: relative;
}

.word-count-dot.complete {
  background: var(--green);
}

.word-count-dot .tooltip {
  display: none;
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--ink);
  color: var(--cream);
  font-size: 12px;
  font-family: 'Lora', serif;
  font-style: italic;
  padding: 4px 10px;
  border-radius: 2px;
  white-space: nowrap;
  pointer-events: none;
}

.word-count-dot.show-count .tooltip {
  display: block;
}

.header-right button {
  padding: 7px 16px;
  background: transparent;
  border: 1px solid var(--cream-dark);
  border-radius: 0;
  font-size: 11px;
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.header-right button:hover {
  color: var(--ink);
  border-color: var(--ink-light);
}

/* Writing area */
.writing-container {
  flex: 1;
  display: flex;
  overflow: hidden;
  padding: 32px 24px;
  position: relative;
}

#writingArea {
  flex: 1;
  border: none;
  padding: 0;
  font-family: 'Lora', Georgia, serif;
  font-size: 17px;
  line-height: 1.85;
  color: var(--ink);
  resize: none;
  outline: none;
  background: transparent;
}

#writingArea::placeholder {
  color: #ccc9c0;
  font-style: italic;
}

/* Footer */
.footer {
  padding: 12px 24px;
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
  font-size: 11px;
  color: var(--ink-faint);
  display: flex;
  align-items: center;
  justify-content: space-between;
  letter-spacing: 0.05em;
}

#status {
  margin: 0;
  font-family: 'Lora', serif;
  font-style: italic;
}

.archive-toggle {
  background: none;
  border: none;
  color: var(--ink-faint);
  font-size: 11px;
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 0;
  transition: color 0.2s;
}

.archive-toggle:hover {
  color: var(--ink);
}

/* ───────────────────────────────────────
   Archive panel
─────────────────────────────────────── */
.archive-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 280px;
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10;
}

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

.archive-header h3 {
  font-family: 'Playfair Display', serif;
  font-size: 15px;
  font-weight: 400;
  margin: 0;
  color: var(--ink);
}

.archive-header button {
  background: none;
  border: none;
  font-size: 16px;
  color: var(--ink-faint);
  cursor: pointer;
  line-height: 1;
  padding: 0;
  transition: color 0.2s;
}

.archive-header button:hover {
  color: var(--ink);
}

.archive-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.archive-entry {
  padding: 12px 20px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.15s;
}

.archive-entry:hover {
  background: var(--surface-alt);
}

.archive-entry-date {
  font-family: 'Lora', serif;
  font-size: 13px;
  color: var(--ink);
  font-weight: 400;
}

.archive-entry-words {
  font-size: 11px;
  font-family: 'Inter', sans-serif;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
}

.archive-entry-words.complete {
  color: var(--green);
}

.archive-empty {
  padding: 24px 20px;
  color: var(--ink-faint);
  font-size: 13px;
  font-family: 'Lora', serif;
  font-style: italic;
  text-align: center;
}

/* Archive reader */
.archive-reader {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  padding: 16px 20px;
  overflow-y: auto;
}

.back-btn {
  background: none;
  border: none;
  color: var(--ink-faint);
  font-size: 12px;
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 0;
  margin-bottom: 16px;
  text-align: left;
  transition: color 0.2s;
}

.back-btn:hover {
  color: var(--ink);
}

.archive-reader-date {
  font-family: 'Playfair Display', serif;
  font-size: 14px;
  font-weight: 400;
  color: var(--ink-light);
  margin-bottom: 16px;
}

.archive-reader-content {
  font-family: 'Lora', Georgia, serif;
  font-size: 13px;
  line-height: 1.75;
  color: var(--ink-light);
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Theme toggle button */
#themeToggle {
  font-size: 16px;
  line-height: 1;
  padding: 4px 8px !important;
  border: none !important;
  background: transparent !important;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.2s;
}

#themeToggle:hover {
  opacity: 1;
  background: transparent !important;
}

/* ───────────────────────────────────────
   Responsive
─────────────────────────────────────── */
@media (max-width: 768px) {
  .header {
    padding: 16px 20px;
    flex-wrap: wrap;
    gap: 12px;
  }

  .header h1 {
    font-size: 22px;
    width: 100%;
  }

  .header-right {
    width: 100%;
    justify-content: space-between;
    gap: 12px;
  }

  .writing-container {
    padding: 20px 16px;
  }

  .footer {
    padding: 10px 16px;
  }

  .auth-container {
    padding: 36px 28px 32px;
    margin: 20px;
    border-radius: 0;
  }

  .auth-logo {
    font-size: 30px;
  }
}
