/* The typewriter: a dark room, one light falling from above, a carriage on a rod, and the page of typing that scrolls
   up past it. The page stays black; the typing is in light colours (the carriage's own, or the one chosen). */

#entry.tw {
  --tw-ink: #f6e7bd;
  --tw-bar: #bfc3c9;
  --tw-fs: 19px;
  --tw-lh: 30px;
  --tw-cs: 1;
  position: fixed;
  left: 0;
  top: var(--tw-top, 0px);
  width: 100%;
  height: var(--tw-height, 100dvh);
  z-index: 30;
  overflow: hidden;
  background: var(--void);
  color: var(--tw-ink);
  animation: tw-in 420ms ease both;
  transition: opacity 280ms ease;
}
#entry.tw[hidden] { display: none; }
#entry.tw.is-leaving { opacity: 0; pointer-events: none; }
@keyframes tw-in { from { opacity: 0; } to { opacity: 1; } }

/* The sheet: lines that have gone up fade into the dark at the top. */
.tw-sheet {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 1;
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 90px);
  mask-image: linear-gradient(180deg, transparent 0, #000 90px);
}
.tw-paper {
  position: absolute;
  top: 0;
  height: 0;
  transition: transform 160ms cubic-bezier(.3, .8, .3, 1);
  will-change: transform;
}
.tw-glyph {
  position: absolute;
  height: var(--tw-lh);
  white-space: pre;
  text-align: center;
  color: var(--tw-ink);
  transform-origin: 50% 70%;
  text-shadow: 0 0 1.1px currentColor, 0 0 7px rgba(var(--gold-hi-rgb), 0.28);
  text-shadow: 0 0 1.1px currentColor, 0 0 7px color-mix(in srgb, var(--tw-ink) 28%, transparent);
}
.tw-glyph.latin { font: var(--tw-fs)/var(--tw-lh) var(--font-type); }
/* A Chinese character is set in the hand face and rubbed in, as a stone rubbing is. */
.tw-glyph.cjk {
  font-family: var(--font-hand);
  line-height: var(--tw-lh);
  text-shadow: 0 0 1.6px currentColor, 0 0 2.6px currentColor, 0 0 9px rgba(var(--gold-hi-rgb), 0.34);
  text-shadow: 0 0 1.6px currentColor, 0 0 2.6px currentColor, 0 0 9px color-mix(in srgb, var(--tw-ink) 34%, transparent);
}
.tw-glyph.struck { animation: tw-stamp 150ms ease-out; }
@keyframes tw-stamp {
  0% { opacity: 0.15; filter: blur(1.4px); transform: var(--t) scale(1.3); }
  100% { opacity: var(--o); filter: none; transform: var(--t); }
}
.tw-ghost {
  position: absolute;
  left: 0;
  top: 0;
  height: var(--tw-lh);
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  font: var(--tw-fs)/var(--tw-lh) var(--font-type);
  color: var(--tw-ink);
  opacity: 0.32;
}
.tw-ghost[hidden] { display: none; }

