/* ===== 基础变量 ===== */
:root {
  --bg: #FAF9F6;
  --card-bg: rgba(255, 255, 255, 0.65);
  --card-border: rgba(180, 170, 155, 0.25);
  --text: #2c2416;
  --text-secondary: #8a8070;
  --text-muted: #b5aa9a;
  --accent: #8b7355;
  --accent-light: #c4a97d;
  --danger: #c0392b;
  --success: #6b8e5a;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 2px 16px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.08);
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== 全局 ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

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

/* ===== 容器 ===== */
.app-container {
  max-width: 520px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

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

.title {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
}

.subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ===== 卡片 ===== */
.card {
  background: var(--card-bg);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  transition: var(--transition);
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text);
}

/* ===== 表单 ===== */
.label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.counter-input-row {
  display: flex;
  gap: 8px;
}

.select, .input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  background: rgba(255, 255, 255, 0.7);
  color: var(--text);
  outline: none;
  transition: var(--transition);
  font-family: inherit;
}

.select:focus, .input:focus {
  border-color: var(--accent-light);
  box-shadow: 0 0 0 3px rgba(139, 115, 85, 0.1);
}

/* ===== 上传区 ===== */
.upload-zone {
  border: 2px dashed var(--card-border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  background: rgba(255, 255, 255, 0.3);
}

.upload-zone:hover {
  border-color: var(--accent-light);
  background: rgba(255, 255, 255, 0.5);
}

.upload-zone.drag-over {
  border-color: var(--accent);
  background: rgba(139, 115, 85, 0.06);
}

.upload-icon {
  color: var(--accent-light);
  margin-bottom: 12px;
}

.upload-text {
  font-size: 0.95rem;
  color: var(--text);
  font-weight: 500;
}

.upload-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 6px;
}

/* 预览区 */
.preview-area {
  text-align: center;
}

.preview-img {
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  background: rgba(0, 0, 0, 0.03);
}

.preview-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

/* ===== 按钮 ===== */
.btn {
  padding: 10px 22px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(139, 115, 85, 0.25);
}

.btn-primary:hover {
  background: #7a6548;
}

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

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--card-border);
}

.btn-outline:hover {
  border-color: var(--accent-light);
  color: var(--accent);
}

.btn-loading {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== 结果区 ===== */
.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.result-item {
  background: rgba(139, 115, 85, 0.06);
  border-radius: var(--radius-sm);
  padding: 14px 10px;
  text-align: center;
  transition: var(--transition);
}

.result-item .cat-name {
  display: block;
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.result-item .cat-count {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.result-total {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  padding: 12px 0;
  border-top: 1px solid var(--card-border);
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.result-total strong {
  font-size: 1.4rem;
  color: var(--text);
}

.result-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 12px;
}

/* ===== 调整区 ===== */
.adjust-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.adjust-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(139, 115, 85, 0.04);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.adjust-item .adj-label {
  font-size: 0.85rem;
  color: var(--text);
  flex: 1;
}

.adjust-item .adj-input {
  width: 56px;
  padding: 6px 8px;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  text-align: center;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, 0.7);
  outline: none;
}

.adjust-item .adj-input:focus {
  border-color: var(--accent-light);
}

.adjust-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

/* ===== 历史记录 ===== */
.history-list {
  max-height: 300px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--card-border);
  cursor: pointer;
  transition: var(--transition);
}

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

.history-item:hover {
  opacity: 0.7;
}

.history-item .hi-info {
  flex: 1;
}

.history-item .hi-date {
  font-size: 0.9rem;
  font-weight: 500;
}

.history-item .hi-counter {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.history-item .hi-total {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
}

.history-item .hi-arrow {
  color: var(--text-muted);
  margin-left: 8px;
  font-size: 0.8rem;
}

.empty-hint {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 20px 0;
}

/* ===== 骨架屏 ===== */
.skeleton-container {
  padding: 8px 0;
}

.skeleton-row {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

.skeleton-box {
  height: 16px;
  background: linear-gradient(90deg, rgba(139, 115, 85, 0.08) 25%, rgba(139, 115, 85, 0.15) 50%, rgba(139, 115, 85, 0.08) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(44, 36, 22, 0.9);
  color: #fff;
  padding: 10px 24px;
  border-radius: 20px;
  font-size: 0.85rem;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 1000;
  animation: toastIn 0.3s ease;
}

.toast.error {
  background: rgba(192, 57, 43, 0.9);
}

.toast.success {
  background: rgba(107, 142, 90, 0.9);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== 工具类 ===== */
.hidden {
  display: none !important;
}

/* ===== 响应式 ===== */
@media (max-width: 400px) {
  .app-container {
    padding: 12px 10px 32px;
  }
  .card {
    padding: 16px;
  }
  .title {
    font-size: 1.4rem;
  }
  .result-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .adjust-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}