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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #0a0a0a;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  width: 100%; height: 100%;
  position: relative;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  opacity: 0;
  transition: opacity 0.6s ease;
  pointer-events: none;
  cursor: pointer;
}
.screen.active {
  opacity: 1;
  pointer-events: auto;
}

.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1000;
  background: repeating-linear-gradient(
    0deg,
    rgba(0,0,0,0.03) 0px,
    rgba(0,0,0,0.03) 1px,
    transparent 1px,
    transparent 2px
  );
}

.screen-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  background-size: 400% 400%;
  animation: gradientShift 8s ease infinite;
}
@keyframes gradientShift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.glitch {
  position: relative;
  font-size: clamp(2rem, 8vw, 5rem);
  font-weight: 400;
  text-align: center;
  z-index: 1;
  line-height: 1.2;
}
.glitch::before,
.glitch::after {
  content: attr(data-text);
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  text-align: center;
}
.glitch::before {
  animation: glitch1 2.5s infinite;
  clip-path: polygon(0 0, 100% 0, 100% 45%, 0 45%);
}
.glitch::after {
  animation: glitch2 2.5s infinite;
  clip-path: polygon(0 55%, 100% 55%, 100% 100%, 0 100%);
}

@keyframes glitch1 {
  0%, 90%, 100% { transform: translate(0); }
  92% { transform: translate(-3px, 1px); }
  94% { transform: translate(3px, -1px); }
  96% { transform: translate(-2px, -1px); }
}
@keyframes glitch2 {
  0%, 90%, 100% { transform: translate(0); }
  91% { transform: translate(2px, 1px); }
  93% { transform: translate(-3px, -1px); }
  95% { transform: translate(1px, 2px); }
}

.typewriter-cursor {
  display: inline-block;
  width: 2px;
  animation: blink 0.7s step-end infinite;
  margin-left: 2px;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.fact-text {
  font-size: clamp(1.5rem, 6vw, 3.5rem);
  text-align: center;
  z-index: 1;
  line-height: 1.3;
  max-width: 80%;
}

.fact-image {
  z-index: 1;
  max-width: 60%;
  max-height: 40vh;
  margin-top: 1.5rem;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-radius: 4px;
}

.tap-hint {
  position: absolute;
  bottom: 2rem;
  font-size: 0.85rem;
  opacity: 0.4;
  z-index: 1;
  animation: fadeInUp 1s ease 1.5s both;
  letter-spacing: 0.1em;
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 0.4; transform: translateY(0); }
}

.letter-screen {
  overflow-y: auto;
  cursor: default;
  align-items: center;
  justify-content: flex-start;
  padding-top: 3rem;
  padding-bottom: 3rem;
}

.paper {
  position: relative;
  z-index: 1;
  width: clamp(280px, 85vw, 600px);
  min-height: auto;
  max-height: 75vh;
  overflow-y: auto;
  padding: clamp(1.2rem, 4vw, 2.5rem) clamp(1rem, 3vw, 2rem);
  background: #faf8f5;
  box-shadow:
    0 2px 15px rgba(0,0,0,0.3),
    0 0 40px rgba(0,0,0,0.1);
  transform: rotate(-0.5deg);
  line-height: 1.8;
  color: #2a2a2a;
  font-size: clamp(0.9rem, 2.5vw, 1.15rem);
  white-space: pre-wrap;
  word-wrap: break-word;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,0.25) transparent;
}
.paper::-webkit-scrollbar { width: 6px; }
.paper::-webkit-scrollbar-track { background: transparent; margin: 0.5rem 0; }
.paper::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.2);
  border-radius: 3px;
  transition: background 0.2s;
}
.paper::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.4); }
.letter-screen { scrollbar-width: none; }
.letter-screen::-webkit-scrollbar { display: none; }

.paper-header {
  text-align: right;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  opacity: 0.6;
  font-size: 0.85rem;
  line-height: 1.4;
}
.paper-header .paper-location { display: block; }
.paper-header .paper-date { display: block; font-style: italic; opacity: 0.85; }

.pdf-container {
  width: min(90%, 700px);
  z-index: 1;
}
.pdf-upload-btn {
  display: block;
  margin: 1rem auto;
  padding: 0.8rem 2rem;
  border: 2px dashed rgba(255,255,255,0.3);
  background: transparent;
  color: inherit;
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
  border-radius: 8px;
  transition: border-color 0.3s;
}
.pdf-upload-btn:hover { border-color: rgba(255,255,255,0.6); }
.pdf-embed {
  width: 100%;
  height: 80vh;
  border: none;
  border-radius: 8px;
  background: #faf8f5;
}

.share-btn {
  position: fixed;
  top: 1rem; right: 1rem;
  z-index: 999;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: inherit;
  font-family: inherit;
  font-size: 0.8rem;
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: all 0.3s;
  letter-spacing: 0.05em;
}
.share-btn:hover { background: rgba(255,255,255,0.2); }
.share-btn.copied { background: rgba(100,255,100,0.2); border-color: rgba(100,255,100,0.4); }

