@font-face {
  font-family: 'NeoDunggeunmo';
  src: url('./fonts/neodgm.woff') format('woff');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #050505;
  font-family: 'NeoDunggeunmo', '굴림', Gulim, 'Malgun Gothic', sans-serif;
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  word-break: keep-all;
}

/* ===== Mobile frame — always mobile-sized, even on desktop ===== */
.frame {
  width: 100%;
  min-width: 320px;
  max-width: 430px;
  height: 100dvh;
  max-height: 932px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  background: #2b1a12;
  box-shadow: 0 0 60px rgba(0,0,0,0.8);
  border: 4px solid #000;
  flex-shrink: 0;
}

@media (min-width: 431px) {
  body { display: flex; align-items: center; justify-content: center; }
  .frame { height: 90vh; border-radius: 6px; }
}


/* ===== RPG tile-map scene ===== */
/* Scrolls vertically when the background's real aspect ratio can't fit the frame,
   instead of letting background-size:cover crop/misalign it against the overlays. */
.scene-scroll {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
}
.rpg-scene {
  position: relative;
  width: 100%;
  aspect-ratio: 853 / 1844; /* bg.png's native size — keeps it undistorted, uncropped */
  background: #1c130c url('./images/bg.png') no-repeat center top;
  background-size: contain;
  image-rendering: pixelated;
}

/* Invisible clickable zone over the counter/merchant art in bg.png.
   Click it to walk up to the counter, then start the dialogue. */
.merchant-block {
  position: absolute;
  left: 32%;
  top: 14%;
  width: 41%;
  height: 13%;
  z-index: 15;
  cursor: pointer;
}

/* Invisible clickable zones over the side tables/props drawn in bg.png */
.object-block {
  position: absolute;
  z-index: 14;
  cursor: pointer;
}
#swordTable { left: 0%; top: 58%; width: 31%; height: 10%; }
#potionTable { left: 77%; top: 48%; width: 21%; height: 12%; }
#fruitTable { left: 79%; top: 63%; width: 20%; height: 12%; }
#bookTable { left: 0%; top: 66%; width: 31%; height: 12%; }
#chalkboard { left: 16%; top: 21%; width: 14%; height: 9%; }
#oldBooks { left: 74%; top: 20%; width: 14%; height: 7%; }

/* Subtle glow on the book table — only appears after the player has talked
   to the merchant once, so it doesn't feel like a spoiler up front. */
.object-block.glow {
  animation: prop-glow 3.2s ease-in-out infinite;
  border-radius: 6px;
}
@keyframes prop-glow {
  0%, 100% { box-shadow: 0 0 6px 1px rgba(255, 224, 102, 0.25); }
  50% { box-shadow: 0 0 14px 4px rgba(255, 224, 102, 0.55); }
}

/* Tile grid — fixed square cells, only 'path' tiles are walkable */
.tile-map {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  /* top is set in px by script.js so the grid's vertical origin can be nudged */
}
/* Tiles are invisible hit-zones now — the red carpet in bg.png IS the path */
.tile-grass {
  pointer-events: none;
}
.tile-path {
  cursor: pointer;
}

/* Sprites: real PNGs, crisp pixel scaling.
   Height is set in px by script.js (tied to the scene, not the tile grid)
   so shrinking the tiles doesn't shrink the characters. */
.sprite {
  position: absolute;
  width: auto;
  z-index: 10;
  transform: translate(-50%, -85%);
  image-rendering: pixelated;
  filter: drop-shadow(1px 3px 1px rgba(0,0,0,0.4));
  pointer-events: none;
}
.player-sprite {
  z-index: 12;
  transition: left 0.18s linear, top 0.18s linear;
}
.player-sprite.walking { animation: walk-bounce 0.25s ease-in-out infinite; }
@keyframes walk-bounce {
  0%, 100% { margin-top: 0; }
  50% { margin-top: -3px; }
}
.player-sprite.face-left { transform: translate(-50%, -85%) scaleX(-1); }

/* ===== Zoom overlay: RPG shop menu — a modal, not a full takeover =====
   Leaves the scene visible around the edges instead of covering the whole screen. */
.zoom-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 6, 3, 0.55);
  z-index: 100;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 8% 4% 5%;
}
.zoom-overlay.active { display: flex; }

