:root {
  --bg: #f7f5f2;
  --surface: #fffdf9;
  --surface-soft: #faf8f5;
  --text: #2c2c2c;
  --muted: #7a736d;
  --line: rgba(44, 44, 44, 0.09);
  --green: #2d5016;
  --orange: #d4784c;
  --orange-soft: #f0d8ca;
  --shadow: 0 22px 70px rgba(67, 54, 42, 0.13);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(circle at 10% 0%, rgba(212, 120, 76, 0.10), transparent 30%),
    linear-gradient(180deg, #f8f5ef 0%, var(--bg) 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.7;
  overflow: hidden;
}

button,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  min-height: 100%;
  display: flex;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 600px;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
}

@media (min-width: 680px) {
  body {
    padding: 20px;
  }

  .app-shell {
    align-items: center;
  }

  .app {
    height: min(860px, calc(100vh - 40px));
    border: 1px solid rgba(255, 255, 255, 0.72);
    border-radius: 28px;
    box-shadow: var(--shadow);
  }
}

.app-header {
  padding: 18px 18px 10px;
  background: rgba(245, 243, 240, 0.94);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.app-header h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 680;
  letter-spacing: 0.08em;
}

.app-header p {
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.new-chat {
  flex: 0 0 auto;
  margin-top: 3px;
  padding: 7px 11px;
  border-radius: 999px;
  background: rgba(255, 253, 249, 0.74);
  color: #6d625a;
  border: 1px solid rgba(44, 44, 44, 0.08);
  font-size: 13px;
}

.new-chat:active {
  transform: translateY(1px);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 8px 12px 12px;
  background: rgba(245, 243, 240, 0.94);
  border-bottom: 1px solid var(--line);
  position: relative;
}

.tabs::after {
  content: "";
  position: absolute;
  left: 12px;
  right: auto;
  bottom: 5px;
  width: calc((100% - 24px - 12px) / 3);
  height: 3px;
  border-radius: 999px;
  background: var(--orange);
  transform: translateX(calc(var(--active-index, 0) * (100% + 6px)));
  transition: transform 0.28s ease;
}

.tabs[data-active-index="0"] {
  --active-index: 0;
}

.tabs[data-active-index="1"] {
  --active-index: 1;
}

.tabs[data-active-index="2"] {
  --active-index: 2;
}

.tab {
  min-height: 42px;
  border-radius: 15px;
  background: transparent;
  color: #6d625a;
  border: 1px solid transparent;
  font-size: 15px;
  transition: color 0.2s ease, background 0.2s ease, transform 0.2s ease;
  position: relative;
  z-index: 1;
}

.tab.active {
  background: rgba(212, 120, 76, 0.10);
  color: #8a4d32;
  border-color: rgba(212, 120, 76, 0.12);
  box-shadow: none;
}

.tab-panel {
  min-height: 0;
  display: none;
}

.tab-panel.active {
  display: flex;
  animation: panelFade 0.24s ease both;
}

@keyframes panelFade {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#chatPanel {
  flex-direction: column;
  padding: 14px 14px calc(12px + var(--safe-bottom));
  gap: 12px;
}

.daily-card {
  flex: 0 0 auto;
  background: linear-gradient(135deg, rgba(255, 253, 249, 0.96), rgba(250, 248, 245, 0.82));
  border: 1px solid rgba(212, 120, 76, 0.18);
  border-radius: 20px;
  padding: 13px 14px;
  box-shadow: 0 10px 26px rgba(92, 70, 50, 0.06);
}

.daily-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: #75513d;
  font-size: 14px;
  font-weight: 650;
}

.daily-head button {
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  padding: 2px;
  white-space: nowrap;
}

.daily-card p {
  margin: 8px 0 0;
  color: #3c332d;
}

.daily-card.collapsed p {
  display: none;
}

.message-list {
  min-height: 0;
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 13px;
  padding: 2px 2px 8px;
}

.message-list::-webkit-scrollbar {
  width: 8px;
}

.message-list::-webkit-scrollbar-thumb {
  background: rgba(45, 80, 22, 0.13);
  border-radius: 999px;
}

