/* ═══════════════════════════════════════════
   HARU TALK — Design System
   粉藍配色收斂版 · 2025
═══════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,500;0,9..40,700;1,9..40,300&family=Noto+Sans+TC:wght@300;400;700&display=swap');

:root {
  /* Palette */
  --pink:        #d8a851;
  --pink-light:  #f3d591;
  --pink-dim:    rgba(216, 168, 81, 0.16);
  --blue:        #73b9d4;
  --blue-light:  #c4e7f2;
  --blue-dim:    rgba(115, 185, 212, 0.14);
  --navy:        #17263b;

  /* Surface */
  --bg:          #edf3f7;
  --surface:     #ffffff;
  --surface-2:   #f7fafc;
  --surface-3:   #e8eef4;

  /* Text */
  --ink:         #1e2a35;
  --ink-2:       #4a5568;
  --muted:       #8a96a8;

  /* Border */
  --line:        rgba(180, 160, 175, 0.28);
  --line-strong: rgba(180, 160, 175, 0.5);

  /* Elevation */
  --shadow-sm:   0 1px 3px rgba(30, 50, 72, 0.06), 0 1px 2px rgba(30, 50, 72, 0.04);
  --shadow-md:   0 4px 16px rgba(30, 50, 72, 0.08), 0 2px 6px rgba(30, 50, 72, 0.05);

  /* Radius */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-xl: 24px;

  /* Type */
  --font-display: 'DM Sans', 'Noto Sans TC', system-ui, sans-serif;
  --font-body:    'Noto Sans TC', 'DM Sans', system-ui, sans-serif;
  --app-height: 100dvh;
  --keyboard-offset: 0px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  height: 100%;
  overflow: hidden;
}

body {
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  position: fixed;
  inset: 0;
  width: 100%;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  background-image:
    radial-gradient(circle at 17px 16px, rgba(216, 168, 81, 0.42) 0 1px, transparent 1.6px),
    radial-gradient(circle at 4px 5px, rgba(255,255,255,0.72) 0 1px, transparent 1.5px),
    linear-gradient(180deg, rgba(115, 185, 212, 0.16), rgba(23, 38, 59, 0.08));
  background-size: 34px 34px, 46px 46px, 100% 100%;
  background-position: 0 0, 18px 20px, 0 0;
  background-attachment: fixed;
}

