:root {
  --bg-deep: #080c24;
  --bg-primary: #0d1130;
  --bg-card: #151a3a;
  --bg-card-alt: #1a2045;
  --accent: #7c6cf0;
  --accent-glow: rgba(124, 108, 240, 0.35);
  --gold: #f0c050;
  --text: #eaeaf0;
  --text2: #9898be;
  --text3: #5e5e82;
  --border: rgba(255,255,255,0.07);
  --glass: rgba(18,22,52,0.82);
  --radius: 16px;
  --radius-sm: 10px;
  --danger: #f05060;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  height: 100dvh; overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%;
  background: var(--bg-deep);
  color: var(--text);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}

/* ---- Particle Canvas ---- */
#particle-canvas {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  z-index: 0; pointer-events: none;
}

/* ---- App Shell ---- */
#app {
  position: relative; z-index: 1;
  height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ---- Pages ---- */
.page {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  opacity: 0; pointer-events: none;
  transform: translateY(12px);
  transition: opacity .3s ease, transform .3s ease;
  overflow: hidden;
}
.page.visible {
  opacity: 1; pointer-events: auto;
  transform: translateY(0);
}

/* ---- Navbar ---- */
.navbar {
  position: relative; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  height: 56px; padding: 0 20px;
  flex-shrink: 0;
  transition: background .3s;
}
.navbar.blurred {
  background: var(--glass);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
.nav-brand {
  font-size: 18px; font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--gold));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.nav-btn {
  background: rgba(124,108,240,0.15); color: var(--accent);
  border: 1px solid rgba(124,108,240,0.3);
  border-radius: 20px; padding: 6px 18px;
  font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all .2s;
  touch-action: manipulation;
}
.nav-btn:active { transform: scale(0.95); background: rgba(124,108,240,0.3); }

