/* ============================================================
   AiMing v12 Design System
   Unified red→purple brand, iOS-style rounded cards,
   light + dark theme, fluid responsive layout.
   ============================================================ */

/* --- Design Tokens --- */
:root {
  /* Brand gradient */
  --brand-red: #E63946;
  --brand-red-2: #DC2A40;
  --brand-purple: #6A40C8;
  --brand-purple-2: #764BA2;
  --brand-gradient: linear-gradient(90deg, #E63946 0%, #6A40C8 100%);
  --brand-gradient-strong: linear-gradient(90deg, #E63946 0%, #B8368A 45%, #6A40C8 100%);
  --brand-gradient-soft: linear-gradient(135deg, rgba(230,57,70,.08), rgba(106,64,200,.08));

  /* Semantic (light) */
  --bg: #FFFFFF;
  --bg-elev: #F5F5F7;
  --bg-elev-2: #FAFAFB;
  --bg-overlay: rgba(0, 0, 0, .45);
  --border: #E5E5EA;
  --border-strong: #D1D1D6;
  --text: #1C1C1E;
  --text-muted: #6E6E73;
  --text-inverse: #FFFFFF;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 16px rgba(0, 0, 0, .06);
  --shadow-float: 0 8px 32px rgba(0, 0, 0, .12);
  /* Chinese fortune semantics: Red = Good (auspicious), Black = Bad (inauspicious) */
  --success: #E63946;
  --danger:  #1C1C1E;
  --warning: #FF9500;
  --chip-bg: #F2F2F7;
  --god-red: #E63946;
  --god-dark: #2C2C2E;
  --day-highlight: #FCE4E6;
  --day-highlight-border: #E63946;

  /* Radius / spacing */
  --r-xs: 8px;  --r-sm: 12px; --r-md: 16px; --r-lg: 20px;
  --r-xl: 24px; --r-pill: 999px;
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-7: 28px; --sp-8: 32px;

  /* Typography */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
          "Noto Sans Thai", "Sarabun", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fs-xs: 12px; --fs-sm: 13px; --fs-md: 15px; --fs-lg: 17px;
  --fs-xl: 20px; --fs-2xl: 24px; --fs-3xl: 28px; --fs-4xl: 34px;
  --fw-reg: 400; --fw-med: 500; --fw-semi: 600; --fw-bold: 700; --fw-heavy: 800;

  /* Motion */
  --ease: cubic-bezier(.2, .8, .2, 1);
  --dur-fast: 150ms;
  --dur: 220ms;
  --dur-slow: 360ms;

  /* Layout */
  --app-max-narrow: 720px;
  --app-max-wide: 1100px;
  --sidebar-w: 300px;
  --header-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

:root[data-theme="dark"] {
  --bg: #0A0A0A;
  --bg-elev: #1C1C1E;
  --bg-elev-2: #1A1A1A;
  --bg-overlay: rgba(0, 0, 0, .6);
  --border: #2C2C2E;
  --border-strong: #3A3A3C;
  --text: #FFFFFF;
  --text-muted: #A1A1A6;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, .6), 0 4px 16px rgba(0, 0, 0, .4);
  --shadow-float: 0 8px 32px rgba(0, 0, 0, .6);
  --chip-bg: #1C1C1E;
  --god-red: #FF4D5E;
  --god-dark: #3A3A3C;
  --success: #FF4D5E;
  --danger:  #48484A;
  --day-highlight: #3A1C20;
  --day-highlight-border: #FF4D5E;
}

/* --- Reset & Base --- */
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
html { min-height: 100%; }
body { min-height: 100vh; }

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; padding: 0; }
input, textarea, select { font-family: inherit; }
a { color: var(--brand-purple); text-decoration: none; }
:root[data-theme="dark"] a { color: #9B7FE0; }

/* --- App Shell --- */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.page-narrow {
  width: 100%;
  max-width: var(--app-max-narrow);
  margin: 0 auto;
  padding: 0 var(--sp-4);
}

.page-wide {
  width: 100%;
  max-width: var(--app-max-wide);
  margin: 0 auto;
}

/* --- Header (generic top bar) --- */
.topbar {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-4);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-title {
  flex: 1;
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-title .dot-accent { color: var(--brand-red); }
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--r-pill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  transition: background-color var(--dur-fast) var(--ease);
}
.icon-btn:hover { background: var(--bg-elev); }
.icon-btn svg { width: 24px; height: 24px; stroke-width: 2; }

.avatar-chip {
  height: 40px;
  min-width: 40px;
  padding: 0 6px 0 4px;
  border-radius: var(--r-pill);
  background: var(--brand-gradient);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: white;
  font-weight: var(--fw-bold);
  font-size: var(--fs-sm);
  cursor: pointer;
  border: none;
  transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.avatar-chip:hover { transform: scale(1.04); box-shadow: 0 4px 12px rgba(230,57,70,.25); }
.avatar-chip .persona-emoji {
  display: inline-flex;
  width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
}
.avatar-chip .persona-caret {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: .9;
}
.avatar-chip .persona-caret svg { width: 14px; height: 14px; stroke-width: 2.5; }

.avatar-calendar {
  width: 40px;
  height: 40px;
  border-radius: var(--r-pill);
  background: var(--brand-gradient);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: white;
  transition: transform var(--dur-fast) var(--ease);
}
.avatar-calendar:hover { transform: scale(1.05); }
.avatar-calendar svg { width: 20px; height: 20px; }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--r-pill);
  font-size: var(--fs-md);
  font-weight: var(--fw-semi);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
  min-height: 44px;
}
.btn-primary {
  background: var(--brand-gradient);
  color: white;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); box-shadow: var(--shadow-card); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.btn-ghost {
  background: var(--bg-elev);
  color: var(--text);
}
.btn-ghost:hover { background: var(--border); }

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border-strong);
}
.btn-outline:hover { background: var(--bg-elev); }