.boot-loader {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 2147483647;
  display: flex;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
  color: var(--navy);
  background:
    linear-gradient(135deg, rgba(255,255,255,0.76) 25%, transparent 25%),
    linear-gradient(225deg, rgba(255,255,255,0.6) 25%, transparent 25%),
    radial-gradient(circle at 50% 18%, rgba(243,213,145,0.36) 0 1px, transparent 1.8px),
    linear-gradient(180deg, #f8fbfd 0%, #e9f3f8 100%);
  background-size: 30px 30px, 30px 30px, 36px 36px, 100% 100%;
  background-position: 0 0, 15px 15px, 0 0, 0 0;
  isolation: isolate;
  pointer-events: auto;
  transition: opacity 320ms ease, visibility 320ms ease;
}

.boot-loader.is-done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.boot-card {
  position: relative;
  display: grid;
  place-items: center;
  width: 152px;
  height: 152px;
  border: 1px solid rgba(255,255,255,0.9);
  border-radius: 30px;
  background:
    linear-gradient(160deg, rgba(255,255,255,0.92), rgba(255,255,255,0.48)),
    linear-gradient(135deg, rgba(240,184,206,0.34), rgba(168,212,232,0.34));
  box-shadow:
    0 24px 56px rgba(30, 50, 72, 0.16),
    inset 0 0 0 1px rgba(255,255,255,0.66);
  overflow: hidden;
}

.boot-card::before {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px dashed rgba(106, 174, 203, 0.42);
  border-radius: 24px;
  animation: boot-scan 1.8s ease-in-out infinite;
}

.boot-avatar {
  position: relative;
  z-index: 1;
  width: 86px;
  height: 86px;
  animation: boot-float 1.7s ease-in-out infinite;
}

.boot-hair {
  position: absolute;
  inset: 3px 8px 24px;
  border-radius: 38px 38px 24px 24px;
  background: linear-gradient(135deg, #f6f7fb, #dce8ef 46%, var(--blue));
  box-shadow: inset 10px -8px 0 rgba(255,255,255,0.16);
}

.boot-hair::before,
.boot-hair::after {
  content: "";
  position: absolute;
  top: -8px;
  width: 28px;
  height: 28px;
  border-radius: 8px 20px 8px 20px;
  background: linear-gradient(135deg, var(--pink-light), var(--blue-light));
  transform: rotate(-20deg);
}

.boot-hair::before { left: 6px; }
.boot-hair::after {
  right: 4px;
  transform: rotate(30deg) scaleX(-1);
}

.boot-face {
  position: absolute;
  left: 13px;
  right: 13px;
  bottom: 8px;
  height: 55px;
  border: 2px solid rgba(255,255,255,0.8);
  border-radius: 26px 26px 24px 24px;
  background: linear-gradient(180deg, #fff1f6, #fffafc);
  box-shadow: 0 8px 18px rgba(30, 50, 72, 0.14);
}

.boot-eye {
  position: absolute;
  top: 22px;
  width: 8px;
  height: 13px;
  border-radius: 999px;
  background: var(--navy);
  box-shadow: 0 0 0 3px rgba(106,174,203,0.12);
  animation: boot-blink 2.2s ease-in-out infinite;
}

.boot-eye:first-child { left: 18px; }
.boot-eye:nth-child(2) { right: 18px; }

.boot-mouth {
  position: absolute;
  left: 50%;
  bottom: 11px;
  width: 14px;
  height: 7px;
  border-bottom: 2px solid var(--pink);
  border-radius: 0 0 999px 999px;
  transform: translateX(-50%);
}

.boot-ring {
  position: absolute;
  inset: 32px;
  border: 2px solid rgba(255,255,255,0.78);
  border-top-color: rgba(212,127,160,0.82);
  border-right-color: rgba(106,174,203,0.82);
  border-radius: 50%;
  animation: boot-spin 1.2s linear infinite;
}

.boot-spark {
  position: absolute;
  z-index: 2;
  width: 10px;
  height: 10px;
  background: white;
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  filter: drop-shadow(0 2px 4px rgba(30,50,72,0.12));
  animation: boot-twinkle 1.4s ease-in-out infinite;
}

.boot-spark-a { left: 26px; top: 30px; }
.boot-spark-b { right: 24px; top: 48px; animation-delay: 260ms; }
.boot-spark-c { left: 46px; bottom: 26px; animation-delay: 520ms; }

.boot-copy {
  display: grid;
  gap: 3px;
  text-align: center;
}

.boot-copy strong {
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--navy);
}

.boot-copy span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.boot-progress {
  width: min(220px, 68vw);
  height: 8px;
  padding: 2px;
  border: 1px solid rgba(180,160,175,0.5);
  border-radius: 999px;
  background: rgba(255,255,255,0.72);
  overflow: hidden;
}

.boot-progress span {
  display: block;
  width: 44%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--pink), var(--blue));
  animation: boot-load 1.1s ease-in-out infinite;
}

@keyframes boot-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}

@keyframes boot-blink {
  0%, 88%, 100% { transform: scaleY(1); }
  92%, 96% { transform: scaleY(0.12); }
}

@keyframes boot-spin {
  to { transform: rotate(360deg); }
}

@keyframes boot-scan {
  0%, 100% { opacity: 0.42; transform: scale(0.96); }
  50% { opacity: 0.9; transform: scale(1.02); }
}

@keyframes boot-twinkle {
  0%, 100% { opacity: 0.34; transform: scale(0.8) rotate(0deg); }
  50% { opacity: 1; transform: scale(1.18) rotate(45deg); }
}

@keyframes boot-load {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(260%); }
}

/* ── Base elements ── */
button, input, select, textarea { font: inherit; color: inherit; }

h2 { font-family: var(--font-display); font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em; }
h3 { font-family: var(--font-display); font-size: 1.05rem; font-weight: 700; letter-spacing: -0.01em; }

/* ═══════════════════════════════════════════
   APP SHELL
═══════════════════════════════════════════ */
.app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(100%, 1280px);
  height: var(--app-height);
  max-height: var(--app-height);
  min-height: 0;
  box-sizing: border-box;
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 16px 24px;
  gap: 16px;
  overflow: hidden;
}

