/* ==================== CSS Variables ==================== */
:root {
  /* 主题色 */
  --primary: #ff6b6b;
  --primary-dark: #ee5a24;
  --primary-light: #ffa07a;
  --secondary: #4ecdc4;
  --secondary-dark: #3bb8b0;
  --accent: #ffe66d;
  --accent-dark: #ffd32a;
  
  /* 背景色 */
  --bg-dark: #1a1a2e;
  --bg-medium: #16213e;
  --bg-light: #0f3460;
  --bg-card: #232946;
  --bg-card-hover: #2d3561;
  
  /* 文字色 */
  --text-primary: #fffffe;
  --text-secondary: #a7a9be;
  --text-muted: #6b6d7b;
  --text-accent: #ff6b6b;
  
  /* 属性色 */
  --color-intelligence: #a78bfa;
  --color-charm: #f472b6;
  --color-health: #34d399;
  --color-wealth: #fbbf24;
  --color-mood: #60a5fa;
  --color-luck: #c084fc;
  
  /* 其他 */
  --radius: 12px;
  --radius-lg: 20px;
  --shadow: 0 4px 20px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.4);
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  
  /* 字体 */
  --font-main: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* ==================== Reset & Base ==================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-main);
  background: var(--bg-dark);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
  -webkit-touch-callout: none;
}

/* 背景装饰 */
body::before {
  content: '';
  position: fixed;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: 
    radial-gradient(circle at 20% 80%, rgba(255,107,107,0.1) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(78,205,196,0.1) 0%, transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(255,230,109,0.05) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* ==================== Container ==================== */
.container {
  width: 100%;
  max-width: 520px;
  min-width: 480px;
  margin: 0 auto;
  padding: 16px;
  position: relative;
  z-index: 1;
}

/* ==================== Screens ==================== */
.screen {
  display: none;
  min-height: 100vh;
  padding: 10px 0;
}

.screen.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-screen.active {
  align-items: flex-start;
  padding-top: 10px;
}

/* 游戏屏幕固定宽度 */
#game-screen .container {
  width: 520px;
  min-width: 520px;
  max-width: 520px;
  box-sizing: border-box;
}

/* ==================== Typography ==================== */
.game-title {
  font-size: 4rem;
  font-weight: 900;
  text-align: center;
  margin-bottom: 10px;
  background: linear-gradient(135deg, var(--primary), var(--accent), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: none;
  letter-spacing: 0.1em;
}

.title-char {
  display: inline-block;
  animation: titleBounce 0.6s ease-out calc(var(--i) * 0.15s) both;
}

.subtitle {
  text-align: center;
  color: var(--text-secondary);
  font-size: 1.1rem;
  margin-bottom: 40px;
  animation: fadeInUp 0.8s ease-out 0.4s both;
}

.screen-title {
  font-size: 1.8rem;
  text-align: center;
  margin-bottom: 10px;
  color: var(--text-primary);
}

.screen-desc {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 30px;
  font-size: 0.95rem;
}

/* ==================== Global ==================== */
* {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

/* 允许输入框选中（如果有） */
input, textarea {
  -webkit-user-select: auto;
  -moz-user-select: auto;
  -ms-user-select: auto;
  user-select: auto;
}

/* ==================== Buttons ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font-main);
  gap: 8px;
  position: relative;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  -webkit-touch-callout: none;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.1), transparent);
  opacity: 0;
  transition: var(--transition);
  pointer-events: none;
}

.btn:hover::after {
  opacity: 1;
}

/* 选择按钮不需要白色渐变 */
.btn-choice::after {
  display: none;
}

.btn:active {
  transform: scale(0.95);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: 0 4px 15px rgba(255,107,107,0.3);
}

.btn-primary:hover {
  box-shadow: 0 6px 25px rgba(255,107,107,0.5);
  transform: translateY(-2px);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid rgba(255,255,255,0.1);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255,255,255,0.2);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid rgba(255,255,255,0.1);
}

.btn-ghost:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text-primary);
}