.btn-block { width: 100%; }

/* --- Chip / pill --- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--r-pill);
  background: var(--chip-bg);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: var(--fw-med);
  white-space: nowrap;
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
  border: 1px solid transparent;
}
.chip:hover { border-color: var(--border-strong); }
.chip-brand {
  background: var(--brand-gradient);
  color: white;
}

/* 10-god badge */
.god-badge {
  display: inline-block;
  padding: 2px var(--sp-2);
  border-radius: var(--r-xs);
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  color: white;
  background: var(--god-red);
  letter-spacing: .02em;
}
.god-badge.dark { background: var(--god-dark); }
.god-badge.auspicious { background: var(--success); }
.god-badge.inauspicious { background: var(--danger); }
.god-badge.neutral { background: var(--text-muted); }

/* Tag pill (used in day detail good/bad sections) */
.tag {
  display: inline-block;
  padding: 2px var(--sp-2);
  border-radius: var(--r-pill);
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  color: white;
}
.tag-success { background: var(--success); }
.tag-danger  { background: var(--danger); }

.forecast-section {
  margin-top: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  background: var(--bg-elev-2);
  border-left: 3px solid var(--border);
}
.forecast-section.forecast-good { border-left-color: var(--success); }
.forecast-section.forecast-bad  { border-left-color: var(--danger); }
.forecast-section .forecast-section-title { margin-bottom: var(--sp-2); }

/* Pillar row: Heaven stem + Earth branch Chinese characters with 10-God badges */
.pillar-row {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
}
.stem-cell {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.stem-cell .han-char {
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  color: var(--text);
  line-height: 1;
  min-width: 1em;
  text-align: center;
}

/* --- Card --- */
.card {
  background: var(--bg-elev);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  box-shadow: var(--shadow-card);
}
.card-plain {
  background: var(--bg-elev);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
}
.card-gradient {
  background: var(--brand-gradient);
  color: white;
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-card);
}
.card-gradient-strong {
  background: var(--brand-gradient-strong);
  color: white;
  border-radius: var(--r-lg);
  padding: var(--sp-5);
}

/* Grouped list (iOS-style) */
.group-list {
  background: var(--bg-elev);
  border-radius: var(--r-md);
  overflow: hidden;
}
.group-list .row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease);
  border-bottom: 1px solid var(--border);
}
.group-list .row:last-child { border-bottom: none; }
.group-list .row:hover { background: var(--bg-elev-2); }
.group-list .row .row-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  color: var(--text);
}
.group-list .row .row-label {
  flex: 1;
  font-size: var(--fs-md);
  color: var(--text);
}
.group-list .row .row-sublabel {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: 2px;
}
.group-list .row .row-trailing {
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
}

/* --- Input / Textarea --- */
.text-field {
  width: 100%;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: var(--fs-md);
  outline: none;
  transition: border-color var(--dur-fast) var(--ease);
}
.text-field:focus { border-color: var(--brand-purple); }
.text-field::placeholder { color: var(--text-muted); }

.input-pill {
  width: 100%;
  padding: 14px 56px 14px var(--sp-5);
  border-radius: var(--r-pill);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: var(--fs-md);
  outline: none;
  resize: none;
  min-height: 52px;
  max-height: 160px;
  font-family: inherit;
  line-height: 1.4;
}
.input-pill:focus { border-color: var(--brand-purple); }

/* --- Toast --- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--sp-8) + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--r-pill);
  font-size: var(--fs-sm);
  font-weight: var(--fw-med);
  box-shadow: var(--shadow-float);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
  z-index: 1000;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* --- Modal --- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: var(--sp-4);
  animation: fadeIn var(--dur) var(--ease);
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg);
  border-radius: var(--r-xl);
  padding: var(--sp-5);
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow: auto;
  box-shadow: var(--shadow-float);
  animation: popIn var(--dur) var(--ease);
}
.modal-title {
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
  margin: 0 0 var(--sp-2) 0;
  color: var(--text);
}
.modal-subtitle {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin: 0 0 var(--sp-4) 0;
}
.modal-close {
  position: absolute;
  top: var(--sp-4);
  right: var(--sp-4);
}

/* Selector option card (model/language) */
.option-card {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4);
  background: var(--bg-elev);
  border-radius: var(--r-md);
  cursor: pointer;
  border: 2px solid transparent;
  transition: all var(--dur-fast) var(--ease);
  margin-bottom: var(--sp-3);
}
.option-card:hover { background: var(--bg-elev-2); }
.option-card.selected {
  border-color: var(--brand-red);
}
.option-card .option-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--r-pill);
  background: var(--bg-elev-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 20px;
  overflow: hidden;
}
.option-card .option-label {
  flex: 1;
  font-weight: var(--fw-semi);
  color: var(--text);
}
.option-card .option-check {
  width: 28px;
  height: 28px;
  border-radius: var(--r-pill);
  background: var(--brand-red);
  color: white;
  display: none;
  align-items: center;
  justify-content: center;
}
.option-card.selected .option-check { display: inline-flex; }