/* ═══════════════════════════════════════════
   HEADER
═══════════════════════════════════════════ */
.app-header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 20px;
  border-radius: var(--r-xl);
  border: 1px solid var(--line-strong);
  background: rgba(255,255,255,0.88);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-sm);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.brand-dot {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.88), rgba(255,255,255,0.1)),
    linear-gradient(135deg, var(--navy), var(--blue) 58%, var(--pink));
  box-shadow: 0 0 0 3px rgba(255,255,255,0.7), 0 4px 10px rgba(30, 50, 72, 0.14);
  animation: pulse-dot 2.4s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 3px var(--pink-dim); }
  50%       { box-shadow: 0 0 0 6px var(--pink-dim); }
}

.brand-name {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--navy);
}

.brand-sub {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 2px 7px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
}

.header-nav {
  display: flex;
  gap: 4px;
  flex: 1;
  justify-content: center;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 180ms ease;
}

.tab:hover {
  color: var(--ink);
  background: var(--surface-3);
}

.tab.active {
  color: var(--navy);
  background: white;
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
  font-weight: 700;
}

.tab-icon { font-size: 0.7rem; opacity: 0.7; }

.header-status { flex: 0 0 auto; }

.auth-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.tab:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.tab:disabled:hover {
  color: var(--muted);
  background: transparent;
}

/* ═══════════════════════════════════════════
   VIEW SWITCHING
═══════════════════════════════════════════ */
.view {
  display: none;
  min-height: 0;
  overflow: hidden;
}
.view.active {
  display: grid;
  animation: fadeUp 200ms ease-out both;
}

#viewerView {
  grid-template-rows: minmax(0, 1fr);
}

#studioView {
  grid-template-rows: auto minmax(0, 1fr);
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════
   VIEWER VIEW
═══════════════════════════════════════════ */
.viewer-layout {
  display: grid;
  grid-template-columns: minmax(0, 860px);
  gap: 16px;
  align-items: stretch;
  justify-content: center;
  min-height: 0;
  height: 100%;
}

/* Chat column */
.chat-col {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 0;
  border: 1px solid rgba(255,255,255,0.82);
  border-radius: 28px;
  background: var(--surface);
  box-shadow:
    0 18px 42px rgba(30, 50, 72, 0.14),
    inset 0 0 0 1px rgba(30, 50, 72, 0.08);
  overflow: hidden;
  min-height: 0;
  height: 100%;
}

.chat-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.92), rgba(249,245,247,0.94)),
    linear-gradient(90deg, rgba(106,174,203,0.12), rgba(212,127,160,0.1));
}

.chat-toolbar > div {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.chat-toolbar strong {
  color: var(--navy);
  font-family: var(--font-display);
  font-size: 1rem;
}

.chat-toolbar span {
  color: var(--muted);
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-toggle {
  display: inline-flex;
  margin-left: auto;
  flex: 0 0 auto;
}

.stat-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.stat-item strong {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--navy);
}

.stat-item span {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
}

.stat-divider {
  width: 1px;
  height: 20px;
  background: var(--line-strong);
}

/* Thread */
.thread {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 22px;
  display: grid;
  align-content: start;
  gap: 12px;
}

.chat-body {
  background:
    linear-gradient(rgba(255,255,255,0.72), rgba(255,255,255,0.72)),
    linear-gradient(90deg, rgba(106,174,203,0.12) 1px, transparent 1px),
    linear-gradient(180deg, rgba(212,127,160,0.1) 1px, transparent 1px),
    var(--surface);
  background-size: auto, 24px 24px, 24px 24px, auto;
}

.empty-state {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.8;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 48px 24px;
}

.presence-card {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 14px;
  width: min(360px, 100%);
  padding: 24px 20px 22px;
  border: 1px solid rgba(216, 168, 81, 0.28);
  border-radius: 26px;
  background:
    radial-gradient(circle at 50% 16%, rgba(243,213,145,0.3), transparent 34%),
    linear-gradient(180deg, rgba(255,255,255,0.96), rgba(247,250,252,0.92));
  box-shadow:
    0 18px 46px rgba(23, 38, 59, 0.12),
    inset 0 0 0 1px rgba(255,255,255,0.7);
  overflow: hidden;
}

.presence-card::before {
  content: "";
  position: absolute;
  inset: 14px;
  border: 1px dashed rgba(115, 185, 212, 0.34);
  border-radius: 20px;
  pointer-events: none;
}

.presence-orbit {
  position: absolute;
  inset: 18px 28px auto;
  height: 46px;
  pointer-events: none;
}

.presence-orbit span {
  position: absolute;
  width: 9px;
  height: 9px;
  background: var(--pink-light);
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  animation: presenceTwinkle 1.7s ease-in-out infinite;
}

.presence-orbit span:nth-child(1) { left: 12%; top: 26px; }
.presence-orbit span:nth-child(2) { left: 48%; top: 3px; animation-delay: 220ms; }
.presence-orbit span:nth-child(3) { right: 12%; top: 30px; animation-delay: 440ms; }

.presence-avatar {
  position: relative;
  display: grid;
  place-items: center;
  width: 82px;
  height: 82px;
  margin-top: 6px;
  border-radius: 28px;
  background: linear-gradient(150deg, rgba(23,38,59,0.08), rgba(115,185,212,0.16));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.7);
}

