/* 食材随机选择器 - 样式表 */
:root {
  --primary-color: #FF6B35;
  --secondary-color: #FF8C5A;
  --accent-color: #4A3728;
  --bg-color: #FFF8F0;
  --card-bg: #FFFFFF;
  --text-color: #333333;
  --text-light: #666666;
  --border-color: #E8E0D8;
  --shadow: 0 4px 20px rgba(74, 55, 40, 0.1);
  --radius: 16px;
  --radius-sm: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', 'PingFang SC', 'Hiragino Sans GB', sans-serif;
  background: var(--bg-color);
  color: var(--text-color);
  min-height: 100vh;
  line-height: 1.6;
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
}

/* 头部 */
.header {
  text-align: center;
  padding: 30px 0;
}

.header h1 {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--primary-color);
  margin-bottom: 8px;
}

.header p {
  color: var(--text-light);
  font-size: 0.95rem;
}

/* 筛选区域 */
.filter-section {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

/* 搜索框 */
.search-box {
  position: relative;
  margin-bottom: 20px;
  display: flex;
  gap: 10px;
  align-items: center;
}

.search-input-wrapper {
  position: relative;
  flex: 1;
}

#search-input {
  width: 100%;
  padding: 12px 40px 12px 16px;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  transition: all 0.25s ease;
  outline: none;
  box-sizing: border-box;
}

#search-input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.1);
}

.search-btn {
  padding: 12px 20px;
  background: var(--primary-color);
  color: #FFF;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
  white-space: nowrap;
}

.search-btn:hover {
  background: #E85A2A;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(255, 107, 53, 0.3);
}

.search-clear-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--border-color);
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text-light);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-clear-btn:hover {
  background: var(--primary-color);
  color: #FFF;
}

/* 搜索下拉预览 */
.search-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  max-height: 360px;
  overflow-y: auto;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}

.search-dropdown.show {
  display: block;
}

.search-dropdown-item {
  padding: 10px 16px;
  cursor: pointer;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border-color);
  transition: background 0.12s;
}

.search-dropdown-item:last-child {
  border-bottom: none;
}

.search-dropdown-item:hover {
  background: var(--bg-color);
  color: var(--primary-color);
}

/* 常见/全部切换开关 */
.common-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  padding: 8px 12px;
  border: 2px solid var(--border-color);
  border-radius: 20px;
  background: var(--bg-color);
  transition: border-color 0.25s;
}

.common-toggle:hover {
  border-color: var(--primary-color);
}

.common-toggle .toggle-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-light);
  transition: color 0.2s;
}

.common-toggle.active .toggle-label[data-mode="common"],
.common-toggle:not(.active) .toggle-label[data-mode="all"] {
  color: var(--primary-color);
}

.toggle-switch {
  width: 36px;
  height: 20px;
  background: #ccc;
  border-radius: 10px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}

.common-toggle.active .toggle-switch {
  background: var(--primary-color);
}

.toggle-knob {
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: left 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.common-toggle.active .toggle-knob {
  left: 18px;
}

/* 展开/折叠按钮 */
.filter-expand-btn {
  margin-top: 8px;
  padding: 6px 14px;
  background: var(--bg-color);
  color: var(--primary-color);
  border: 2px solid var(--border-color);
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: all 0.2s;
}

.filter-expand-btn:hover {
  border-color: var(--primary-color);
  background: #FFF;
}



.filter-group {
  margin-bottom: 20px;
}

.filter-group:last-child {
  margin-bottom: 0;
}

.filter-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent-color);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.filter-label::before {
  content: '';
  width: 4px;
  height: 16px;
  background: var(--primary-color);
  border-radius: 2px;
}

.filter-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* 展开/折叠按钮 - 行内"..."样式，与 filter-tag 一致 */
.filter-expand-btn {
  padding: 8px 14px;
  background: var(--bg-color);
  color: var(--primary-color);
  border: 2px solid var(--border-color);
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: all 0.2s;
  line-height: inherit;
}

.filter-expand-btn:hover {
  border-color: var(--primary-color);
  background: #FFF;
}

/* 标题栏"查看全部/折叠起来"按钮 */
.filter-expand-label-btn {
  margin-left: auto;
  padding: 4px 12px;
  background: transparent;
  color: var(--primary-color);
  border: 1px dashed var(--primary-color);
  border-radius: 16px;
  font-size: 0.75rem;
  cursor: pointer;
  user-select: none;
  transition: all 0.2s;
  flex-shrink: 0;
}

.filter-expand-label-btn:hover {
  background: rgba(255, 107, 53, 0.08);
  border-style: solid;
}

.filter-tag {
  padding: 8px 16px;
  background: var(--bg-color);
  border: 2px solid var(--border-color);
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.25s ease;
  user-select: none;
}

.filter-tag:hover {
  border-color: var(--secondary-color);
  background: #FFF;
}

.filter-tag.active {
  background: var(--primary-color);
  border-color: var(--primary-color);
  color: #FFF;
}

.filter-tag.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* 单选模式 */
.filter-tags.single-select .filter-tag {
  border-radius: var(--radius-sm);
}

.filter-tags.single-select .filter-tag.active {
  border-radius: var(--radius-sm);
}

