* { box-sizing: border-box; }

:root {
  --primary: #42a5f5;
  --primary-dark: #1976d2;
  --primary-light: #e3f2fd;
  --bg: #fafafa;
  --card: #ffffff;
  --border: #e0e0e0;
  --text: #333;
  --text-light: #777;
  --accent: #66bb6a;
  --warn: #ef5350;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
}

body {
  font-family: "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

/* ===== Header ===== */
.app-header {
  background: linear-gradient(135deg, #42a5f5, #1e88e5);
  color: white;
  padding: 20px;
  box-shadow: var(--shadow);
}
.app-header h1 {
  margin: 0 0 12px 0;
  font-size: 1.6rem;
}
.steps {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}
.step-btn {
  background: rgba(255,255,255,0.2);
  color: white;
  border: none;
  padding: 8px 14px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
}
.step-btn.active {
  background: white;
  color: var(--primary-dark);
  font-weight: bold;
}
.step-btn:hover:not(.active) {
  background: rgba(255,255,255,0.3);
}
.arrow {
  color: rgba(255,255,255,0.7);
  font-size: 1.2rem;
}

/* ===== Main ===== */
main {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.step-panel {
  display: none;
  animation: fadeIn 0.3s;
}
.step-panel.active { display: block; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

h2 {
  margin: 0 0 8px 0;
  color: var(--primary-dark);
}
.lead {
  color: var(--text-light);
  margin: 0 0 24px 0;
}

/* ===== Settings ===== */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.setting-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  box-shadow: var(--shadow);
}
.setting-card .label {
  display: block;
  font-size: 0.9rem;
  color: var(--text-light);
  margin-bottom: 12px;
}
.number-input {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.number-input button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: white;
  font-size: 1.2rem;
  cursor: pointer;
  font-weight: bold;
  color: var(--primary);
}
.number-input button:hover {
  background: var(--primary);
  color: white;
}
.number-input input {
  width: 60px;
  height: 40px;
  text-align: center;
  font-size: 1.4rem;
  font-weight: bold;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.setting-card .unit {
  display: block;
  margin-top: 8px;
  color: var(--text-light);
  font-size: 0.85rem;
}

/* ===== Budget Card ===== */
.budget-card {
  background: var(--card);
  border: 2px solid var(--primary);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.budget-label {
  display: block;
  font-size: 1rem;
  font-weight: bold;
  color: var(--primary-dark);
  margin-bottom: 10px;
}
.budget-input-wrap {
  display: flex;
  align-items: stretch;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.2s;
  background: white;
}
.budget-input-wrap:focus-within {
  border-color: var(--primary);
}
.budget-input-wrap .currency-mark {
  display: flex;
  align-items: center;
  padding: 0 14px;
  background: #f5f5f5;
  color: var(--text-light);
  font-size: 1.4rem;
  font-weight: bold;
  border-right: 1px solid var(--border);
}
.budget-input-wrap input {
  flex: 1;
  min-width: 0;          /* iOS で flex+input が膨らむ問題対策 */
  width: 100%;
  font-size: 1.4rem;
  font-weight: bold;
  padding: 12px 14px;
  border: none;
  outline: none;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  text-align: right;
  color: var(--text);
}
/* Chrome/Safari の数値スピナーを非表示 */
.budget-input-wrap input::-webkit-outer-spin-button,
.budget-input-wrap input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.budget-input-wrap input[type="number"] {
  -moz-appearance: textfield;
}
.budget-hint {
  margin: 8px 0 0 0;
  font-size: 0.8rem;
  color: var(--text-light);
}

.summary-box {
  background: var(--primary-light);
  border-left: 4px solid var(--primary);
  padding: 14px 18px;
  border-radius: 8px;
  margin-bottom: 20px;
}

/* ===== Recipes ===== */
.recipe-section { margin-bottom: 32px; }
.recipe-section h3 {
  margin: 0 0 12px 0;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.section-title { font-weight: bold; }
.shuffle-section-btn {
  margin-left: auto;
  background: white;
  border: 1px solid var(--primary);
  color: var(--primary);
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}
.shuffle-section-btn:hover {
  background: var(--primary);
  color: white;
}
.shuffle-section-btn:active { transform: scale(0.95); }
.hint {
  font-size: 0.85rem;
  color: var(--text-light);
  font-weight: normal;
  margin-left: 8px;
}
.recipe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
.recipe-card {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
}
.recipe-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.recipe-card.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}
.recipe-card .name {
  font-weight: bold;
  font-size: 1rem;
}
.recipe-card .recipe-cost {
  font-size: 0.85rem;
  color: var(--primary-dark);
  font-weight: bold;
}
.recipe-card .cost-note {
  font-size: 0.7rem;
  color: var(--text-light);
  font-weight: normal;
}
.recipe-card .ingredients {
  font-size: 0.8rem;
  color: var(--text-light);
  flex-grow: 1;
}
.recipe-card .card-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}
.recipe-card .recipe-link {
  flex: 1;
  text-align: center;
  background: #f5f5f5;
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  text-decoration: none;
  color: var(--text);
}
.recipe-card .recipe-link:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.recipe-card .check-icon {
  position: absolute;
  top: 8px;
  right: 8px;
  color: var(--primary);
  font-size: 1.2rem;
  display: none;
}
.recipe-card.selected .check-icon { display: block; }

/* ===== Buttons ===== */
.actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 24px;
  flex-wrap: wrap;
}
/* 画面下に固定する actions（ステップ2用） */
.sticky-actions {
  position: sticky;
  bottom: 0;
  margin: 24px -20px 0;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
  background: rgba(250, 250, 250, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  z-index: 50;
}
button.primary, button.secondary, button.omakase {
  font-size: 1rem;
  padding: 12px 24px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-weight: bold;
  transition: all 0.2s;
}
button.primary {
  background: var(--primary);
  color: white;
}
button.primary:hover { background: var(--primary-dark); }
button.secondary {
  background: white;
  border: 1px solid var(--border);
  color: var(--text);
}
button.secondary:hover { background: #f5f5f5; }
button.omakase {
  background: var(--accent);
  color: white;
  padding: 6px 14px;
  font-size: 0.9rem;
  margin-left: 12px;
}
button.omakase:hover { background: #43a047; }

/* ===== Budget Summary on Shopping List ===== */
.total-box {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  padding: 18px 20px;
  border-radius: 12px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  box-shadow: var(--shadow);
}
.total-label { font-size: 1rem; opacity: 0.9; }
.total-amount {
  font-size: 1.8rem;
  font-weight: bold;
}
.budget-box {
  background: var(--card);
  border: 2px solid var(--accent);
  border-radius: 10px;
  padding: 14px 18px;
  margin-bottom: 20px;
}
.budget-box.over {
  border-color: var(--warn);
  background: #ffebee;
}
.budget-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 0.95rem;
}
.budget-status {
  font-weight: bold;
  color: var(--accent);
}
.budget-box.over .budget-status { color: var(--warn); }
.budget-bar {
  height: 8px;
  background: #eee;
  border-radius: 4px;
  overflow: hidden;
}
.budget-bar-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s;
}
.budget-box.over .budget-bar-fill { background: var(--warn); }

/* ===== Shopping List ===== */
.list-category {
  background: var(--card);
  border-radius: 10px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.list-category-header {
  background: #f5f5f5;
  padding: 10px 16px;
  font-weight: bold;
  border-bottom: 1px solid var(--border);
}
.list-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  padding: 10px 16px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: #fafafa; }
.list-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
  accent-color: var(--primary);
  grid-row: span 2;
  align-self: center;
}
.item-main {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.item-name {
  font-weight: 500;
  flex: 1;
}
.item-amount {
  color: var(--text-light);
  font-size: 0.9rem;
}
.item-cost {
  color: var(--primary-dark);
  font-weight: bold;
  font-size: 0.9rem;
  margin-left: auto;
}
.item-recipes {
  font-size: 0.75rem;
  color: var(--text-light);
  grid-column: 2;
}
.list-item.checked .item-name,
.list-item.checked .item-amount,
.list-item.checked .item-cost,
.list-item.checked .item-recipes {
  text-decoration: line-through;
  color: #bbb;
}

.empty {
  text-align: center;
  color: var(--text-light);
  padding: 40px 20px;
  background: var(--card);
  border-radius: 10px;
}

@media (max-width: 600px) {
  .app-header h1 { font-size: 1.3rem; }
  .step-btn { font-size: 0.8rem; padding: 6px 10px; }
  main { padding: 16px; }
  .actions { justify-content: stretch; }
  .actions button { flex: 1; }
  .total-amount { font-size: 1.4rem; }
}
