:root {
  color-scheme: light;
  --chat-bg: #ece5dd;
  --header-bg: #075e54;
  --header-fg: #ffffff;
  --system-bg: #ffffff;
  --player-bg: #dcf8c6;
  --text: #111b21;
  --muted: #667781;
  --accent: #128c7e;
  --composer-bg: #f0f2f5;
  --shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  --map-route-a: #732982;
  font-family: "Segoe UI", "Noto Sans TC", "PingFang TC", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #0b141a;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

button,
a,
input {
  touch-action: manipulation;
}

#app.chat-app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  max-width: 40rem;
  margin: 0 auto;
  background: var(--chat-bg);
  background-image: radial-gradient(
    rgba(255, 255, 255, 0.18) 0.6px,
    transparent 0.6px
  );
  background-size: 12px 12px;
}

.chat-header {
  flex: 0 0 auto;
  background: var(--header-bg);
  color: var(--header-fg);
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-top));
  padding-top: calc(0.75rem + env(safe-area-inset-top));
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  z-index: 2;
}

.chat-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.header-identity {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  flex: 1;
}

.header-avatar {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  flex: 0 0 auto;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.2);
}

.chat-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  min-width: 0;
  flex: 1;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-height: 1.25;
}

.pride-progress {
  display: flex;
  gap: 0.4rem;
  justify-content: space-between;
}

.pride-letter {
  flex: 1;
  text-align: center;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.35rem 0;
  border-radius: 0.4rem;
  background: rgba(255, 255, 255, 0.12);
  font-size: 0.85rem;
}

.pride-letter.is-complete {
  background: #25d366;
  color: #073b2a;
}

.chat-transcript {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0.85rem 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.bubble-row {
  display: flex;
  width: 100%;
}

.bubble-row--system {
  justify-content: flex-start;
}

.bubble-row--player {
  justify-content: flex-end;
}

.bubble {
  max-width: 82%;
  padding: 0.55rem 0.7rem;
  border-radius: 0.7rem;
  box-shadow: var(--shadow);
  color: var(--text);
  line-height: 1.45;
}

.bubble--system {
  background: var(--system-bg);
  border-top-left-radius: 0.15rem;
}

.bubble--pride-progress {
  max-width: 100%;
  padding: 0.5rem 0.55rem;
}

.pride-pills {
  display: flex;
  gap: 0.35rem;
  align-items: stretch;
  justify-content: space-between;
}

.pride-pill {
  flex: 1 1 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.12em;
  min-width: 2.5rem;
  padding: 0.45rem 0.9rem;
  border-radius: 0.45rem;
  border: 1px solid #d4dbd6;
  background: #eef1ef;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  line-height: 1.2;
  white-space: nowrap;
}

.pride-pill.is-complete {
  background: #d4f5e2;
  border-color: #8ed9ad;
  color: #0b6b3a;
}

.bubble--player {
  background: var(--player-bg);
  border-top-right-radius: 0.15rem;
}

.bubble-text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.95rem;
}

.bubble-nav {
  display: inline-block;
  margin-top: 0.45rem;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.95rem;
}

.bubble-image,
.bubble-embed {
  display: block;
  width: 100%;
  border-radius: 0.45rem;
  margin-bottom: 0.45rem;
  border: 0;
}

.bubble-embed {
  aspect-ratio: 16 / 9;
  min-height: 10rem;
}

.bubble-image--player {
  margin-bottom: 0;
  max-width: 12rem;
  max-height: 16rem;
  object-fit: cover;
}

.bubble-image-wrap {
  position: relative;
  display: inline-block;
  line-height: 0;
  max-width: 12rem;
}

.bubble-image-wrap .bubble-image--player {
  max-width: 100%;
}

.bubble-image-sending {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.45rem;
  background: rgba(17, 27, 33, 0.45);
}

.bubble-image-spinner {
  width: 1.45rem;
  height: 1.45rem;
  border: 0.18rem solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: bubble-image-spin 0.8s linear infinite;
}

@keyframes bubble-image-spin {
  to {
    transform: rotate(360deg);
  }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.file-input-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  z-index: -1;
}

.bubble-image-placeholder {
  aspect-ratio: 16 / 9;
  min-height: 7rem;
  margin-bottom: 0.45rem;
  border-radius: 0.45rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: #fff;
  background: linear-gradient(
    135deg,
    #e40303,
    #ff8c00,
    #ffed00,
    #008026,
    #24408e,
    #732982
  );
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.bubble-content-image {
  display: block;
  width: 100%;
  margin: 0 0 0.45rem;
}

.bubble-content-image .bubble-image-placeholder,
.bubble-content-image .bubble-image {
  margin-bottom: 0;
}

.bubble-content-image .bubble-image {
  display: none;
}

.bubble-content-image.is-ready .bubble-image-placeholder {
  display: none;
}

.bubble-content-image.is-ready .bubble-image {
  display: block;
}

.bubble-route-map {
  display: block;
  width: 100%;
  margin: 0 0 0.45rem;
  padding: 0;
  border: 0;
  background: transparent;
}

.bubble-route-map-hit {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 7rem;
  padding: 0;
  border: 0;
  border-radius: 0.45rem;
  overflow: hidden;
  cursor: pointer;
  background: transparent;
}

.bubble-route-map-hit:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.bubble-route-map .bubble-image-placeholder {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  aspect-ratio: auto;
  border-radius: 0;
}

.bubble-route-map-canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  opacity: 0;
  pointer-events: none;
}

