/* ===================================================================
   Korea Life RPG — Minimal Design (Apple / Airbnb style)
   =================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Noto+Sans+KR:wght@400;500;600;700&display=swap');

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

:root {
  --bg: #FAFAFA;
  --surface: #FFFFFF;
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.15);
  --text: #1D1D1F;
  --text-muted: #6E6E73;
  --text-subtle: #A1A1A6;
  --accent: #0071E3;
  --success: #34C759;
  --success-bg: #E9F9EE;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.12);
}

body {
  font-family: 'Inter', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.5;
}

/* ===================================================================
   MENU SCREEN
   =================================================================== */

.menu-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  max-width: 1000px;
  margin: 0 auto;
}

.menu-eyebrow {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--text-subtle);
  text-transform: uppercase;
  margin-bottom: 12px;
  animation: fadeIn 0.6s ease;
}

h1 {
  font-size: 44px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
  letter-spacing: -0.02em;
  text-align: center;
  animation: fadeIn 0.6s ease 0.1s backwards;
}

.subtitle {
  color: var(--text-muted);
  font-size: 18px;
  font-weight: 400;
  margin-bottom: 48px;
  text-align: center;
  animation: fadeIn 0.6s ease 0.2s backwards;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.progress-bar-wrap {
  width: 100%;
  max-width: 900px;
  margin-bottom: 32px;
  animation: fadeIn 0.6s ease 0.3s backwards;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.progress-track {
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--text);
  transition: width 0.4s ease;
  border-radius: 999px;
}

.missions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  width: 100%;
  max-width: 900px;
}

.mission-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 28px 24px;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  animation: cardIn 0.5s ease backwards;
}

.mission-card:nth-child(1) { animation-delay: 0.40s; }
.mission-card:nth-child(2) { animation-delay: 0.45s; }
.mission-card:nth-child(3) { animation-delay: 0.50s; }
.mission-card:nth-child(4) { animation-delay: 0.55s; }
.mission-card:nth-child(5) { animation-delay: 0.60s; }
.mission-card:nth-child(6) { animation-delay: 0.65s; }
.mission-card:nth-child(7) { animation-delay: 0.70s; }
.mission-card:nth-child(8) { animation-delay: 0.75s; }
.mission-card:nth-child(9) { animation-delay: 0.80s; }

@keyframes cardIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.mission-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.mission-card:active {
  transform: translateY(0);
}

.mission-icon {
  display: block;
  width: 44px;
  height: 44px;
  margin-bottom: 20px;
  color: var(--accent);
}

.mission-icon svg {
  display: block;
  width: 44px;
  height: 44px;
}

.mission-title {
  color: var(--text);
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 6px;
  letter-spacing: -0.01em;
}

.mission-desc {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.5;
  font-weight: 400;
}

.mission-status {
  position: absolute;
  top: 20px;
  right: 20px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--bg);
  color: var(--text-subtle);
  letter-spacing: 0.02em;
}

.mission-status.cleared {
  background: var(--success-bg);
  color: var(--success);
}

.mission-card.cleared {
  border-color: var(--success);
  background: var(--success-bg);
}

.footer {
  color: var(--text-subtle);
  font-size: 13px;
  margin-top: 48px;
  text-align: center;
  font-weight: 400;
}

/* ===================================================================
   MODE TOGGLE (단기 / 장기)
   =================================================================== */

.mode-toggle {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  gap: 4px;
  margin-bottom: 10px;
  animation: fadeIn 0.6s ease 0.25s backwards;
}

.mode-btn {
  padding: 10px 28px;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  width: auto;
  transition: all 0.2s ease;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.mode-btn.active {
  background: var(--text);
  color: var(--surface);
}

.mode-btn:hover:not(.active) {
  color: var(--text);
}

.mode-btn:active {
  transform: scale(0.97);
}

.mode-desc {
  font-size: 13px;
  color: var(--text-subtle);
  margin-bottom: 28px;
  font-weight: 400;
  animation: fadeIn 0.6s ease 0.28s backwards;
}

/* ===================================================================
   STEP BADGE
   =================================================================== */

.step-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--text-subtle);
  text-transform: uppercase;
  display: block;
  margin-bottom: 10px;
}