/* ---- Scroll Container ---- */
.scroll-container {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* ---- Hero ---- */
.hero {
  position: relative;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  min-height: 75vh; padding: 40px 24px;
  text-align: center;
}
.hero-glow {
  position: absolute; top: 15%; left: 50%; transform: translateX(-50%);
  width: 320px; height: 320px; border-radius: 50%;
  background: radial-gradient(circle, var(--accent-glow) 0%, rgba(240,192,80,0.12) 40%, transparent 70%);
  filter: blur(50px); pointer-events: none;
  animation: pulse-glow 4s ease-in-out infinite;
}
@keyframes pulse-glow {
  0%,100% { opacity: .45; transform: translateX(-50%) scale(1); }
  50% { opacity: .75; transform: translateX(-50%) scale(1.15); }
}
.hero-badge {
  display: inline-block; padding: 6px 18px;
  border: 1px solid rgba(240,192,80,0.3);
  border-radius: 20px; font-size: 13px;
  color: var(--gold); margin-bottom: 16px;
  background: rgba(240,192,80,0.08);
  animation: title-in .8s ease-out;
}
.hero-title {
  font-size: 56px; font-weight: 800; margin: 0;
  background: linear-gradient(135deg, #fff 30%, var(--accent) 70%, var(--gold));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: title-in .8s ease-out;
}
@keyframes title-in { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.hero-sub {
  font-size: 16px; color: var(--text2); margin: 12px 0 0;
  animation: title-in .8s ease-out .15s both;
  letter-spacing: 2px;
}
.hero-desc {
  font-size: 14px; color: var(--text2); margin: 16px 0 0;
  line-height: 1.8; max-width: 320px;
  animation: title-in .8s ease-out .25s both;
}
.hero-actions {
  display: flex; gap: 12px; margin-top: 28px;
  animation: title-in .8s ease-out .35s both;
}
.hero-btn {
  padding: 12px 28px; border-radius: 24px;
  font-size: 15px; font-weight: 600;
  cursor: pointer; transition: all .2s;
  touch-action: manipulation;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.06); color: var(--text);
}
.hero-btn.primary {
  background: linear-gradient(135deg, var(--accent), #6050d0);
  color: #fff; border: none;
}
.hero-btn:active { transform: scale(0.95); opacity: .85; }
.hero-hint {
  margin-top: 40px; font-size: 13px; color: var(--text3);
  animation: bounce-hint 2s ease-in-out infinite;
}
@keyframes bounce-hint { 0%,100% { transform: translateY(0); opacity:.6; } 50% { transform: translateY(8px); opacity:1; } }

/* ---- Character Scroll ---- */
.char-scroll {
  display: flex; gap: 14px; padding: 0 20px;
  overflow-x: auto; overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}
.char-scroll::-webkit-scrollbar { display: none; }
.char-card {
  flex: 0 0 130px; scroll-snap-align: start;
  display: flex; flex-direction: column; align-items: center;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 12px;
  transition: transform .2s; touch-action: manipulation;
  opacity: 0; transform: translateY(16px);
  animation: card-in .5s ease-out forwards;
}
.char-card:nth-child(1) { animation-delay: .1s; }
.char-card:nth-child(2) { animation-delay: .15s; }
.char-card:nth-child(3) { animation-delay: .2s; }
.char-card:nth-child(4) { animation-delay: .25s; }
.char-card:nth-child(5) { animation-delay: .3s; }
.char-card:nth-child(6) { animation-delay: .35s; }
.char-card:active { transform: scale(0.96); }
.char-avatar {
  width: 56px; height: 56px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700; color: #fff;
  margin-bottom: 10px;
}
.char-name {
  font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 4px;
}
.char-role {
  font-size: 12px; color: var(--text3);
}

/* ---- Stats / Game Data ---- */
.stats-section { padding: 8px 0; }
.stats-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px; padding: 0 20px;
}
.stats-grid .stat-item:last-child {
  grid-column: 1 / -1;
}
.stat-item {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  text-align: center; cursor: pointer;
  transition: transform .2s; touch-action: manipulation;
}
.stat-item:active { transform: scale(0.97); }
.stat-icon { font-size: 28px; margin-bottom: 6px; }
.stat-label { font-size: 12px; color: var(--text3); margin-bottom: 4px; }
.stat-value {
  font-size: 15px; color: var(--text); font-weight: 600;
  line-height: 1.4; min-height: 21px;
  transition: opacity .2s;
}

/* ---- Login Prompt ---- */
.login-prompt {
  display: flex; align-items: center; justify-content: space-between;
  margin: 0 20px 16px; padding: 12px 16px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.login-prompt.hidden { display: none; }
.login-prompt span { font-size: 13px; color: var(--text2); }
.btn-login-prompt {
  background: rgba(124,108,240,0.15); color: var(--accent);
  border: 1px solid rgba(124,108,240,0.3);
  border-radius: 16px; padding: 6px 16px;
  font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all .2s; touch-action: manipulation;
}
.btn-login-prompt:active { transform: scale(0.95); background: rgba(124,108,240,0.3); }

/* ---- User Bar ---- */
.user-bar {
  display: flex; align-items: center; justify-content: space-between;
  margin: 0 20px 12px; padding: 10px 16px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.user-bar.hidden { display: none; }
.user-bar-left { display: flex; align-items: center; gap: 10px; }
.user-bar-left .avatar-circle { width: 32px; height: 32px; font-size: 14px; }
.user-bar-left span { font-size: 14px; font-weight: 600; }
.user-bar-actions { display: flex; gap: 8px; }
.user-bar-btn {
  background: rgba(255,255,255,0.06); color: var(--text2);
  border: 1px solid var(--border); border-radius: 16px;
  padding: 5px 14px; font-size: 12px;
  cursor: pointer; transition: all .2s; touch-action: manipulation;
}
.user-bar-btn:active { transform: scale(0.95); background: rgba(255,255,255,0.1); }

/* ---- Section Title ---- */
.sec-title {
  font-size: 20px; font-weight: 700; margin: 0 0 16px;
  padding: 0 24px;
}

/* ---- Showcase ---- */
.showcase { padding: 0 0 8px; }
.card-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px; padding: 0 20px;
}
.showcase-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  cursor: pointer; transition: transform .2s, background .2s;
  touch-action: manipulation;
  opacity: 0; transform: translateY(20px);
  animation: card-in .5s ease-out forwards;
}
.showcase-card:nth-child(1) { animation-delay: .1s; }
.showcase-card:nth-child(2) { animation-delay: .2s; }
.showcase-card:nth-child(3) { animation-delay: .3s; }
.showcase-card:nth-child(4) { animation-delay: .4s; }
@keyframes card-in { to { opacity: 1; transform: translateY(0); } }
.showcase-card:active { transform: scale(0.97); background: var(--bg-card-alt); }
.card-icon { font-size: 28px; margin-bottom: 8px; }
.card-label { font-size: 13px; color: var(--text2); margin-bottom: 6px; font-weight: 500; }
.card-value { font-size: 15px; color: var(--text); font-weight: 600; line-height: 1.4; min-height: 21px; }

.showcase-card.feature-card .card-value {
  font-size: 13px; color: var(--text2); font-weight: 400;
}

/* Mood card */
.mood-card { grid-column: 1 / -1; }
.mood-row { display: flex; gap: 8px; margin: 8px 0; }
.mood-btn {
  flex: 1; font-size: 28px; padding: 8px 0;
  background: rgba(255,255,255,0.04); border: 2px solid transparent;
  border-radius: 12px; cursor: pointer;
  transition: all .2s; touch-action: manipulation;
}
.mood-btn:active { transform: scale(0.9); }
.mood-btn.active { border-color: var(--accent); background: rgba(124,108,240,0.15); transform: scale(1.1); }
.mood-result { color: var(--accent); font-size: 14px; text-align: center; }

/* Time card */
.time-display {
  font-size: 28px; font-weight: 700; letter-spacing: 2px;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(135deg, var(--gold), var(--accent));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ---- Forum / Composer ---- */
.forum { padding: 8px 0 0; }
.composer {
  margin: 0 20px 16px; padding: 16px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all .3s;
}
.composer.hidden { display: none; }
.composer-header { display: flex; gap: 12px; align-items: flex-start; }
.avatar-circle {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; color: #fff;
}
.avatar-circle.large { width: 72px; height: 72px; font-size: 28px; }
#post-input {
  flex: 1; background: rgba(255,255,255,0.05); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 14px; font-size: 16px; font-family: inherit;
  resize: none; outline: none; min-height: 60px;
  transition: border-color .2s; line-height: 1.5;
  -webkit-user-select: text; user-select: text;
}
#post-input:focus { border-color: var(--accent); }
#post-input::placeholder { color: var(--text3); }
.composer-actions {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 10px;
}
.char-count { font-size: 12px; color: var(--text3); }
.btn-send {
  background: linear-gradient(135deg, var(--accent), #6050d0);
  color: #fff; border: none; border-radius: 20px;
  padding: 8px 24px; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all .2s; touch-action: manipulation;
}
.btn-send:active { transform: scale(0.95); opacity: .85; }
.btn-send:disabled { opacity: .4; pointer-events: none; }

/* ---- Post Card ---- */
.post-card {
  margin: 0 20px 12px; padding: 16px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius);
  opacity: 0; transform: translateY(12px);
  animation: card-in .4s ease-out forwards;
}
.post-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.post-author { font-size: 14px; font-weight: 600; }
.post-time { font-size: 12px; color: var(--text3); margin-left: auto; }
.post-content {
  font-size: 15px; line-height: 1.6; color: var(--text); margin-bottom: 12px;
  word-break: break-word; white-space: pre-wrap;
  -webkit-user-select: text; user-select: text;
}
.post-actions { display: flex; gap: 16px; }
.post-action-btn {
  display: flex; align-items: center; gap: 5px;
  background: none; border: none; color: var(--text2);
  font-size: 13px; cursor: pointer; padding: 4px 8px;
  border-radius: 8px; transition: all .2s; touch-action: manipulation;
}
.post-action-btn:active { transform: scale(0.9); }
.post-action-btn.liked { color: var(--danger); }
.post-action-btn .icon { font-size: 16px; }

/* Comments */
.comments-section {
  margin-top: 12px; padding-top: 12px;
  border-top: 1px solid var(--border);
  display: none;
}
.comments-section.open { display: block; }
.comment-item {
  display: flex; gap: 8px; margin-bottom: 10px; align-items: flex-start;
}
.comment-item .avatar-circle { width: 28px; height: 28px; font-size: 12px; }
.comment-body { flex: 1; }
.comment-meta { font-size: 12px; color: var(--text2); margin-bottom: 2px; }
.comment-text { font-size: 14px; color: var(--text); line-height: 1.4; }
.comment-form { display: flex; gap: 8px; margin-top: 10px; align-items: center; }
.comment-form input {
  flex: 1; background: rgba(255,255,255,0.05); color: var(--text);
  border: 1px solid var(--border); border-radius: 20px;
  padding: 8px 14px; font-size: 14px; font-family: inherit;
  outline: none; transition: border-color .2s;
  -webkit-user-select: text; user-select: text;
}
.comment-form input:focus { border-color: var(--accent); }
.comment-form input::placeholder { color: var(--text3); }
.comment-form button {
  background: var(--accent); color: #fff; border: none;
  border-radius: 20px; padding: 8px 14px; font-size: 13px;
  font-weight: 600; cursor: pointer; flex-shrink: 0;
  transition: all .2s; touch-action: manipulation;
}
.comment-form button:active { transform: scale(0.95); }

/* ---- Empty State ---- */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text3); }
.empty-icon { font-size: 48px; margin-bottom: 12px; }