.bubble-route-map.is-ready .bubble-image-placeholder {
  visibility: hidden;
  pointer-events: none;
}

.bubble-route-map.is-ready .bubble-route-map-canvas {
  z-index: 2;
  opacity: 1;
}

.bubble-route-map-credit {
  display: none;
  margin: 0.3rem 0 0;
  font-size: 0.72rem;
  line-height: 1.35;
  color: var(--muted);
}

.bubble-route-map-credit[hidden] {
  display: none;
}

.bubble-route-map.is-ready .bubble-route-map-credit:not([hidden]) {
  display: block;
}

.bubble-route-map-credit a {
  color: var(--accent);
}

.bubble-route-map .map-checkpoint-badge {
  width: 28px;
  height: 28px;
  font-size: 0.75rem;
}

.completion-code {
  margin: 0.75rem 0 0;
  padding: 0.7rem 0.85rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 0.35rem;
  font-size: 0.95rem;
  color: var(--text);
  background: #fffbe6;
  border: 2px solid var(--accent);
  border-radius: 0.55rem;
  text-align: center;
}

.completion-code-label {
  font-weight: 600;
  letter-spacing: 0;
}

.completion-code-value {
  font-family: ui-monospace, "Cascadia Mono", monospace;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: #111b21;
}

.typing-indicator {
  display: flex;
  gap: 0.25rem;
  align-items: center;
  min-width: 3.2rem;
  min-height: 1.6rem;
}

.typing-indicator span {
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: #8696a0;
  animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typing-bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  30% {
    transform: translateY(-0.2rem);
    opacity: 1;
  }
}

.chat-composer {
  flex: 0 0 auto;
  background: var(--composer-bg);
  padding: 0.55rem 0.7rem calc(0.55rem + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.composer-form {
  display: flex;
  gap: 0.45rem;
}

.composer-input {
  flex: 1;
  border: 0;
  border-radius: 1.2rem;
  padding: 0.55rem 0.9rem;
  font: inherit;
  font-size: 16px;
  background: #fff;
}

.composer-send {
  width: 2.5rem;
  height: 2.5rem;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
}

.choice-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.choice-button {
  border: 0;
  border-radius: 0.7rem;
  padding: 0.7rem 0.85rem;
  background: #fff;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.choice-button:disabled {
  opacity: 0.65;
  cursor: wait;
}

.choice-button:active {
  background: #e7ffee;
}

.composer-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.composer-hint a {
  color: var(--accent);
}

.offline-toast {
  position: fixed;
  left: 50%;
  bottom: calc(5.5rem + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(1rem);
  max-width: calc(100% - 2rem);
  padding: 0.65rem 0.95rem;
  border-radius: 0.7rem;
  background: #111b21;
  color: #fff;
  font-size: 0.85rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  z-index: 20;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.offline-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.install-overlay {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  padding-top: max(1.25rem, env(safe-area-inset-top));
  padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
  background: rgba(11, 20, 26, 0.55);
}

.install-banner {
  flex: 0 1 auto;
  width: min(22rem, 100%);
  margin: 0;
  padding: 0;
  overflow: hidden;
  border-radius: 0.7rem;
  background: var(--system-bg);
  color: var(--text);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
}

.install-banner-title {
  margin: 0;
  padding: 0.75rem 1rem;
  background: var(--header-bg);
  color: var(--header-fg);
  font-size: 1.05rem;
  font-weight: 600;
}

.install-banner-body {
  margin: 0;
  padding: 0.85rem 1rem;
  font-size: 0.95rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.install-banner-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: var(--composer-bg);
  padding: 0.75rem 0.9rem;
}

.install-banner-dismiss {
  width: 100%;
  border: 0;
  border-radius: 0.7rem;
  padding: 0.8rem 0.9rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow);
}

.install-banner-continue {
  width: 100%;
  border: 0;
  border-radius: 0.7rem;
  padding: 0.8rem 0.9rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: #fff;
  color: var(--accent);
  box-shadow: var(--shadow);
}

.unsupported-browser {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  padding: 2rem 1.25rem;
  color: #fff;
  text-align: center;
  font-size: 1.05rem;
}

.unsupported-browser-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.unsupported-browser-body {
  margin: 0;
  max-width: 22rem;
  font-size: 0.95rem;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.88);
}

.unsupported-browser-action {
  display: inline-block;
  margin-top: 0.35rem;
  padding: 0.75rem 1.1rem;
  border-radius: 0.7rem;
  background: #128c7e;
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}

button.unsupported-browser-action {
  appearance: none;
  border: 0;
  font: inherit;
  cursor: pointer;
}

#app.consent-screen,
#app.language-screen,
#app.closed-screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  max-width: 40rem;
  margin: 0 auto;
  background: var(--chat-bg);
  color: var(--text);
}

.consent-header,
.language-header,
.closed-header {
  flex: 0 0 auto;
  background: var(--header-bg);
  color: var(--header-fg);
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-top));
  padding-top: calc(0.75rem + env(safe-area-inset-top));
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.consent-title,
.language-title,
.closed-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.consent-main {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 1.25rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.consent-legal-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.consent-intro,
.consent-declined {
  margin: 0;
  line-height: 1.5;
}

.consent-placeholder {
  margin: 0;
  padding: 1rem 0.95rem;
  border-radius: 0.7rem;
  background: #fff;
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.92rem;
  line-height: 1.5;
}

.consent-declined {
  padding: 0.9rem 0.95rem;
  border-radius: 0.7rem;
  background: #fff;
  box-shadow: var(--shadow);
  font-weight: 600;
}

.closed-main {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 1.25rem 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  text-align: center;
}

.closed-figure {
  margin: 0;
  width: 100%;
}

.closed-image {
  display: block;
  width: 100%;
  max-height: 18rem;
  object-fit: contain;
  border-radius: 0.7rem;
  background: #1b1224;
  box-shadow: var(--shadow);
}

.closed-text {
  align-self: stretch;
  margin: 0;
  padding: 0.9rem 0.95rem;
  border-radius: 0.7rem;
  background: #fff;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  font-size: 0.98rem;
  line-height: 1.5;
  text-align: center;
}

.closed-text p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.consent-actions,
.language-actions {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: var(--composer-bg);
  padding: 0.75rem 0.9rem calc(0.75rem + env(safe-area-inset-bottom));
}

#app.language-screen .language-actions {
  margin-top: auto;
}