.mission-card.cleared .step-badge {
  color: var(--success);
}

/* ===================================================================
   LOCKED MISSION CARD
   =================================================================== */

.mission-card.locked {
  opacity: 0.42;
  cursor: not-allowed;
  filter: grayscale(0.25);
}

.mission-card.locked:hover {
  transform: none;
  box-shadow: none;
  border-color: var(--border);
}

/* ===================================================================
   LOCKED TOAST NOTIFICATION
   =================================================================== */

#locked-toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: rgba(29, 29, 31, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: white;
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 300;
  white-space: nowrap;
  max-width: calc(100vw - 40px);
  text-align: center;
  text-overflow: ellipsis;
  overflow: hidden;
}

#locked-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===================================================================
   GAME SCREEN
   =================================================================== */

#game {
  position: fixed;
  top: 48px; /* clear the mission HUD */
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
}

#background {
  position: absolute;
  inset: 0;
  background-repeat: no-repeat;
  background-position: top center;
  background-size: cover;
  transition: background-image 0.5s ease;
}

#background::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0.4) 100%);
  pointer-events: none;
}

#dialogue {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 80px);
  max-width: 780px;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: var(--text);
  padding: 28px 32px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 10;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

#text {
  margin-bottom: 20px;
  font-size: 17px;
  font-weight: 500;
  min-height: 48px;
  white-space: pre-line;
  word-break: keep-all;
  line-height: 1.6;
  color: var(--text);
  letter-spacing: -0.01em;
  cursor: pointer;
}

#choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

button {
  padding: 14px 20px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  transition: all 0.15s ease;
  text-align: left;
  width: 100%;
  letter-spacing: -0.01em;
  word-break: keep-all;
  line-height: 1.5;
}

button:hover {
  background: var(--bg);
  border-color: var(--border-strong);
}

button:active {
  transform: scale(0.99);
}


#hint {
  font-size: 15px;
  color: var(--text);
  text-align: center;
  display: none;
  margin-top: 8px;
  font-weight: 500;
  cursor: pointer;
  padding: 14px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
  letter-spacing: -0.01em;
  width: 100%;
  box-sizing: border-box;
}

#hint:hover {
  background: var(--bg);
  border-color: var(--border-strong);
}

/* ===================================================================
   IN-DIALOGUE WORD TOOLTIPS
   =================================================================== */

.word-tip {
  color: var(--accent);
  text-decoration: underline dotted var(--accent);
  text-underline-offset: 3px;
  cursor: pointer;
  position: relative;
  display: inline;
  border-radius: 3px;
  transition: background 0.1s ease;
}

.word-tip:hover,
.word-tip.active {
  background: rgba(0, 113, 227, 0.08);
}

.word-tip::after {
  content: attr(data-en);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #1D1D1F;
  color: #fff;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  font-style: normal;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease, transform 0.15s ease;
  transform: translateX(-50%) translateY(4px);
  z-index: 30;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

.word-tip::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #1D1D1F;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 30;
}

.word-tip.active::after,
.word-tip.active::before {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===================================================================
   MISSION HUD
   =================================================================== */

#mission-hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 48px;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 16px;
  z-index: 40;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

#hud-title {
  flex: 1;
  text-align: center;
  color: rgba(255, 255, 255, 0.92);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.hud-spacer {
  width: 72px; /* mirrors back-btn width so title stays centered */
}

/* ===================================================================
   BACK BUTTON (inside HUD)
   =================================================================== */

#back-btn {
  padding: 7px 14px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  z-index: 50;
  transition: all 0.15s ease;
  width: auto;
  white-space: nowrap;
  flex-shrink: 0;
}

#back-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  transform: none;
}

/* ===================================================================
   VOCABULARY SCREEN
   =================================================================== */

#vocab-screen {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 20, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 200;
  padding: 20px;
  animation: overlayFade 0.3s ease;
}

