/* Refreshed, minimalist responsive UI for character chat */
:root {
  --bg: #f7fafc;
  --card: #ffffff;
  --muted: #94a3b8;
  --accent: #2563eb;
  --accent-2: #7c3aed;
  --success: #16a34a;
  --shadow: 0 8px 24px rgba(2, 6, 23, 0.08);
}

* {
  box-sizing: border-box
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  background: linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
  color: #0f172a;
  display: flex;
  justify-content: center;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;

}

/* Restrict game to a mobile-like viewport */

.mobile-wrapper {
  width: 100%;
  max-width: 480px;
  /* ← target mobile width */
  min-height: 100vh;
  background: linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
  overflow-x: hidden;
  position: relative;
}

.app-shell {
  max-width: 600px;
  width: 100%;
  margin: 18px auto;
  padding: 16px;
  /* constrain overall shell to viewport so inner areas can scroll cleanly */
  min-height: calc(100vh - 36px);
  max-height: calc(100vh - 36px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* keep scroll inside messages area */
}

.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
  margin-bottom: 16px;
}

.title-wrap {
  flex: 1;
  align-items: center;
  text-align: center;
}

.char-name {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700
}

#status-bar {
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-weight: bold;
}

#status-bar.success {
  background-color: #d1fae5;
  color: #065f46;
  border-color: #10b981;
}


.level-nav {
  position: absolute;
  top: 16px;
  right: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid #e6edf3;
  box-shadow: var(--shadow);
  text-decoration: none;
  font-size: 18px
}

.level-nav:hover {
  transform: translateY(-1px)
}

/* image inside level-nav */
.level-nav .level-icon {
  display: block;
  max-width: 70%;
  max-height: 70%;
  width: auto;
  height: auto;
}

/* visual success state */

.level-nav.attention {
  background: #22c55e;
  border-color: #16a34a;
  color: #ffffff;
  transform: scale(1.08);
  box-shadow: 0 0 0 4px rgba(34, 197, 94, .35), 0 8px 24px rgba(2, 6, 23, .25);
  animation: blinkGreen 1.2s ease-in-out infinite;
}

@keyframes blinkGreen {

  0%,
  100% {
    filter: brightness(1);
    box-shadow: 0 0 0 4px rgba(34, 197, 94, .35), 0 8px 24px rgba(2, 6, 23, .25);
  }

  50% {
    filter: brightness(1.15);
    box-shadow: 0 0 0 6px rgba(34, 197, 94, .55), 0 10px 28px rgba(2, 6, 23, .35);
  }
}

.card {
  background: var(--card);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  /* allow children to shrink */
  max-height: 100%;
  overflow: hidden;
  /* ensure inner messages area handles scrolling */
}

.character-top {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding-bottom: 8px
}

.character-image img {
  width: 150px;
  height: 150px;
  object-fit: cover;
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(2, 6, 23, 0.06)
}

.character-image img.hidden {
  display: none
}

.chat-area {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  /* prevent double scrollbars */
}

.chat-controls {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 6px
}

.icon-btn {
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer
}

.icon-btn:hover {
  background: #eef2ff
}

