/* ===========================================================
   Pixel Pages — Cozy literary journal theme
   Deep-forest ground, cream ink, a single terracotta ember.
   Fraunces (serif) for what you read; Inter for the chrome.
   =========================================================== */

:root {
  --bg:        #1F2A24; /* deep forest at dusk */
  --surface:   #32443A; /* cards, entries */
  --field:     #2A3830; /* writing surface, a touch deeper */
  --primary:   #5B8C5A; /* active nav, quiet accents */
  --tan:       #C2A878; /* labels, meta, hairlines */
  --accent:    #D97757; /* the one ember: CTA, ribbons, focus */
  --text:      #F2EAD3; /* cream ink */
  --sage:      #A9D18E; /* positive feedback, hovers */

  --hair:      rgba(194, 168, 120, 0.22); /* tan hairline border */
  --hair-soft: rgba(194, 168, 120, 0.14);

  --serif: 'Fraunces', Georgia, 'Times New Roman', serif;
  --sans:  'Inter', system-ui, -apple-system, sans-serif;

  --r:    14px;
  --r-sm: 10px;
  --r-pill: 999px;

  --shadow:      0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-soft: 0 4px 16px rgba(0, 0, 0, 0.22);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  font-family: var(--sans);
  color: var(--text);
  background-color: var(--bg);
  /* warm ember glow spilling from the top, instead of scanlines */
  background-image:
    radial-gradient(900px 460px at 50% -8%, rgba(217, 119, 87, 0.14), transparent 62%),
    radial-gradient(700px 500px at 100% 0%, rgba(91, 140, 90, 0.10), transparent 60%);
  background-attachment: fixed;
  display: flex;
  justify-content: center;
  padding: 40px 20px 64px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Centered reading column — the page is the journal, cards float on it */
.console {
  width: 100%;
  max-width: 680px;
}

/* ---------- Top bar ---------- */
.topbar {
  text-align: center;
  border-bottom: 1px solid var(--hair);
  padding-bottom: 26px;
  margin-bottom: 32px;
}

.logo-mark {
  display: block;
  width: 88px;
  height: 88px;
  margin: 0 auto 6px;
  /* a faint ember halo ties the mark to the accent */
  filter: drop-shadow(0 4px 18px rgba(217, 119, 87, 0.28));
}

.logo {
  font-family: var(--serif);
  font-optical-sizing: auto;
  font-weight: 600;
  font-size: clamp(2rem, 6vw, 2.9rem);
  letter-spacing: -0.01em;
  margin: 0 0 6px;
  color: var(--text);
}

.tagline {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 1.05rem;
  color: var(--tan);
  margin: 0 0 22px;
}

.nav {
  display: flex;
  gap: 10px;
  justify-content: center;
}

/* ---------- Buttons ---------- */
.btn,
.nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--hair);
  border-radius: var(--r-sm);
  padding: 10px 18px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.18s ease, border-color 0.18s ease,
              color 0.18s ease, transform 0.12s ease, box-shadow 0.18s ease;
}

.nav-btn {
  border-radius: var(--r-pill);
  padding: 9px 20px;
}

.btn:hover,
.nav-btn:hover {
  border-color: var(--tan);
  background: rgba(194, 168, 120, 0.10);
}

.btn:active,
.nav-btn:active {
  transform: translateY(1px);
}

.nav-btn.active {
  background: var(--primary);
  border-color: transparent;
  color: var(--bg);
  font-weight: 600;
}

.nav-btn.active:hover {
  background: var(--primary);
}

/* the single strong call to action */
.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--bg);
  font-weight: 600;
}

.btn-primary:hover {
  background: #e2865c;
  border-color: transparent;
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(217, 119, 87, 0.28);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: none;
}