/* --- Sidebar (drawer / persistent) --- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 340px;
  max-width: 85vw;
  height: 100vh;
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform var(--dur) var(--ease);
  z-index: 50;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}
.sidebar.open { transform: translateX(0); }
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur) var(--ease);
  z-index: 40;
}
.sidebar-backdrop.open { opacity: 1; pointer-events: auto; }

.sidebar-top {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  flex-wrap: wrap;
}
.sidebar-top .pill-btn,
.sidebar-top .pill-btn:link,
.sidebar-top .pill-btn:visited,
.sidebar-top .pill-btn:hover,
.sidebar-top .pill-btn:active {
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--r-pill);
  background: var(--brand-red);
  color: #FFFFFF;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semi);
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  text-decoration: none;
}
.sidebar-top .pill-btn svg { stroke: #FFFFFF; }

.sidebar-actions {
  display: flex;
  gap: var(--sp-2);
  padding: 0 var(--sp-4) var(--sp-3);
}
.sidebar-actions .new-chat-btn {
  flex-shrink: 0;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-pill);
  background: var(--bg-elev);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semi);
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
}
.sidebar-actions .search-wrap {
  flex: 1;
  position: relative;
}
.sidebar-actions .search-wrap svg {
  position: absolute;
  left: var(--sp-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 18px;
  height: 18px;
}
.sidebar-actions .search-wrap input {
  width: 100%;
  padding: var(--sp-3) var(--sp-3) var(--sp-3) 40px;
  border-radius: var(--r-pill);
  background: var(--bg-elev);
  border: 1px solid transparent;
  color: var(--text);
  outline: none;
}

.sidebar-list {
  flex: 1 0 auto;
  padding: 0 var(--sp-4) var(--sp-4);
}
.conv-row {
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-elev);
  border-radius: var(--r-md);
  margin-bottom: var(--sp-2);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
  position: relative;
}
.conv-row:hover { background: var(--bg-elev-2); }
.conv-row.active {
  background: var(--brand-gradient);
  color: white;
}
.conv-row .title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: var(--fw-med);
}
.conv-row .menu-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-pill);
  color: inherit;
  opacity: .7;
}
.conv-row .menu-btn:hover { opacity: 1; background: rgba(255,255,255,.15); }
.conv-row .pin-marker { color: var(--brand-red); font-size: var(--fs-xs); }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border-top: 1px solid var(--border);
}
.sidebar-footer .avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--r-pill);
  background: var(--bg-elev);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.sidebar-footer .name { font-weight: var(--fw-semi); }
.sidebar-footer .profile-badge {
  display: inline-block;
  padding: 2px var(--sp-2);
  border-radius: var(--r-pill);
  background: var(--brand-gradient);
  color: white;
  font-size: var(--fs-xs);
  margin-left: var(--sp-2);
}

.conv-menu-pop {
  position: absolute;
  right: var(--sp-3);
  top: 100%;
  margin-top: var(--sp-1);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-float);
  min-width: 180px;
  z-index: 30;
  display: none;
}
.conv-menu-pop.open { display: block; }
.conv-menu-pop .menu-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-sm);
  cursor: pointer;
  color: var(--text);
}
.conv-menu-pop .menu-item:hover { background: var(--bg-elev); }
.conv-menu-pop .menu-item.danger { color: var(--danger); }

/* --- Chat layout (split-pane: each side scrolls independently) --- */
.chat-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 0;         /* allow shrink below content intrinsic width */
  max-width: 100%;
  overflow: hidden;
  padding-top: var(--safe-top);
}
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-4);
}