.consent-agree,
.consent-decline,
.language-choice {
  border: 0;
  border-radius: 0.7rem;
  padding: 0.8rem 0.9rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.consent-agree,
.language-choice {
  background: var(--accent);
  color: #fff;
}

.consent-decline {
  background: #fff;
  color: var(--muted);
}

.map-open-button {
  flex: 0 0 auto;
  width: 2.4rem;
  height: 2.4rem;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.map-open-button:focus-visible,
.map-overlay-close:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.map-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  background: #fff;
}

.map-overlay[hidden] {
  display: none;
}

.map-overlay-chrome {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: var(--header-bg);
  color: var(--header-fg);
  padding: 0.65rem 0.85rem;
  padding-top: calc(0.65rem + env(safe-area-inset-top));
}

.map-overlay-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.map-overlay-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.map-overlay-close {
  width: 2.2rem;
  height: 2.2rem;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.map-overlay-canvas {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  background: #dce6dc;
}

.map-checkpoint.leaflet-div-icon,
.map-user.leaflet-div-icon {
  background: transparent;
  border: none;
}

.map-checkpoint-badge {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-weight: 800;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.map-checkpoint.is-pending .map-checkpoint-badge {
  background: #fff;
  color: #732982;
  border: 2px solid #732982;
}

.map-checkpoint.is-next .map-checkpoint-badge {
  background: #ffed00;
  color: #3d3200;
  border: 2px solid #c9a000;
}

.map-checkpoint.is-complete .map-checkpoint-badge {
  background: #25d366;
  color: #073b2a;
  border: 2px solid #073b2a;
}

.map-checkpoint-check {
  position: absolute;
  right: -0.15rem;
  top: -0.15rem;
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
  background: #073b2a;
  color: #fff;
  font-size: 0.55rem;
  line-height: 0.9rem;
  text-align: center;
}

.map-checkpoint-nav {
  display: inline-block;
  margin-top: 0.35rem;
  padding: 0.2rem 0;
  color: var(--accent);
  font-weight: 600;
}

.map-route-arrow.leaflet-div-icon {
  background: transparent;
  border: none;
  pointer-events: none;
}

.map-route-arrow-head {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-origin: 50% 50%;
}

.map-route-arrow-head::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 12px solid var(--map-route-a);
  transform: translate(-50%, -55%);
  filter: drop-shadow(0 0 1px #fff);
}

.map-route-arrow.is-compact .map-route-arrow-head::before {
  border-left-width: 5px;
  border-right-width: 5px;
  border-bottom-width: 9px;
}

.map-user {
  pointer-events: auto;
}

.map-user-dot {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #2a81cb;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(42, 129, 203, 0.45);
}

.map-user-pulse {
  position: absolute;
  top: 0;
  left: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(42, 129, 203, 0.28);
  animation: map-user-pulse 1.8s ease-out infinite;
}

@keyframes map-user-pulse {
  0% {
    transform: scale(0.55);
    opacity: 0.9;
  }
  100% {
    transform: scale(1.35);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .map-user-pulse {
    animation: none;
  }

  .bubble-image-spinner {
    animation: none;
  }
}
