@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=VT323&display=swap');

:root {
  --bg-outer: #070b17;
  --frame-border: #e2e8f0;
  --frame-shadow: #0f172a;
  --hud-bg: rgba(11, 18, 36, 0.86);
  --accent-gold: #fcd34d;
  --accent-rose: #e11d48;
  --text-light: #f8fafc;
  --text-dark: #0f172a;
}

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

html,
body {
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at center, #111b33 0%, var(--bg-outer) 100%);
  color: var(--text-light);
  font-family: 'VT323', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow: hidden;
  user-select: none;
}

.hidden {
  display: none !important;
}

.viewport {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  gap: 8px;
}

/* Top retro status bar */
.hud-bar {
  width: min(96vw, calc((100vh - 76px) * 16 / 9));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  background: var(--hud-bg);
  border: 3px solid var(--frame-border);
  box-shadow: 0 0 0 3px var(--frame-shadow);
  font-size: 1.2rem;
  letter-spacing: 0.03em;
}

.hud-title {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(0.58rem, 1.1vw, 0.82rem);
  color: var(--accent-gold);
  text-shadow: 2px 2px 0 #1e293b;
  white-space: nowrap;
}

.hud-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.hud-pill {
  background: rgba(15, 23, 42, 0.96);
  border: 2px solid #94a3b8;
  padding: 3px 12px;
  font-size: 1.25rem;
  color: #f8fafc;
  letter-spacing: 0.04em;
  text-shadow: 1px 1px 0 #020617;
  white-space: nowrap;
}

.hud-pill strong {
  color: var(--accent-gold);
  font-weight: normal;
}

/* 16:9 Pixel-Art Stage */
.stage-wrapper {
  position: relative;
  width: min(96vw, calc((100vh - 76px) * 16 / 9));
  aspect-ratio: 16 / 9;
  border: 4px solid var(--frame-border);
  box-shadow:
    0 0 0 4px var(--frame-shadow),
    0 24px 60px rgba(0, 0, 0, 0.65);
  background: #0a1024;
  overflow: hidden;
}

#village-canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: default;
}

#village-canvas.is-clickable {
  cursor: pointer;
}

/* Razor-sharp HiDPI DOM Hover Tooltip (never pixelated by canvas scaling!) */
.hover-tooltip {
  position: absolute;
  transform: translate(-50%, -100%);
  margin-top: -10px;
  padding: 4px 12px;
  background: rgba(11, 18, 36, 0.95);
  color: #ffffff;
  border: 2px solid var(--tooltip-accent, #fde68a);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.55);
  font-family: 'VT323', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(1.1rem, 1.75vw, 1.4rem);
  line-height: 1.1;
  letter-spacing: 0.04em;
  white-space: nowrap;
  pointer-events: none;
  z-index: 25;
}

.hover-tooltip::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translateX(-50%);
  border-width: 6px 6px 0 6px;
  border-style: solid;
  border-color: var(--tooltip-accent, #fde68a) transparent transparent transparent;
}

/* ==========================================================================
   Phase 3: Pokémon-Style RPG Dialog Box
   ========================================================================== */
.pkmn-dialog {
  position: absolute;
  left: 3%;
  right: 3%;
  bottom: 3%;
  max-height: 48%;
  background: #f8fafc;
  color: var(--text-dark);
  border: 4px solid #1e293b;
  box-shadow:
    inset 0 0 0 3px #cbd5e1,
    0 10px 28px rgba(0, 0, 0, 0.6);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  z-index: 30;
  cursor: pointer;
}

.pkmn-portrait-box {
  width: clamp(72px, 10vw, 108px);
  height: clamp(72px, 10vw, 108px);
  background: linear-gradient(180deg, #bae6fd 0%, #e0f2fe 70%, #f1f5f9 100%);
  border: 3px solid #1e293b;
  box-shadow: inset 0 0 0 2px #94a3b8;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.pkmn-portrait-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 8%;
  image-rendering: pixelated;
  pointer-events: none;
}

.pkmn-portrait-box canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  pointer-events: none;
}

.pkmn-content {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 4px;
}

.pkmn-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pkmn-speaker {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(0.62rem, 1.05vw, 0.85rem);
  background: #1e293b;
  color: #fde68a;
  padding: 4px 10px;
  letter-spacing: 0.04em;
}

.pkmn-mood {
  font-size: 1.25rem;
  line-height: 1;
}

.pkmn-text {
  font-size: clamp(1.25rem, 2.2vw, 1.75rem);
  line-height: 1.28;
  letter-spacing: 0.02em;
  color: #020617;
  min-height: 2.3em;
  user-select: text;
}

.pkmn-next {
  position: absolute;
  right: 2px;
  bottom: 0;
  color: #dc2626;
  font-size: 1.2rem;
  animation: pkmnBounce 0.7s infinite alternate;
}

@keyframes pkmnBounce {
  from { transform: translateY(0); }
  to { transform: translateY(4px); }
}

.pkmn-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}

