/* =========================================================
   Writetyper — The Typewriter
   Built entirely from gradients, shadows and shapes so it
   stays razor-sharp at any size and loads with zero images.
   Stacking (back -> front): paper -> platen -> bail -> body.
   ========================================================= */

.stage {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  perspective: 1400px;
}

.typewriter {
  --tw-w: min(760px, 92vw);
  --paper-overlap: 40px;
  position: relative;
  width: var(--tw-w);
  display: flex;
  flex-direction: column;
  align-items: center;
  filter: drop-shadow(0 38px 30px rgba(20, 14, 8, 0.28));
}

/* ---------------- Paper ---------------- */
.paper-zone {
  position: relative;
  z-index: 1;
  width: 62%;
  display: flex;
  justify-content: center;
}

.paper {
  position: relative;
  width: 100%;
  min-height: 360px;
  padding-bottom: var(--paper-overlap);
  background:
    linear-gradient(180deg, var(--paper) 0%, #fbf8f0 100%);
  border-radius: 4px 4px 2px 2px;
  box-shadow: var(--shadow-paper);
  transform-origin: bottom center;
}

/* faint fibre + warmth on the sheet */
.paper::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    radial-gradient(circle at 30% 0%, rgba(255, 255, 255, 0.7), transparent 60%),
    radial-gradient(circle at 100% 100%, rgba(139, 111, 71, 0.06), transparent 55%);
  pointer-events: none;
}

/* torn-ish top edge highlight */
.paper-edge {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 10px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), transparent);
  border-radius: 4px 4px 0 0;
}

.paper-body {
  position: relative;
  padding: clamp(1.4rem, 1rem + 1.6vw, 2.4rem) clamp(1.3rem, 1rem + 1.4vw, 2.2rem) 0;
  min-height: 300px;
}

.prompt-meta {
  font-family: var(--font-type);
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--brown-soft);
  margin-bottom: 1.1rem;
  min-height: 0.9rem;
  opacity: 0;
  transition: opacity var(--t-med) var(--ease-soft);
}

.prompt-meta.show {
  opacity: 0.9;
}

.prompt-text {
  font-family: var(--font-type);
  font-size: var(--fs-prompt);
  line-height: 1.95;
  color: var(--ink);
  letter-spacing: 0.01em;
  word-break: break-word;
  min-height: 6rem;
}

.prompt-text .placeholder {
  color: var(--ink-faint);
  font-family: var(--font-serif);
  font-size: 1.05rem;
  line-height: 1.7;
}

.prompt-text .placeholder-key {
  color: var(--brown-deep);
  font-weight: 600;
}

/* very light inked imperfection on typed glyphs */
.prompt-text .typed {
  text-shadow: 0 0 0.4px rgba(43, 40, 38, 0.4);
}

/* blinking cursor */
.cursor {
  display: inline-block;
  width: 0.62ch;
  height: 1.05em;
  margin-left: 1px;
  transform: translateY(0.18em);
  background: var(--ink);
  opacity: 0.85;
}

.cursor.blink {
  animation: cursor-blink 1.06s steps(1) infinite;
}

.typewriter.is-typing .cursor {
  animation: none;
  opacity: 0.9;
}

/* ---------------- Platen (roller) ---------------- */
.machine {
  position: relative;
  z-index: 2;
  width: 100%;
  margin-top: calc(var(--paper-overlap) * -1);
}