.crt-screen {
  position: relative;
  width: 100%;
  max-height: 100%;
  background: linear-gradient(#3a2416, #2a1810);
  color: #fff8e8;
  overflow-y: auto;
  overflow-x: hidden;
  border: 3px solid #ffe066;
  border-radius: 10px;
  box-shadow: 0 0 0 3px #6b4a24, 0 10px 24px rgba(0,0,0,0.6);
}
.scanlines { display: none; }

.app-view { display: flex; flex-direction: column; }
.app-view.hidden { display: none; }

.app-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 3px solid #6b4a24;
  background: linear-gradient(#a97f3c, #8a6228);
  position: sticky;
  top: 0;
  z-index: 2;
}
.app-title {
  font-size: 15px;
  letter-spacing: 1px;
  color: #2a1810;
  font-weight: bold;
  flex: 1;
}
.close-btn, .back-btn {
  background: #fff8e8;
  border: 2px solid #3a2416;
  color: #2a1810;
  font-size: 13px;
  font-weight: bold;
  padding: 4px 10px;
  cursor: pointer;
  font-family: inherit;
  border-radius: 3px;
}

/* Fixed at the very top of the screen (outside the app-header card), not per-view */
.close-later-global {
  position: absolute;
  top: 2%;
  right: 3%;
  z-index: 110;
  background: #fff8e8;
  border: 2px solid #3a2416;
  color: #2a1810;
  font-size: 11px;
  font-weight: bold;
  white-space: nowrap;
  padding: 5px 9px;
  cursor: pointer;
  font-family: inherit;
  border-radius: 3px;
  box-shadow: 0 3px 6px rgba(0,0,0,0.4);
}

/* ===== Payment-confirmed celebration: purchased potion + "꿀꺽 꿀꺽" ===== */
.drink-celebration {
  position: absolute;
  inset: 0;
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(10, 6, 3, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}
.drink-celebration.hidden { display: none; }
.drink-celebration.show { opacity: 1; }
.drink-celebration img {
  width: 34%;
  max-width: 140px;
  image-rendering: pixelated;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.6));
  animation: drink-bob 0.6s ease-in-out infinite;
}
.drink-sound {
  font-size: 20px;
  font-weight: bold;
  color: #ffe066;
  text-shadow: 0 0 8px rgba(255,224,102,0.8), 2px 2px 0 #2a1810;
  animation: drink-pulse 0.5s ease-in-out infinite alternate;
}
@keyframes drink-bob {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-10px) rotate(2deg); }
}
@keyframes drink-pulse {
  from { transform: scale(1); opacity: 0.85; }
  to { transform: scale(1.12); opacity: 1; }
}

/* Manual fallback for confirming payment, in case tab-focus auto-detection
   doesn't fire on a given browser/device. */