.pkmn-choice-btn,
.pkmn-btn,
.lego-btn {
  font-family: 'VT323', monospace;
  font-size: clamp(1.05rem, 1.6vw, 1.35rem);
  background: #e2e8f0;
  color: #0f172a;
  border: 3px solid #1e293b;
  padding: 4px 12px;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.08s ease;
}

.pkmn-choice-btn:hover,
.pkmn-btn:hover,
.lego-btn:hover:not(:disabled) {
  background: #cbd5e1;
  transform: translateY(-1px);
}

.pkmn-choice-btn.is-primary,
.pkmn-btn.is-primary,
.lego-btn.is-primary {
  background: #be123c;
  color: #ffffff;
  border-color: #881337;
}

.pkmn-choice-btn.is-primary:hover,
.pkmn-btn.is-primary:hover,
.lego-btn.is-primary:hover:not(:disabled) {
  background: #9f1239;
}

.lego-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.pkmn-passphrase-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pkmn-hint {
  font-size: 1.05rem;
  color: #475569;
}

.pkmn-input-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pkmn-input {
  flex: 1;
  min-width: 160px;
  font-family: 'VT323', monospace;
  font-size: 1.35rem;
  padding: 4px 10px;
  border: 3px solid #1e293b;
  background: #ffffff;
  color: #0f172a;
  outline: none;
  user-select: text;
}

.pkmn-input:focus {
  border-color: #be123c;
}

.pkmn-error {
  font-size: 1.1rem;
  color: #be123c;
  min-height: 1.1em;
}

/* ==========================================================================
   Phase 4: Reward Modal (Postcards, Lego Instructions, Highlights)
   ========================================================================== */
.reward-modal {
  position: absolute;
  inset: 0;
  background: rgba(7, 11, 23, 0.78);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 40;
}

.reward-modal-card {
  position: relative;
  width: min(94%, 700px);
  max-height: 92%;
  overflow-y: auto;
  background: #fdf8ef;
  color: #1e293b;
  border: 4px solid #1e293b;
  box-shadow:
    inset 0 0 0 4px #e2d5be,
    0 20px 50px rgba(0, 0, 0, 0.65);
  padding: 20px 24px;
}

.reward-close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  font-family: 'Press Start 2P', monospace;
  font-size: 0.75rem;
  background: #1e293b;
  color: #f8fafc;
  border: 2px solid #0f172a;
  cursor: pointer;
  z-index: 5;
}

.reward-close-btn:hover {
  background: #be123c;
}

.reward-meta-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 14px;
}

.reward-badge {
  background: #e2e8f0;
  border: 2px solid #475569;
  padding: 2px 10px;
  font-size: 1.1rem;
  color: #0f172a;
}

.reward-badge.is-candy {
  background: #fef3c7;
  border-color: #b45309;
  color: #78350f;
}

.reward-badge.is-note {
  background: #ffe4e6;
  border-color: #be123c;
  color: #881337;
}

/* 3D Flippable Postcard (Front = Written Letter, Back = Full-Bleed Photo, IDENTICAL size!) */
.flip-card-scene {
  perspective: 1200px;
  width: 100%;
}

