:root {
  --ink: #4a3b3c;
  --ink-soft: #7c6769;
  --card-bg: rgba(255, 252, 248, 0.82);
  --card-border: rgba(255, 255, 255, 0.92);
  --shadow-soft: 0 10px 30px rgba(92, 62, 70, 0.14);
  --pink: #ff8fb1;
  --pink-light: #ffe4ee;
  --sky: #7cc4fa;
  --butter: #ffd972;
  --radius-xl: 24px;
  --radius-pill: 999px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Zen Maru Gothic', 'Noto Sans TC', 'Microsoft JhengHei', sans-serif;
  color: var(--ink);
  background: #dff4ff;
}

#canvas-container {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  cursor: grab;
}

#canvas-container.pointer-hover {
  cursor: pointer;
}

#canvas-container:active {
  cursor: grabbing;
}

/* ===== Speech Bubble ===== */
.speech-bubble {
  position: fixed;
  top: 0;
  left: 0;
  transform: translate(-50%, -100%) scale(1);
  background: #ffffff;
  color: var(--ink);
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: 0.03em;
  padding: 10px 18px;
  border-radius: 22px;
  border: 3px solid #594446;
  box-shadow: 0 8px 22px rgba(89, 68, 70, 0.16);
  pointer-events: none;
  z-index: 30;
  white-space: nowrap;
  transition: opacity 0.25s ease, transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -11px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-top: 11px solid #594446;
}

.speech-bubble::before {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 8px solid #ffffff;
  z-index: 1;
}

.speech-bubble.hidden {
  opacity: 0;
  transform: translate(-50%, -80%) scale(0.75);
}

/* ===== Top Left HUD ===== */
.hud-top-left {
  position: fixed;
  top: 18px;
  left: 18px;
  z-index: 20;
  pointer-events: none;
}

.profile-card {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 2.5px solid var(--card-border);
  border-radius: var(--radius-xl);
  padding: 12px 18px 12px 14px;
  box-shadow: var(--shadow-soft);
  max-width: 340px;
}

.profile-badge {
  width: 52px;
  height: 52px;
  border-radius: 18px;
  background: linear-gradient(135deg, #fff5f8, #ffdce8);
  border: 2px solid #ffffff;
  box-shadow: 0 4px 12px rgba(255, 143, 177, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.7rem;
  flex-shrink: 0;
}

.profile-info {
  min-width: 0;
  flex: 1;
}

.profile-title-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.profile-title-row h1 {
  font-size: 1.2rem;
  font-weight: 900;
  line-height: 1.2;
}

.char-jp {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.75);
  padding: 1px 8px;
  border-radius: var(--radius-pill);
}

.lore-tag {
  display: inline-block;
  margin-top: 4px;
  font-size: 0.72rem;
  font-weight: 800;
  color: #8f4e5c;
  background: linear-gradient(135deg, #fff5f8, #ffeaf0);
  border: 1.5px solid #ffd0df;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
}

.char-desc {
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin-top: 3px;
  line-height: 1.35;
}

.affection-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 7px;
}

.affection-label {
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
}

.affection-track {
  flex: 1;
  height: 9px;
  background: rgba(255, 143, 177, 0.2);
  border-radius: var(--radius-pill);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.8);
}