.message {
  max-width: 82%;
  animation: fadeUp 0.3s ease-out both;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message.ai {
  align-self: flex-start;
}

.message.user {
  align-self: flex-end;
}

.message-name {
  margin: 0 0 4px 7px;
  color: var(--muted);
  font-size: 12px;
}

.message.user .message-name {
  margin: 0 7px 4px 0;
  text-align: right;
  color: rgba(45, 80, 22, 0.66);
}

.bubble {
  padding: 12px 14px;
  border-radius: 18px;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 8px 18px rgba(64, 54, 44, 0.06);
}

.message.ai .bubble {
  background: var(--surface-soft);
  border: 1px solid rgba(44, 44, 44, 0.06);
  border-top-left-radius: 7px;
}

.message.thinking .bubble {
  color: var(--muted);
}

.typing-dots {
  display: inline-flex;
  gap: 3px;
  margin-left: 5px;
  vertical-align: 2px;
}

.typing-dots i {
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: rgba(212, 120, 76, 0.72);
  animation: dotPulse 0.9s ease-in-out infinite;
}

.typing-dots i:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dots i:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes dotPulse {
  0%, 80%, 100% {
    transform: translateY(0);
    opacity: 0.35;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.message.user .bubble {
  background: linear-gradient(135deg, #2d5016, #3f6425);
  color: #fffdf9;
  border-top-right-radius: 7px;
  box-shadow: 0 10px 22px rgba(45, 80, 22, 0.16);
}

.composer {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 9px;
  background: rgba(255, 253, 249, 0.72);
  border: 1px solid rgba(44, 44, 44, 0.08);
  border-radius: 18px;
  padding: 8px;
}

textarea {
  width: 100%;
  min-height: 42px;
  max-height: 112px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  padding: 9px 8px 7px;
}

textarea::placeholder {
  color: #aaa19a;
}

.composer button {
  min-height: 42px;
  border-radius: 14px;
  background: var(--orange);
  color: white;
  padding: 10px 15px;
  box-shadow: 0 8px 18px rgba(212, 120, 76, 0.22);
}

.composer button:disabled {
  opacity: 0.5;
  cursor: default;
  box-shadow: none;
}

.role-panel,
.community-panel {
  align-items: center;
  justify-content: center;
  padding: 22px;
  overflow-y: auto;
}

.community-panel {
  align-items: stretch;
  justify-content: flex-start;
}

.role-card,
.empty-state {
  width: 100%;
  max-width: 460px;
  background: rgba(255, 253, 249, 0.76);
  border: 1px solid rgba(44, 44, 44, 0.08);
  border-radius: 28px;
  padding: 28px 18px;
  text-align: center;
  box-shadow: 0 16px 45px rgba(70, 56, 44, 0.08);
}

.avatar {
  width: 106px;
  height: 106px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--orange-soft);
  font-size: 54px;
  box-shadow: inset 0 0 0 8px rgba(255, 253, 249, 0.58);
}

.role-card h2,
.empty-state h2 {
  margin: 0 0 4px;
  font-size: 24px;
}

.character-meta {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
}

.intimacy-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin: 14px 0 16px;
}

.progress {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #eee7df;
  box-shadow: inset 0 1px 3px rgba(64, 54, 44, 0.08);
}

.progress span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--orange), #e8a06d);
  transition: width 0.28s ease;
}

.intimacy-row strong {
  color: #6a4a38;
  font-size: 13px;
  white-space: nowrap;
}

.role-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 10px;
}

.role-tags span {
  background: #f4efe9;
  color: #5f493b;
  border: 1px solid rgba(212, 120, 76, 0.16);
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 14px;
}

.role-card p,
.empty-state p {
  margin: 0;
  color: var(--muted);
}

.character-section {
  text-align: center;
}

.status-text {
  margin-top: 9px;
  color: #4a4039;
  font-size: 15px;
}

.memory-board {
  margin-top: 22px;
  display: grid;
  gap: 16px;
  text-align: left;
}

.memory-section {
  background: rgba(250, 248, 245, 0.72);
  border: 1px solid rgba(44, 44, 44, 0.06);
  border-radius: 18px;
  padding: 13px;
}

.memory-section h3 {
  margin: 0 0 10px;
  color: #4a4039;
  font-size: 15px;
  font-weight: 650;
}

.memory-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.memory-tags span {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 9px;
  background: #f4efe9;
  color: #5f493b;
  border: 1px solid rgba(212, 120, 76, 0.14);
  font-size: 13px;
}