.platen {
  position: relative;
  z-index: 3;
  width: 100%;
  height: 46px;
  border-radius: 26px;
  background:
    linear-gradient(180deg, #4b443c 0%, #322c26 18%, var(--rubber) 52%, #15110e 100%);
  box-shadow:
    inset 0 2px 3px rgba(255, 255, 255, 0.18),
    inset 0 -6px 10px rgba(0, 0, 0, 0.55),
    0 6px 12px -6px rgba(0, 0, 0, 0.5);
}

/* subtle rolling sheen */
.platen::before {
  content: "";
  position: absolute;
  inset: 6px 70px;
  border-radius: 20px;
  background: repeating-linear-gradient(90deg,
      rgba(255, 255, 255, 0.05) 0 2px,
      transparent 2px 26px);
  opacity: 0.5;
}

.knob {
  position: absolute;
  top: 50%;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  transform: translateY(-50%);
  background:
    radial-gradient(circle at 38% 32%, #5b5249, #2a241f 62%, #120f0c 100%);
  box-shadow:
    inset 0 2px 3px rgba(255, 255, 255, 0.25),
    inset 0 -4px 8px rgba(0, 0, 0, 0.6),
    0 4px 10px -3px rgba(0, 0, 0, 0.55);
}

.knob::after {
  content: "";
  position: absolute;
  inset: 14px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 40% 35%, #6c6258, #2a241f 70%);
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.3);
}

.knob-left {
  left: -34px;
}

.knob-right {
  right: -34px;
}

/* ---------------- Paper bail ---------------- */
.paper-bail {
  position: absolute;
  z-index: 4;
  top: -14px;
  left: 8%;
  right: 8%;
  height: 6px;
  border-radius: 6px;
  background: linear-gradient(180deg, #6e6358, #2c2722);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
  display: flex;
  justify-content: space-between;
  padding: 0 12%;
}

.bail-roller {
  width: 26px;
  height: 14px;
  margin-top: -4px;
  border-radius: 8px;
  background: radial-gradient(circle at 40% 30%, #4a423a, #1a1612);
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.2);
}

/* ---------------- Body / chassis ---------------- */
.body {
  position: relative;
  z-index: 2;
  margin-top: -14px;
  padding: 34px clamp(1rem, 4%, 2.4rem) 0;
  border-radius: 16px 16px 26px 26px / 14px 14px 60px 60px;
  background:
    linear-gradient(180deg, var(--machine-hi) 0%, var(--machine) 30%, var(--machine-lo) 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.08),
    inset 0 -10px 24px rgba(0, 0, 0, 0.55),
    var(--shadow-machine);
  /* slight outward slope: wider at the keyboard */
  clip-path: polygon(4% 0, 96% 0, 100% 78%, 100% 100%, 0 100%, 0 78%);
}

/* warm metallic top sheen */
.body::before {
  content: "";
  position: absolute;
  top: 0;
  left: 12%;
  right: 12%;
  height: 38%;
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 0%, rgba(201, 162, 39, 0.14), transparent 70%);
  pointer-events: none;
}

/* ---- Ribbon deck (type basket) ---- */
.ribbon-deck {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16%;
  height: 40px;
  margin: -14px auto 14px;
  width: 70%;
}

.ribbon-spool {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 42% 38%, #3c3630, #1a1612 70%),
    var(--machine-lo);
  box-shadow:
    inset 0 0 0 4px rgba(0, 0, 0, 0.5),
    inset 0 2px 3px rgba(255, 255, 255, 0.12),
    0 3px 6px -2px rgba(0, 0, 0, 0.6);
  position: relative;
}

.ribbon-spool::after {
  content: "";
  position: absolute;
  inset: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #6b3f2e, #3a1f16);
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.18);
}

/* the type guide where the keys strike the page */
.type-guide {
  width: 56px;
  height: 30px;
  border-radius: 6px 6px 10px 10px;
  background: linear-gradient(180deg, #d9b24e, #9c7c2c);
  box-shadow:
    inset 0 1px 2px rgba(255, 255, 255, 0.5),
    inset 0 -3px 5px rgba(0, 0, 0, 0.4),
    0 2px 5px -1px rgba(0, 0, 0, 0.5);
  position: relative;
}

.type-guide::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 6px;
  width: 3px;
  height: 16px;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.45);
  border-radius: 2px;
}

/* ---- Keyboard ---- */
.keyboard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  padding: 6px 0 14px;
}

.key-row {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.key {
  width: clamp(26px, 4.4vw, 38px);
  height: clamp(26px, 4.4vw, 38px);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--font-type);
  font-size: clamp(0.6rem, 1.4vw, 0.78rem);
  color: #2c2722;
  background:
    radial-gradient(circle at 42% 32%, #fbf6ea 0%, var(--key-face) 55%, #d9cfb8 100%);
  box-shadow:
    0 0 0 2px var(--key-ring),
    0 0 0 3.5px rgba(120, 96, 64, 0.3),
    0 4px 5px -1px rgba(0, 0, 0, 0.55),
    inset 0 -2px 3px rgba(0, 0, 0, 0.18),
    inset 0 2px 2px rgba(255, 255, 255, 0.8);
  transition: transform 90ms var(--ease-soft), box-shadow 90ms var(--ease-soft);
  user-select: none;
}

.key.wide {
  width: 56%;
  border-radius: 16px;
}

.key.pressed {
  transform: translateY(3px) scale(0.97);
  box-shadow:
    0 0 0 2px var(--key-ring),
    0 0 0 3.5px rgba(120, 96, 64, 0.3),
    0 1px 2px rgba(0, 0, 0, 0.5),
    inset 0 -1px 2px rgba(0, 0, 0, 0.25);
}

/* spacebar row */
.space-row {
  margin-top: 2px;
}

.nameplate {
  margin: 2px auto 16px;
  font-family: var(--font-type);
  font-size: 0.82rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  text-align: center;
  color: var(--gold-soft);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.6);
  opacity: 0.92;
}

/* little front feet */
.body-foot {
  position: absolute;
  bottom: -8px;
  width: 70px;
  height: 16px;
  border-radius: 0 0 10px 10px;
  background: linear-gradient(180deg, #211d19, #0d0a08);
  box-shadow: 0 8px 14px -6px rgba(0, 0, 0, 0.6);
}

.foot-left {
  left: 12%;
}

.foot-right {
  right: 12%;
}

/* ---- Ink splatter (added on finish) ---- */
.ink-splatter {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.ink-dot {
  position: absolute;
  width: var(--d, 4px);
  height: var(--d, 4px);
  border-radius: 50%;
  background: var(--ink);
  opacity: 0;
  transform: scale(0);
  animation: ink-pop 620ms var(--ease-spring) forwards;
}
