: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);
  font-family: "Segoe UI", "Noto Sans TC", "PingFang TC", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: #0b141a;
}

#app.chat-app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  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;
  margin-bottom: 0.6rem;
}

.chat-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.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;
  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--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-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;
}

.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;
}

.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);
}

.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;
  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-banner {
  position: sticky;
  bottom: 0;
  margin: 0.4rem 0.5rem 0.15rem;
  padding: 0.75rem 0.85rem;
  border-radius: 0.7rem;
  background: linear-gradient(
    135deg,
    #e40303,
    #ff8c00,
    #ffed00,
    #008026,
    #24408e,
    #732982
  );
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  box-shadow: var(--shadow);
  z-index: 3;
}

.install-banner-title,
.install-banner-body,
.install-banner-hint {
  margin: 0 0 0.35rem;
}

.install-banner-title {
  font-weight: 700;
  font-size: 0.95rem;
}

.install-banner-body,
.install-banner-hint {
  font-size: 0.82rem;
  line-height: 1.4;
}

.install-banner-hint {
  margin-bottom: 0.55rem;
}

.install-banner-actions {
  display: flex;
  gap: 0.45rem;
  justify-content: flex-end;
}

.install-banner-dismiss,
.install-banner-install {
  border: 0;
  border-radius: 0.5rem;
  padding: 0.4rem 0.7rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.install-banner-dismiss {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.install-banner-install {
  background: #fff;
  color: #732982;
}

.unsupported-browser {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.25rem;
  color: #fff;
  text-align: center;
  font-size: 1.05rem;
}

#app.consent-screen,
#app.language-screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 40rem;
  margin: 0 auto;
  background: var(--chat-bg);
  color: var(--text);
}

.consent-header,
.language-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 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.consent-main {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1.25rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.consent-intro,
.consent-declined {
  margin: 0;
  line-height: 1.5;
}

.consent-placeholder {
  margin: 0;
  padding: 1rem 0.95rem;
  border-radius: 0.7rem;
  border: 2px dashed #c9a227;
  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;
}

.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-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  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-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,
.route-choice-map {
  width: 100%;
  background: #dce6dc;
}

.map-overlay-canvas {
  flex: 1 1 auto;
  min-height: 0;
}

.route-choice-map-hint {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--muted);
}

.route-choice-map {
  height: 14rem;
  border-radius: 0.7rem;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.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-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-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;
  }
}