.affection-fill {
  height: 100%;
  background: linear-gradient(90deg, #ff9ebb, #ff6c9c);
  border-radius: var(--radius-pill);
  transition: width 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.affection-pts {
  font-size: 0.72rem;
  font-weight: 800;
  color: #e35d89;
  min-width: 24px;
  text-align: right;
}

/* ===== Top Right HUD ===== */
.hud-top-right {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 25;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.hud-right-drawer {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.mobile-menu-toggle {
  display: none;
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  border: 2.5px solid var(--card-border);
  border-radius: var(--radius-pill);
  padding: 7px 14px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 900;
  color: var(--ink);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
}

.mode-nav-row {
  display: flex;
  gap: 8px;
}

.race-launch-btn,
.fly-launch-btn {
  text-decoration: none;
  color: #ffffff;
  font-weight: 900;
  font-size: 0.88rem;
  letter-spacing: 0.03em;
  padding: 8px 15px;
  border-radius: var(--radius-pill);
  border: 2.5px solid #ffffff;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
}

.race-launch-btn {
  background: linear-gradient(135deg, #ff7098, #ffaa4c);
  box-shadow: 0 8px 20px rgba(255, 112, 152, 0.36);
}

.fly-launch-btn {
  background: linear-gradient(135deg, #52b4f7, #7d92ff);
  box-shadow: 0 8px 20px rgba(82, 180, 247, 0.36);
}

.race-launch-btn:hover,
.fly-launch-btn:hover {
  transform: translateY(-2px) scale(1.05);
}

.tool-group {
  display: flex;
  gap: 6px;
  background: var(--card-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 2.5px solid var(--card-border);
  border-radius: var(--radius-pill);
  padding: 5px 7px;
  box-shadow: var(--shadow-soft);
}

.tool-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: transparent;
  font-size: 1.15rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s ease, border-color 0.2s ease;
}

.tool-btn:hover {
  transform: scale(1.12);
  background: rgba(255, 255, 255, 0.75);
}

.tool-btn:active {
  transform: scale(0.92);
}

.tool-btn.active {
  background: #ffffff;
  border-color: var(--pink);
  box-shadow: 0 3px 10px rgba(255, 143, 177, 0.28);
}

/* ===== Hint Pill ===== */
.hint-pill {
  position: fixed;
  top: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  background: rgba(255, 252, 248, 0.72);
  backdrop-filter: blur(10px);
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: var(--radius-pill);
  padding: 7px 16px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-soft);
  box-shadow: 0 6px 20px rgba(89, 68, 70, 0.08);
  pointer-events: none;
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.hint-pill.faded {
  opacity: 0;
  transform: translateX(-50%) translateY(-10px);
}

/* ===== Bottom Dock ===== */
.hud-bottom {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 24px);
}

.action-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 2.5px solid var(--card-border);
  border-radius: var(--radius-xl);
  padding: 8px 12px;
  box-shadow: var(--shadow-soft);
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  border: 2px solid rgba(90, 68, 70, 0.12);
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.action-btn:hover {
  transform: translateY(-3px) scale(1.04);
  background: #ffffff;
  border-color: var(--pink);
  box-shadow: 0 6px 14px rgba(255, 143, 177, 0.24);
}

.action-btn:active {
  transform: translateY(0) scale(0.95);
}

.action-btn.active {
  background: linear-gradient(135deg, #fff0f5, #ffdbe9);
  border-color: #ff7ba6;
  color: #c2396a;
  box-shadow: 0 4px 12px rgba(255, 123, 166, 0.3);
}

.action-btn.action-special {
  background: linear-gradient(135deg, #fffdf0, #ffefbf);
  border-color: #f3c24d;
}

.action-btn.action-special:hover {
  border-color: #e5a922;
  box-shadow: 0 6px 14px rgba(243, 194, 77, 0.32);
}

.action-icon {
  font-size: 1.05rem;
  line-height: 1;
}

/* Character Dock */
.character-dock {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 2.5px solid var(--card-border);
  border-radius: 26px;
  padding: 6px 10px;
  box-shadow: var(--shadow-soft);
  max-width: min(1040px, calc(100vw - 24px));
}

.char-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px 5px 7px;
  border-radius: var(--radius-pill);
  border: 2.5px solid transparent;
  background: rgba(255, 255, 255, 0.68);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.24s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.char-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent-soft);
  border: 1.5px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.94rem;
}

.char-btn:hover {
  transform: translateY(-3px);
  background: #ffffff;
  border-color: var(--accent);
}

.char-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  box-shadow: 0 5px 14px rgba(92, 62, 70, 0.14);
  transform: translateY(-2px) scale(1.04);
}

/* Photo Flash */
.photo-flash {
  position: fixed;
  inset: 0;
  background: #ffffff;
  opacity: 0;
  pointer-events: none;
  z-index: 100;
  transition: opacity 0.35s ease;
}

.photo-flash.flash {
  opacity: 0.85;
  transition: opacity 0.05s ease;
}

/* Night theme slight card glow */
body.theme-night .profile-card,
body.theme-night .tool-group,
body.theme-night .action-bar,
body.theme-night .character-dock {
  background: rgba(255, 250, 255, 0.88);
  box-shadow: 0 10px 30px rgba(15, 16, 48, 0.35);
}

/* Responsive & Dedicated Mobile Mode (triggers on body.is-mobile for BOTH portrait & landscape iPhone!) */
body.is-mobile .hint-pill { display: none; }
body.is-mobile .hud-top-left { top: max(8px, env(safe-area-inset-top)); left: 8px; }
body.is-mobile .hud-top-right { top: max(8px, env(safe-area-inset-top)); right: 8px; }
body.is-mobile .mobile-menu-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; padding: 0; border-radius: 50%;
}
body.is-mobile .hud-right-drawer {
  display: none;
  background: rgba(255, 252, 248, 0.96);
  backdrop-filter: blur(16px);
  border: 2px solid #ffffff;
  border-radius: 18px;
  padding: 8px;
  box-shadow: 0 12px 28px rgba(70, 50, 58, 0.24);
}
body.is-mobile .hud-right-drawer.open { display: flex; }
body.is-mobile .profile-card {
  padding: 5px 10px 5px 6px; gap: 7px; border-radius: 999px; max-width: 195px;
}
body.is-mobile .profile-badge { width: 28px; height: 28px; font-size: 1rem; border-radius: 50%; }
body.is-mobile .profile-title-row h1 { font-size: 0.86rem; }
body.is-mobile .char-jp,
body.is-mobile .lore-tag,
body.is-mobile .char-desc,
body.is-mobile .affection-track { display: none; }
body.is-mobile .affection-row { margin-top: 1px; gap: 4px; }
body.is-mobile .affection-label,
body.is-mobile .affection-pts { font-size: 0.64rem; }
body.is-mobile .hud-bottom {
  bottom: max(8px, env(safe-area-inset-bottom));
  gap: 5px;
  width: calc(100vw - 14px);
  max-width: calc(100vw - 14px);
}
body.is-mobile .action-bar,
body.is-mobile .character-dock {
  width: 100%;
  flex-wrap: nowrap;
  justify-content: flex-start;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 4px 7px;
  gap: 5px;
  border-radius: 999px;
  background: rgba(255, 252, 248, 0.78);
}
body.is-mobile .action-bar::-webkit-scrollbar,
body.is-mobile .character-dock::-webkit-scrollbar { display: none; }
body.is-mobile .action-btn { flex-shrink: 0; padding: 5px 9px; font-size: 0.74rem; gap: 4px; }
body.is-mobile .char-btn { flex-shrink: 0; padding: 3px 8px 3px 4px; font-size: 0.74rem; gap: 4px; }
body.is-mobile .char-avatar { width: 22px; height: 22px; font-size: 0.82rem; }
body.is-mobile .char-btn-name { display: inline; }