.date-pill {
  background: var(--brand-gradient-strong);
  color: white;
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.date-pill .cal-icon {
  width: 40px;
  height: 40px;
  background: rgba(255,255,255,.22);
  border-radius: var(--r-pill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.date-pill .small { font-size: var(--fs-sm); opacity: .9; }
.date-pill .big { font-size: var(--fs-xl); font-weight: var(--fw-bold); }

.msg-row {
  display: flex;
  margin-bottom: var(--sp-4);
  animation: fadeUp var(--dur) var(--ease);
}
.msg-row.user { justify-content: flex-end; }
.msg-row.ai { justify-content: flex-start; align-items: flex-start; gap: var(--sp-3); }

.bubble-user {
  max-width: 80%;
  padding: var(--sp-3) var(--sp-4);
  background: var(--brand-gradient);
  color: white;
  border-radius: 20px 20px 4px 20px;
  font-size: var(--fs-md);
  line-height: 1.55;
  box-shadow: var(--shadow-card);
  word-wrap: break-word;
}
.bubble-ai {
  max-width: 85%;
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 4px 20px 20px 20px;
  font-size: var(--fs-md);
  line-height: 1.7;
  word-wrap: break-word;
}
.bubble-ai img { max-width: 100%; border-radius: var(--r-sm); }
.bubble-ai p { margin: 0 0 var(--sp-2) 0; }
.bubble-ai p:last-child { margin-bottom: 0; }
.bubble-ai h1, .bubble-ai h2, .bubble-ai h3 {
  margin-top: var(--sp-3);
  margin-bottom: var(--sp-2);
  font-weight: var(--fw-bold);
}
.bubble-ai ul, .bubble-ai ol { margin: var(--sp-2) 0; padding-left: var(--sp-5); }
.bubble-ai li { margin-bottom: var(--sp-1); }
.bubble-ai code {
  background: var(--bg-elev-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 90%;
}

.ai-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--r-pill);
  background:
    radial-gradient(circle at 30% 30%, #FFD1E8, transparent 40%),
    radial-gradient(circle at 70% 70%, #B794F6, transparent 40%),
    linear-gradient(135deg, #FBBF24, #A78BFA 60%, #60A5FA);
  flex-shrink: 0;
  box-shadow: 0 0 8px rgba(167,139,250,.4);
}
.ai-name {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-bottom: var(--sp-1);
  font-weight: var(--fw-semi);
}

.msg-ai-wrap { display: flex; gap: var(--sp-3); align-items: flex-start; }

.think-panel {
  background: var(--bg-elev);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-3);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease);
  width: fit-content;
  max-width: 100%;
}
.think-panel:hover { background: var(--bg-elev-2); }
.think-panel .think-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  font-weight: var(--fw-semi);
  color: var(--text);
  white-space: nowrap;
}
.think-panel .think-header > span:first-child {
  white-space: nowrap;
}
.think-panel .think-body {
  margin-top: var(--sp-3);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  line-height: 1.6;
  white-space: pre-wrap;
  display: none;
}
.think-panel.open .think-body { display: block; }
.think-panel.open .chev { transform: rotate(180deg); }
.think-panel .chev { transition: transform var(--dur) var(--ease); }

.placeholder-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  color: var(--text-muted);
  padding: var(--sp-3) var(--sp-4);
  animation: pulse 1.6s ease-in-out infinite;
}

.tool-status-box {
  background: linear-gradient(135deg, rgba(52,199,89,.12), rgba(52,199,89,.04));
  border-left: 3px solid var(--success);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-sm);
  margin: var(--sp-2) 0;
  color: var(--text);
  font-size: var(--fs-sm);
}
.web-search-status-box {
  background: linear-gradient(135deg, rgba(96,165,250,.12), rgba(96,165,250,.04));
  border-left: 3px solid #60A5FA;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-sm);
  margin: var(--sp-2) 0;
  color: var(--text);
  font-size: var(--fs-sm);
}

.msg-actions {
  display: flex;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
  margin-left: 44px;
}
.msg-action-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--r-pill);
  background: var(--bg-elev);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  transition: all var(--dur-fast) var(--ease);
}
.msg-action-btn:hover { background: var(--bg-elev-2); color: var(--text); }
.msg-action-btn svg { width: 14px; height: 14px; }

/* Quick chip rail */
.chip-rail {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  scroll-snap-type: x mandatory;
  max-width: 100%;
  min-width: 0;
  -webkit-overflow-scrolling: touch;
  cursor: grab;
  user-select: none;
}
.chip-rail.dragging { cursor: grabbing; }
.chip-rail.dragging .chip { pointer-events: none; }
.chip-rail::-webkit-scrollbar { display: none; }
.chip-rail .chip { scroll-snap-align: start; }

/* Composer */
.composer {
  padding: var(--sp-2) var(--sp-4) calc(var(--sp-3) + var(--safe-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
}
.composer-inner {
  position: relative;
  max-width: 880px;
  margin: 0 auto;
}
.composer .send-btn {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 44px;
  height: 44px;
  border-radius: var(--r-pill);
  background: var(--brand-gradient);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--dur-fast) var(--ease);
}
.composer .send-btn:hover:not(:disabled) { transform: scale(1.05); }
.composer .send-btn:disabled { opacity: .5; cursor: not-allowed; }
.composer .send-btn svg { width: 20px; height: 20px; }

/* Image preview strip */
.image-preview-strip {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
  padding: 0 var(--sp-4) var(--sp-2);
}
.image-preview-item {
  width: 64px;
  height: 64px;
  border-radius: var(--r-sm);
  background-size: cover;
  background-position: center;
  position: relative;
  border: 1px solid var(--border);
}
.image-preview-item .remove {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 20px;
  height: 20px;
  border-radius: var(--r-pill);
  background: var(--danger);
  color: white;
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Attach toolbar (composer left side) */
.attach-row {
  position: absolute;
  left: 6px;
  bottom: 6px;
  display: inline-flex;
  gap: 4px;
  z-index: 1;
}
.composer .attach-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.composer .attach-btn:hover { background: var(--bg-elev); color: var(--brand-red); }
.composer .attach-btn svg { width: 18px; height: 18px; }
.composer.has-attach-row .input-pill { padding-left: 88px; }

/* PDF / file attachment chip */
.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  font-size: var(--fs-sm);
  position: relative;
  max-width: 240px;
}
.attach-chip .attach-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--r-xs);
  background: var(--brand-gradient);
  color: white;
  flex-shrink: 0;
}
.attach-chip .attach-icon svg { width: 14px; height: 14px; }
.attach-chip .attach-meta { display: flex; flex-direction: column; min-width: 0; }
.attach-chip .attach-name {
  font-weight: var(--fw-semi);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}
.attach-chip .attach-size { font-size: var(--fs-xs); color: var(--text-muted); }
.attach-chip .remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: var(--r-pill);
  background: var(--danger);
  color: white;
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* Ghost button (sidebar history/future entries) */
.ghost-btn {
  flex-shrink: 0;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semi);
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  border: 1px solid var(--border);
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.ghost-btn:hover { background: var(--bg-elev); border-color: var(--border-strong); }
.ghost-btn svg { width: 16px; height: 16px; }