#vocab-panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 36px 40px 32px;
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 32px 64px rgba(0, 0, 0, 0.5);
  animation: popIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  gap: 0;
}

.vocab-eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-subtle);
  margin-bottom: 8px;
}

.vocab-heading {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.vocab-hint {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 24px;
  line-height: 1.5;
}

#vocab-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 28px;
}

.vocab-card {
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  user-select: none;
}

.vocab-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.vocab-card.revealed {
  border-color: var(--accent);
  background: #EFF6FF;
}

.vocab-kr {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.vocab-rom {
  font-size: 11px;
  color: var(--text-subtle);
  font-style: italic;
  line-height: 1.3;
}

.vocab-divider {
  display: block;
  height: 1px;
  background: var(--border);
  margin: 8px 0 4px;
  transition: background 0.2s ease;
}

.vocab-card.revealed .vocab-divider {
  background: rgba(0, 113, 227, 0.2);
}

.vocab-en {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
  line-height: 1.4;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.3s ease, opacity 0.25s ease;
}

.vocab-card.revealed .vocab-en {
  max-height: 60px;
  opacity: 1;
  color: var(--accent);
}

#vocab-start-btn {
  width: 100%;
  padding: 16px 24px;
  background: var(--text);
  color: var(--surface);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  letter-spacing: -0.01em;
  transition: all 0.15s ease;
}

#vocab-start-btn:hover {
  background: #000;
  transform: none;
}

/* ===================================================================
   USER PROFILE MODAL
   =================================================================== */

#profile-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 500;
  padding: 20px;
  animation: overlayFade 0.3s ease;
}

#profile-overlay.active {
  display: flex;
}

#profile-panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 36px 40px 32px;
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 32px 64px rgba(0, 0, 0, 0.35);
  animation: popIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  gap: 0;
}

.profile-eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-subtle);
  margin-bottom: 8px;
}

.profile-heading {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.profile-subheading {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 28px;
  line-height: 1.5;
}

.form-group {
  margin-bottom: 18px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  letter-spacing: -0.01em;
}

.form-label .form-required {
  color: #FF3B30;
  margin-left: 2px;
}

.form-input,
.form-select {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s ease;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236E6E73' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
  cursor: pointer;
}

.form-input:focus,
.form-select:focus {
  border-color: var(--accent);
}

.form-input.error,
.form-select.error {
  border-color: #FF3B30;
}

.form-radio-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.radio-option {
  flex: 1;
  min-width: 120px;
}

.radio-option input[type="radio"] {
  display: none;
}

.radio-option label {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 11px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
  width: 100%;
}

.radio-option input[type="radio"]:checked + label {
  border-color: var(--text);
  background: var(--text);
  color: var(--surface);
}

.form-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 0 18px;
}

#arrival-group {
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.25s ease;
}

#profile-submit {
  width: 100%;
  padding: 15px 24px;
  background: var(--text);
  color: var(--surface);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  letter-spacing: -0.01em;
  transition: all 0.15s ease;
  margin-top: 8px;
}

#profile-submit:hover {
  background: #000;
  transform: none;
}

.profile-error-msg {
  font-size: 12px;
  color: #FF3B30;
  margin-top: 4px;
  display: none;
}

/* Profile button on menu */
#profile-btn {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 9px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  width: auto;
  z-index: 10;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
  display: none;
}

#profile-btn:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

/* ===================================================================
   MISSION COMPLETE POPUP
   =================================================================== */

#missionComplete {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 999;
  animation: overlayFade 0.3s ease;
}

