/* 夢チャンネル · the drop page. Oneiric Glass: the form is a letter, sending it is posting it into
   the TV. Pixel art stays pixel art: sprites scale by whole numbers (--px), nearest-neighbour. */

@font-face {
  font-family: "Ark Pixel";
  src: url("fonts/ark-pixel-16px-latin.woff2") format("woff2");
  font-display: swap;
}

:root {
  --px: 4px;                 /* one art pixel */
  --void: #0b0a10;
  --night: #14121c;
  --text: #eee4f6;
  --dim: #9b91b4;
  --pink: #e872c4;
  --pink-ink: #a8408a;       /* pink that reads on paper */
  --cyan: #6fd6c4;
  --lilac: #b99ce0;
  --paper: #f1e9f9;
  --paper-shade: #ddd0ee;
  --ink: #2a2140;
  --faint-ink: #857a9e;
  --rim: #8b6fae;
  --font: "Ark Pixel", ui-monospace, monospace;
}
@media (max-width: 359px) {
  :root { --px: 3px; }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--void);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: none;
  font-smooth: never;
  -webkit-tap-highlight-color: transparent;
}
img { image-rendering: pixelated; image-rendering: crisp-edges; }

/* ── the sky: the channel's own night, scaled by whole pixels (app.js sets --sky) ── */
.sky {
  position: fixed;
  inset: 0;
  /* the sky's own top colour above it on a tall screen: its dithering stays fine-grained */
  background:
    url("art/sky.png") center bottom / calc(240px * var(--sky, 2)) auto no-repeat,
    url("art/stars.png") center top / calc(240px * var(--sky, 2)) auto repeat,
    #170f2b;
  image-rendering: pixelated;
  z-index: -1;
}
.star {
  position: absolute;
  width: var(--px);
  height: var(--px);
  background: #fff6fd;
  opacity: 0;
  animation: twinkle var(--t, 5s) steps(1, end) var(--d, 0s) infinite;
}
@keyframes twinkle {
  0%, 70%, 100% { opacity: 0; }
  76%, 88% { opacity: .9; }
  82% { opacity: .45; }
}