/* ---- Load More ---- */
.btn-load-more {
  display: block; margin: 8px auto 20px;
  background: rgba(124,108,240,0.1); color: var(--accent);
  border: 1px solid rgba(124,108,240,0.2); border-radius: 20px;
  padding: 10px 28px; font-size: 14px; cursor: pointer;
  transition: all .2s; touch-action: manipulation;
}
.btn-load-more:active { transform: scale(0.95); }
.btn-load-more.hidden { display: none; }
.bottom-spacer { height: 40px; }

/* ---- Auth Page ---- */
.auth-wrap {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 20px 24px; position: relative;
}
.back-btn {
  position: absolute; top: 12px; left: 16px;
  background: none; border: none; color: var(--text2);
  font-size: 15px; cursor: pointer; padding: 8px;
  touch-action: manipulation; z-index: 5;
}
.auth-card {
  width: 100%; max-width: 360px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 20px; padding: 32px 24px;
  text-align: center;
}
.auth-logo { font-size: 48px; margin-bottom: 8px; }
.auth-title { font-size: 22px; font-weight: 700; margin: 0 0 24px; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form.hidden { display: none; }
.auth-form input {
  background: rgba(255,255,255,0.06); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 16px; font-size: 16px; font-family: inherit;
  outline: none; transition: border-color .2s;
  -webkit-user-select: text; user-select: text;
}
.auth-form input:focus { border-color: var(--accent); }
.auth-form input::placeholder { color: var(--text3); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #6050d0);
  color: #fff; border: none; border-radius: var(--radius-sm);
  padding: 14px; font-size: 16px; font-weight: 600;
  cursor: pointer; transition: all .2s; margin-top: 4px;
  touch-action: manipulation;
}
.btn-primary:active { transform: scale(0.97); opacity: .85; }
.btn-text {
  background: none; border: none; color: var(--accent);
  font-size: 13px; cursor: pointer; padding: 8px;
  touch-action: manipulation;
}
.auth-switch {
  margin-top: 20px; font-size: 14px; color: var(--text2);
  display: flex; align-items: center; justify-content: center; gap: 4px;
}

/* ---- Profile ---- */
.profile-section { padding: 16px 24px; }
.profile-card {
  display: flex; flex-direction: column; align-items: center;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px 20px;
}
.profile-name { font-size: 20px; font-weight: 700; margin-top: 12px; }
.profile-date { font-size: 13px; color: var(--text3); margin-top: 4px; }
.btn-danger {
  width: 100%; background: rgba(240,80,96,0.12); color: var(--danger);
  border: 1px solid rgba(240,80,96,0.25); border-radius: var(--radius-sm);
  padding: 14px; font-size: 16px; font-weight: 600;
  cursor: pointer; transition: all .2s; touch-action: manipulation;
}
.btn-danger:active { transform: scale(0.97); opacity: .8; }

/* ---- Toast ---- */
.toast {
  position: fixed; z-index: 100;
  bottom: calc(80px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%) translateY(16px);
  background: var(--bg-card); color: var(--text);
  border: 1px solid var(--border);
  border-radius: 24px; padding: 10px 24px;
  font-size: 14px; font-weight: 500;
  opacity: 0; pointer-events: none;
  transition: all .3s ease;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- Scrollbar ---- */
.scroll-container::-webkit-scrollbar { width: 3px; }
.scroll-container::-webkit-scrollbar-track { background: transparent; }
.scroll-container::-webkit-scrollbar-thumb { background: rgba(124,108,240,0.3); border-radius: 3px; }