/* Refresh-the-prompt button — a quiet ember-tinted pill with a spin */
.prompt-refresh {
  gap: 8px;
  border-radius: var(--r-pill);
  color: var(--accent);
  border-color: rgba(217, 119, 87, 0.42);
}
.prompt-refresh:hover {
  color: var(--accent);
  background: rgba(217, 119, 87, 0.10);
  border-color: var(--accent);
}
.refresh-icon {
  width: 15px;
  height: 15px;
  flex: none;
}
.prompt-refresh.spin .refresh-icon {
  animation: spin-once 0.5s ease;
  transform-origin: 50% 50%;
}
@keyframes spin-once {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* keyboard focus — terracotta ring reads clearly on the dark ground */
.btn:focus-visible,
.nav-btn:focus-visible,
.answer-input:focus-visible,
.entry-delete:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Shared eyebrow labels ---------- */
.label {
  display: block;
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--tan);
  margin-bottom: 14px;
}

/* ---------- Views ---------- */
.view {
  animation: rise 0.28s ease both;
}

.hidden {
  display: none !important;
}

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

/* ---------- Prompt card — the chapter opener (signature) ---------- */
/* ---------- Streak card ---------- */
.streak-card {
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: var(--r);
  padding: 22px 24px 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-soft);
}

.streak-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.streak-head .label {
  margin-bottom: 0;
}

/* Two columns: stats on the left, month calendar on the right */
.streak-body {
  display: flex;
  gap: 26px;
  margin-top: 18px;
  align-items: flex-start;
}

.streak-stats {
  flex: 0 0 auto;
  min-width: 128px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: var(--tan);
}
.streak-current {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 8px;
  margin-bottom: 4px;
}
.streak-current .flame {
  font-size: 1.6rem;
  line-height: 1;
}
.streak-current b {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 2.6rem;
  line-height: 1;
  color: var(--accent);
}
.streak-current-label {
  flex-basis: 100%;
  color: var(--text);
  font-size: 0.95rem;
}
.streak-stat {
  font-size: 0.95rem;
}
.streak-stat b {
  color: var(--text);
  font-weight: 600;
}

/* Calendar */
.streak-cal {
  flex: 1 1 auto;
  min-width: 0;
}
.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.cal-month {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--text);
}
.cal-nav {
  background: transparent;
  border: 1px solid var(--hair);
  color: var(--tan);
  border-radius: var(--r-sm);
  width: 30px;
  height: 30px;
  font-size: 0.75rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.cal-nav:hover:not(:disabled) {
  color: var(--accent);
  border-color: var(--accent);
}
.cal-nav:disabled {
  opacity: 0.35;
  cursor: default;
}
.cal-nav:focus-visible,
#share-streak:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 6px;
}
.cal-weekdays span {
  text-align: center;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--tan);
  opacity: 0.75;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.cal-cell {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  border-radius: var(--r-sm);
  background: var(--field);
  color: rgba(242, 234, 211, 0.6);
  box-shadow: inset 0 0 0 1px var(--hair-soft);
}
.cal-cell.is-blank {
  background: transparent;
  box-shadow: none;
}
.cal-cell.is-future {
  opacity: 0.4;
}
.cal-cell.is-today {
  box-shadow: inset 0 0 0 2px var(--tan);
}
/* written days: clearly colored, then shaded up by how much you wrote */
.cal-cell[data-level="1"] { background: var(--primary); box-shadow: none; color: var(--bg); font-weight: 600; }
.cal-cell[data-level="2"] { background: var(--sage);    box-shadow: none; color: var(--bg); font-weight: 600; }
.cal-cell[data-level="3"] { background: var(--accent);  box-shadow: none; color: var(--bg); font-weight: 600; }
.cal-cell[data-level="2"].is-today,
.cal-cell[data-level="3"].is-today,
.cal-cell[data-level="1"].is-today { box-shadow: inset 0 0 0 2px var(--text); }

.streak-empty {
  margin: 14px 0 0;
  font-family: var(--serif);
  font-style: italic;
  color: var(--tan);
  font-size: 0.95rem;
}

/* Stack on narrow screens: stats above the calendar */
@media (max-width: 520px) {
  .streak-body {
    flex-direction: column;
    gap: 18px;
  }
  .streak-stats {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px 18px;
  }
  .streak-current-label { flex-basis: auto; }
}

/* ---------- Minimized streak badge (floats at the side) ---------- */
.streak-badge {
  position: fixed;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid rgba(217, 119, 87, 0.42);
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-soft);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.streak-badge:hover {
  border-color: var(--accent);
  transform: translateY(-50%) scale(1.06);
  box-shadow: var(--shadow);
}
.streak-badge:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.streak-badge .badge-flame {
  font-size: 1.3rem;
  line-height: 1;
}
.streak-badge .badge-n {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.35rem;
  line-height: 1;
  color: var(--accent);
}