.world {
  max-width: 420px;
  margin: 0 auto;
  padding: calc(28px + env(safe-area-inset-top)) 18px calc(28px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── the TV: the 夢 logo, its moon, Morgana on the lid ── */
.masthead { text-align: center; }
.tv {
  position: relative;
  width: calc(52 * var(--px));
  height: calc(55 * var(--px));
  margin: calc(16 * var(--px)) auto calc(4 * var(--px));
}
.tv-picture {
  position: absolute;
  inset: 0;
  transform-origin: 50% 45%;
  animation: warm .45s cubic-bezier(.3, 1.8, .5, 1) both;
  filter: drop-shadow(0 0 calc(3 * var(--px)) rgba(232, 114, 196, .28));
}
.tv-logo { width: 100%; height: 100%; display: block; }
.tv-glint {
  position: absolute;
  inset: 0;
  -webkit-mask: url("art/yume-logo.png") 0 0 / 100% 100%;
  mask: url("art/yume-logo.png") 0 0 / 100% 100%;
  background: linear-gradient(100deg, transparent 0 42%, rgba(255, 220, 245, .75) 42% 50%, transparent 50%) -100% 0 / 300% 100% no-repeat;
  animation: glint .8s .5s ease-in-out both;
}
@keyframes warm {
  0% { transform: scale(1.06, .02); filter: brightness(2.4); }
  25% { transform: scale(1.06, .05); }
  100% { transform: scale(1, 1); }
}
@keyframes glint {
  from { background-position: -100% 0; }
  to { background-position: 160% 0; }
}
.moon {
  position: absolute;
  left: calc(44 * var(--px));
  top: calc(-9 * var(--px));
  width: calc(14 * var(--px));
  height: calc(17 * var(--px));
  animation: bob 3.6s steps(1, end) infinite;
}
@keyframes bob {
  0%, 49.9% { transform: translateY(0); }
  50%, 100% { transform: translateY(var(--px)); }
}
.cat {
  position: absolute;
  left: calc(6 * var(--px));
  top: calc(-12 * var(--px));
  width: calc(18 * var(--px));
  height: calc(18 * var(--px));
}
.cat.hop { animation: hop .5s steps(4, end); }
@keyframes hop {
  0%, 100% { transform: translateY(0); }
  40% { transform: translateY(calc(-3 * var(--px))); }
  70% { transform: translateY(calc(-1 * var(--px))); }
}
.tv.received .tv-picture { animation: flicker .6s steps(1, end); }
@keyframes flicker {
  0% { filter: brightness(2.2) drop-shadow(0 0 calc(6 * var(--px)) var(--pink)); }
  20% { filter: brightness(.7); }
  40% { filter: brightness(1.8) drop-shadow(0 0 calc(5 * var(--px)) var(--pink)); }
  100% { filter: brightness(1) drop-shadow(0 0 calc(3 * var(--px)) rgba(232, 114, 196, .28)); }
}
.tv-bubble {
  position: absolute;
  right: calc(-6 * var(--px));
  top: calc(-4 * var(--px));
  margin: 0;
  padding: 2px 8px;
  background: var(--paper);
  color: var(--ink);
  white-space: nowrap;
  box-shadow: 0 0 0 var(--px) var(--rim);
  opacity: 0;
  transform: translateY(var(--px));
  pointer-events: none;
}
.tv-bubble.on { animation: bubble 2.6s steps(1, end) both; }
@keyframes bubble {
  0% { opacity: 0; transform: translateY(var(--px)); }
  8%, 88% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(0); }
}

h1 { margin: 6px 0 0; font-weight: normal; line-height: 1.2; }
.logotype {
  display: block;
  margin: 0 auto 8px;
  width: calc(73 * 3px);
  height: calc(17 * 3px);
}
.title { display: block; font-size: 32px; color: var(--text); text-shadow: 2px 2px 0 var(--void); }
.lede { margin: 10px 4px 26px; color: var(--cyan); text-shadow: 2px 2px 0 var(--void); }

/* ── the letter: paper with stepped pixel corners, a lilac rim, the channel's stamp ── */
.letter {
  position: relative;
  width: 100%;
  padding-bottom: 46px;
}
.letter, .paper { --step: var(--px); }
.paper {
  position: relative;
  background: var(--paper);
  color: var(--ink);
  padding: 18px 18px 44px;
  clip-path: polygon(
    0 calc(2 * var(--step)), var(--step) calc(2 * var(--step)), var(--step) var(--step), calc(2 * var(--step)) var(--step), calc(2 * var(--step)) 0,
    calc(100% - 2 * var(--step)) 0, calc(100% - 2 * var(--step)) var(--step), calc(100% - var(--step)) var(--step), calc(100% - var(--step)) calc(2 * var(--step)), 100% calc(2 * var(--step)),
    100% calc(100% - 2 * var(--step)), calc(100% - var(--step)) calc(100% - 2 * var(--step)), calc(100% - var(--step)) calc(100% - var(--step)), calc(100% - 2 * var(--step)) calc(100% - var(--step)), calc(100% - 2 * var(--step)) 100%,
    calc(2 * var(--step)) 100%, calc(2 * var(--step)) calc(100% - var(--step)), var(--step) calc(100% - var(--step)), var(--step) calc(100% - 2 * var(--step)), 0 calc(100% - 2 * var(--step)));
  box-shadow: inset 0 0 0 var(--px) var(--paper-shade);
  transform-origin: 50% 100%;
}
.letter-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
}
.to { color: var(--pink-ink); padding-top: 4px; }
.stamp {
  display: grid;
  place-items: center;
  width: calc(17 * 3px + 12px);
  height: calc(19 * 3px + 12px);
  background:
    radial-gradient(circle, var(--paper) 2px, transparent 2.5px) -3px -3px / 6px 6px,
    var(--lilac);
  padding: 6px;
  outline: 2px dashed rgba(42, 33, 64, .25);
  outline-offset: -4px;
}
.stamp img { width: calc(17 * 3px); height: calc(19 * 3px); background: var(--night); }

