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

:root {
  --pixel-font: 'Press Start 2P', monospace;
  --body-font: 'VT323', monospace;
  --card-bg: rgba(10, 12, 24, 0.88);
  --card-border: #ffd54f;
  --accent: #ffd54f;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--body-font);
  background: #000;
  color: #fff;
}

/* ===== Game canvas ===== */
#game {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  image-rendering: pixelated;
  z-index: 0;
  cursor: default;
}
#game.over-character { cursor: pointer; }

/* ===== HUD ===== */
.hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  z-index: 20;
  font-family: var(--pixel-font);
  text-shadow: 2px 2px 0 #000;
  pointer-events: none;
}
.hud-name { font-size: 12px; color: #fff; }
.hud-world { font-size: 9px; color: var(--accent); margin-top: 6px; }
.hud-right { display: flex; gap: 8px; }
.hud-btn {
  pointer-events: auto;
  font-family: var(--pixel-font);
  font-size: 8px;
  color: #fff;
  background: rgba(0,0,0,0.65);
  border: 2px solid #fff;
  padding: 8px 10px;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 3px 3px 0 rgba(0,0,0,0.5);
}
.hud-btn:hover { background: var(--accent); color: #000; border-color: #000; }

/* ===== Story column ===== */
#story { position: relative; z-index: 10; pointer-events: none; transition: opacity 0.25s ease; }
#story a, #story .card { pointer-events: auto; }

/* Chat focus mode: while the digital twin is open, clear the narration away so
   there's only one text surface on screen. Layout (and therefore scrolling)
   is untouched — the game keeps advancing behind the panel. */
body.chat-open #story { opacity: 0; pointer-events: none; }
body.chat-open #story .card { pointer-events: none; }

.title-screen {
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 22px;
  padding: 0 16px;
}
.title-screen h1 {
  font-family: var(--pixel-font);
  font-size: clamp(22px, 5vw, 44px);
  color: #fff;
  text-shadow: 4px 4px 0 #d32f2f, 8px 8px 0 rgba(0,0,0,0.4);
}
.title-screen .subtitle {
  font-family: var(--pixel-font);
  font-size: clamp(11px, 2.2vw, 18px);
  color: var(--accent);
  text-shadow: 3px 3px 0 rgba(0,0,0,0.5);
}
.press-start {
  font-family: var(--pixel-font);
  font-size: 11px;
  color: #fff;
  animation: blink 1.2s steps(2) infinite;
  text-shadow: 2px 2px 0 #000;
}
.hint { font-size: 22px; color: rgba(255,255,255,0.85); text-shadow: 1px 1px 0 #000; }
@keyframes blink { 50% { opacity: 0; } }

/* Level sections: tall scroll runway, card pinned high on the RIGHT so the
   character (drawn at ~32% from the left) and the scenery stay unobstructed. */
.level-section { min-height: 170vh; position: relative; padding-top: 10vh; }

.card {
  width: min(520px, 43vw);
  margin: 0 clamp(16px, 5vw, 96px) 0 auto;
  background: var(--card-bg);
  border: 4px solid var(--card-border);
  box-shadow: 6px 6px 0 rgba(0,0,0,0.55);
  padding: 20px 24px;
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.5s ease, transform 0.5s ease;
  position: sticky;
  top: 6vh;
}
.card.visible { opacity: 1; transform: translateY(0); }

.card .world-tag {
  font-family: var(--pixel-font);
  font-size: 9px;
  color: var(--accent);
  margin-bottom: 10px;
}
.card h2 {
  font-family: var(--pixel-font);
  font-size: clamp(13px, 2.4vw, 19px);
  line-height: 1.5;
  margin-bottom: 6px;
}
.card .role { font-size: 22px; color: #9fd7ff; margin-bottom: 2px; }
.card .years { font-size: 19px; color: rgba(255,255,255,0.6); margin-bottom: 12px; }
.card p { font-size: 21px; line-height: 1.35; margin-bottom: 10px; color: #f4f4f4; }
.card .facts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.card .fact {
  font-family: var(--pixel-font);
  font-size: 7.5px;
  background: #1b5e20;
  border: 2px solid #66bb6a;
  color: #d7ffd9;
  padding: 6px 8px;
}

.resume-section {
  min-height: 60vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  background: linear-gradient(transparent, rgba(0,0,0,0.85) 40%);
  pointer-events: auto;
}
.resume-section h2 { font-family: var(--pixel-font); font-size: 14px; color: var(--accent); }
.resume-section p { font-size: 24px; }
.resume-section a { color: #9fd7ff; }

/* ===== Chat panel ===== */
.chat-panel {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: min(400px, calc(100vw - 32px));
  height: min(540px, calc(100vh - 100px));
  background: #0e1020;
  border: 4px solid var(--accent);
  box-shadow: 8px 8px 0 rgba(0,0,0,0.6);
  z-index: 40;
  display: flex;
  flex-direction: column;
  transform: translateY(24px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.chat-panel.open { opacity: 1; transform: translateY(0); pointer-events: auto; }

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 3px solid rgba(255, 213, 79, 0.4);
  background: rgba(255, 213, 79, 0.08);
}
.chat-title { display: flex; gap: 10px; align-items: center; }
.chat-avatar { font-size: 26px; }
.chat-name { font-family: var(--pixel-font); font-size: 10px; }
.chat-status { font-size: 16px; color: #9fd7ff; margin-top: 4px; }
.chat-close {
  background: none;
  border: 2px solid #fff;
  color: #fff;
  font-size: 14px;
  width: 30px; height: 30px;
  cursor: pointer;
}
.chat-close:hover { background: #d32f2f; border-color: #d32f2f; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg {
  max-width: 85%;
  padding: 10px 12px;
  font-size: 20px;
  line-height: 1.3;
  border: 2px solid;
  white-space: pre-wrap;
}
.msg-bot { align-self: flex-start; background: #16324f; border-color: #4a90d9; }
.msg-user { align-self: flex-end; background: #2e4620; border-color: #7cb342; }
.msg-error { align-self: flex-start; background: #4a1414; border-color: #d32f2f; color: #ffb4b4; }
.msg-typing { align-self: flex-start; color: #9fd7ff; border: none; font-size: 22px; animation: blink 1s steps(2) infinite; }

.chat-input-row {
  display: flex;
  border-top: 3px solid rgba(255, 213, 79, 0.4);
}
#chat-input {
  flex: 1;
  background: #090a14;
  color: #fff;
  border: none;
  outline: none;
  padding: 12px 14px;
  font-family: var(--body-font);
  font-size: 20px;
}
#chat-send {
  background: var(--accent);
  color: #000;
  border: none;
  padding: 0 18px;
  font-size: 18px;
  cursor: pointer;
}
#chat-send:disabled { opacity: 0.5; cursor: default; }

/* Narrow screens: the card can't sit beside the character, so it goes back to
   centered — pinned to the top and height-capped, while game.js drops the ground
   line to 90% so the character stands below the card instead of behind it.
   Type is sized in vh as well as px so a long blurb can't push past the cap. */
@media (max-width: 900px) {
  .card {
    width: min(600px, 94vw);
    margin: 0 auto;
    padding: 11px 13px;
    top: 9.5vh;         /* clears the stacked HUD above it */
    max-height: 58vh;   /* character starts at ~68vh */
    overflow: hidden;
  }
  .card h2 { font-size: min(14px, 1.82vh); line-height: 1.26; margin-bottom: 4px; }
  .card .role { font-size: min(16.5px, 2.1vh); line-height: 1.2; }
  .card .years { font-size: min(15px, 1.92vh); margin-bottom: 6px; }
  .card p { font-size: min(16.5px, 2.08vh); line-height: 1.21; margin-bottom: 4px; }
  .card .world-tag { font-size: min(8px, 1.15vh); margin-bottom: 5px; }
  .card .facts { gap: 5px; margin-top: 7px; }
  .card .fact { font-size: min(7px, 1.0vh); padding: 4px 5px; border-width: 2px; }
}

@media (max-width: 600px) {
  .hud { padding: 7px 9px; align-items: flex-start; }
  .hud-name { font-size: 9px; }
  /* Stack the buttons so the level label gets the full width of the row,
     and drop the level title (the card heading below already shows it). */
  .hud-left { min-width: 0; flex: 1; }
  .hud-world {
    font-size: 7px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    margin-top: 5px;
  }
  .hud-world .w-title { display: none; }
  .hud-right { flex: 0 0 auto; flex-direction: column; align-items: flex-end; gap: 4px; }
  .hud-btn { font-size: 7px; padding: 5px 6px; white-space: nowrap; }
  .card { padding: 10px 11px; }
}

/* Short landscape phones: almost no vertical room, so trim harder still */
@media (max-height: 480px) {
  .card { top: 2vh; max-height: 62vh; padding: 10px 12px; }
  .card p { font-size: min(16px, 2.6vh); }
}