@keyframes overlayFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.popup-box {
  background: var(--surface);
  color: var(--text);
  padding: 40px 48px;
  border-radius: var(--radius-lg);
  text-align: center;
  box-shadow: var(--shadow-lg);
  max-width: 420px;
  width: 90%;
  animation: popIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

.popup-box h2 {
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 12px;
  color: var(--text);
  letter-spacing: -0.02em;
}

.popup-box p {
  font-size: 15px;
  margin: 8px 0;
  color: var(--text-muted);
  line-height: 1.6;
  font-weight: 400;
}

.popup-box p:last-of-type {
  font-size: 13px;
  color: var(--text-subtle);
  margin-top: 24px;
}

/* ===================================================================
   CHATBOT
   =================================================================== */

#chatbot-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--text);
  border: none;
  cursor: pointer;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: white;
  box-shadow: var(--shadow-md);
  transition: all 0.2s ease;
  padding: 0;
}

#chatbot-toggle:hover {
  transform: scale(1.05);
  box-shadow: var(--shadow-lg);
  background: #000;
}

#chatbot-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 540px;
  max-height: calc(100vh - 140px);
  background: var(--surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: none;
  flex-direction: column;
  z-index: 100;
  overflow: hidden;
  animation: panelIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

#chatbot-panel.open {
  display: flex;
}

@keyframes panelIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

#chatbot-header {
  background: var(--surface);
  color: var(--text);
  padding: 16px 20px;
  font-weight: 600;
  font-size: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.01em;
}

#chatbot-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 0;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background 0.15s ease;
}

#chatbot-close:hover {
  background: var(--bg);
  transform: none;
}

#chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg);
}

.chat-msg {
  padding: 10px 14px;
  border-radius: 14px;
  max-width: 85%;
  font-size: 14px;
  line-height: 1.55;
  word-wrap: break-word;
  word-break: keep-all;
  animation: msgIn 0.2s ease;
  letter-spacing: -0.005em;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-msg.user {
  background: var(--text);
  color: var(--surface);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.chat-msg.bot {
  background: var(--surface);
  color: var(--text);
  align-self: flex-start;
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  white-space: pre-wrap;
}

.chat-msg.bot strong {
  font-weight: 600;
}

.chat-msg.bot em {
  font-style: italic;
}

.chat-msg.bot code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
}

.chat-msg.typing {
  color: var(--text-subtle);
  font-style: italic;
}

#chatbot-input-wrap {
  display: flex;
  gap: 8px;
  padding: 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

#chatbot-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  color: var(--text);
  background: var(--bg);
}

#chatbot-input:focus {
  border-color: var(--text);
  background: var(--surface);
}

#chatbot-send {
  padding: 0 18px;
  background: var(--text);
  color: var(--surface);
  border: none;
  border-radius: 20px;
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
  width: auto;
  letter-spacing: -0.01em;
}

#chatbot-send:hover {
  background: #000;
  transform: none;
}

#chatbot-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ===================================================================
   RESPONSIVE
   =================================================================== */

@media (max-width: 640px) {
  h1 { font-size: 32px; }
  .subtitle { font-size: 16px; margin-bottom: 32px; }
  .missions { grid-template-columns: 1fr; }
  .mission-card { padding: 24px 20px; }

  #game { top: 44px; }
  #mission-hud { height: 44px; }
  #hud-title { font-size: 13px; }

  #dialogue {
    bottom: 20px;
    width: calc(100% - 32px);
    padding: 20px;
  }

  #text { font-size: 15px; }
  button { padding: 12px 16px; font-size: 14px; }

  .popup-box { padding: 32px 24px; }
  .popup-box h2 { font-size: 24px; }

  #vocab-panel { padding: 28px 20px 24px; }
  #vocab-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .vocab-heading { font-size: 18px; }

  #chatbot-panel {
    width: calc(100vw - 24px);
    right: 12px;
    bottom: 88px;
    height: 480px;
  }

  #chatbot-toggle {
    width: 52px;
    height: 52px;
    bottom: 20px;
    right: 20px;
    font-size: 20px;
  }
}

/* Portrait phones: keep the full-screen background; crop horizontally from center
   so subjects in center-composed scenes stay visible. Cap dialogue height so
   the background image is not fully obscured when many choices appear. */
@media (max-width: 640px) and (orientation: portrait) {
  #background {
    background-position: center center;
  }

  #dialogue {
    max-height: 52vh;
    overflow-y: auto;
  }
}