.quote-list {
  display: grid;
  gap: 9px;
}

.memory-quote {
  border-left: 3px solid rgba(212, 120, 76, 0.45);
  padding-left: 10px;
}

.memory-quote p {
  margin: 0 0 4px;
  color: var(--text);
  font-size: 14px;
}

.memory-quote time,
.memory-empty {
  color: var(--muted);
  font-size: 13px;
}

.memory-empty {
  margin: 0;
}

.memory-hint {
  align-self: center;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(212, 120, 76, 0.12);
  color: #8a5539;
  font-size: 13px;
  animation: fadeUp 0.18s ease-out both;
}

.milestone-list {
  display: grid;
  gap: 7px;
}

.milestone {
  color: var(--muted);
  font-size: 14px;
}

.milestone.done {
  color: #4f6b35;
}

.community-page {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  display: grid;
  gap: 14px;
}

.community-title {
  text-align: left;
}

.community-title h2 {
  margin: 0 0 4px;
  font-size: 24px;
}

.community-title p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.debate-list {
  display: grid;
  gap: 14px;
}

.debate-card {
  background: rgba(255, 253, 249, 0.78);
  border: 1px solid rgba(44, 44, 44, 0.08);
  border-radius: 24px;
  padding: 16px;
  box-shadow: 0 16px 42px rgba(70, 56, 44, 0.08);
}

.debate-card.expanded {
  border-color: rgba(212, 120, 76, 0.26);
}

.debate-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: #75513d;
  font-size: 14px;
  font-weight: 650;
}

.debate-card-head small {
  color: var(--muted);
  font-weight: 500;
}

.debate-card h3 {
  margin: 9px 0 13px;
  color: var(--text);
  font-size: 17px;
  line-height: 1.45;
}

.debate-sides {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 9px;
}

.side-card {
  border-radius: 17px;
  padding: 12px;
  text-align: left;
  border: 1px solid rgba(44, 44, 44, 0.06);
}

.side-card.pro {
  background: rgba(45, 80, 22, 0.07);
}

.side-card.con {
  background: rgba(212, 120, 76, 0.10);
}

.side-card strong {
  display: block;
  color: #4a4039;
  font-size: 14px;
  margin-bottom: 4px;
}

.side-card p,
.side-card blockquote {
  margin: 0;
}

.side-card p {
  color: #4f473f;
  font-size: 14px;
}

.side-card blockquote {
  margin-top: 6px;
  color: var(--text);
  font-size: 15px;
}

.vs {
  justify-self: center;
  align-self: center;
  width: 40px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #f1e8df;
  color: #8a5539;
  font-size: 12px;
  font-weight: 700;
}

.watch-debate,
.new-debate {
  width: 100%;
  min-height: 42px;
  margin-top: 13px;
  border-radius: 15px;
  color: #fffdf9;
  background: var(--orange);
  box-shadow: 0 10px 22px rgba(212, 120, 76, 0.16);
}

.new-debate {
  margin-top: 0;
  background: var(--orange);
  box-shadow: 0 10px 22px rgba(212, 120, 76, 0.16);
}

.debate-record {
  display: none;
  margin-top: 14px;
  padding-top: 13px;
  border-top: 1px solid var(--line);
}

.debate-record.show {
  display: grid;
  gap: 10px;
}

.debate-record h4 {
  margin: 0;
  color: #4a4039;
  font-size: 15px;
}

.debate-turn {
  background: rgba(250, 248, 245, 0.78);
  border: 1px solid rgba(44, 44, 44, 0.05);
  border-radius: 16px;
  padding: 11px 12px;
}

.turn-speaker {
  color: #4a4039;
  font-size: 14px;
  font-weight: 650;
}

.turn-speaker span {
  margin-left: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.debate-turn p {
  margin: 5px 0 0;
  color: var(--text);
  font-size: 15px;
}

.debate-notice {
  min-height: 22px;
  margin: 0;
  color: #8a5539;
  font-size: 14px;
  text-align: center;
}

@media (min-width: 520px) {
  .debate-sides {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  }
}

@media (max-width: 380px) {
  .app-header {
    padding-left: 16px;
    padding-right: 16px;
  }

  .tabs {
    padding-left: 10px;
    padding-right: 10px;
  }

  .tab {
    font-size: 14px;
  }

  .message {
    max-width: 88%;
  }
}