/* On narrower screens there's no side margin — tuck it into the corner */
@media (max-width: 900px) {
  .streak-badge {
    top: auto;
    bottom: 18px;
    right: 16px;
    transform: none;
    flex-direction: row;
    gap: 6px;
    padding: 9px 14px;
  }
  .streak-badge:hover {
    transform: scale(1.06);
  }
}

.prompt-card {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: var(--r);
  padding: 26px 26px 24px;
  margin-bottom: 30px;
  box-shadow: var(--shadow-soft);
}

/* faint quotation-mark watermark */
.prompt-card::before {
  content: "\201C";
  position: absolute;
  top: -0.34em;
  right: 0.12em;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 9rem;
  line-height: 1;
  color: rgba(217, 119, 87, 0.14);
  pointer-events: none;
}

/* hairline rule under the eyebrow */
.prompt-card .label {
  position: relative;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--hair);
}

.prompt-card .label::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -1px;
  width: 42px;
  height: 2px;
  background: var(--accent);
}

.prompt-text {
  position: relative;
  font-family: var(--serif);
  font-optical-sizing: auto;
  font-weight: 500;
  font-size: clamp(1.6rem, 4.4vw, 2.35rem);
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--text);
  margin: 18px 0 22px;
  text-wrap: balance;
}

/* ---------- Answer block ---------- */
.answer-block {
  margin-bottom: 8px;
}

.answer-input {
  width: 100%;
  /* the writing space dominates the screen: about half the viewport,
     with a comfortable floor on short windows */
  min-height: clamp(320px, 52vh, 640px);
  resize: vertical;
  font-family: var(--serif);
  font-size: 1.1rem;
  line-height: 1.7;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--hair);
  border-radius: var(--r);
  padding: 18px 20px;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.answer-input::placeholder {
  color: rgba(242, 234, 211, 0.42);
  font-style: italic;
}

.answer-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(217, 119, 87, 0.22);
}

.answer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  gap: 12px;
}

.word-count {
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--tan);
  font-variant-numeric: tabular-nums;
}

.save-msg {
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--sage);
  min-height: 1.2em;
  margin: 14px 0 0;
}

/* ---------- Notebook ---------- */
.notebook-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}

.notebook-head .label {
  margin-bottom: 0;
}

.entries {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.entry {
  background: var(--surface);
  border: 1px solid var(--hair);
  border-left: 3px solid var(--accent); /* bookmark ribbon */
  border-radius: var(--r);
  padding: 20px 22px;
  box-shadow: var(--shadow-soft);
}

.entry-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--tan);
  margin-bottom: 12px;
}

.entry-prompt {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.3rem;
  line-height: 1.3;
  color: var(--text);
  margin: 0 0 10px;
}

.entry-answer {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.08rem;
  line-height: 1.65;
  color: rgba(242, 234, 211, 0.92);
  white-space: pre-wrap;
  word-wrap: break-word;
  margin: 0 0 16px;
}

.entry-delete {
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--tan);
  background: transparent;
  border: 1px solid var(--hair);
  border-radius: var(--r-sm);
  padding: 7px 14px;
  cursor: pointer;
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.entry-delete:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(217, 119, 87, 0.08);
}

.empty-note {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.15rem;
  color: var(--tan);
  text-align: center;
  padding: 48px 16px;
  border: 1px dashed var(--hair);
  border-radius: var(--r);
}

/* ---------- Footer ---------- */
.footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: space-between;
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--tan);
  border-top: 1px solid var(--hair);
  margin-top: 36px;
  padding-top: 18px;
}

.footer span:last-child {
  font-style: italic;
  opacity: 0.85;
}