.line {
  display: grid;
  grid-template-columns: 64px 1fr;
  align-items: end;
  gap: 8px;
  padding: 6px 0 2px;
  background: repeating-linear-gradient(90deg, var(--faint-ink) 0 4px, transparent 4px 8px) left bottom / 100% 2px no-repeat;
}
.line:focus-within { background: linear-gradient(var(--pink), var(--pink)) left bottom / 100% 2px no-repeat; }
.line.note { grid-template-columns: 1fr; gap: 2px; margin-top: 12px; }
.label { color: var(--pink-ink); }
input, textarea {
  font: 16px/1.5 var(--font);
  color: var(--ink);
  background: transparent;
  border: 0;
  border-radius: 0;
  outline: none;
  width: 100%;
  min-width: 0;
  padding: 2px 0;
  caret-color: var(--pink);
  -webkit-appearance: none;
  appearance: none;
}
textarea { resize: none; display: block; min-height: 48px; }
::placeholder { color: var(--faint-ink); opacity: 1; }
.hint { margin: 6px 0 10px; color: var(--faint-ink); min-height: 24px; }
.hint.good { color: #2f7f70; }
.hint.wait { color: var(--pink-ink); }
.hint.bad { color: #b0365f; }
.count { position: absolute; right: 18px; bottom: 14px; margin: 0; color: var(--faint-ink); }
.shake { animation: shake .3s steps(4, end); }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(calc(-1 * var(--px))); }
  75% { transform: translateX(var(--px)); }
}

/* ── the seal: press it and the letter closes ── */
.seal {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  font: 16px/1 var(--font);
  cursor: pointer;
}
.seal-wax {
  width: calc(18 * var(--px));
  height: calc(18 * var(--px));
  filter: drop-shadow(0 var(--px) 0 rgba(11, 10, 16, .55));
  transition: transform .08s steps(2, end);
}
.seal:hover .seal-wax { transform: translateY(calc(-1 * var(--px))); }
.seal:active .seal-wax { transform: translateY(calc(0.5 * var(--px))); filter: none; }
.seal:focus-visible { outline: none; }
.seal:focus-visible .seal-wax { outline: 2px dashed var(--pink); outline-offset: 4px; }
.seal-label { text-shadow: 2px 2px 0 var(--void); }
.seal[disabled] { cursor: progress; }

/* closing: the paper folds down into an envelope (stepped, like a sprite) */
.letter.closing .paper { animation: fold .36s steps(6, end) forwards; }
.letter.closing .seal { visibility: hidden; }
@keyframes fold {
  from { transform: scaleY(1); opacity: 1; }
  to { transform: scaleY(.06); opacity: 0; }
}
.flying {
  position: fixed;
  left: 0;
  top: 0;
  width: calc(24 * var(--px));
  height: calc(24 * var(--px));
  z-index: 10;
  pointer-events: none;
}

/* ── after: the letter is in the TV ── */
.sent {
  width: 100%;
  text-align: center;
  padding: 18px 16px 20px;
  background: rgba(20, 18, 28, .82);
  box-shadow: 0 0 0 var(--px) var(--rim), 0 0 0 calc(2 * var(--px)) rgba(11, 10, 16, .6);
  animation: appear .3s steps(3, end) both;
}
.sent h2 { margin: 0 0 8px; font-size: 16px; font-weight: normal; color: var(--pink); }
.sent p { margin: 0 0 8px; }
.sent-small { color: var(--dim); }
@keyframes appear { from { opacity: 0; transform: translateY(var(--px)); } }
.again {
  margin-top: 8px;
  font: 16px/1 var(--font);
  color: var(--ink);
  background: var(--cyan);
  border: 0;
  padding: 10px 14px;
  cursor: pointer;
  box-shadow: 0 var(--px) 0 #3f9e8d;
}
.again:active { transform: translateY(var(--px)); box-shadow: none; }
.again:focus-visible { outline: 2px dashed var(--pink); outline-offset: 4px; }

.status { min-height: 24px; margin: 14px 0 0; text-align: center; color: var(--pink); text-shadow: 2px 2px 0 var(--void); }
footer { margin-top: 26px; text-align: center; color: var(--dim); text-shadow: 2px 2px 0 var(--void); }
footer p { margin: 0 0 6px; }
.sig { color: var(--lilac); }

[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
  .star { display: none; }
}