.messages {
  flex: 1;
  overflow: auto;
  border-radius: 10px;
  padding: 12px;
  background: linear-gradient(180deg, #fbfdff, #ffffff);
  border: 1px solid #eef2f6;
  min-height: 0;
  /* allow to shrink within the card */
  /* scroll only here */
}

/* Reuse bubble styles but tweak sizes */
.speech-row {
  display: flex;
  margin: 8px 0
}

.speech-row.left {
  justify-content: flex-start
}

.speech-row.right {
  justify-content: flex-end
}

.bubble {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.35;
  box-shadow: 0 4px 10px rgba(2, 6, 23, 0.04);
  word-wrap: break-word
}

.bubble.agent {
  background: #e8e8e8;
  color: #0f172a;
  margin-left: 6px;
  border-radius: 14px
}

.bubble.agent::after {
  content: "";
  position: absolute
}

.bubble.user {
  background: linear-gradient(180deg, var(--accent), #034bbd);
  color: #fff;
  margin-right: 6px;
  border-radius: 14px
}

.bubble.agent.thinking {
  animation: pulse 1.1s ease-in-out infinite;
  background: linear-gradient(180deg, #f1f6ff, #fbfdff)
}

@keyframes pulse {
  0% {
    transform: translateY(0)
  }

  50% {
    transform: translateY(-3px)
  }

  100% {
    transform: translateY(0)
  }
}

/* Composer */
.composer {
  display: flex;
  gap: 8px;
  padding: 10px;
  margin-top: 10px;
  border-top: 1px solid #eef2f6
}

.msg-input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid #e6eef7;
  background: #fbfdff;
  font-size: 1rem
}

.msg-input:focus {
  outline: none;
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.08);
  border-color: var(--accent)
}

.send-btn {
  background: linear-gradient(180deg, var(--accent), #0b5ed7);
  color: #fff;
  border: none;
  padding: 0 18px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600
}

.send-btn:active {
  transform: translateY(1px)
}

/* keep old ID selector compatibility */
#log {
  padding: 12px
}

#log::-webkit-scrollbar {
  height: 8px;
  width: 8px
}

#log::-webkit-scrollbar-thumb {
  background: rgba(2, 6, 23, 0.12);
  border-radius: 6px
}

/* World map hub on index.html */
.world-map {
  position: fixed;
  inset: 0;
  background: #f8fafc;
  border: 2px dashed #e2e8f0;
  overflow: hidden;
}

/* Map background image that fills the map area without stretching */
.map-background {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 100%;
  height: 100%;
  transform: translate(-50%, -50%);
  object-fit: contain;
  /* maintain aspect ratio and cover entire area */
  object-position: center center;
  pointer-events: none;
  z-index: 0;
}

.char-marker {
  position: absolute;
  width: 192px;
  height: 192px;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform .15s ease;
  z-index: 10;
}

.char-marker:hover {
  transform: translate(-50%, -50%) scale(1.20);
}

/* circular ring around the GIF for clickable indication */
.char-marker::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: calc(100% + 16px);
  height: calc(100% + 16px);
  border-radius: 50%;
  border: 4px solid rgba(37, 99, 235, 0.9);
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.06);
  transition: transform .15s ease, border-color .15s ease, opacity .15s ease;
  pointer-events: none;
  z-index: 11;
}

.char-gif {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  box-shadow: 0 10px 18px rgba(2, 6, 23, .16);
  z-index: 12;
}

.char-marker.unavailable {
  pointer-events: none;
  opacity: .8;
}

.char-marker.unavailable .char-gif {
  opacity: .45;
  filter: grayscale(1) drop-shadow(0 4px 10px rgba(2, 6, 23, .12));
}

.char-marker.unavailable::before {
  border-color: rgba(2, 6, 23, 0.06);
  opacity: .6;
}

.level-hub {
  display: flex;
  flex-direction: column;
}

.level-row {
  display: flex;
  align-items: center;
  position: relative;
  padding: 20px 20px;
  gap: 20px;
}

.level-circle {
  width: 48px;
  height: 48px;
  background: #ffe27a;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: bold;
  border: 3px solid #d7b14c;
  z-index: 5;
}

.level-left-image img {
  width: 64px;
  height: auto;
}

.characters {
  display: flex;
}

.characters img {
  width: 80px;
  height: auto;
  cursor: pointer;
  transition: transform .12s ease;
}

.characters img:hover {
  transform: translateY(-6px) scale(1.03);
}

.characters img.unavailable {
  opacity: 0.4;
  filter: grayscale(100%);
}

.title-image {
  width: 100%;
  height: auto;
  max-height: 50vh;
  object-fit: cover;
  display: block;
}