/* --- Welcome / FAQ --- */
.welcome-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6) var(--sp-4);
  text-align: center;
  color: var(--text-muted);
}
.welcome-wrap h2 {
  color: var(--text);
  font-size: var(--fs-2xl);
  margin: 0 0 var(--sp-2) 0;
}

/* --- Four Pillars table --- */
.four-pillars {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-2);
  margin: var(--sp-4) 0;
}
.pillar-col {
  background: var(--bg-elev);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-2);
  text-align: center;
  position: relative;
  overflow: hidden;
  border: 2px solid transparent;
}
.pillar-col.highlight {
  background: var(--day-highlight);
  border-color: var(--day-highlight-border);
}
.pillar-col .col-title {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  font-weight: var(--fw-bold);
  padding: 4px var(--sp-2);
  border-radius: var(--r-xs);
  background: var(--bg-elev-2);
  display: inline-block;
  margin-bottom: var(--sp-2);
}
.pillar-col .stem-han {
  font-size: var(--fs-3xl);
  font-weight: var(--fw-bold);
  line-height: 1;
  margin: var(--sp-2) 0;
}
.pillar-col .element-label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-bottom: var(--sp-2);
}
.pillar-col .branch-wrap {
  margin-top: var(--sp-2);
  padding-top: var(--sp-2);
  border-top: 1px solid var(--border);
}
.pillar-col .branch-row {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  justify-content: center;
  width: 100%;
}
.pillar-col .branch-han {
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  line-height: 1;
}
.pillar-col .hidden-stems-right {
  display: inline-flex;
  flex-direction: column;
  gap: 0;
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.1;
  font-weight: var(--fw-semi);
}
.pillar-col .animal-label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: var(--sp-1);
}
.pillar-col .life-badge {
  position: absolute;
  top: var(--sp-2);
  right: var(--sp-2);
  padding: 2px var(--sp-2);
  border-radius: var(--r-xs);
  background: var(--day-highlight-border);
  color: white;
  font-size: 10px;
  font-weight: var(--fw-bold);
}
/* 10-God badge variants for profile four-pillars: red for heaven, dark for earth */
.pillar-col .god-badge {
  display: inline-block;
  padding: 3px var(--sp-2);
  border-radius: var(--r-xs);
  font-size: 11px;
  font-weight: var(--fw-bold);
  color: white;
  margin: var(--sp-1) 0;
  letter-spacing: .02em;
  white-space: nowrap;
}
.pillar-col .god-badge-red { background: var(--danger); }
.pillar-col .god-badge-green { background: var(--success); }
.pillar-col .god-badge-dark {
  background: var(--text);
  color: var(--bg);
}
:root[data-theme="dark"] .pillar-col .god-badge-dark {
  background: var(--text-muted);
  color: var(--bg);
}

