/* ============================================================
   1’rie — typewriter edition
   a letter to the world, typed as you scroll
   ============================================================ */

:root {
  --blue: #0032ff;
  --white: #ffffff;
  --paper: #fdfdfa;
  --mono: "Space Mono", ui-monospace, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--mono);
  background: var(--blue);
  color: var(--blue);
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--blue); color: var(--white); }

a { color: inherit; }

/* ---------- fixed HUD ---------- */

.hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1rem, 3vw, 2.5rem);
  color: var(--white);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  z-index: 10;
}
.hud-left { display: flex; align-items: baseline; gap: 0.8rem; flex-wrap: wrap; }
.hud-brand, .hud-link {
  background: var(--blue);
  padding: 0.35em 0.8em;
  border-radius: 999px;
}
.hud-brand { font-weight: 700; }
.hud-link { text-decoration: none; opacity: 0.85; }
.hud-link:hover { opacity: 1; text-decoration: underline; }
.sound-toggle {
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: var(--white);
  background: var(--blue);
  border: 1.5px solid var(--white);
  border-radius: 999px;
  padding: 0.35em 0.9em;
  cursor: pointer;
  white-space: nowrap;
}
.sound-toggle[aria-pressed="true"] { background: var(--white); color: var(--blue); }

.scroll-hint {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  color: var(--white);
  background: var(--blue);
  border: 1.5px solid var(--white);
  border-radius: 999px;
  padding: 0.5em 1.1em;
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  z-index: 10;
  animation: hint 1.8s ease-in-out infinite;
  transition: opacity 0.5s ease;
}
.scroll-hint.gone { opacity: 0; }
@keyframes hint {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(6px); }
}

.progress-line {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 3px;
  z-index: 11;
}
.progress-line i {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--white);
  transform: scaleX(0);
  transform-origin: left;
}

/* ---------- the paper ---------- */

.stage {
  display: flex;
  justify-content: center;
}
/* typing mode (JS on): stage is fixed, paper slides under the typing line */
body.typing .stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
}
.paper {
  width: min(740px, 93vw);
  margin-top: 12vh;
  background: var(--paper);
  padding: clamp(1.8rem, 6vw, 4.5rem);
  padding-bottom: 30vh;
  border-radius: 4px 4px 0 0;
  box-shadow: 0 40px 120px rgba(0, 10, 80, 0.5);
  position: relative;
  height: max-content;
  will-change: transform;
  /* faint typewriter guide lines */
  background-image: linear-gradient(rgba(0, 50, 255, 0.045) 1px, transparent 1px);
  background-size: 100% 2em;
}

.t {
  font-size: clamp(0.92rem, 2.3vw, 1.12rem);
  line-height: 2;
  margin-bottom: 1.6em;
  overflow-wrap: break-word;
}
.t.small { font-size: 0.78em; opacity: 0.75; }
.t.head { letter-spacing: 0.18em; text-transform: uppercase; font-weight: 700; }
.t.big {
  font-size: clamp(2.6rem, 9vw, 5.2rem);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
}
.t.big .reg { font-size: 0.35em; vertical-align: super; }
.t.sig { font-weight: 700; font-style: italic; font-size: 1.3em; }
.t.app .idx { opacity: 0.5; font-size: 0.85em; }
.t.app b { font-weight: 700; }

/* typed characters — hidden until "typed" (only when JS runs) */
.word { display: inline-block; white-space: nowrap; }
.char { display: inline-block; white-space: pre; }
body.typing .char { visibility: hidden; }
body.typing .char.on { visibility: visible; }

/* strike-out correction */
.char.struck {
  text-decoration: line-through;
  text-decoration-thickness: 0.14em;
  text-decoration-color: var(--blue);
}

/* stamped app icons */
.t-stamp {
  width: clamp(34px, 5vw, 48px);
  height: auto;
  border-radius: 23%;
  vertical-align: middle;
  margin: 0 0.35em;
  box-shadow: 0 6px 18px rgba(0, 10, 80, 0.25);
}
.t-stamp--glyph { background: var(--white); padding: 5px; }
body.typing .t-stamp {
  opacity: 0;
  transform: scale(1.7) rotate(-12deg);
}
body.typing .t-stamp.on {
  opacity: 1;
  transform: scale(1) rotate(-3deg);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.15s ease;
}

/* the blinking typing head */
.type-cursor {
  position: absolute;
  width: 0.55em;
  height: 1.4em;
  background: var(--blue);
  display: none;
  animation: blink 1s steps(1) infinite;
  pointer-events: none;
}
body.typing .type-cursor { display: block; }
@keyframes blink { 0%, 60% { opacity: 1; } 61%, 100% { opacity: 0; } }

/* ---------- press run : the mini game past the end of the letter ---------- */

.press-run {
  position: fixed;
  inset: 0;
  background: var(--blue);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.1rem;
  z-index: 9;
  color: var(--white);
  text-align: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.45s ease, visibility 0.45s;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.press-run.live {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
.press-run-title {
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 700;
  line-height: 1.9;
  opacity: 0.9;
}
#game-canvas {
  display: block;
  width: min(92vw, 860px);
  height: clamp(220px, 44vh, 400px);
}
.press-run-sub {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.65;
}
.press-run-exit {
  position: absolute;
  bottom: calc(1.1rem + env(safe-area-inset-bottom, 0px));
  left: 0;
  right: 0;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.55;
}

/* ---------- reduced motion / no-JS : the letter reads as a plain page ---------- */

@media (prefers-reduced-motion: reduce) {
  .scroll-hint, .progress-line { display: none; }
}