.btn-lg {
  padding: 16px 36px;
  font-size: 1.15rem;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.btn:disabled::after {
  display: none;
}

.btn-choice {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 2px solid rgba(255,255,255,0.1);
  width: 100%;
  padding: 12px 16px;
  text-align: left;
  margin-bottom: 8px;
  font-size: 0.9rem;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  -webkit-touch-callout: none;
}

.btn-choice:hover {
  border-color: var(--primary);
  background: rgba(255,107,107,0.1);
  transform: translateX(2px);
}

.btn-choice:active {
  transform: scale(0.98);
}

.btn-choice.selected {
  border-color: var(--primary);
  background: rgba(255,107,107,0.15);
}

.btn-choice:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-choice:disabled:hover {
  transform: none;
}

/* ==================== Start Screen ==================== */
.title-section {
  margin-bottom: 40px;
}

.start-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 300px;
  margin: 0 auto;
  animation: fadeInUp 0.8s ease-out 0.6s both;
}

.version {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 40px;
  animation: fadeInUp 0.8s ease-out 0.8s both;
}

/* ==================== Talent Grid ==================== */
.talent-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 30px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 10px;
}

.talent-card {
  background: var(--bg-card);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 12px 8px;
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  -webkit-touch-callout: none;
}

.talent-card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255,255,255,0.2);
  transform: translateY(-2px);
}

.talent-card.selected {
  border-color: var(--primary);
  background: rgba(255,107,107,0.1);
  box-shadow: 0 0 15px rgba(255,107,107,0.2);
}

.talent-card .talent-icon {
  font-size: 1.5rem;
}

.talent-card .talent-name {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-primary);
  white-space: nowrap;
}

.talent-card .talent-desc {
  font-size: 0.7rem;
  color: var(--text-secondary);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.screen-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ==================== Status Bar ==================== */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 15px;
  padding: 12px 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.age-display {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.age-label {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.age-value {
  font-size: 2rem;
  font-weight: 900;
  color: var(--primary);
  font-family: var(--font-mono);
  line-height: 1;
}

.age-unit {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.phase-badge {
  padding: 6px 14px;
  background: rgba(255,255,255,0.1);
  border-radius: 20px;
  font-size: 0.85rem;
  color: var(--text-primary);
}

/* ==================== Attributes Panel ==================== */
.attributes-panel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 15px;
}

.attr-item {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.attr-item .attr-icon {
  font-size: 1.2rem;
}

.attr-item .attr-name {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.attr-bar {
  height: 6px;
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
  overflow: hidden;
}

.attr-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
  width: 50%;
}

.attr-item[data-attr="intelligence"] .attr-fill { background: var(--color-intelligence); }
.attr-item[data-attr="charm"] .attr-fill { background: var(--color-charm); }
.attr-item[data-attr="health"] .attr-fill { background: var(--color-health); }
.attr-item[data-attr="wealth"] .attr-fill { background: var(--color-wealth); }
.attr-item[data-attr="mood"] .attr-fill { background: var(--color-mood); }
.attr-item[data-attr="luck"] .attr-fill { background: var(--color-luck); }

.attr-value {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.hidden-attr .attr-name::after {
  content: ' 🔒';
  font-size: 0.7rem;
}

/* ==================== Event Area ==================== */
.event-area {
  margin-bottom: 15px;
}

.event-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,0.05);
  min-height: 180px;
  height: auto;
}

.event-icon {
  font-size: 2.5rem;
  text-align: center;
  margin-bottom: 12px;
  animation: popIn 0.4s ease-out;
}

.event-text {
  font-size: 1rem;
  line-height: 1.7;
  color: var(--text-primary);
  text-align: center;
  margin-bottom: 12px;
  min-height: 50px;
}

.event-effects {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 12px;
  min-height: 28px;
  overflow: hidden;
}

.effect-tag {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  animation: fadeInUp 0.3s ease-out;
  white-space: nowrap;
}

.effect-tag.positive {
  background: rgba(52,211,153,0.15);
  color: #34d399;
}

.effect-tag.negative {
  background: rgba(239,68,68,0.15);
  color: #ef4444;
}

.effect-tag.neutral {
  background: rgba(255,255,255,0.1);
  color: var(--text-secondary);
}

.event-choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 40px;
}

/* ==================== Game Actions ==================== */
.game-actions {
  text-align: center;
}

/* ==================== Ending Screen ==================== */
.ending-card {
  text-align: center;
  animation: fadeInUp 0.8s ease-out;
}

.ending-title {
  font-size: 1.8rem;
  margin-bottom: 10px;
}

.ending-icon {
  font-size: 5rem;
  margin: 20px 0;
  animation: popIn 0.6s ease-out 0.2s both;
}

.ending-type {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 10px;
}

.ending-desc {
  font-size: 1rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 30px;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

/* Tombstone */
.tombstone {
  background: linear-gradient(135deg, #2d2d2d, #1a1a1a);
  border: 3px solid #444;
  border-radius: var(--radius-lg);
  padding: 24px;
  margin: 20px auto;
  max-width: 400px;
  position: relative;
}

.tombstone::before {
  content: '';
  position: absolute;
  top: -15px;
  left: 50%;
  transform: translateX(-50%);
  width: 30px;
  height: 30px;
  background: #444;
  border-radius: 50%;
}

.tombstone-header {
  font-size: 1.1rem;
  color: #888;
  margin-bottom: 12px;
}

.tombstone-text {
  font-size: 1rem;
  color: #ccc;
  font-style: italic;
  line-height: 1.6;
}

/* Life Stats */
.life-stats {
  margin: 30px auto;
  max-width: 400px;
}

.life-stats h3 {
  margin-bottom: 16px;
  color: var(--text-primary);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat-item {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
}

/* Share Section */
.share-section {
  margin: 30px auto;
  max-width: 400px;
}

.share-section h3 {
  margin-bottom: 16px;
}

.share-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  text-align: left;
  font-size: 0.9rem;
  line-height: 1.8;
  color: var(--text-secondary);
  margin-bottom: 16px;
  white-space: pre-line;
  border: 1px solid rgba(255,255,255,0.1);
}

.share-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 20px;
}

.ending-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 20px;
}

/* ==================== History Screen ==================== */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 30px;
  max-height: 60vh;
  overflow-y: auto;
}

.history-item {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid rgba(255,255,255,0.05);
}

.history-item:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255,255,255,0.1);
}

