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

body {
  font-family: 'Segoe UI', sans-serif;
  background: linear-gradient(135deg, #ff9a56, #ff6b6b);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

/* ===== Container ===== */
.container {
  background: white;
  border-radius: 24px;
  padding: 36px 40px 32px;
  width: 460px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

/* ===== Header ===== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
}
h1 { font-size: 1.85rem; color: #333; }
.header-btns { display: flex; gap: 8px; }
.icon-circle-btn {
  background: none;
  border: 2px solid #eee;
  border-radius: 50%;
  width: 36px; height: 36px;
  font-size: 1rem;
  cursor: pointer;
  color: #aaa;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.icon-circle-btn:hover { border-color: #ff6b6b; color: #ff6b6b; background: #fff0f0; }
.subtitle { color: #999; font-size: 0.88rem; margin-bottom: 16px; }

/* ===== Diet Toggle ===== */
.diet-toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: #f7f7f7;
  border-radius: 12px;
  border: 1.5px solid #eee;
  margin-bottom: 20px;
  transition: all 0.3s;
}
.diet-toggle-row.active { background: #f0fff4; border-color: #81c784; }

.toggle-wrap {
  position: relative;
  width: 46px; height: 26px;
  flex-shrink: 0;
}
.toggle-wrap input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #ddd;
  border-radius: 26px;
  transition: 0.3s;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  width: 20px; height: 20px;
  left: 3px; bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.3s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.toggle-wrap input:checked + .toggle-slider { background: #66bb6a; }
.toggle-wrap input:checked + .toggle-slider::before { transform: translateX(20px); }

.diet-label { font-size: 0.9rem; font-weight: 600; color: #888; }
.diet-toggle-row.active .diet-label { color: #388e3c; }
.diet-hint { margin-left: auto; font-size: 0.75rem; color: #bbb; }
.diet-toggle-row.active .diet-hint { color: #81c784; }

/* ===== Steps ===== */
.steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 22px;
}
.step {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.88rem;
  background: #eee; color: #aaa;
  transition: all 0.3s;
}
.step.active { background: #ff6b6b; color: white; }
.step.done   { background: #ffb3b3; color: white; }
.step-line { flex: 1; height: 2px; background: #eee; max-width: 60px; }

/* ===== Section ===== */
.section { display: none; }
.section.visible { display: block; }
.section-title {
  font-size: 0.98rem; font-weight: 700; color: #555; margin-bottom: 14px;
}
.section-hint { font-weight: 400; color: #aaa; }

/* ===== Category Grid ===== */
.category-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 22px;
}
.cat-btn {
  border: 2px solid #eee;
  border-radius: 16px;
  padding: 14px 8px 12px;
  cursor: pointer;
  background: #fafafa;
  transition: all 0.2s;
  font-size: 0.82rem;
  color: #666;
}
.cat-btn .cat-emoji { font-size: 1.7rem; display: block; margin-bottom: 5px; }
.cat-btn.selected {
  border-color: #ff6b6b;
  background: #fff0f0;
  color: #ff6b6b;
  font-weight: 700;
}
.cat-kcal-badge {
  display: block;
  font-size: 0.68rem;
  color: #bbb;
  margin-top: 4px;
  font-weight: 400;
}
.cat-btn.selected .cat-kcal-badge { color: #ffb3b3; }

/* ===== Result Box ===== */
.result-box {
  background: #fff5f0;
  border: 2px dashed #ff6b6b;
  border-radius: 18px;
  padding: 28px 20px 22px;
  margin-bottom: 14px;
  min-height: 148px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
}
.result-emoji { font-size: 3rem; margin-bottom: 10px; }
.result-text  { font-size: 1.9rem; font-weight: 700; color: #ff6b6b; }
.result-kcal  {
  display: none;
  margin-top: 10px;
  padding: 4px 14px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 700;
  color: white;
}
.result-sub { font-size: 0.8rem; color: #bbb; margin-top: 6px; }

/* ===== Buttons ===== */
.btn {
  border: none;
  border-radius: 50px;
  padding: 13px 28px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

.btn-primary {
  background: linear-gradient(135deg, #ff9a56, #ff6b6b);
  color: white;
  width: 100%;
  box-shadow: 0 6px 20px rgba(255,107,107,0.38);
}
.btn-primary:hover:not(:disabled) {
  box-shadow: 0 10px 28px rgba(255,107,107,0.5);
  transform: translateY(-2px);
}

.btn-ghost {
  background: none;
  border: none;
  color: #bbb;
  font-size: 0.85rem;
  padding: 10px 16px;
  cursor: pointer;
  display: block;
  margin: 8px auto 0;
  font-weight: 600;
  transition: color 0.2s;
}
.btn-ghost:hover { color: #ff6b6b; }

/* ===== Action Buttons (after picking) ===== */
.action-btns {
  display: none;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}
.btn-action {
  border: 1.5px solid #eee;
  border-radius: 12px;
  padding: 10px 6px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  background: #fafafa;
  color: #666;
  transition: all 0.2s;
  line-height: 1.4;
}
.btn-action:hover { border-color: #ff6b6b; background: #fff0f0; color: #ff6b6b; }
.btn-action:disabled { opacity: 0.35; cursor: not-allowed; }

/* ===== Animations ===== */
@keyframes bounce {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.2); }
}
.spinning .result-emoji { animation: bounce 0.1s ease infinite; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.result-reveal { animation: fadeUp 0.3s ease forwards; }

/* ===== Modals ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }

.modal {
  background: white;
  border-radius: 20px;
  width: 100%;
  max-width: 460px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  overflow: hidden;
}
.modal-header {
  padding: 18px 22px 14px;
  border-bottom: 1px solid #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.modal-header h2 { font-size: 1.08rem; color: #333; }
.modal-header-right { display: flex; align-items: center; gap: 8px; }
.modal-close {
  background: none; border: none;
  font-size: 1.25rem; color: #bbb; cursor: pointer; padding: 4px;
  line-height: 1; transition: color 0.2s;
}
.modal-close:hover { color: #ff6b6b; }
.modal-body { padding: 18px 22px; overflow-y: auto; flex: 1; }

/* ===== History Modal ===== */
.history-empty {
  text-align: center; color: #ccc;
  padding: 48px 0; font-size: 0.9rem; line-height: 1.8;
}
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border: 1.5px solid #f0f0f0;
  border-radius: 12px;
  background: #fafafa;
}
.history-emoji { font-size: 1.6rem; }
.history-info { flex: 1; min-width: 0; }
.history-name { font-weight: 700; color: #333; font-size: 0.93rem; }
.history-meta { font-size: 0.73rem; color: #bbb; margin-top: 2px; }
.history-kcal {
  font-size: 0.72rem; font-weight: 700;
  padding: 3px 9px; border-radius: 10px;
  color: white; white-space: nowrap; flex-shrink: 0;
}
.btn-clear {
  background: none;
  border: 1.5px solid #ef5350;
  color: #ef5350;
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.75rem; font-weight: 600;
  cursor: pointer; transition: all 0.2s;
}
.btn-clear:hover { background: #ef5350; color: white; }

/* ===== Settings Modal ===== */
.setting-cat-list { display: flex; flex-direction: column; gap: 10px; }
.setting-cat-item {
  border: 1.5px solid #eee; border-radius: 14px; overflow: hidden;
}
.setting-cat-item.expanded { border-color: #ffb3b3; }

.setting-cat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; cursor: pointer;
  background: #fafafa; transition: background 0.15s;
  user-select: none;
}
.setting-cat-header:hover,
.setting-cat-item.expanded .setting-cat-header { background: #fff0f0; }

.setting-cat-emoji { font-size: 1.3rem; }
.setting-cat-meta { flex: 1; display: flex; flex-direction: column; }
.setting-cat-name  { font-weight: 700; color: #333; font-size: 0.88rem; }
.setting-cat-count { font-size: 0.7rem; color: #bbb; }
.setting-cat-actions { display: flex; gap: 4px; }
.btn-icon {
  background: none; border: none; cursor: pointer;
  font-size: 0.9rem; padding: 3px 6px; border-radius: 7px;
  color: #ccc; transition: all 0.15s;
}
.btn-icon:hover { background: #ffeaea; color: #ff6b6b; }
.btn-icon[disabled] { opacity: 0.25; pointer-events: none; }

.setting-cat-body {
  display: none; padding: 12px 14px;
  border-top: 1px solid #f5f5f5; background: white;
}
.setting-cat-item.expanded .setting-cat-body { display: block; }

.food-list { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.food-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: 8px; background: #f8f8f8;
}
.food-item-emoji { font-size: 1rem; min-width: 22px; text-align: center; }
.food-item-name  { flex: 1; font-size: 0.82rem; color: #444; }
.food-item-kcal  { font-size: 0.72rem; color: #bbb; min-width: 52px; text-align: right; }
.food-item-del {
  background: none; border: none; color: #ddd;
  cursor: pointer; font-size: 0.88rem; padding: 2px 5px;
  border-radius: 5px; transition: all 0.15s;
}
.food-item-del:hover { background: #ffeaea; color: #e53935; }
.empty-food-msg { font-size: 0.78rem; color: #ccc; text-align: center; padding: 8px 0; }

.add-food-row { display: flex; gap: 5px; }
.input-emoji {
  width: 48px; padding: 7px 4px; text-align: center;
  border: 1.5px solid #eee; border-radius: 9px;
  font-size: 1rem; outline: none; transition: border-color 0.2s;
}
.input-emoji:focus { border-color: #ff6b6b; }
.input-text {
  padding: 7px 10px;
  border: 1.5px solid #eee; border-radius: 9px;
  font-size: 0.82rem; outline: none; transition: border-color 0.2s;
}
.input-text:focus { border-color: #ff6b6b; }
.input-kcal {
  width: 64px; padding: 7px 8px; text-align: center;
  border: 1.5px solid #eee; border-radius: 9px;
  font-size: 0.82rem; outline: none; transition: border-color 0.2s;
}
.input-kcal:focus { border-color: #ff6b6b; }
.flex1 { flex: 1; }
.btn-add {
  padding: 7px 11px; background: #ff6b6b; color: white;
  border: none; border-radius: 9px; font-weight: 700;
  cursor: pointer; font-size: 0.85rem; transition: background 0.15s;
}
.btn-add:hover { background: #ff4f4f; }

.add-cat-section {
  margin-top: 14px; padding-top: 14px; border-top: 1px dashed #eee;
}
.section-label {
  font-size: 0.72rem; font-weight: 700; color: #bbb;
  text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 10px;
}
.add-cat-row { display: flex; gap: 6px; }
.btn-add-cat {
  padding: 9px 14px;
  background: linear-gradient(135deg, #ff9a56, #ff6b6b);
  color: white; border: none; border-radius: 10px;
  font-weight: 700; cursor: pointer; font-size: 0.88rem;
  white-space: nowrap;
  box-shadow: 0 3px 10px rgba(255,107,107,0.3);
  transition: opacity 0.15s;
}
.btn-add-cat:hover { opacity: 0.88; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 30px; left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: rgba(30,30,30,0.85);
  color: white; padding: 10px 22px;
  border-radius: 30px; font-size: 0.86rem;
  opacity: 0; pointer-events: none;
  transition: all 0.28s ease;
  z-index: 200; white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