/* The rod, one kind to a carriage, and the carriage that rides it. */
.tw-rod {
  position: absolute;
  left: 0;
  right: 0;
  height: 11px;
  z-index: 2;
  border-radius: 6px;
  box-shadow: 0 7px 12px rgba(0, 0, 0, 0.6);
}
.tw-rod::before,
.tw-rod::after {
  content: '';
  position: absolute;
  top: -4px;
  width: 14px;
  height: 19px;
  border-radius: 4px;
  background: linear-gradient(180deg, #5a5446, #1f1b15);
}
.tw-rod::before { left: 0; }
.tw-rod::after { right: 0; }
.tw-rod.steel { background: linear-gradient(180deg, #e6eaee, #8d949c 45%, #454b52); }
.tw-rod.copper { background: linear-gradient(180deg, #ffc9a0, #c0703c 45%, #6b3416); }
.tw-rod.black { background: linear-gradient(180deg, #5c5e63, #232427 50%, #0c0c0e); }
.tw-rod.wood { background: linear-gradient(180deg, #b98652, #7a4a24 50%, #3e220f); }
.tw-carriage {
  position: absolute;
  width: 140px;
  height: 70px;
  z-index: 3;
  transform: scale(var(--tw-cs));
  transform-origin: 50% 50%;
  transition: left 60ms linear;
  filter: drop-shadow(var(--tw-sx, 6px) 11px 7px rgba(0, 0, 0, 0.62));
}
.tw-body { position: absolute; inset: 0; }
.tw-car { display: block; }
.tw-bar {
  position: absolute;
  left: 50%;
  margin-left: -2px;
  width: 4px;
  height: 17px;
  z-index: 4;
  border-radius: 2px;
  background: linear-gradient(90deg, #8d8266, var(--tw-bar), #8d8266);
}
.tw-bar::before {
  content: '';
  position: absolute;
  left: -6px;
  top: -4px;
  width: 16px;
  height: 5px;
  border-radius: 1px;
  background: linear-gradient(180deg, #f2e8cc, #8d8266);
  box-shadow: 0 0 6px rgba(var(--gold-hi-rgb), 0.5);
}
.tw-bar.hit { animation: tw-hit 95ms ease-out; }
@keyframes tw-hit { 0% { transform: translateY(7px); } 45% { transform: translateY(-5px); } 100% { transform: translateY(0); } }

/* What an input method is still choosing. */
.tw-tag {
  position: absolute;
  z-index: 6;
  padding: 3px 9px;
  border: 1px solid rgba(var(--gold-rgb), 0.3);
  border-radius: 6px;
  background: rgba(10, 8, 6, 0.88);
  color: var(--tw-ink);
  font: 14px/1.3 var(--font-hand);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 150ms;
  pointer-events: none;
}
.tw-tag.on { opacity: 1; }

/* The light: no lamp, only what it does (see typewriter-light.js). */
.tw-light { position: absolute; inset: 0; z-index: 5; pointer-events: none; }
.tw-light canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.tw-glow { mix-blend-mode: screen; }

/* The words about it, and the real field, which is there to be typed in and is not seen. */
.tw-top {
  position: absolute;
  z-index: 6;
  top: max(12px, env(safe-area-inset-top));
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font: 12px/1.5 var(--font-ui);
  letter-spacing: 0.06em;
  color: rgba(207, 194, 162, 0.55);
  pointer-events: none;
}
.tw-count { font-family: var(--font-type); white-space: nowrap; }
#entry.tw.is-full .tw-count { color: #e6c88a; }
.tw-field {
  position: absolute;
  inset: 0;
  z-index: 9;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  outline: 0;
  resize: none;
  opacity: 0;
  color: transparent;
  caret-color: transparent;
  background: transparent;
  font-size: 16px;   /* not less: a phone zooms the page in to a smaller field */
  cursor: text;
  /* The page turns text selection off; a place to write must not. */
  -webkit-user-select: text;
  user-select: text;
}
#entry .entry-actions {
  position: absolute;
  z-index: 10;
  left: 0;
  right: 0;
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  pointer-events: none;
}
#entry .entry-button {
  pointer-events: auto;
  position: relative;
  min-height: 44px;
  padding: 0.42rem 1rem;
  border: 0;
  border-top: 1px solid rgba(207, 171, 104, 0.85);
  border-bottom: 1px solid rgba(207, 171, 104, 0.85);
  border-radius: 0;
  background: #2a2118;
  color: #f3dfb6;
  font: 400 0.95rem/1.4 var(--font-hand);
  cursor: pointer;
  box-shadow: inset 0 3px 0 rgba(207, 171, 104, 0.22), inset 0 -3px 0 rgba(207, 171, 104, 0.22);
  transition: background 180ms ease, transform 180ms ease;
}
#entry .entry-button:hover,
#entry .entry-button:focus-visible { background: #1c1611; transform: translateY(-2px); }
#entry .entry-button:active { transform: translateY(1px); }
#entry .entry-button.primary {
  border: 0;
  box-shadow: none;
  clip-path: polygon(8px 0, calc(100% - 8px) 0, 100% 8px, 100% calc(100% - 8px), calc(100% - 8px) 100%, 8px 100%, 0 calc(100% - 8px), 0 8px);
  background: linear-gradient(116deg, #c9a45a, #f3e6c0 36%, #e4cf8e 64%, #b9924a);
  color: #24180f;
}
#entry .entry-button.primary:hover,
#entry .entry-button.primary:focus-visible { background: linear-gradient(116deg, #d7b86a, #fff6df 40%, #f0e0b0 68%, #c9a45a); }

/* The flyleaf's mark (its look is portal.css's) is in the room, so that it follows what the keyboard leaves of the screen;
   typewriter.js stands it under the carriage. Above the field, so that a touch on it is its own. */
#entry .tw-flyleaf {
  position: absolute;
  z-index: 11;
  left: max(0.35rem, env(safe-area-inset-left));
  top: 12px;
}
#entry .tw-flyleaf[hidden] { display: none; }

@media (max-width: 640px) {
  .tw-keys { display: none; }
  .tw-top { justify-content: flex-end; }
}
@media (prefers-reduced-motion: reduce) {
  #entry.tw { animation: none; transition: none; }
  .tw-paper { transition: none; }
  .tw-glyph.struck, .tw-bar.hit { animation: none; }
}