.history-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.history-item-title {
  font-weight: 600;
  color: var(--text-primary);
}

.history-item-date {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.history-item-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.history-item-stats {
  display: flex;
  gap: 16px;
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.history-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-size: 1rem;
}

/* ==================== About Screen ==================== */
.about-content {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 30px;
  line-height: 1.8;
  color: var(--text-secondary);
}

.about-content p {
  margin-bottom: 12px;
}

.about-content hr {
  border: none;
  border-top: 1px solid rgba(255,255,255,0.1);
  margin: 16px 0;
}

.about-tips {
  color: var(--accent);
  font-weight: 600;
}

/* ==================== Toast ==================== */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 0.95rem;
  z-index: 1000;
  transition: transform 0.3s ease;
  pointer-events: none;
  border: 1px solid rgba(255,255,255,0.1);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* ==================== Scrollbar ==================== */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.2);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.3);
}

/* ==================== Responsive ==================== */
@media (max-width: 520px) {
  html {
    font-size: 14px;
  }
  
  .container {
    padding: 12px;
    min-width: auto;
    max-width: 100%;
  }
  
  /* 移动端游戏屏幕不固定宽度 */
  #game-screen .container {
    width: 100%;
    min-width: auto;
    max-width: 100%;
  }
  
  .game-title {
    font-size: 3rem;
  }
  
  .attributes-panel {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  
  .attr-item {
    padding: 8px;
  }
  
  .talent-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .event-card {
    padding: 18px;
    min-height: auto;
  }
  
  .event-icon {
    font-size: 2.5rem;
  }
  
  .event-text {
    font-size: 1rem;
  }
  
  .btn-lg {
    padding: 14px 28px;
    font-size: 1.05rem;
  }
  
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
}

@media (max-width: 360px) {
  .talent-grid {
    grid-template-columns: 1fr;
  }
  
  .attributes-panel {
    grid-template-columns: repeat(2, 1fr);
  }
}