.flip-card-inner {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  min-height: 300px;
  max-height: 62vh;
  transform-style: preserve-3d;
  transition: transform 0.62s cubic-bezier(0.22, 1, 0.36, 1);
}

.flip-card-inner.is-flipped {
  transform: rotateY(180deg);
}

.flip-card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.flip-card-back {
  transform: rotateY(180deg);
}

.postcard-frame.is-fixed-size {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  padding: 14px 16px;
}

.postcard-frame.is-fixed-size .postcard-message {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  font-size: clamp(1.08rem, 1.75vw, 1.45rem);
  line-height: 1.35;
  padding: 8px 6px;
}

.postcard-frame.is-fixed-size .postcard-footer {
  margin-top: 6px;
  padding-top: 6px;
  font-size: 1.08rem;
}

.postcard-frame.is-fixed-size .postcard-actions {
  margin-top: 8px;
}

.postcard-photo-back {
  position: relative;
  width: 100%;
  height: 100%;
  background: #ffffff;
  border: 4px solid #1e293b;
  padding: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
  cursor: pointer;
}

.postcard-back-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border: 1px solid #cbd5e1;
}

.postcard-flip-corner {
  position: absolute;
  right: 14px;
  bottom: 14px;
  font-family: 'VT323', monospace;
  font-size: 1.15rem;
  background: rgba(15, 23, 42, 0.82);
  color: #f8fafc;
  border: 2px solid #f8fafc;
  padding: 3px 10px;
  cursor: pointer;
}

.postcard-flip-corner:hover {
  background: #be123c;
}

.postcard-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

/* Vintage Polaroid Photo inside Highlights */
.reward-polaroid {
  margin: 10px auto 14px;
  padding: 8px 8px 18px;
  background: #ffffff;
  border: 3px solid #1e293b;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.2);
  max-width: 440px;
  text-align: center;
}

.reward-polaroid-img {
  display: block;
  width: 100%;
  max-height: 280px;
  object-fit: cover;
  border: 1px solid #cbd5e1;
  cursor: zoom-in;
}

.reward-polaroid-img.is-zoomed {
  max-height: none;
  object-fit: contain;
  cursor: zoom-out;
}

/* Postcard Style */
.postcard-frame {
  border: 4px dashed #be123c;
  padding: 16px;
  background: #fffdf7;
}

.postcard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-right: 28px;
}

.postcard-title {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(0.75rem, 1.3vw, 1rem);
  color: #9f1239;
}

.postcard-stamp {
  border: 2px dotted #1e293b;
  background: #dbeafe;
  padding: 6px 8px;
  text-align: center;
  min-width: 72px;
}

.postcard-stamp-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.postcard-stamp-text {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.45rem;
  margin-top: 4px;
  color: #1e3a8a;
}

.postcard-message {
  background: repeating-linear-gradient(
    transparent,
    transparent 27px,
    rgba(148, 163, 184, 0.35) 28px
  );
  padding: 12px 8px;
  font-size: clamp(1.3rem, 2.1vw, 1.65rem);
  line-height: 1.45;
  color: #1e293b;
  min-height: 92px;
  user-select: text;
}

.postcard-footer {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 2px solid #cbd5e1;
  font-size: 1.2rem;
  color: #475569;
}