/* ---------- Small screens ---------- */
@media (max-width: 480px) {
  body { padding: 24px 14px 48px; }
  .logo-mark { width: 68px; height: 68px; }
  .prompt-card { padding: 22px 20px; }
  .prompt-card::before { font-size: 7rem; }
  .answer-footer { flex-direction: column; align-items: stretch; }
  .answer-footer .btn-primary { width: 100%; }
  .nav-btn { padding: 9px 16px; }

  /* Comfortable thumb targets on touch screens */
  .btn, .nav-btn { min-height: 44px; }

  /* Auth actions stack full-width so the primary action is easy to hit */
  .auth-actions { flex-direction: column; }
  .auth-actions .btn { width: 100%; }

  .auth-panel { padding: 22px 18px; }
  .auth-user-email { max-width: 58vw; }

  .entry { padding: 18px 18px; }
  .entry-delete { min-height: 40px; }
}

/* ---------- Respect reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------- Auth ---------- */
.auth-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px 12px;
  margin-bottom: 18px;
}

.auth-user {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 100%;
}

.auth-user-email {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--tan);
  max-width: 60vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-panel {
  max-width: 420px;
  margin: 0 auto 30px;
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: var(--r);
  padding: 26px;
  box-shadow: var(--shadow-soft);
  animation: rise 0.28s ease both;
}

.auth-form .label { margin-top: 14px; }
.auth-form .label:first-child { margin-top: 0; }

.auth-input {
  width: 100%;
  font-family: var(--sans);
  font-size: 1rem;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--hair);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.auth-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(217, 119, 87, 0.22);
}

.auth-error {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--accent);
  min-height: 1.2em;
  margin: 12px 0 0;
}

.auth-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.auth-switch {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--tan);
  margin: 16px 0 0;
  text-align: center;
}

.auth-link {
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 4px;
}

.auth-link:hover { text-decoration: underline; }

/* Screen title sits centered over the card, echoing the switch line below */
.auth-heading {
  text-align: center;
  margin-bottom: 22px;
}

/* Supporting line under a screen title (e.g. the reset instructions) */
.auth-intro {
  font-family: var(--sans);
  font-size: 0.9rem;
  color: var(--tan);
  text-align: center;
  margin: -8px 0 20px;
}

/* Positive confirmation, in the sage used elsewhere for success */
.auth-note {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--sage);
  min-height: 1.2em;
  margin: 8px 0 0;
}
.auth-note:empty { display: none; }

/* Field that failed validation — a warmer ember to draw the eye */
.auth-input.invalid {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(217, 119, 87, 0.22);
}

/* ---------- Button loading + disabled feedback ---------- */
.btn:disabled,
.btn-primary:disabled {
  opacity: 0.6;
  cursor: default;
  transform: none;
  box-shadow: none;
}
.btn:disabled:hover {
  background: transparent;
  border-color: var(--hair);
}
.btn-primary:disabled:hover {
  background: var(--accent);
  transform: none;
  box-shadow: none;
}

.spinner {
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  margin-right: 0.5em;
  vertical-align: -0.14em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 1.5s; }
}

/* ---------- "All prompts answered" state ---------- */
.all-done {
  position: relative;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(1.4rem, 3.6vw, 1.9rem);
  line-height: 1.3;
  color: var(--sage);
  margin: 18px 0 22px;
  text-wrap: balance;
}

/* ---------- Saved confirmation modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 20, 17, 0.66);
  backdrop-filter: blur(2px);
  animation: modal-fade 0.2s ease both;
}

@keyframes modal-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-card {
  width: 100%;
  max-width: 380px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: var(--r);
  padding: 30px 28px 26px;
  box-shadow: var(--shadow);
  animation: modal-pop 0.24s cubic-bezier(0.2, 0.8, 0.3, 1.2) both;
}

@keyframes modal-pop {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--bg);
  background: var(--sage);
  border-radius: var(--r-pill);
  box-shadow: 0 6px 18px rgba(169, 209, 142, 0.3);
}

.modal-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.5rem;
  line-height: 1.25;
  color: var(--text);
  margin: 0 0 8px;
}

.modal-text {
  font-family: var(--sans);
  font-size: 0.92rem;
  color: var(--tan);
  margin: 0 0 22px;
}

.modal-card .btn-primary {
  min-width: 120px;
}

@media (prefers-reduced-motion: reduce) {
  .modal-overlay,
  .modal-card { animation: none; }
}