.element-stem-wood { color: #22C55E; }
.element-stem-fire { color: #EF4444; }
.element-stem-earth { color: #B45309; }
.element-stem-metal { color: #D1D5DB; }
.element-stem-water { color: #3B82F6; }
:root[data-theme="dark"] .element-stem-metal { color: #9CA3AF; }

/* --- Profile-specific --- */
.element-tag-group {
  display: flex;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-top: var(--sp-2);
}
.element-tag {
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-pill);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semi);
  background: var(--bg-elev-2);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
}
.element-tag.water { background: #D6EAFF; color: #0B5AB8; }
.element-tag.wood  { background: #D1F2DC; color: #0F7A3E; }
.element-tag.metal { background: #EFEFEF; color: #555; }
.element-tag.fire  { background: #FFD7D7; color: #B00020; }
.element-tag.earth { background: #F7ECD7; color: #8A5A00; }
:root[data-theme="dark"] .element-tag.water { background: #0B3A66; color: #8BC4FF; }
:root[data-theme="dark"] .element-tag.wood { background: #0F3A1E; color: #86EFAC; }
:root[data-theme="dark"] .element-tag.metal { background: #3A3A3C; color: #D1D5DB; }
:root[data-theme="dark"] .element-tag.fire { background: #4A1616; color: #FCA5A5; }
:root[data-theme="dark"] .element-tag.earth { background: #3A2A10; color: #FCD4A8; }

.profile-table {
  background: var(--bg-elev);
  border-radius: var(--r-md);
  padding: var(--sp-4);
}
.profile-table .p-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--border);
}
.profile-table .p-row:last-child { border-bottom: none; }
.profile-table .p-row .p-key { color: var(--text-muted); }
.profile-table .p-row .p-val { color: var(--text); font-weight: var(--fw-semi); }

/* AIMING Friend card */
.friend-card {
  background: var(--brand-gradient-strong);
  color: white;
  padding: var(--sp-5);
  border-radius: var(--r-lg);
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease);
}
.friend-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-float); }
.friend-card .title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--sp-2);
}
.friend-card .title {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
}
.friend-card .days-left {
  font-size: var(--fs-sm);
  background: rgba(255,255,255,.18);
  padding: 2px var(--sp-3);
  border-radius: var(--r-pill);
}
.friend-card .desc { font-size: var(--fs-sm); opacity: .94; line-height: 1.5; }

/* Two-column row (referral + items) */
.two-col {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--sp-3);
  margin: var(--sp-3) 0;
}
.referral-card {
  background: var(--brand-gradient);
  color: white;
  padding: var(--sp-4);
  border-radius: var(--r-lg);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  cursor: pointer;
}
.referral-card .icon-circle {
  width: 44px;
  height: 44px;
  background: rgba(255,255,255,.18);
  border-radius: var(--r-pill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.referral-card .r-title { font-weight: var(--fw-bold); }
.referral-card .r-sub { font-size: var(--fs-xs); opacity: .9; }

.items-tile {
  background: var(--bg-elev);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  text-align: center;
  cursor: pointer;
  position: relative;
  transition: background-color var(--dur-fast) var(--ease);
}
.items-tile:hover { background: var(--bg-elev-2); }
.items-tile .tile-icon {
  width: 40px;
  height: 40px;
  margin: 0 auto var(--sp-2);
  background: var(--bg-elev-2);
  border-radius: var(--r-pill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.items-tile .tile-label {
  font-size: var(--fs-sm);
  font-weight: var(--fw-semi);
  color: var(--text);
}
.items-tile .badge {
  position: absolute;
  top: var(--sp-2);
  right: var(--sp-2);
  width: 20px;
  height: 20px;
  background: var(--brand-red);
  color: white;
  border-radius: var(--r-pill);
  font-size: var(--fs-xs);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--fw-bold);
}

/* --- Calendar page --- */
.calendar-header {
  background: var(--brand-gradient-strong);
  color: white;
  padding: var(--sp-4) var(--sp-4) var(--sp-6);
  border-radius: var(--r-lg);
  margin: var(--sp-3) 0;
  position: relative;
}
.calendar-header .title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-4);
}
.calendar-header .title-row .title { font-size: var(--fs-xl); font-weight: var(--fw-bold); }
.calendar-header .month-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.calendar-header .month-row .nav-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--r-pill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: white;
}
.calendar-header .month-row .nav-btn:hover { background: rgba(255,255,255,.15); }
.calendar-header .month-row .month-label {
  font-weight: var(--fw-semi);
  font-size: var(--fs-lg);
  min-width: 120px;
  text-align: center;
}
.calendar-header .mode-toggle {
  position: absolute;
  right: var(--sp-4);
  top: 52%;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-pill);
  background: rgba(255,255,255,.18);
  color: white;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semi);
}
.date-strip {
  display: flex;
  gap: var(--sp-2);
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: var(--sp-1);
  cursor: grab;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  user-select: none;
}
.date-strip.dragging { cursor: grabbing; scroll-behavior: auto; }
.date-strip.dragging .date-tile { pointer-events: none; }
.date-strip::-webkit-scrollbar { display: none; }
.date-tile {
  flex-shrink: 0;
  width: 52px;
  padding: var(--sp-2);
  border-radius: var(--r-sm);
  background: var(--brand-red);
  color: white;
  text-align: center;
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
  position: relative;
}
.date-tile:hover { transform: translateY(-2px); }
.date-tile.today {
  background: white;
  color: var(--text);
}
.date-tile .dow { font-size: var(--fs-xs); opacity: .9; }
.date-tile .dom { font-size: var(--fs-xl); font-weight: var(--fw-bold); }
.date-tile .dot-today {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-radius: var(--r-pill);
  background: var(--brand-red);
}

.day-summary {
  background: var(--bg-elev);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  margin: var(--sp-3) 0;
  box-shadow: var(--shadow-card);
}
.day-summary .status-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-3);
}
.day-summary .status-row .status-tag {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: var(--fs-sm);
  color: var(--text);
}
.day-summary .status-row .logo-mark {
  color: var(--brand-purple);
}
.day-summary .stems-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  margin: var(--sp-2) 0;
}
.day-summary .stems-row .stem-block {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: var(--fw-bold);
  font-size: var(--fs-lg);
}
.day-summary .stems-row .stem-block .colored-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--r-pill);
  display: inline-block;
  background: var(--danger);
}
.day-summary .stems-row .stem-block .colored-dot.green { background: var(--success); }
.day-summary .description {
  color: var(--text);
  line-height: 1.6;
  margin: var(--sp-3) 0;
}
.day-summary .read-more {
  display: block;
  width: 100%;
  padding: var(--sp-3);
  border-radius: var(--r-pill);
  background: var(--brand-gradient);
  color: white;
  text-align: center;
  font-weight: var(--fw-semi);
  margin-top: var(--sp-3);
}

