:root {
  --ground:  #171320;
  --raised:  #241C2E;
  --raised-2:#2C2237;
  --bone:    #E8DFD3;
  --muted:   #8A7F94;
  --sodium:  #E2B23C;
  --predawn: #6E7FA8;

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Instrument Sans", -apple-system, BlinkMacSystemFont, sans-serif;

  --space-1: 0.5rem;
  --space-2: 0.875rem;
  --space-3: 1.5rem;
  --space-4: 2.5rem;
  --space-5: 4rem;

  --radius: 18px;
  --radius-sm: 10px;

  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--ground);
  color: var(--bone);
}

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea {
  font-family: inherit;
  color: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 2px solid var(--sodium);
  outline-offset: 3px;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* header */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-3);
  flex-shrink: 0;
}

.wordmark-btn {
  background: none;
  border: none;
  padding: var(--space-1) 0;
  cursor: pointer;
}

.wordmark {
  font-family: var(--font-display);
  font-variation-settings: "WONK" 1, "opsz" 30;
  font-style: italic;
  font-weight: 500;
  font-size: 1.3rem;
  letter-spacing: 0.01em;
  color: var(--bone);
}

.icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  padding: var(--space-1);
  border-radius: 999px;
  display: inline-flex;
  cursor: pointer;
  transition: color 0.2s ease, background 0.2s ease;
}

.icon-btn:hover { color: var(--bone); background: rgba(232, 223, 211, 0.06); }

/* screens */

#screens {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  padding: var(--space-3);
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  animation: screen-in 0.5s ease both;
}

.screen.active { display: flex; }

@keyframes screen-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .screen { animation: none; }
}

/* entry screen */

.entry-form {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding-top: var(--space-4);
}

.entry-label {
  font-family: var(--font-display);
  font-variation-settings: "WONK" 1, "opsz" 40;
  font-weight: 480;
  font-size: 1.6rem;
  color: var(--bone);
}

.entry-textarea {
  flex: 1;
  min-height: 30vh;
  resize: none;
  background: transparent;
  border: none;
  color: var(--bone);
  font-family: var(--font-display);
  font-variation-settings: "WONK" 0, "opsz" 20;
  font-size: 1.5rem;
  line-height: 1.5;
  caret-color: var(--sodium);
}

.entry-textarea::placeholder {
  color: var(--muted);
  opacity: 0.65;
}

.entry-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  padding-bottom: var(--space-3);
}

.char-counter {
  font-size: 0.85rem;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.2s ease, color 0.2s ease;
}

.char-counter.visible { opacity: 1; }
.char-counter.warning { color: var(--sodium); }

/* buttons */

.btn {
  border: none;
  border-radius: 999px;
  padding: 0.85em 1.6em;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.2s ease, background 0.2s ease;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--sodium);
  color: #241a08;
}

.btn-primary:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-ghost {
  background: var(--raised);
  color: var(--bone);
}

.btn-ghost:hover { background: var(--raised-2); }

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  font-size: 0.9rem;
  padding: var(--space-2) 0;
  align-self: center;
}

.link-btn:hover { color: var(--bone); }

/* questions screen */

#screen-questions {
  position: relative;
  justify-content: flex-end;
  min-height: 100%;
}

.close-btn {
  position: absolute;
  top: var(--space-1);
  right: var(--space-1);
  z-index: 20;
}

.memory-stack {
  position: relative;
  flex: 1;
  width: 100%;
  min-height: 200px;
  overflow: hidden;
  mask-image: linear-gradient(to bottom, black 65%, transparent 100%);
}

.memory-stack--final {
  flex: 1;
  min-height: 45vh;
}

.stack-item {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--space-3);
  font-family: var(--font-display);
  font-variation-settings: "WONK" 1, "opsz" 24;
  font-size: 1.3rem;
  line-height: 1.5;
  color: var(--bone);
  transition: transform 1.1s cubic-bezier(0.22, 1, 0.36, 1), filter 1.1s ease, opacity 1.1s ease;
  transform: translateY(calc(var(--depth, 0) * -20px));
  filter: blur(calc(var(--depth, 0) * 3.2px));
  opacity: calc(1 - var(--depth, 0) * 0.14);
  z-index: calc(100 - var(--depth, 0));
}

.stack-item .stack-item-label {
  display: block;
  font-family: var(--font-body);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--predawn);
  margin-bottom: 0.3em;
}

@media (prefers-reduced-motion: reduce) {
  .stack-item {
    transition: filter 0.4s ease, opacity 0.4s ease;
    transform: none;
  }
}

