/* ===== Reset & Variables ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --line-green: #06C755;
  --line-green-dark: #04A847;
  --line-bg: #7B96B2;
  --bubble-bot: #FFFFFF;
  --bubble-user: #06C755;
  --text-primary: #111111;
  --text-secondary: #666666;
  --text-muted: #999999;
  --border: #E5E5E5;
  --bg-light: #F7F8FA;
  --card-shadow: 0 2px 12px rgba(0,0,0,0.08);
  --font: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
  --phone-w: 375px;
  --phone-h: 100dvh;
}
html, body {
  font-family: var(--font);
  background: #1a1a2e;
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ===== Phone Frame (desktop centering) ===== */
#app {
  width: var(--phone-w);
  max-width: 100vw;
  height: var(--phone-h);
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  background: #fff;
}
@media (min-width: 500px) {
  body { display: flex; align-items: center; justify-content: center; }
  #app {
    height: 812px;
    border-radius: 24px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  }
}

/* ===== Fake Status Bar ===== */
.status-bar {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  font-size: 12px;
  font-weight: 600;
}
.status-bar .time { font-size: 15px; font-weight: 700; }
.status-bar-icons { display: flex; gap: 4px; font-size: 11px; }

/* ================================================================
   LOGIN SCREEN
   ================================================================ */
.login-screen {
  height: 100%;
  background: linear-gradient(135deg, #06C755 0%, #04A847 50%, #028A3D 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-logo {
  width: 80px;
  height: 80px;
  background: rgba(255,255,255,0.2);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  margin-bottom: 16px;
  backdrop-filter: blur(10px);
}
.login-title {
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 4px;
  text-align: center;
}
.login-subtitle {
  color: rgba(255,255,255,0.8);
  font-size: 13px;
  margin-bottom: 32px;
}
.login-card {
  width: 100%;
  max-width: 320px;
  background: #fff;
  border-radius: 16px;
  padding: 28px 24px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.15);
}
.login-field {
  margin-bottom: 16px;
}
.login-field label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.login-field input {
  width: 100%;
  height: 44px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 0 14px;
  font-size: 15px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
}
.login-field input:focus {
  border-color: var(--line-green);
}
.login-btn {
  width: 100%;
  height: 48px;
  background: var(--line-green);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.2s;
}
.login-btn:active { background: var(--line-green-dark); }
.login-error {
  color: #E53935;
  font-size: 12px;
  text-align: center;
  margin-top: 12px;
  min-height: 18px;
}
.login-api-toggle {
  color: rgba(255,255,255,0.6);
  font-size: 11px;
  margin-top: 16px;
  cursor: pointer;
  text-decoration: underline;
}
.login-api-field {
  width: 100%;
  max-width: 320px;
  margin-top: 12px;
  display: none;
}
.login-api-field.show { display: block; }
.login-api-field input {
  width: 100%;
  height: 40px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 10px;
  padding: 0 14px;
  font-size: 13px;
  font-family: var(--font);
  color: #fff;
  outline: none;
}
.login-api-field input::placeholder { color: rgba(255,255,255,0.5); }

/* ================================================================
   TALK LIST SCREEN
   ================================================================ */
.talk-screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #fff;
}
.talk-header {
  background: #fff;
  padding: 0 16px 12px;
}
.talk-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}
.talk-header h1 {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary);
}
.talk-header-icons {
  display: flex;
  gap: 16px;
  font-size: 18px;
  color: var(--text-muted);
}
.talk-search {
  width: 100%;
  height: 36px;
  background: #F0F0F0;
  border-radius: 18px;
  border: none;
  padding: 0 16px;
  font-size: 14px;
  font-family: var(--font);
  color: var(--text-muted);
  outline: none;
}

/* Talk entries */
.talk-list {
  flex: 1;
  overflow-y: auto;
}
.talk-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  transition: background 0.1s;
  position: relative;
}
.talk-entry:active { background: #F5F5F5; }
.talk-entry.disabled { opacity: 0.5; pointer-events: none; }
.talk-entry + .talk-entry { border-top: 0.5px solid #F0F0F0; }
.talk-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
  position: relative;
}
.talk-avatar.official {
  background: linear-gradient(135deg, #E53935, #B71C1C);
}
.talk-avatar.personal { background: #E8E8E8; }
.talk-avatar.group { background: #FFD93D; }
.official-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 20px;
  height: 20px;
  background: var(--line-green);
  border-radius: 50%;
  border: 2px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: #fff;
}
.talk-content {
  flex: 1;
  min-width: 0;
}
.talk-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 3px;
}
.talk-preview {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.talk-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}
.talk-time {
  font-size: 11px;
  color: var(--text-muted);
}
.talk-badge {
  min-width: 20px;
  height: 20px;
  background: #E53935;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  padding: 0 6px;
}

/* Bottom tab bar */
.tab-bar {
  height: 56px;
  background: #fff;
  border-top: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding-bottom: env(safe-area-inset-bottom, 0);
  flex-shrink: 0;
}
.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 10px;
  color: var(--text-muted);
}
.tab-item.active { color: var(--line-green); }
.tab-item .tab-icon { font-size: 22px; }

/* ================================================================
   CHAT SCREEN
   ================================================================ */
.chat-screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--line-bg);
}