.hours-section {
  margin-top: var(--sp-5);
}
.hours-section-title {
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  margin: 0 0 var(--sp-3) 0;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.hour-card {
  background: var(--bg-elev);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  margin-bottom: var(--sp-3);
}
.hour-card .time-row {
  font-weight: var(--fw-bold);
  margin-bottom: var(--sp-2);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  justify-content: space-between;
  flex-wrap: wrap;
}
.hour-card .time-row .pillar-row .han-char {
  font-size: var(--fs-xl);
}
.hour-card .time-range { color: var(--text); }
.hour-card .pillar { color: var(--brand-red); font-weight: var(--fw-bold); }
.hour-card .hour-desc {
  color: var(--text);
  font-size: var(--fs-sm);
  line-height: 1.55;
}
.hour-card.favorable { border-left: 3px solid var(--success); }
.hour-card.unfavorable { border-left: 3px solid var(--danger); }
.hour-card.mixed { border-left: 3px solid transparent; }
.hour-card .hour-pillar { margin-bottom: var(--sp-2); }
.hour-card .hour-pillar .han-char { font-size: var(--fs-xl); }

/* Month picker grid */
.month-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-2);
}
.month-grid .month-cell {
  padding: var(--sp-3);
  text-align: center;
  border-radius: var(--r-md);
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid transparent;
  font-weight: var(--fw-semi);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.month-grid .month-cell:hover { background: var(--bg-elev-2); }
.month-grid .month-cell.is-today { border-color: var(--brand-red); }
.month-grid .month-cell.active {
  background: var(--brand-gradient);
  color: #fff;
  border-color: transparent;
}

/* --- Package page --- */
.package-features {
  margin-top: var(--sp-5);
}
.feature-row {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--border);
}
.feature-row:last-child { border-bottom: none; }
.feature-check {
  width: 28px;
  height: 28px;
  border-radius: var(--r-pill);
  background: var(--brand-red);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-weight: var(--fw-bold);
}
.feature-text .feature-title { font-weight: var(--fw-semi); }
.feature-text .feature-desc { font-size: var(--fs-sm); color: var(--text-muted); }

/* --- UUID gate (index.html) --- */
.uuid-gate {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6);
  background: var(--bg);
  position: relative;
  overflow: hidden;
}
.uuid-gate::before {
  content: '';
  position: absolute;
  top: -60%;
  left: -40%;
  width: 120%;
  height: 120%;
  background: radial-gradient(ellipse at center, rgba(230,57,70,.08), transparent 60%),
              radial-gradient(ellipse at 75% 30%, rgba(106,64,200,.12), transparent 60%);
  pointer-events: none;
  z-index: 0;
}
.uuid-gate .content {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 480px;
}
.uuid-gate .brand-logo {
  width: 80px;
  height: 80px;
  border-radius: 22px;
  background: var(--brand-gradient-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto var(--sp-5);
  box-shadow: 0 16px 36px rgba(106,64,200,.35);
}
.uuid-gate h1 {
  font-size: var(--fs-3xl);
  font-weight: var(--fw-heavy);
  text-align: center;
  margin: 0 0 var(--sp-2);
  color: var(--text);
}
.uuid-gate .subtitle {
  text-align: center;
  color: var(--text-muted);
  margin: 0 0 var(--sp-6);
  font-size: var(--fs-md);
}
.uuid-gate .person-card {
  background: var(--bg-elev);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  margin-bottom: var(--sp-3);
  position: relative;
}
.uuid-gate .person-card label {
  display: block;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-bottom: var(--sp-2);
  font-weight: var(--fw-semi);
}
.uuid-gate .person-card .remove-btn {
  position: absolute;
  top: var(--sp-2);
  right: var(--sp-2);
  width: 28px;
  height: 28px;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--text-muted);
}
.uuid-gate .person-card .remove-btn:hover { background: var(--border); color: var(--danger); }
.uuid-gate .add-btn {
  background: transparent;
  color: var(--brand-red);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-lg);
  padding: var(--sp-3);
  width: 100%;
  font-weight: var(--fw-semi);
  font-size: var(--fs-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
  margin-bottom: var(--sp-5);
}
.uuid-gate .add-btn:hover { background: var(--brand-gradient-soft); }

/* --- Timeline (history/future) legacy restyle --- */
.timeline-container {
  padding: var(--sp-4);
}
.timeline-event {
  background: var(--bg-elev);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  margin-bottom: var(--sp-3);
  border-left: 4px solid var(--brand-red);
  box-shadow: var(--shadow-card);
}
.timeline-event .year {
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
  color: var(--brand-red);
}
.timeline-event .pillar {
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  color: var(--text);
  margin-bottom: var(--sp-2);
}
.timeline-event .details {
  color: var(--text-muted);
  font-size: var(--fs-sm);
  line-height: 1.55;
}

/* --- Utility --- */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.spacer-sm { height: var(--sp-3); }
.spacer-md { height: var(--sp-5); }
.spacer-lg { height: var(--sp-8); }

/* --- Animations --- */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes popIn {
  from { opacity: 0; transform: scale(.95); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes pulse {
  0%, 100% { opacity: .55; }
  50% { opacity: 1; }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- History / Future timeline --- */
.events-hero {
  background: var(--brand-gradient-strong);
  color: white;
  padding: var(--sp-5) var(--sp-4) var(--sp-5);
  margin: 0 calc(var(--sp-4) * -1);
  padding-top: calc(var(--sp-5) + var(--safe-top));
  border-radius: 0 0 var(--r-xl) var(--r-xl);
  margin-bottom: var(--sp-4);
}
.events-hero .hero-title { font-weight: var(--fw-bold); font-size: var(--fs-xl); margin-bottom: 4px; }
.events-hero .hero-desc { font-size: var(--fs-sm); opacity: .92; line-height: 1.5; }
.events-hero .hero-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,.18);
  color: white;
  width: 36px;
  height: 36px;
  border-radius: var(--r-pill);
  margin-bottom: var(--sp-3);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--sp-2);
  margin: var(--sp-4) 0;
}
.stat-card {
  background: var(--bg-elev);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-2);
  text-align: center;
}
.stat-card .stat-num {
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  color: var(--brand-red);
  line-height: 1.1;
}
.stat-card .stat-label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: 4px;
}