.question-card {
  background: var(--raised);
  border-radius: var(--radius);
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  position: relative;
  z-index: 50;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}

.progress-dots {
  display: flex;
  gap: 6px;
}

.progress-dots .dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--muted);
  opacity: 0.4;
}

.progress-dots .dot.done { background: var(--sodium); opacity: 1; }
.progress-dots .dot.current { background: var(--bone); opacity: 1; }

.question-text {
  font-family: var(--font-display);
  font-variation-settings: "WONK" 1, "opsz" 30;
  font-size: 1.4rem;
  font-weight: 500;
  margin: 0;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.suggestion-chip {
  background: var(--raised-2);
  border: 1px solid rgba(232, 223, 211, 0.1);
  color: var(--bone);
  border-radius: 999px;
  padding: 0.6em 1.1em;
  font-size: 0.92rem;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.suggestion-chip:hover { background: #382b47; }
.suggestion-chip:active { transform: scale(0.96); }

.free-text-form {
  display: flex;
  gap: var(--space-1);
}

.free-text-input {
  flex: 1;
  background: var(--ground);
  border: 1px solid rgba(232, 223, 211, 0.1);
  border-radius: var(--radius-sm);
  padding: 0.7em 1em;
  color: var(--bone);
  font-size: 0.95rem;
}

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

.skip-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  align-self: center;
  padding: 0.3em;
}

.skip-btn:hover { color: var(--bone); }

/* generating screen */

#screen-generating {
  justify-content: flex-end;
  align-items: center;
  text-align: center;
  min-height: 100%;
}

.generating-status {
  font-family: var(--font-display);
  font-style: italic;
  font-variation-settings: "WONK" 1;
  color: var(--muted);
  font-size: 1.1rem;
  padding: var(--space-4) 0 var(--space-3);
  animation: breathe 3.2s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .generating-status { animation: none; opacity: 0.85; }
}

/* result screen */

.result-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding-top: var(--space-2);
}

.result-image-wrap {
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--raised);
  aspect-ratio: 1 / 1;
}

.result-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.declined-message {
  background: var(--raised);
  border-radius: var(--radius);
  padding: var(--space-3);
  font-family: var(--font-display);
  font-variation-settings: "WONK" 1, "opsz" 24;
  font-size: 1.2rem;
  color: var(--bone);
}

.result-title {
  font-family: var(--font-display);
  font-variation-settings: "WONK" 1, "opsz" 40;
  font-weight: 500;
  font-size: 1.7rem;
  margin: 0.2em 0 0;
}

.result-dream-text {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.6;
  margin: 0;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  padding-top: var(--space-1);
}

/* journal screen */

.journal-heading {
  font-family: var(--font-display);
  font-variation-settings: "WONK" 1, "opsz" 60;
  font-weight: 500;
  font-size: 2rem;
  margin: var(--space-2) 0 var(--space-3);
}

.journal-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  font-family: var(--font-display);
  font-variation-settings: "WONK" 1;
  font-style: italic;
  font-size: 1.2rem;
  padding-bottom: var(--space-5);
}

.journal-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-2);
  padding-bottom: var(--space-4);
}

.journal-entry {
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--raised);
  cursor: pointer;
  position: relative;
  aspect-ratio: 1 / 1;
  border: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  text-align: left;
}

.journal-entry img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.journal-entry.text-only {
  padding: var(--space-2);
  justify-content: center;
}

.journal-entry.text-only .journal-entry-title {
  font-family: var(--font-display);
  font-variation-settings: "WONK" 1, "opsz" 24;
  font-size: 1.05rem;
}

.journal-entry-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: var(--space-1) var(--space-2);
  background: linear-gradient(to top, rgba(23,19,32,0.92), transparent);
  font-family: var(--font-display);
  font-variation-settings: "WONK" 1;
  font-size: 0.92rem;
}

.journal-entry-date {
  display: block;
  font-family: var(--font-body);
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 0.15em;
}

/* toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: var(--space-3);
  transform: translateX(-50%) translateY(120%);
  background: var(--raised-2);
  color: var(--bone);
  padding: 0.8em 1.4em;
  border-radius: 999px;
  font-size: 0.9rem;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  transition: transform 0.3s ease, opacity 0.3s ease, visibility 0.3s;
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
}

.toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  visibility: visible;
}

/* responsive */

@media (min-width: 640px) {
  .journal-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 400px) {
  .entry-label { font-size: 1.4rem; }
  .entry-textarea { font-size: 1.3rem; }
}