.presence-hair {
  position: absolute;
  width: 58px;
  height: 54px;
  border-radius: 28px 28px 18px 18px;
  background: linear-gradient(135deg, #f8f9fc, #dce8ef 58%, var(--blue-light));
  box-shadow: 0 8px 18px rgba(23,38,59,0.12);
}

.presence-hair::before,
.presence-hair::after {
  content: "";
  position: absolute;
  top: -7px;
  width: 18px;
  height: 24px;
  border-radius: 7px 18px 7px 18px;
  background: linear-gradient(135deg, var(--pink-light), #f8f9fc);
}

.presence-hair::before { left: 4px; transform: rotate(-20deg); }
.presence-hair::after { right: 4px; transform: rotate(28deg) scaleX(-1); }

.presence-face {
  position: absolute;
  bottom: 13px;
  width: 42px;
  height: 34px;
  border-radius: 18px 18px 16px 16px;
  background:
    radial-gradient(circle at 30% 48%, var(--blue) 0 3px, transparent 3.5px),
    radial-gradient(circle at 70% 48%, var(--blue) 0 3px, transparent 3.5px),
    linear-gradient(180deg, #fff7f2, #fffefe);
  border: 1px solid rgba(255,255,255,0.78);
}

.presence-copy {
  position: relative;
  display: grid;
  gap: 7px;
  justify-items: center;
}

.presence-copy strong {
  color: var(--navy);
  font-family: var(--font-display);
  font-size: 1rem;
}

.presence-copy p {
  max-width: 28ch;
  color: var(--ink-2);
}

.presence-copy small {
  color: var(--pink);
  font-size: 0.75rem;
  font-weight: 700;
}

@keyframes presenceTwinkle {
  0%, 100% { opacity: 0.32; transform: scale(0.78) rotate(0deg); }
  50% { opacity: 1; transform: scale(1.18) rotate(45deg); }
}

/* Composer */
.composer {
  position: sticky;
  bottom: var(--keyboard-offset);
  z-index: 2;
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,0.95);
  display: grid;
  gap: 10px;
}

.composer textarea {
  width: 100%;
  min-height: 72px;
  max-height: 140px;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface-2);
  outline: none;
  transition: border-color 150ms, box-shadow 150ms;
  line-height: 1.65;
}

.composer textarea:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 3px var(--pink-dim);
  background: white;
}

.composer-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
}

.toggle-line {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--ink-2);
  cursor: pointer;
}

.toggle-line input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--pink);
  cursor: pointer;
}

.char-count {
  font-size: 0.75rem;
  color: var(--muted);
}

/* Settings column */
.settings-col {
  display: grid;
  align-content: start;
  gap: 10px;
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 30;
  width: min(420px, calc(100vw - 24px));
  max-height: calc(100dvh - 32px);
  padding: 14px;
  overflow-y: auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-xl);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow-md);
  transform: translate(-50%, -48%) scale(0.98);
  opacity: 0;
  pointer-events: none;
  transition: transform 180ms ease, opacity 180ms ease;
}