/* Timeline (single column, alternating not used — cleaner mobile-first) */
.timeline {
  position: relative;
  padding-left: var(--sp-5);
  margin: var(--sp-3) 0;
}
.timeline::before {
  content: '';
  position: absolute;
  left: 12px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(180deg, var(--brand-red) 0%, var(--brand-purple) 100%);
  opacity: .3;
}
.tl-item {
  position: relative;
  margin-bottom: var(--sp-4);
}
.tl-dot {
  position: absolute;
  left: calc(var(--sp-5) * -1 + 4px);
  top: 18px;
  width: 16px;
  height: 16px;
  border-radius: var(--r-pill);
  background: var(--bg);
  border: 3px solid var(--brand-red);
  box-shadow: 0 0 0 4px rgba(230, 57, 70, .18);
}
.tl-dot.annual   { border-color: var(--brand-purple); box-shadow: 0 0 0 4px rgba(106, 64, 200, .18); }
.tl-dot.monthly  { border-color: var(--brand-red); }
.tl-card {
  background: var(--bg-elev);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  border-left: 3px solid var(--brand-red);
}
.tl-card.career   { border-left-color: var(--brand-purple); }
.tl-card.personal { border-left-color: var(--brand-red); }
.tl-card .tl-head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  margin-bottom: var(--sp-2);
}
.tl-year {
  font-weight: var(--fw-bold);
  color: var(--brand-red);
  font-size: var(--fs-lg);
}
.tl-pillar {
  display: inline-block;
  padding: 2px var(--sp-3);
  border-radius: var(--r-pill);
  background: var(--brand-gradient-strong);
  color: white;
  font-weight: var(--fw-bold);
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', sans-serif;
  font-size: var(--fs-md);
  letter-spacing: .04em;
}
.tl-chip {
  display: inline-block;
  padding: 2px var(--sp-2);
  border-radius: var(--r-pill);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semi);
  background: var(--bg-elev-2);
  color: var(--text-muted);
}
.tl-chip.career   { background: rgba(106, 64, 200, .12); color: var(--brand-purple); }
.tl-chip.personal { background: rgba(230, 57, 70, .12); color: var(--brand-red); }
:root[data-theme="dark"] .tl-chip.career   { background: rgba(106, 64, 200, .25); color: #B89AFF; }
:root[data-theme="dark"] .tl-chip.personal { background: rgba(230, 57, 70, .25); color: #FF8B9A; }
.tl-interactions {
  margin-top: var(--sp-2);
  padding-top: var(--sp-2);
  border-top: 1px dashed var(--border);
  font-size: var(--fs-sm);
  color: var(--text);
}
.tl-interactions ul { padding-left: var(--sp-4); margin: 4px 0; }
.tl-commentary {
  margin-top: var(--sp-3);
  padding: var(--sp-3);
  background: var(--bg);
  border-radius: var(--r-sm);
  border-left: 3px solid var(--success);
  font-size: var(--fs-sm);
  font-style: italic;
  color: var(--text-muted);
  line-height: 1.55;
}
.tl-commentary .tl-commentary-label {
  font-style: normal;
  font-weight: var(--fw-bold);
  color: var(--text);
  display: block;
  margin-bottom: 4px;
}

/* Loading indicator with spinner + time counter */
.loading-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-6) var(--sp-4);
  color: var(--text-muted);
  text-align: center;
}
.loading-spinner {
  width: 32px;
  height: 32px;
  border-radius: var(--r-pill);
  border: 3px solid var(--border);
  border-top-color: var(--brand-red);
  border-right-color: var(--brand-purple);
  animation: spin .9s linear infinite;
}
.loading-label {
  font-size: var(--fs-md);
  font-weight: var(--fw-semi);
  color: var(--text);
}
.loading-eta {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.loading-progress-track {
  width: min(240px, 80%);
  height: 4px;
  border-radius: var(--r-pill);
  background: var(--border);
  overflow: hidden;
}
.loading-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--brand-gradient);
  transition: width .4s linear;
}

/* --- Responsive breakpoints --- */
@media (min-width: 768px) {
  .chat-scroll { padding: var(--sp-5) var(--sp-6); }
  .composer { padding: var(--sp-3) var(--sp-6) calc(var(--sp-4) + var(--safe-bottom)); }
}

/* Persistent sidebar on chat — show as left bar on tablets and desktops */
@media (min-width: 768px) {
  .chat-layout .sidebar {
    position: relative;
    transform: none;
    width: var(--sidebar-w);
    height: 100vh;
    flex-shrink: 0;
    max-width: var(--sidebar-w);
    overflow-y: auto;
  }
  .chat-layout .sidebar-backdrop { display: none; }
  .chat-layout .menu-btn-hamburger { display: none !important; }
  .chat-layout .sidebar-close-btn { display: none; }
}

@media (max-width: 767px) {
  .page-narrow { padding: 0 var(--sp-3); }
  .chat-scroll { padding: var(--sp-3); }
  .two-col { grid-template-columns: 1fr 1fr; }
  .friend-card { padding: var(--sp-4); }
  .modal { max-width: 100%; }
  .pillar-col { padding: var(--sp-2) 4px; }
  .pillar-col .stem-han { font-size: var(--fs-2xl); }
  .pillar-col .branch-han { font-size: var(--fs-lg); }
}

@media (max-width: 400px) {
  .four-pillars { gap: 4px; }
  .pillar-col .stem-han { font-size: var(--fs-xl); }
}
