:root {
  --bg-1: #14111f;
  --bg-2: #1d1730;
  --bg-3: #231b38;
  --ink: #efe6d8;          /* cream */
  --ink-soft: #d9cdea;     /* lavender-cream */
  --lavender: #b9a7e0;
  --blue: #9fb7e8;
  --glow: 142, 124, 195;   /* #8e7cc3 */
  --muted: rgba(205, 190, 235, 0.38);

  --font-write: "Cormorant Garamond", Georgia, serif;
  --font-ui: "Inter", system-ui, sans-serif;
  --write-size: 1.85rem;
  --write-lh: 1.7;
  --lines: 4;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background:
    radial-gradient(120% 90% at 50% 110%, #2a2045 0%, transparent 60%),
    linear-gradient(160deg, var(--bg-1) 0%, var(--bg-2) 55%, var(--bg-3) 100%);
  background-color: var(--bg-1);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

#motes {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Breathing glow: 4s in, 6s out */
.glow {
  position: fixed;
  left: 50%;
  top: 50%;
  width: min(1100px, 140vw);
  height: min(800px, 110vh);
  translate: -50% -50%;
  background: radial-gradient(closest-side, rgba(var(--glow), 0.22), rgba(var(--glow), 0.07) 55%, transparent 100%);
  filter: blur(20px);
  pointer-events: none;
  animation: breathe 10s infinite;
}

@keyframes breathe {
  0%   { opacity: 0.45; scale: 0.92; animation-timing-function: cubic-bezier(.45, 0, .55, 1); }
  40%  { opacity: 0.9;  scale: 1.04; animation-timing-function: cubic-bezier(.45, 0, .55, 1); }
  100% { opacity: 0.45; scale: 0.92; }
}

.stage {
  position: relative;
  height: 100%;
  display: grid;
  place-items: center;
  padding: 16px;
}

.box {
  position: relative;
  width: min(640px, 100%);
  height: calc(var(--write-size) * var(--write-lh) * var(--lines) + 2 * 28px);
  padding: 28px 34px;
  border-radius: 18px;
  background: rgba(40, 32, 64, 0.35);
  border: 1px solid rgba(200, 180, 255, 0.08);
  box-shadow:
    inset 0 0 40px rgba(var(--glow), 0.06),
    0 30px 80px -30px rgba(5, 3, 15, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  overflow: hidden;
  cursor: text;
  transition: border-color 1.2s ease, box-shadow 1.2s ease;
}

.box.focused {
  border-color: rgba(200, 180, 255, 0.14);
  box-shadow:
    inset 0 0 50px rgba(var(--glow), 0.09),
    0 30px 80px -30px rgba(5, 3, 15, 0.7);
}

.page,
.placeholder,
.ghost {
  font-family: var(--font-write);
  font-size: var(--write-size);
  line-height: var(--write-lh);
  font-weight: 400;
}

.page {
  position: relative;
  color: var(--ink);
  text-shadow: 0 0 18px rgba(var(--glow), 0.25);
  overflow-wrap: anywhere;
  will-change: transform;
}

.word .ink {
  transition: color 0.6s ease;
}
.word .ink .off { visibility: hidden; }

/* Soft breathing caret instead of a hard blink */
.caret {
  display: inline-block;
  width: 1.5px;
  height: 1.05em;
  margin-left: 1px;
  vertical-align: -0.16em;
  background: var(--ink);
  border-radius: 1px;
  box-shadow: 0 0 8px rgba(239, 230, 216, 0.5);
  opacity: 0;
}
.box.focused .caret {
  animation: caret 1.4s ease-in-out infinite;
}
@keyframes caret {
  0%, 100% { opacity: 0.9; }
  50%      { opacity: 0.1; }
}
.box.typing .caret { animation: none; opacity: 0.9; }

.placeholder {
  position: absolute;
  left: 34px;
  top: 28px;
  font-style: italic;
  color: var(--lavender);
  opacity: 0.45;
  pointer-events: none;
  transition: opacity 2.4s ease;
}
.placeholder.hidden {
  opacity: 0;
  transition: opacity 0.5s ease;
}

/* Real input: invisible, covers the box so taps focus it (mobile keyboards). */
.input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  resize: none;
  border: 0;
  padding: 0;
  font-size: 16px;
  color: transparent;
  background: transparent;
  caret-color: transparent;
  cursor: text;
}

.ghosts {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.ghost {
  position: absolute;
  white-space: pre;
  line-height: normal;
  color: var(--ink);
}
.ghost span {
  display: inline-block;
  will-change: transform, opacity, filter;
}

.hint {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 28px;
  margin: 0;
  text-align: center;
  font-size: 12px;
  font-weight: 300;
  letter-spacing: 0.14em;
  color: var(--muted);
  pointer-events: none;
}

/* Tuning panel */
.tune {
  position: fixed;
  top: 16px;
  right: 16px;
  width: min(300px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(22, 18, 36, 0.88);
  border: 1px solid rgba(200, 180, 255, 0.12);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 11px;
  color: var(--ink-soft);
  z-index: 10;
}
.tune header,
.tune footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.tune header { margin-bottom: 10px; }
.tune footer { margin-top: 10px; text-transform: none; letter-spacing: 0.04em; }
.tune-actions { display: flex; gap: 6px; }
.tune button {
  font: inherit;
  text-transform: none;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
  background: rgba(var(--glow), 0.15);
  border: 1px solid rgba(var(--glow), 0.3);
  border-radius: 6px;
  padding: 3px 8px;
  cursor: pointer;
}
.tune button:hover { background: rgba(var(--glow), 0.28); }
.tune-row { margin: 8px 0; }
.tune-row label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 2px;
}
.tune-row output { color: var(--ink); font-variant-numeric: tabular-nums; }
.tune-row input { width: 100%; accent-color: var(--lavender); }

@media (max-width: 560px) {
  :root { --write-size: 1.45rem; }
  .box { padding: 22px 22px; height: calc(var(--write-size) * var(--write-lh) * var(--lines) + 2 * 22px); }
  .placeholder { left: 22px; top: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  .glow { animation: none; opacity: 0.6; }
  #motes { display: none; }
}