.settings-col.open {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
  pointer-events: auto;
}

.settings-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-backdrop {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(30, 42, 53, 0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.settings-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.settings-form {
  display: grid;
  gap: 12px;
}

.settings-field {
  display: grid;
  gap: 8px;
}

.settings-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  display: grid;
  gap: 10px;
}

.login-card .input-row {
  display: flex;
  gap: 8px;
}

.login-card .input-row input { flex: 1; min-width: 0; }

.card-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.daily-card {
  background:
    radial-gradient(circle at 90% 10%, rgba(106, 174, 203, 0.15), transparent 50%),
    var(--surface);
}

.daily-text {
  font-size: 0.88rem;
  color: var(--navy);
  font-weight: 500;
  line-height: 1.5;
}

/* ── Chips ── */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: white;
  color: var(--ink-2);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 150ms ease;
}

.chip:hover {
  border-color: var(--pink);
  color: var(--pink);
}

.chip.active {
  background: linear-gradient(135deg, var(--navy), var(--blue) 62%, var(--pink));
  border-color: transparent;
  color: white;
  font-weight: 700;
}

/* Route track */
.route-track {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 6px;
}

.route-step {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.route-node {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: white;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--muted);
  font-family: var(--font-display);
  transition: all 200ms;
}

.route-label-text {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  transition: color 200ms;
}

.route-line-seg {
  flex: 1;
  height: 1px;
  background: var(--line-strong);
  min-width: 12px;
}

.route-step.active .route-node {
  background: linear-gradient(135deg, var(--navy), var(--blue) 62%, var(--pink));
  border-color: transparent;
  color: white;
  box-shadow: 0 2px 8px var(--pink-dim);
}

.route-step.active .route-label-text { color: var(--navy); font-weight: 700; }

.route-step.done .route-node {
  background: var(--blue-dim);
  border-color: var(--blue);
  color: var(--blue);
}

/* ═══════════════════════════════════════════
   STUDIO VIEW
═══════════════════════════════════════════ */
.studio-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 4px 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}

.studio-topbar h2 { color: var(--navy); }

.studio-topbar .eyebrow {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 2px;
}

.studio-topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--pink-dim);
  color: var(--pink);
  font-size: 0.75rem;
  font-weight: 700;
  border: 1px solid rgba(212, 127, 160, 0.3);
}

.badge-blue {
  background: var(--blue-dim);
  color: var(--blue);
  border-color: rgba(106, 174, 203, 0.3);
}

.studio-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
  min-height: 0;
  height: 100%;
}

/* Viewer column */
.viewer-col {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.search-wrap input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface-2);
  outline: none;
  font-size: 0.85rem;
  transition: border-color 150ms, box-shadow 150ms;
}

.search-wrap input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-dim);
  background: white;
}

.viewer-list {
  display: grid;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
}

.viewer-card {
  display: grid;
  gap: 5px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-2);
  text-align: left;
  cursor: pointer;
  transition: all 150ms ease;
}

.viewer-card:hover {
  border-color: var(--pink-light);
  background: white;
}

.viewer-card.active {
  border-color: var(--pink);
  background: white;
  box-shadow: 0 0 0 3px var(--pink-dim);
}

.viewer-card.unread {
  border-color: rgba(212, 127, 160, 0.42);
  background: linear-gradient(160deg, rgba(212, 127, 160, 0.12), rgba(255, 255, 255, 0.96));
}

.viewer-card.unread strong::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 7px;
  border-radius: 50%;
  background: var(--pink);
  vertical-align: middle;
}

.viewer-card strong {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--navy);
}

.viewer-card span {
  font-size: 0.75rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Detail column */
.detail-col {
  border: 1px solid var(--line-strong);
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  min-height: 0;
  height: 100%;
  display: grid;
}

.detail-empty {
  min-height: 400px;
}

.detail-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-height: 0;
  height: 100%;
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.detail-header .eyebrow {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  display: block;
  margin-bottom: 2px;
}

/* Tool grid */
.detail-tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.tool-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: white;
  display: grid;
  gap: 8px;
  font-size: 0.84rem;
}

.live-cue .field-title {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 4px;
}