/* Highlight Style (Day 12 & Day 24) */
.highlight-frame {
  text-align: center;
  padding: 16px;
  border: 4px solid #d97706;
  background: linear-gradient(180deg, #fffbeb 0%, #fef3c7 100%);
}

.highlight-frame.is-christmas {
  border-color: #be123c;
  background: linear-gradient(180deg, #fff1f2 0%, #fef3c7 100%);
}

.highlight-banner {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.72rem;
  color: #ffffff;
  background: #b45309;
  display: inline-block;
  padding: 5px 12px;
  margin-bottom: 10px;
}

.highlight-frame.is-christmas .highlight-banner {
  background: #be123c;
}

.highlight-icon {
  font-size: 2.6rem;
  margin: 4px 0;
}

.highlight-title {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(0.95rem, 1.8vw, 1.35rem);
  color: #0f172a;
  margin: 6px 0;
}

.highlight-frame .reward-meta-strip {
  justify-content: center;
}

.highlight-message {
  font-size: clamp(1.3rem, 2vw, 1.6rem);
  line-height: 1.35;
  margin: 12px 0;
  color: #1e293b;
}

.highlight-hint {
  background: rgba(255, 255, 255, 0.8);
  border: 2px solid #d97706;
  padding: 8px 12px;
  font-size: 1.25rem;
  color: #92400e;
}

/* Lego Instruction Viewer */
.lego-letter-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

.lego-top-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  padding-right: 36px;
}

.lego-top-bar .lego-rose-pill {
  margin-bottom: 0;
}

.postcard-stamp.is-rose {
  background: #ffe4e6;
}

.lego-rose-pill {
  display: inline-block;
  font-family: 'Press Start 2P', monospace;
  font-size: 0.65rem;
  background: #be123c;
  color: #ffffff;
  padding: 4px 10px;
  margin-bottom: 8px;
}

.lego-title {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(0.8rem, 1.4vw, 1.05rem);
  color: #0f172a;
  margin-bottom: 6px;
}

.lego-intro {
  font-size: 1.25rem;
  color: #334155;
}

.lego-frame {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lego-tip-note {
  background: #fef3c7;
  border: 2px solid #d97706;
  color: #78350f;
  padding: 4px 8px;
  font-size: 0.98rem;
  line-height: 1.2;
}

.lego-step-card {
  background: #ffffff;
  border: 3px solid #1e293b;
  padding: 8px 10px;
  margin-bottom: 6px;
}

.lego-step-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

.lego-step-title-inline {
  font-size: 1.1rem;
  color: #334155;
}

.lego-img-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  overflow: hidden;
}

.lego-img-wrap.is-zoomed {
  overflow: auto;
  max-height: 46vh;
  align-items: flex-start;
}

.lego-step-img {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 36vh;
  object-fit: contain;
  border: 2px solid #cbd5e1;
  background: #ffffff;
  cursor: zoom-in;
}

.lego-step-img.is-zoomed {
  max-height: none;
  width: 155%;
  max-width: none;
  cursor: zoom-out;
}

.lego-zoom-hint {
  font-size: 0.9rem;
  color: #64748b;
  line-height: 1;
}

.lego-placeholder-note {
  background: #e0f2fe;
  border: 2px solid #0284c7;
  color: #075985;
  padding: 6px 10px;
  font-size: 1.05rem;
  margin-bottom: 10px;
}

.lego-step-card {
  background: #ffffff;
  border: 3px solid #1e293b;
  padding: 14px 16px;
  margin-bottom: 12px;
}

.lego-step-counter {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.65rem;
  color: #be123c;
  margin-bottom: 6px;
}

.lego-step-title {
  font-size: 1.45rem;
  color: #0f172a;
  margin-bottom: 6px;
}

.lego-step-desc {
  font-size: 1.25rem;
  line-height: 1.35;
  color: #334155;
}

.lego-step-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.lego-dots {
  display: flex;
  gap: 6px;
}

.lego-dot {
  width: 10px;
  height: 10px;
  background: #cbd5e1;
  border: 2px solid #475569;
}

.lego-dot.active {
  background: #be123c;
  border-color: #881337;
}

.lego-pdf-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lego-pdf-frame {
  width: 100%;
  height: 240px;
  border: 3px solid #1e293b;
  background: #ffffff;
}

.reward-loading,
.reward-error {
  padding: 20px;
  text-align: center;
  font-size: 1.3rem;
}

@media (max-width: 680px) {
  .hud-bar {
    padding: 6px 10px;
    font-size: 1rem;
  }
  .hud-pill {
    font-size: 0.95rem;
    padding: 2px 6px;
  }
  .pkmn-dialog {
    padding: 10px 12px;
    gap: 10px;
  }
  .reward-modal-card {
    padding: 14px 16px;
  }
}
