/* 基础主题变量 */
:root {
  --bg: linear-gradient(135deg, #fef7ff 0%, #fff1f8 50%, #fef3f2 100%);
  --bg-solid: #fefbff;
  --text: #2d1b3d;
  --muted: #8b5a8c;
  --card: rgba(255, 255, 255, 0.85);
  --card-hover: rgba(255, 255, 255, 0.95);
  --border: rgba(239, 93, 168, 0.15);
  --primary: linear-gradient(135deg, #ff6b9d 0%, #ef5da8 50%, #d946ef 100%);
  --primary-solid: #ef5da8;
  --primary-contrast: #ffffff;
  --secondary: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  --danger: #f87171;
  --success: #34d399;
  --shadow: 0 20px 40px rgba(239, 93, 168, 0.15), 0 8px 16px rgba(239, 93, 168, 0.1);
  --shadow-hover: 0 25px 50px rgba(239, 93, 168, 0.25), 0 12px 24px rgba(239, 93, 168, 0.15);
  --glass: backdrop-filter: blur(20px) saturate(180%);
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: linear-gradient(135deg, #1a0b2e 0%, #16213e 50%, #0f3460 100%);
    --bg-solid: #1a0b2e;
    --text: #f1e6ff;
    --muted: #b794f6;
    --card: rgba(30, 20, 60, 0.85);
    --card-hover: rgba(30, 20, 60, 0.95);
    --border: rgba(255, 117, 195, 0.2);
    --primary: linear-gradient(135deg, #ff75c3 0%, #f093fb 50%, #f5576c 100%);
    --primary-solid: #ff75c3;
    --primary-contrast: #1a0b2e;
    --secondary: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
    --danger: #f87171;
    --success: #34d399;
    --shadow: 0 20px 40px rgba(255, 117, 195, 0.2), 0 8px 16px rgba(255, 117, 195, 0.1);
    --shadow-hover: 0 25px 50px rgba(255, 117, 195, 0.3), 0 12px 24px rgba(255, 117, 195, 0.2);
    --glass: backdrop-filter: blur(20px) saturate(180%);
  }
}

/* 强制浅色与深色 */
:root[data-theme="light"] {
  --bg: linear-gradient(135deg, #fef7ff 0%, #fff1f8 50%, #fef3f2 100%);
  --bg-solid: #fefbff;
  --text: #2d1b3d;
  --muted: #8b5a8c;
  --card: rgba(255, 255, 255, 0.85);
  --card-hover: rgba(255, 255, 255, 0.95);
  --border: rgba(239, 93, 168, 0.15);
  --primary: linear-gradient(135deg, #ff6b9d 0%, #ef5da8 50%, #d946ef 100%);
  --primary-solid: #ef5da8;
  --primary-contrast: #ffffff;
  --secondary: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  --danger: #f87171;
  --success: #34d399;
  --shadow: 0 20px 40px rgba(239, 93, 168, 0.15), 0 8px 16px rgba(239, 93, 168, 0.1);
  --shadow-hover: 0 25px 50px rgba(239, 93, 168, 0.25), 0 12px 24px rgba(239, 93, 168, 0.15);
  --glass: backdrop-filter: blur(20px) saturate(180%);
}

:root[data-theme="dark"] {
  --bg: linear-gradient(135deg, #1a0b2e 0%, #16213e 50%, #0f3460 100%);
  --bg-solid: #1a0b2e;
  --text: #f1e6ff;
  --muted: #b794f6;
  --card: rgba(30, 20, 60, 0.85);
  --card-hover: rgba(30, 20, 60, 0.95);
  --border: rgba(255, 117, 195, 0.2);
  --primary: linear-gradient(135deg, #ff75c3 0%, #f093fb 50%, #f5576c 100%);
  --primary-solid: #ff75c3;
  --primary-contrast: #1a0b2e;
  --secondary: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  --danger: #f87171;
  --success: #34d399;
  --shadow: 0 20px 40px rgba(255, 117, 195, 0.2), 0 8px 16px rgba(255, 117, 195, 0.1);
  --shadow-hover: 0 25px 50px rgba(255, 117, 195, 0.3), 0 12px 24px rgba(255, 117, 195, 0.2);
  --glass: backdrop-filter: blur(20px) saturate(180%);
}

* { 
  box-sizing: border-box; 
  margin: 0;
  padding: 0;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg);
  z-index: -1;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--card);
  var(--glass);
  box-shadow: 0 4px 20px rgba(239, 93, 168, 0.1);
  z-index: 10;
}

.brand { 
  display: flex; 
  align-items: center; 
  gap: 12px; 
}

.brand .logo { 
  font-size: 28px;
  filter: drop-shadow(0 2px 4px rgba(239, 93, 168, 0.3));
  animation: heartbeat 2s ease-in-out infinite;
}

@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.brand h1 { 
  font-size: 24px; 
  font-weight: 800; 
  background: var(--primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.header-actions { display: flex; gap: 12px; }

.icon-btn {
  border: none;
  background: var(--card);
  color: var(--text);
  border-radius: 16px;
  padding: 12px 16px;
  cursor: pointer;
  font-size: 18px;
  box-shadow: var(--shadow);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.icon-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s;
}

.icon-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.icon-btn:hover::before {
  left: 100%;
}

.icon-btn:active {
  transform: translateY(0);
}

.tabs {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  padding: 16px 20px;
  background: var(--card);
  var(--glass);
  position: sticky;
  top: 81px;
  z-index: 9;
  border-radius: 0 0 24px 24px;
  box-shadow: 0 8px 32px rgba(239, 93, 168, 0.1);
}

.tab {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 12px 20px;
  border-radius: 20px;
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.tab::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--primary);
  opacity: 0;
  border-radius: 20px;
  transition: opacity 0.3s ease;
  z-index: -1;
}

.tab:hover:not(.active) {
  color: var(--text);
  background: var(--card-hover);
  transform: translateY(-1px);
}

.tab.active {
  color: var(--primary-contrast);
  font-weight: 700;
}

.tab.active::before {
  opacity: 1;
}

main { 
  width: 100%; 
  max-width: 1200px; 
  margin: 0 auto; 
  padding: 32px 24px; 
  flex: 1; 
}

.tab-panel { display: none; animation: fade 240ms ease-out; }
.tab-panel.active { display: block; }

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

.controls-row { 
  display: flex; 
  justify-content: center; 
  margin: 24px 0 16px; 
}

.names { 
  display: inline-flex; 
  gap: 16px; 
  align-items: center; 
  background: var(--card);
  padding: 20px 24px;
  border-radius: 24px;
  box-shadow: var(--shadow);
  var(--glass);
}

.names input {
  padding: 16px 20px;
  border-radius: 16px;
  border: 2px solid var(--border);
  background: var(--bg-solid);
  color: var(--text);
  min-width: 140px;
  font-size: 16px;
  font-weight: 500;
  transition: all 0.3s ease;
}

.names input:focus {
  outline: none;
  border-color: var(--primary-solid);
  box-shadow: 0 0 0 4px rgba(239, 93, 168, 0.1);
  transform: translateY(-1px);
}

.names .and { 
  color: var(--primary-solid); 
  font-size: 20px;
  font-weight: 700;
}

.filters {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  margin: 20px 0 32px;
  background: var(--card);
  padding: 24px;
  border-radius: 20px;
  box-shadow: var(--shadow);
  var(--glass);
}

.filters label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--text);
}

.filters select { 
  padding: 12px 16px; 
  border-radius: 12px; 
  border: 2px solid var(--border); 
  background: var(--bg-solid); 
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
}

.filters select:focus {
  outline: none;
  border-color: var(--primary-solid);
  box-shadow: 0 0 0 4px rgba(239, 93, 168, 0.1);
}

.switch { 
  display: inline-flex; 
  gap: 12px; 
  align-items: center; 
  cursor: pointer;
}

.switch input { 
  accent-color: var(--primary-solid);
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.card-stage { 
  display: grid; 
  place-items: center; 
  margin: 24px auto 32px; 
  perspective: 1200px; 
}

.card {
  width: min(600px, 90vw);
  height: clamp(200px, 40vh, 400px);
  position: relative;
  transform-style: preserve-3d;
  transition: transform 800ms cubic-bezier(0.175, 0.885, 0.32, 1.275);
  cursor: pointer;
}

.card.flip { transform: rotateY(180deg); }

.card-face {
  position: absolute;
  inset: 0;
  background: var(--card);
  border: 3px solid transparent;
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 32px;
  display: grid;
  place-items: center;
  backface-visibility: hidden;
  font-size: clamp(20px, 2.8vw, 32px);
  line-height: 1.5;
  text-align: center;
  font-weight: 600;
  var(--glass);
  position: relative;
  overflow: hidden;
}

.card-face::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--primary);
  opacity: 0.05;
  border-radius: 21px;
}

.card-front {
  background: linear-gradient(135deg, var(--card) 0%, rgba(255, 255, 255, 0.9) 100%);
}

.card-back { 
  transform: rotateY(180deg); 
  font-size: 80px; 
  color: var(--primary-solid);
  background: linear-gradient(135deg, var(--card) 0%, rgba(255, 255, 255, 0.95) 100%);
}

.actions { 
  display: flex; 
  flex-wrap: wrap; 
  gap: 16px; 
  justify-content: center; 
  margin: 24px 0 16px; 
}

.btn {
  border: none;
  background: var(--card);
  color: var(--text);
  padding: 16px 24px;
  border-radius: 16px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 600;
  box-shadow: var(--shadow);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  min-width: 120px;
}

.btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s;
}

.btn:hover:not(:disabled) {
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
}

.btn:hover:not(:disabled)::before {
  left: 100%;
}

.btn:active:not(:disabled) {
  transform: translateY(-1px);
}

.btn.primary { 
  background: var(--primary); 
  color: var(--primary-contrast);
  font-weight: 700;
}

.btn.danger { 
  background: linear-gradient(135deg, #f87171 0%, #ef4444 100%); 
  color: #ffffff;
}

.btn:disabled { 
  opacity: 0.5; 
  cursor: not-allowed; 
  transform: none !important;
  box-shadow: var(--shadow) !important;
}

.deck-editor h2, .history h2 { 
  margin: 0 0 24px; 
  font-size: 28px;
  font-weight: 800;
  background: var(--primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.add-card { 
  display: grid; 
  grid-template-columns: 1fr 200px auto; 
  gap: 16px; 
  background: var(--card);
  padding: 24px;
  border-radius: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

@media (max-width: 700px) { 
  .add-card { grid-template-columns: 1fr; } 
}

.deck-tools { 
  margin: 24px 0; 
  display: flex; 
  gap: 16px; 
  flex-wrap: wrap; 
}

.deck-list { 
  list-style: none; 
  display: grid; 
  gap: 16px; 
}

.deck-item {
  display: grid;
  grid-template-columns: 1fr 160px auto auto;
  gap: 16px;
  align-items: center;
  padding: 20px;
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  transition: all 0.3s ease;
  var(--glass);
}

.deck-item:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

@media (max-width: 780px) { 
  .deck-item { 
    grid-template-columns: 1fr; 
    align-items: start; 
    gap: 12px;
  } 
}

.deck-item input[type="text"] { 
  padding: 12px 16px; 
  border-radius: 12px; 
  border: 2px solid var(--border); 
  background: var(--bg-solid); 
  color: var(--text);
  font-size: 14px;
  transition: all 0.3s ease;
}

.deck-item input[type="text"]:focus {
  outline: none;
  border-color: var(--primary-solid);
  box-shadow: 0 0 0 4px rgba(239, 93, 168, 0.1);
}

.deck-item .item-actions { 
  display: flex; 
  gap: 12px; 
  justify-content: end; 
}

.history-tools { 
  display: flex; 
  justify-content: flex-end; 
  margin-bottom: 24px; 
}

.history-list { 
  list-style: none; 
  display: grid; 
  gap: 16px; 
}

.history-item { 
  background: var(--card); 
  border-radius: 16px; 
  padding: 20px; 
  box-shadow: var(--shadow);
  transition: all 0.3s ease;
  var(--glass);
}

.history-item:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.history-meta { 
  color: var(--muted); 
  font-size: 14px; 
  margin-top: 12px; 
  display: flex; 
  gap: 16px; 
  font-weight: 500;
}

.modal::backdrop { 
  background: rgba(0, 0, 0, 0.5); 
  backdrop-filter: blur(8px); 
}

.modal .modal-inner { 
  min-width: min(800px, 90vw); 
  border: none; 
  padding: 0; 
  background: var(--card); 
  border-radius: 24px; 
  box-shadow: var(--shadow-hover);
  var(--glass);
}

.modal h3 { 
  margin: 0; 
  padding: 24px 32px; 
  border-bottom: 2px solid var(--border); 
  font-size: 24px;
  font-weight: 700;
  background: var(--primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.modal textarea { 
  width: 100%; 
  resize: vertical; 
  border: none; 
  padding: 24px 32px; 
  background: transparent; 
  color: var(--text); 
  min-height: 300px; 
  font-size: 14px;
  line-height: 1.6;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
}

.modal textarea:focus {
  outline: none;
}

.modal-actions { 
  display: flex; 
  justify-content: flex-end; 
  gap: 16px; 
  padding: 24px 32px; 
  border-top: 2px solid var(--border); 
}

.app-footer { 
  text-align: center; 
  color: var(--muted); 
  padding: 32px 24px; 
  font-size: 16px;
  font-weight: 500;
  background: var(--card);
  var(--glass);
  border-top: 1px solid var(--border);
}

/* 抽卡过渡动画 */
.shake { animation: shake 600ms ease-in-out; }
@keyframes shake {
  0%, 100% { transform: translateX(0) rotate(0deg); }
  10% { transform: translateX(-2px) rotate(-1deg); }
  20% { transform: translateX(2px) rotate(1deg); }
  30% { transform: translateX(-4px) rotate(-2deg); }
  40% { transform: translateX(4px) rotate(2deg); }
  50% { transform: translateX(-6px) rotate(-1deg); }
  60% { transform: translateX(6px) rotate(1deg); }
  70% { transform: translateX(-4px) rotate(-1deg); }
  80% { transform: translateX(2px) rotate(1deg); }
  90% { transform: translateX(-1px) rotate(0deg); }
}

.pop { animation: pop 500ms cubic-bezier(0.68, -0.55, 0.265, 1.55); }
@keyframes pop { 
  0% { transform: scale(0.8) rotate(-5deg); opacity: 0.8; }
  50% { transform: scale(1.05) rotate(2deg); }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* 设置页面样式 */
.settings-group {
  background: var(--card);
  padding: 24px;
  border-radius: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  var(--glass);
}

.settings-group label {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  margin-bottom: 16px;
}

.settings-group select {
  padding: 12px 16px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--bg-solid);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.settings-group select:focus {
  outline: none;
  border-color: var(--primary-solid);
  box-shadow: 0 0 0 4px rgba(239, 93, 168, 0.1);
}

.hint {
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  margin-top: 24px;
  padding: 16px;
  background: var(--card);
  border-radius: 12px;
  var(--glass);
}

/* 响应式优化 */
@media (max-width: 768px) {
  .app-header {
    padding: 16px 20px;
  }
  
  .brand h1 {
    font-size: 20px;
  }
  
  .tabs {
    padding: 12px 16px;
    gap: 4px;
  }
  
  .tab {
    padding: 10px 16px;
    font-size: 14px;
  }
  
  main {
    padding: 24px 16px;
  }
  
  .names {
    flex-direction: column;
    gap: 12px;
  }
  
  .filters {
    flex-direction: column;
    gap: 16px;
  }
  
  .actions {
    flex-direction: column;
    align-items: center;
  }
  
  .btn {
    width: 100%;
    max-width: 300px;
  }
}


/* 额外的视觉增强 */
.card:hover {
  transform: translateY(-5px) scale(1.02);
}

.card-face:hover {
  box-shadow: var(--shadow-hover);
}

/* 加载动画 */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.tab-panel.active {
  animation: fadeInUp 0.5s ease-out;
}

/* 按钮组样式 */
.actions .btn:nth-child(1) {
  background: var(--primary);
  color: var(--primary-contrast);
  font-size: 18px;
  padding: 18px 32px;
  min-width: 160px;
}

.actions .btn:nth-child(1):hover {
  transform: translateY(-4px) scale(1.05);
}

/* 输入框增强 */
input[type="text"], textarea, select {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

input[type="text"]:hover, textarea:hover, select:hover {
  border-color: var(--primary-solid);
}

/* 滚动条样式 */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-solid);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: var(--primary-solid);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

/* 选择文本样式 */
::selection {
  background: var(--primary-solid);
  color: var(--primary-contrast);
}

/* 焦点样式 */
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--primary-solid);
  outline-offset: 2px;
}

/* 卡片内容样式增强 */
.card-front {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0.5px;
}

/* 微交互动画 */
.btn, .tab, .icon-btn {
  transform-origin: center;
}

.btn:active, .tab:active, .icon-btn:active {
  transform: scale(0.95);
}

/* 成功状态样式 */
.btn.success {
  background: var(--success);
  color: white;
}

/* 加载状态 */
.loading {
  position: relative;
  overflow: hidden;
}

.loading::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
  animation: loading 1.5s infinite;
}

@keyframes loading {
  0% { left: -100%; }
  100% { left: 100%; }
}