.live-cue strong { color: var(--navy); font-size: 0.84rem; display: block; }
.live-cue p { color: var(--ink-2); font-size: 0.82rem; margin-top: 4px; }
.live-cue .cue-meta { color: var(--muted); font-size: 0.75rem; }

.memory-area {
  width: 100%;
  min-height: 80px;
  resize: vertical;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  outline: none;
  font-size: 0.83rem;
  line-height: 1.6;
  transition: border-color 150ms, box-shadow 150ms;
}

.memory-area:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-dim);
  background: white;
}

/* Studio thread */
.studio-thread {
  min-height: 0;
  padding: 20px 22px;
  overflow-y: auto;
  background:
    radial-gradient(circle at 8% 8%, rgba(212, 127, 160, 0.05), transparent 30%),
    radial-gradient(circle at 92% 88%, rgba(106, 174, 203, 0.07), transparent 30%),
    var(--surface);
}

/* Reply area */
.reply-area {
  padding: 16px 18px;
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,0.95);
}

.reply-form {
  display: grid;
  gap: 10px;
  transform: translateY(calc(var(--keyboard-offset) * -1));
}

.reply-target {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid rgba(106, 174, 203, 0.3);
  border-radius: var(--r-md);
  background: var(--blue-dim);
  animation: fadeUp 150ms ease-out;
}

.reply-target-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  flex-shrink: 0;
}

.reply-target strong {
  flex: 1;
  min-width: 0;
  font-size: 0.84rem;
  color: var(--navy);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reply-form textarea {
  width: 100%;
  min-height: 72px;
  max-height: 130px;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface-2);
  outline: none;
  line-height: 1.65;
  transition: border-color 150ms, box-shadow 150ms;
}

.reply-form textarea:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 3px var(--pink-dim);
  background: white;
}

.reply-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

/* ═══════════════════════════════════════════
   MESSAGES
═══════════════════════════════════════════ */
.message-row {
  display: flex;
  align-items: end;
  gap: 8px;
  width: 100%;
}

.message-row.from-haru {
  justify-content: start;
}

.message-row.from-viewer {
  justify-content: end;
  flex-direction: row-reverse;
}

.studio-thread .message-row.from-haru {
  justify-content: end;
  flex-direction: row-reverse;
}

.studio-thread .message-row.from-viewer {
  justify-content: start;
  flex-direction: row;
}

.message-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 12px;
  color: white;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.78rem;
  box-shadow: 0 4px 10px rgba(30, 50, 72, 0.14);
  overflow: hidden;
}

.message-avatar.photo {
  background: white;
  padding: 2px;
}

.message-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 10px;
  object-fit: cover;
  display: block;
}

.from-haru .message-avatar {
  background: linear-gradient(135deg, var(--blue), #85c9df);
}

.from-viewer .message-avatar {
  background: linear-gradient(135deg, var(--pink), #e7a6bf);
}

.message-card {
  position: relative;
  max-width: 72%;
  padding: 11px 14px;
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
  background: white;
  font-size: 0.88rem;
  overflow-wrap: anywhere;
  word-break: break-word;
  box-shadow: 0 4px 14px rgba(30, 50, 72, 0.08);
}

/* 觀眾端 viewer messages (right) */
.chat-body .message-card:not(.reply) {
  background: linear-gradient(160deg, rgba(255, 224, 237, 0.98), rgba(255, 247, 251, 0.98));
  border-color: rgba(212, 127, 160, 0.3);
  border-radius: var(--r-lg) var(--r-lg) 4px var(--r-lg);
}

/* 觀眾端 haru replies (left) */
.chat-body .message-card.reply {
  background: linear-gradient(160deg, rgba(255,255,255,0.98), rgba(236, 249, 255, 0.98));
  border-color: rgba(106, 174, 203, 0.3);
  border-radius: var(--r-lg) var(--r-lg) var(--r-lg) 4px;
}

.chat-body .message-card::after,
.studio-thread .message-card::after {
  content: "";
  position: absolute;
  bottom: -1px;
  width: 11px;
  height: 11px;
  background: inherit;
}

.message-card.reply::after {
  left: -5px;
  border-left: 1px solid rgba(106, 174, 203, 0.3);
  border-bottom-left-radius: 9px;
}

.message-card:not(.reply)::after {
  right: -5px;
  border-right: 1px solid rgba(212, 127, 160, 0.3);
  border-bottom-right-radius: 9px;
}

/* 後台端 viewer messages (left) */
.studio-thread .message-card:not(.reply) {
  justify-self: start;
  border-radius: var(--r-lg) var(--r-lg) var(--r-lg) 4px;
}

/* 後台端 haru replies (right) */
.studio-thread .message-card.reply {
  justify-self: end;
  background: linear-gradient(160deg, rgba(212,127,160,0.1), rgba(212,127,160,0.03));
  border-color: rgba(212, 127, 160, 0.3);
  border-radius: var(--r-lg) var(--r-lg) 4px var(--r-lg);
}

.message-card.is-new {
  animation: messageGlow 600ms ease-out both;
}

@keyframes messageGlow {
  0%   { box-shadow: 0 0 0 0 rgba(212, 127, 160, 0); }
  30%  { box-shadow: 0 0 0 4px rgba(212, 127, 160, 0.2); }
  100% { box-shadow: 0 0 0 0 rgba(212, 127, 160, 0); }
}

.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--muted);
}