.progress {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  z-index: 999;
}
.progress-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  transition: all 0.3s;
}
.progress-dot.active { background: rgba(255,255,255,0.7); transform: scale(1.3); }
.progress-dot.visited { background: rgba(255,255,255,0.4); }

.template-retro {
  font-family: 'VT323', monospace;
  color: #00ff41;
}
.template-retro .glitch::before {
  text-shadow: -2px 0 #ff00ff;
}
.template-retro .glitch::after {
  text-shadow: 2px 0 #00ffff;
}
.template-retro .typewriter-cursor {
  background: #00ff41;
  height: 1.2em;
}
.template-retro .paper {
  font-family: 'VT323', monospace;
  font-size: clamp(1.1rem, 3vw, 1.3rem);
  background: #0d1117;
  color: #00ff41;
  border: 1px solid #00ff4133;
}
.template-retro .paper { scrollbar-color: rgba(0,255,65,0.35) transparent; }
.template-retro .paper::-webkit-scrollbar-thumb { background: rgba(0,255,65,0.3); box-shadow: 0 0 4px rgba(0,255,65,0.4); }
.template-retro .paper::-webkit-scrollbar-thumb:hover { background: rgba(0,255,65,0.55); }
.template-retro .paper-header { color: #00ff41; }
.template-retro .progress-dot { background: rgba(0,255,65,0.2); }
.template-retro .progress-dot.active { background: rgba(0,255,65,0.7); }
.template-retro .progress-dot.visited { background: rgba(0,255,65,0.4); }
.template-retro .share-btn { color: #00ff41; }

.template-warm {
  font-family: 'Caveat', cursive;
  color: #3d2c2c;
}
.template-warm .screen-bg {
  filter: saturate(0.8);
}
.template-warm .glitch::before {
  text-shadow: -1px 0 #e07a5f;
}
.template-warm .glitch::after {
  text-shadow: 1px 0 #81b29a;
}
.template-warm .fact-text,
.template-warm .glitch {
  color: #faf8f5;
  text-shadow: 0 2px 20px rgba(0,0,0,0.3);
}
.template-warm .typewriter-cursor {
  background: #faf8f5;
  height: 1.1em;
}
.template-warm .paper {
  font-family: 'Caveat', cursive;
  font-size: clamp(1.2rem, 3.5vw, 1.5rem);
  background: #fdf6ec;
  color: #3d2c2c;
  transform: rotate(-1deg);
}
.template-warm .paper { scrollbar-color: rgba(61,44,44,0.3) transparent; }
.template-warm .paper::-webkit-scrollbar-thumb { background: rgba(61,44,44,0.25); }
.template-warm .paper::-webkit-scrollbar-thumb:hover { background: rgba(224,122,95,0.6); }
.template-warm .tap-hint { color: #faf8f5; }
.template-warm .progress-dot { background: rgba(250,248,245,0.2); }
.template-warm .progress-dot.active { background: rgba(250,248,245,0.7); }
.template-warm .progress-dot.visited { background: rgba(250,248,245,0.4); }
.template-warm .share-btn { color: #faf8f5; }

.template-midnight {
  font-family: 'Inter', sans-serif;
  color: #e0d6ff;
}
.template-midnight .glitch::before {
  text-shadow: -2px 0 #7c3aed;
}
.template-midnight .glitch::after {
  text-shadow: 2px 0 #3b82f6;
}
.template-midnight .fact-text {
  font-weight: 300;
  letter-spacing: 0.02em;
}
.template-midnight .typewriter-cursor {
  background: #e0d6ff;
  height: 1.1em;
}
.template-midnight .paper {
  font-family: 'Inter', sans-serif;
  font-weight: 300;
  background: #1a1435;
  color: #d4ccf0;
  border: 1px solid rgba(124,58,237,0.2);
  box-shadow: 0 0 40px rgba(124,58,237,0.1), 0 2px 15px rgba(0,0,0,0.3);
}
.template-midnight .paper { scrollbar-color: rgba(124,58,237,0.4) transparent; }
.template-midnight .paper::-webkit-scrollbar-thumb { background: rgba(124,58,237,0.35); box-shadow: 0 0 6px rgba(124,58,237,0.3); }
.template-midnight .paper::-webkit-scrollbar-thumb:hover { background: rgba(124,58,237,0.6); }
.template-midnight .paper-header { color: #8b7fc7; }
.template-midnight .progress-dot { background: rgba(224,214,255,0.15); }
.template-midnight .progress-dot.active { background: rgba(124,58,237,0.7); }
.template-midnight .progress-dot.visited { background: rgba(224,214,255,0.3); }
.template-midnight .share-btn { color: #e0d6ff; }

@keyframes screenEnter {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}
.screen.active { animation: screenEnter 0.5s ease both; }

@keyframes letterReveal {
  from { opacity: 0; transform: translateY(30px) rotate(-0.5deg); }
  to { opacity: 1; transform: translateY(0) rotate(-0.5deg); }
}
.paper.revealed { animation: letterReveal 0.8s ease both; }