.checkout-return-btn {
  position: absolute;
  left: 50%;
  bottom: 4%;
  transform: translateX(-50%);
  z-index: 120;
  background: linear-gradient(#ffe066, #d9a83c);
  border: 2px solid #6b4a24;
  color: #2a1810;
  font-family: inherit;
  font-weight: bold;
  font-size: 13px;
  padding: 10px 16px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 4px 10px rgba(0,0,0,0.5);
  animation: checkout-return-pulse 1.6s ease-in-out infinite;
}
.checkout-return-btn.hidden { display: none; }
.checkout-return-btn:disabled { opacity: 0.7; cursor: default; animation: none; }
@keyframes checkout-return-pulse {
  0%, 100% { box-shadow: 0 4px 10px rgba(0,0,0,0.5); }
  50% { box-shadow: 0 4px 18px rgba(255,224,102,0.8); }
}

.app-body { padding: 16px; flex: 1; }
.center-body { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; }

.app-lead {
  font-size: 13px;
  color: #ffe066;
  margin-bottom: 14px;
  text-align: center;
  font-weight: bold;
}

.product-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.product-card {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 3px solid #6b4a24;
  background: linear-gradient(#4a2e1c, #3a2416);
  border-radius: 6px;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  text-align: left;
}
.product-card:active { border-color: #ffe066; transform: scale(0.98); }
.product-icon {
  flex-shrink: 0;
  filter: drop-shadow(1px 2px 1px rgba(0,0,0,0.5));
}
.product-icon img {
  height: 52px;
  width: auto;
  image-rendering: pixelated;
}
.product-info { flex: 1; min-width: 0; }
.product-name {
  font-size: 16px;
  color: #ffe066;
  margin-bottom: 4px;
  font-weight: bold;
}
.product-price {
  font-size: 17px;
  font-weight: bold;
  color: #fff8e8;
}
.product-price::before { content: '🪙 '; }
.product-price .strike {
  text-decoration: line-through;
  color: #9a8265;
  font-size: 12px;
  margin-right: 4px;
}
.discount-badge {
  display: inline-block;
  background: #c0392b;
  color: #fff8e8;
  font-size: 10px;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 3px;
  margin-left: 6px;
  vertical-align: middle;
}
.product-desc {
  font-size: 14px;
  color: #d9c9a8;
  margin-top: 6px;
  line-height: 1.5;
}
.product-desc2 {
  font-size: 14px;
  color: #e8b463;
  margin-top: 2px;
  line-height: 1.5;
}

.app-warning {
  font-size: 14px;
  color: #ffcf5c;
  border: 1px dashed #ffcf5c;
  background: rgba(0,0,0,0.2);
  padding: 8px;
  margin-bottom: 14px;
  line-height: 1.5;
  border-radius: 4px;
}

.q-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.q-step-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid #6b4a24;
  background: #241609;
  color: #d9c9a8;
  font-family: inherit;
  font-weight: bold;
  font-size: 12px;
  cursor: pointer;
}
.q-step-btn.filled {
  border-color: #8a6228;
  background: #4a2e1c;
  color: #fff8e8;
}
.q-step-btn.active {
  border-color: #ffe066;
  background: linear-gradient(#ffe066, #d9a83c);
  color: #2a1810;
}

.q-input-group { margin-bottom: 12px; }
.q-input-group label {
  display: block;
  font-size: 11px;
  color: #ffe066;
  margin-bottom: 4px;
  font-weight: bold;
}
.text-input {
  width: 100%;
  background: #fff8e8;
  border: 2px solid #6b4a24;
  color: #2a1810;
  padding: 8px;
  font-family: inherit;
  font-size: 12px;
  border-radius: 3px;
}
.text-input:focus { outline: none; box-shadow: 0 0 4px #ffe066; }

textarea.text-input {
  font-size: 1.2rem;
  min-height: 90px;
  resize: vertical;
  line-height: 1.5;
}

.primary-btn {
  width: 100%;
  padding: 12px;
  background: linear-gradient(#ffe066, #d9a83c);
  color: #2a1810;
  border: 2px solid #6b4a24;
  border-radius: 4px;
  font-family: inherit;
  font-weight: bold;
  font-size: 13px;
  letter-spacing: 1px;
  cursor: pointer;
  margin-top: 8px;
}
.primary-btn:active { background: #d9a83c; }

.done-msg {
  font-size: 14px;
  color: #fff8e8;
  line-height: 1.7;
}
.email-label {
  font-size: 11px;
  color: #ffe066;
  align-self: flex-start;
  font-weight: bold;
}
.locked-msg {
  font-size: 12px;
  color: #ffcf5c;
  margin-top: 8px;
}
.locked-msg.hidden, .hidden { display: none !important; }

/* ===== Topic selection ===== */
.topic-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.topic-btn {
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border: 3px solid #6b4a24;
  background: linear-gradient(#4a2e1c, #3a2416);
  color: #ffe066;
  font-family: inherit;
  font-weight: bold;
  font-size: 16px;
  border-radius: 6px;
  cursor: pointer;
}
.topic-btn:active { border-color: #ffe066; }
.subtopic-btn {
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  border: 2px solid #6b4a24;
  background: #241609;
  color: #fff8e8;
  font-family: inherit;
  font-size: 15px;
  border-radius: 5px;
  cursor: pointer;
}
.subtopic-btn:active { border-color: #ffe066; }
.topic-back-btn {
  width: 100%;
  text-align: left;
  padding: 8px 4px;
  border: none;
  background: none;
  color: #d9c9a8;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  margin-bottom: 4px;
}

/* ===== Consent (email + privacy agreement) ===== */
.consent-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 14px;
  font-size: 13px;
  color: #fff8e8;
  cursor: pointer;
}
.consent-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: #ffe066;
  margin-top: 1px;
}
.link-btn {
  display: block;
  background: none;
  border: none;
  color: #d9c9a8;
  text-decoration: underline;
  font-family: inherit;
  font-size: 12px;
  padding: 6px 0 0 26px;
  cursor: pointer;
}
.consent-detail {
  margin: 8px 0 0 26px;
  padding: 10px 12px;
  background: rgba(0,0,0,0.25);
  border: 1px dashed #6b4a24;
  border-radius: 4px;
  font-size: 11.5px;
  color: #d9c9a8;
  line-height: 1.7;
}

/* ===== Modals ===== */
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop.active { display: flex; }
.modal-box {
  width: 100%;
  max-width: 320px;
  max-height: 85vh;
  overflow-y: auto;
  background: linear-gradient(#4a2e1c, #3a2416);
  border: 3px solid #ffe066;
  border-radius: 6px;
  box-shadow: 0 0 20px rgba(255,224,102,0.3);
  padding: 18px;
  color: #fff8e8;
}
.modal-title {
  font-size: 14px;
  color: #ffe066;
  margin-bottom: 12px;
  letter-spacing: 1px;
  font-weight: bold;
}
.modal-body { font-size: 12px; line-height: 1.7; margin-bottom: 14px; }
.modal-price { font-size: 18px; color: #ffe066; font-weight: bold; }
.modal-price::before { content: '🪙 '; }
.modal-note { font-size: 10px; color: #d9c9a8; margin-top: 8px; }
.modal-actions { display: flex; gap: 8px; }
.ghost-btn {
  flex: 1;
  padding: 10px;
  background: transparent;
  border: 2px solid #9a8265;
  color: #d9c9a8;
  font-family: inherit;
  cursor: pointer;
  border-radius: 4px;
}
.modal-actions .primary-btn { flex: 2; margin-top: 0; }

.share-link {
  background: #fff8e8;
  border: 2px dashed #6b4a24;
  color: #2a1810;
  padding: 8px;
  font-size: 11px;
  word-break: break-all;
  margin-top: 6px;
  border-radius: 3px;
}

.site-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 9px;
  color: rgba(255,255,255,0.5);
  padding: 6px;
  z-index: 3;
  background: rgba(0,0,0,0.4);
}

/* ===== Dialogue overlay (NPC talk) ===== */
.dialogue-overlay {
  position: absolute;
  inset: 0;
  z-index: 150;
  display: none;
  background: rgba(0,0,0,0.25);
}
.dialogue-overlay.active { display: block; }

.dialogue-close {
  position: absolute;
  top: 4%;
  right: 5%;
  background: #fff8e8;
  border: 2px solid #3a2416;
  color: #2a1810;
  font-size: 13px;
  font-weight: bold;
  width: 28px;
  height: 28px;
  border-radius: 3px;
  cursor: pointer;
}

.dialogue-portrait {
  position: absolute;
  right: 4%;
  bottom: 24%;
  width: 42%;
  max-width: 190px;
  image-rendering: pixelated;
  filter: drop-shadow(2px 6px 4px rgba(0,0,0,0.5));
}
.dialogue-portrait img {
  width: 100%;
  display: block;
}

.dialogue-box {
  position: absolute;
  left: 4%;
  right: 4%;
  bottom: 4%;
  min-height: 22%;
  background: linear-gradient(#3a2416, #241609);
  border: 3px solid #ffe066;
  box-shadow: 0 0 0 3px #6b4a24, 0 6px 12px rgba(0,0,0,0.5);
  border-radius: 4px;
  padding: 12px 16px;
  cursor: pointer;
}
.dialogue-name {
  display: inline-block;
  background: #ffe066;
  color: #2a1810;
  font-weight: bold;
  font-size: 11px;
  padding: 2px 10px;
  border-radius: 3px;
  margin-bottom: 6px;
}
.dialogue-text {
  color: #fff8e8;
  font-size: 17px;
  line-height: 1.7;
  min-height: 2.6em;
}
.dialogue-next {
  position: absolute;
  right: 14px;
  bottom: 10px;
  color: #ffe066;
  font-size: 13px;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink {
  50% { opacity: 0; }
}
.dialogue-choices {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.dialogue-choices .ghost-btn,
.dialogue-choices .primary-btn {
  flex: 1;
  width: auto;
  margin-top: 0;
}

/* ===== Object info popup (click a table/prop) ===== */
.object-info-overlay {
  position: absolute;
  inset: 0;
  z-index: 140;
  display: none;
  background: rgba(0,0,0,0.15);
}
.object-info-overlay.active { display: block; }
/* Same footprint as .dialogue-box, so object interactions match the merchant dialogue size */
.object-info-box {
  position: absolute;
  left: 4%;
  right: 4%;
  bottom: 4%;
  min-height: 22%;
  background: linear-gradient(#3a2416, #241609);
  border: 3px solid #ffe066;
  box-shadow: 0 0 0 3px #6b4a24, 0 6px 12px rgba(0,0,0,0.5);
  border-radius: 4px;
  padding: 12px 16px;
  cursor: pointer;
  text-align: left;
}
.object-info-text {
  color: #fff8e8;
  font-size: 17px;
  line-height: 1.7;
  white-space: pre-line;
}
.object-info-hint {
  color: #ffe066;
  font-size: 10px;
  margin-top: 6px;
  opacity: 0.8;
}
.object-info-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.object-info-actions .ghost-btn,
.object-info-actions .primary-btn {
  flex: 1;
  width: auto;
  margin-top: 0;
}