.message-card p {
  line-height: 1.65;
  white-space: pre-wrap;
  color: var(--ink);
}

.message-card.is-recalled {
  opacity: 0.72;
}

.message-card.is-recalled p {
  color: var(--muted);
  font-style: italic;
}

.waiting-cue {
  margin-top: 2px;
}

.star-typing {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.star-typing i {
  width: 8px;
  height: 8px;
  background: var(--pink);
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  animation: starTyping 1.1s ease-in-out infinite;
}

.star-typing i:nth-of-type(2) { animation-delay: 160ms; }
.star-typing i:nth-of-type(3) { animation-delay: 320ms; }

@keyframes starTyping {
  0%, 100% { opacity: 0.28; transform: translateY(2px) scale(0.78); }
  50% { opacity: 1; transform: translateY(-2px) scale(1.12); }
}

.edit-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  align-items: center;
  justify-items: center;
  padding: 16px;
}

.edit-modal.hidden {
  display: none;
}

.edit-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(30, 42, 53, 0.34);
  backdrop-filter: blur(6px);
}

.edit-modal-panel {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 12px;
  width: min(520px, 100%);
  padding: 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  background: rgba(255,255,255,0.98);
  box-shadow: 0 18px 52px rgba(30, 50, 72, 0.22);
}

.edit-modal-head,
.edit-modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.edit-modal-panel textarea {
  width: 100%;
  min-height: 130px;
  max-height: min(42dvh, 260px);
  resize: vertical;
  padding: 10px 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--line-strong);
  background: rgba(255,255,255,0.92);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.6;
}

.edit-modal-panel textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-dim);
}

.edit-modal-actions {
  justify-content: flex-end;
}

@media (max-width: 760px) {
  .edit-modal {
    align-items: start;
    padding: max(56px, env(safe-area-inset-top)) 12px 12px;
  }

  .edit-modal-panel {
    width: min(520px, 100%);
    max-height: 58dvh;
    overflow: auto;
  }

  .edit-modal-panel textarea {
    min-height: 110px;
    max-height: 30dvh;
  }
}

.reply-context {
  margin-bottom: 8px;
  padding: 6px 10px;
  border-left: 2px solid var(--blue);
  border-radius: 6px;
  background: var(--blue-dim);
  font-size: 0.76rem;
  color: var(--muted);
  font-weight: 500;
}

.message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.inline-reply-button {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: white;
  color: var(--ink-2);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 130ms;
}

.inline-reply-button:hover,
.inline-reply-button.active {
  background: linear-gradient(135deg, var(--navy), var(--blue) 62%, var(--pink));
  border-color: transparent;
  color: white;
}

.inline-reply-button.danger {
  border-color: rgba(190, 80, 96, 0.35);
  color: #9d3f50;
}

.inline-reply-button.danger:hover {
  background: rgba(190, 80, 96, 0.1);
  border-color: rgba(190, 80, 96, 0.55);
  color: #9d3f50;
}

/* ═══════════════════════════════════════════
   BUTTONS
═══════════════════════════════════════════ */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 18px;
  border-radius: var(--r-md);
  border: none;
  background: linear-gradient(135deg, var(--navy), var(--blue) 62%, var(--pink));
  color: white;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 150ms, box-shadow 150ms;
}