/* Chat header */
.chat-header {
  height: 56px;
  background: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border-bottom: 0.5px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}
.chat-back {
  font-size: 24px;
  color: var(--line-green);
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}
.chat-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #E53935, #B71C1C);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.chat-header-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  flex: 1;
}
.chat-header-icons {
  display: flex;
  gap: 14px;
  font-size: 18px;
  color: var(--text-muted);
}

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px 8px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* Date separator */
.date-separator {
  text-align: center;
  margin: 8px 0 16px;
}
.date-separator span {
  background: rgba(0,0,0,0.15);
  color: #fff;
  font-size: 11px;
  padding: 4px 12px;
  border-radius: 12px;
}

/* Message row */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  margin-bottom: 6px;
  animation: msg-in 0.25s ease-out;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg-row.bot { justify-content: flex-start; }
.msg-row.user { justify-content: flex-end; }

.msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #E53935, #B71C1C);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  align-self: flex-start;
}

/* Bubble */
.msg-bubble {
  max-width: 260px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
}
.msg-row.bot .msg-bubble {
  background: var(--bubble-bot);
  color: var(--text-primary);
  border-radius: 0 18px 18px 18px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.msg-row.user .msg-bubble {
  background: var(--bubble-user);
  color: #fff;
  border-radius: 18px 0 18px 18px;
}

/* Image bubble */
.msg-bubble.image {
  padding: 4px;
  overflow: hidden;
}
.msg-bubble.image img {
  display: block;
  width: 100%;
  max-width: 220px;
  border-radius: 14px;
}
.msg-row.bot .msg-bubble.image { border-radius: 0 18px 18px 18px; }
.msg-row.user .msg-bubble.image { border-radius: 18px 0 18px 18px; }

/* Timestamp */
.msg-time {
  font-size: 10px;
  color: rgba(255,255,255,0.6);
  flex-shrink: 0;
  align-self: flex-end;
  margin-bottom: 2px;
}

/* Typing indicator */
.typing-dots {
  display: flex;
  gap: 4px;
  padding: 14px 18px;
}
.typing-dots span {
  width: 8px;
  height: 8px;
  background: #CCC;
  border-radius: 50%;
  animation: typing-bounce 1.4s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* ===== Card Messages (rich content in chat) ===== */
.msg-card {
  background: #fff;
  border-radius: 14px;
  overflow: hidden;
  max-width: 280px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.msg-row.bot .msg-card { border-radius: 0 14px 14px 14px; }

/* Result card */
.result-card { padding: 0; }
.result-card .result-header {
  background: var(--line-green);
  color: #fff;
  padding: 14px 16px;
  text-align: center;
}
.result-card .result-header .check {
  width: 48px;
  height: 48px;
  background: rgba(255,255,255,0.25);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin: 0 auto 8px;
  animation: pop 0.5s ease-out;
}
@keyframes pop {
  0% { transform: scale(0.3); opacity: 0; }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}
.result-card .result-header h3 {
  font-size: 15px;
  font-weight: 800;
}
.result-card .result-body { padding: 12px 16px; }
.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #F0F0F0;
  font-size: 13px;
}
.result-row:last-child { border-bottom: none; }
.result-label { color: var(--text-muted); font-weight: 600; }
.result-value { color: var(--text-primary); font-weight: 700; text-align: right; }
.result-value.green { color: var(--line-green); }

/* Confidence bar */
.confidence-bar {
  width: 80px;
  height: 5px;
  background: #E8E8E8;
  border-radius: 3px;
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
  margin-right: 6px;
}
.confidence-fill {
  height: 100%;
  background: linear-gradient(90deg, #06C755, #04E762);
  border-radius: 3px;
  transition: width 1s ease-out;
}

/* Token award in card */
.token-award-card {
  background: linear-gradient(135deg, #06C755, #04A847);
  padding: 14px 16px;
  text-align: center;
  color: #fff;
}
.token-award-card .amount {
  font-size: 28px;
  font-weight: 900;
  letter-spacing: 1px;
}
.token-award-card .label {
  font-size: 12px;
  opacity: 0.85;
}

/* AI feedback */
.ai-feedback {
  padding: 12px 16px;
  border-top: 1px solid #F0F0F0;
}
.ai-feedback-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.ai-feedback-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea, #764ba2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}
.ai-feedback-name {
  font-size: 11px;
  font-weight: 700;
  color: #667eea;
}
.ai-feedback-text {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ===== Event Cards (carousel) ===== */
.event-carousel {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding: 4px 0;
  max-width: 280px;
}
.event-carousel::-webkit-scrollbar { display: none; }
.event-card {
  flex-shrink: 0;
  width: 220px;
  background: #fff;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  scroll-snap-align: start;
}
.event-card-header {
  padding: 16px 14px 10px;
}
.event-card-icon {
  font-size: 28px;
  margin-bottom: 8px;
}
.event-card-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.event-card-detail {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 8px;
}
.event-card-token {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #E8F8EE;
  color: var(--line-green);
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 12px;
}
.event-card-footer {
  padding: 0 14px 14px;
}
.event-join-btn {
  width: 100%;
  height: 36px;
  background: var(--line-green);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.2s;
}
.event-join-btn:active { background: var(--line-green-dark); }
.event-join-btn:disabled {
  background: #CCC;
  cursor: default;
}

/* ===== Balance Card ===== */
.balance-card {
  background: #fff;
  border-radius: 14px;
  overflow: hidden;
  max-width: 280px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.msg-row.bot .balance-card { border-radius: 0 14px 14px 14px; }
.balance-header {
  background: linear-gradient(135deg, #E53935, #B71C1C);
  padding: 20px 16px;
  text-align: center;
  color: #fff;
}
.balance-amount {
  font-size: 36px;
  font-weight: 900;
  letter-spacing: 1px;
}
.balance-label {
  font-size: 12px;
  opacity: 0.85;
  margin-top: 2px;
}
.balance-history {
  padding: 12px 16px;
}
.balance-history-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 12px;
  border-bottom: 1px solid #F5F5F5;
}
.history-item:last-child { border-bottom: none; }
.history-desc { color: var(--text-secondary); }
.history-amount { font-weight: 700; }
.history-amount.earn { color: var(--line-green); }
.history-amount.spend { color: #E53935; }
.history-empty {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 12px 0;
}

/* ===== Reward Cards ===== */
.reward-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 280px;
}
.reward-card {
  background: #fff;
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  display: flex;
  align-items: center;
  gap: 12px;
}
.reward-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: #F0F0F0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.reward-info { flex: 1; min-width: 0; }
.reward-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
}
.reward-cost {
  font-size: 11px;
  color: var(--text-muted);
}
.reward-exchange-btn {
  height: 32px;
  padding: 0 14px;
  background: var(--line-green);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  flex-shrink: 0;
}
.reward-exchange-btn:disabled {
  background: #DDD;
  color: #999;
  cursor: default;
}

/* ===== Ranking Card ===== */
.ranking-card {
  background: #fff;
  border-radius: 14px;
  overflow: hidden;
  max-width: 280px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.msg-row.bot .ranking-card { border-radius: 0 14px 14px 14px; }
.ranking-header {
  background: linear-gradient(135deg, #FFD700, #FFA500);
  padding: 14px 16px;
  text-align: center;
  color: #fff;
  font-size: 15px;
  font-weight: 800;
}
.ranking-list { padding: 8px 16px; }
.ranking-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 13px;
  border-bottom: 1px solid #F5F5F5;
}
.ranking-item:last-child { border-bottom: none; }
.ranking-item.me {
  background: #E8F8EE;
  margin: 0 -16px;
  padding: 8px 16px;
  border-radius: 8px;
}
.ranking-pos {
  width: 24px;
  text-align: center;
  font-weight: 800;
  color: var(--text-muted);
}
.ranking-name { flex: 1; font-weight: 600; color: var(--text-primary); }
.ranking-score { font-weight: 700; color: var(--line-green); }

/* ===== Chat Input Bar ===== */
.chat-input-area {
  flex-shrink: 0;
  background: #fff;
  z-index: 10;
}
.chat-input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 0.5px solid var(--border);
}
.chat-input-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 50%;
  transition: background 0.2s;
}
.chat-input-btn:active { background: #F0F0F0; }
.chat-input-btn.camera { color: var(--text-muted); }
.chat-input-btn.send {
  background: var(--line-green);
  color: #fff;
  font-size: 16px;
}
.chat-input-btn.send:disabled {
  background: #DDD;
  color: #fff;
}
.chat-text-input {
  flex: 1;
  height: 36px;
  border: 1.5px solid #E8E8E8;
  border-radius: 18px;
  padding: 0 14px;
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
}
.chat-text-input:focus { border-color: var(--line-green); }
.chat-text-input::placeholder { color: #CCC; }

/* Rich menu toggle */
.rich-menu-toggle {
  width: 100%;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-muted);
  transition: color 0.2s;
}
.rich-menu-toggle:active { color: var(--line-green); }
.rich-menu-toggle.open { color: var(--line-green); }

/* ===== Rich Menu Panel ===== */
.rich-menu {
  background: #fff;
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.3s ease;
  max-height: 0;
  opacity: 0;
}
.rich-menu.open {
  max-height: 160px;
  opacity: 1;
}
.rich-menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: #E8E8E8;
  margin: 0 12px 8px;
  border-radius: 12px;
  overflow: hidden;
}
.rich-menu-item {
  background: #fff;
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
  transition: background 0.1s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.rich-menu-item:active { background: #F5F5F5; }
.rich-menu-item .rm-icon { font-size: 26px; }
.rich-menu-item .rm-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-primary);
}

/* ===== Loading Overlay ===== */
.analyzing-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.analyzing-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.analyzing-text {
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}

/* ===== Confetti ===== */
.confetti-container {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 200;
  overflow: hidden;
}
.confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  animation: confetti-fall 2.5s ease-out forwards;
}
@keyframes confetti-fall {
  0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* ===== Utility ===== */
.hidden { display: none !important; }