/* 结果区域 */
.result-section {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 40px 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
  text-align: center;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.result-placeholder {
  color: var(--text-light);
  font-size: 1rem;
}

.result-card {
  animation: fadeInUp 0.4s ease;
}

.result-label {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-bottom: 12px;
}

.result-name {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--accent-color);
  margin-bottom: 16px;
}

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

.result-tag {
  padding: 4px 12px;
  background: var(--bg-color);
  border-radius: 12px;
  font-size: 0.75rem;
  color: var(--text-light);
}

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

/* 按钮区域 */
.action-section {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn {
  padding: 14px 32px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
}

.btn-primary {
  background: var(--primary-color);
  color: #FFF;
}

.btn-primary:hover {
  background: #E85A2A;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255, 107, 53, 0.3);
}

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

.btn-secondary {
  background: var(--bg-color);
  color: var(--accent-color);
  border: 2px solid var(--border-color);
}

.btn-secondary:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
}

/* 统计信息 */
.stats {
  text-align: center;
  padding: 16px;
  color: var(--text-light);
  font-size: 0.85rem;
}

.stats strong {
  color: var(--primary-color);
}

/* 滚动动画 */
.rolling {
  animation: rolling 0.1s ease infinite;
}

@keyframes rolling {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* 显示结果状态 */
.show-result .result-placeholder {
  display: none;
}

.show-result .result-card {
  display: block;
}

/* 响应式 */
@media (max-width: 600px) {
  .container {
    padding: 16px;
  }

  .header h1 {
    font-size: 1.8rem;
  }

  .filter-section,
  .result-section {
    padding: 20px 16px;
  }

  .result-name {
    font-size: 2rem;
  }

  .filter-tag {
    padding: 6px 12px;
    font-size: 0.8rem;
  }

  .filter-expand-btn {
    padding: 6px 12px;
    font-size: 0.8rem;
  }

  .btn {
    padding: 12px 24px;
    font-size: 0.9rem;
  }

  .action-section {
    flex-direction: column;
  }

  .action-section .btn {
    width: 100%;
  }
}

/* 食物大全模态框 */
.catalog-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  animation: fadeIn 0.3s ease;
}

.catalog-modal.show {
  display: flex;
  justify-content: center;
  align-items: center;
}

.catalog-content {
  background: var(--card-bg);
  border-radius: var(--radius);
  max-width: 800px;
  width: 90%;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s ease;
}

.catalog-header {
  padding: 20px 24px;
  border-bottom: 2px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.catalog-header h2 {
  font-size: 1.5rem;
  color: var(--accent-color);
  margin: 0;
}

.catalog-search-input {
  flex: 1;
  min-width: 120px;
  max-width: 240px;
  padding: 8px 12px;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
}

.catalog-search-input:focus {
  border-color: var(--primary-color);
}

.catalog-close {
  background: none;
  border: none;
  font-size: 2rem;
  cursor: pointer;
  color: var(--text-light);
  line-height: 1;
  transition: color 0.2s;
}

.catalog-close:hover {
  color: var(--primary-color);
}

.catalog-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.catalog-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.catalog-item {
  padding: 12px;
  background: var(--bg-color);
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-color);
  transition: all 0.2s;
}

.catalog-item:hover {
  background: var(--primary-color);
  color: #FFF;
  transform: translateY(-2px);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

/* 内联结果区域（搜索框下方） */
.result-section-inline {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 30px 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
  text-align: center;
  min-height: 240px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

#result-tags {
  min-height: 60px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  align-items: center;
}

/* 内联操作按钮区域 */
.action-section-inline {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.action-section-inline .btn {
  flex: 1;
  min-width: 120px;
}

/* 响应式调整 */
@media (max-width: 600px) {
  .search-box {
    flex-wrap: wrap;
    gap: 8px;
  }

  .search-input-wrapper {
    flex: 0 0 100%;
    order: 1;
  }

  .search-btn {
    flex: 1;
    min-width: 0;
    order: 2;
    padding: 10px 12px;
    font-size: 0.85rem;
  }

  .common-toggle {
    order: 3;
    padding: 6px 10px;
  }

  .search-clear-btn {
    /* 在 .search-input-wrapper 内定位，无需额外 right */
  }

  .action-section-inline {
    flex-direction: column;
  }

  .action-section-inline .btn {
    width: 100%;
  }
}

/* ========== Tooltip 提示 ========== */
.allergen-tooltip {
  position: relative;
  display: inline-block;
  background: #4A3728;
  color: #FFF5E6;
  font-size: 0.82rem;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  margin-top: 8px;
  max-width: 360px;
  line-height: 1.5;
  box-shadow: 0 4px 14px rgba(74, 55, 40, 0.25);
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}

.allergen-tooltip.show {
  opacity: 1;
  transform: translateY(0);
}

.allergen-tooltip::before {
  content: '';
  position: absolute;
  top: -6px;
  left: 24px;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 6px solid #4A3728;
}

.allergen-tooltip .tooltip-emoji {
  margin-right: 4px;
}

.allergen-tooltip .tooltip-close {
  position: absolute;
  top: 2px;
  right: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  color: #C5A880;
  padding: 2px 4px;
  line-height: 1;
}