.btn-primary:hover {
  opacity: 0.9;
  box-shadow: 0 2px 12px rgba(212, 127, 160, 0.35);
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--line-strong);
  background: white;
  color: var(--ink-2);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 150ms;
}

.btn-ghost:hover {
  border-color: var(--pink-light);
  color: var(--navy);
  background: var(--surface-2);
}

.compact {
  height: 26px;
  padding: 0 8px;
  font-size: 0.75rem;
  border-radius: var(--r-sm);
}

/* ═══════════════════════════════════════════
   FORM ELEMENTS
═══════════════════════════════════════════ */
input:not([type="checkbox"]):not([type="search"]),
select {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface-2);
  outline: none;
  font-size: 0.85rem;
  transition: border-color 150ms, box-shadow 150ms;
}

input:not([type="checkbox"]):not([type="search"]):focus,
select:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 3px var(--pink-dim);
  background: white;
}

select { cursor: pointer; }

/* ═══════════════════════════════════════════
   STATUS PILL
═══════════════════════════════════════════ */
.status-pill {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 11px;
  border-radius: 999px;
  background: var(--blue-dim);
  border: 1px solid rgba(106, 174, 203, 0.3);
  color: var(--navy);
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}

/* ═══════════════════════════════════════════
   UTILITIES
═══════════════════════════════════════════ */
.hidden { display: none !important; }

/* ═══════════════════════════════════════════
   REDUCED MOTION
═══════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}

/* ═══════════════════════════════════════════
   RWD
═══════════════════════════════════════════ */
@media (max-width: 960px) {
  .app { padding: 8px 10px 12px; gap: 10px; }

  .app-header {
    flex-wrap: wrap;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--r-lg);
  }

  .header-status { order: -1; margin-left: auto; }

  .viewer-layout {
    grid-template-columns: 1fr;
  }

  .studio-layout {
    grid-template-columns: 260px minmax(0, 1fr);
  }

  .detail-tools { grid-template-columns: 1fr; }

  .reply-actions {
    flex-wrap: wrap;
  }

  .reply-actions .btn-ghost { flex: 1; }
  .reply-actions .btn-primary { width: 100%; }
}

@media (max-width: 760px) {
  html,
  body {
    height: 100%;
    min-height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    position: fixed;
    inset: 0;
    width: 100%;
  }

  .app {
    height: var(--app-height);
    max-height: var(--app-height);
    min-height: 0;
    padding: 8px 8px max(8px, env(safe-area-inset-bottom));
    gap: 8px;
    overflow: hidden;
  }

  .app-header {
    align-content: start;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--r-md);
  }

  .header-brand {
    min-width: 0;
  }

  .brand-sub,
  .header-status {
    display: none;
  }

  .auth-controls {
    margin-left: auto;
  }

  .header-nav {
    order: 2;
    flex-basis: 100%;
  }

  .tab {
    flex: 1;
    justify-content: center;
  }

  #viewerView,
  .viewer-layout,
  .chat-col {
    min-height: 0;
    height: 100%;
  }

  .chat-col:focus-within {
    grid-template-rows: auto minmax(96px, 1fr) auto;
  }

  .chat-toolbar {
    padding: 8px 10px;
  }

  .thread {
    min-height: 0;
    padding: 12px;
    overflow-y: auto;
    touch-action: pan-y;
  }

  .chat-body {
    max-height: none;
  }

  .composer {
    padding: 10px;
    gap: 8px;
    flex: 0 0 auto;
  }

  .composer textarea {
    font-size: 16px;
    min-height: 56px;
    max-height: 92px;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }

  .message-card {
    max-width: 88%;
  }

  .studio-topbar {
    align-items: flex-start;
    gap: 8px;
  }

  .studio-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(120px, 28%) minmax(0, 1fr);
  }

  .viewer-col {
    min-height: 0;
  }
}

@media (max-width: 600px) {
  .composer-footer { flex-wrap: nowrap; }
  .btn-primary { width: 100%; }
  .composer-footer .btn-primary { width: auto; }
  .studio-topbar { flex-wrap: wrap; gap: 10px; }
}
