/* --- CSS Reset & Variables --- */
:root {
  --brand-blue: #1e50a2;
  --food-orange: #E64A19;
  --food-orange-light: #fff5f2;
  --background-color: #faf9f6;
  --text-color: #333333;
  --card-bg-color: #ffffff;
  --footer-bg-color: #ffffff;
  --border-color: #e0e0e0;
  --primary-action: var(--food-orange);
  --safe-bottom: env(safe-area-inset-bottom, 20px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  font-family: "M PLUS Rounded 1c", sans-serif;
  background-color: var(--background-color);
  color: var(--text-color);
  padding-bottom: calc(90px + var(--safe-bottom));
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none; /* バウンス防止 */
}

/* --- Loading --- */
.loading-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background-color: var(--background-color);
  display: flex; flex-direction: column; justify-content: center;
  align-items: center; z-index: 2000;
  transition: opacity 0.3s;
}
.spinner {
  border: 4px solid rgba(30, 80, 162, 0.1); width: 40px; height: 40px;
  border-radius: 50%; border-left-color: var(--brand-blue);
  animation: spin 0.8s ease infinite; margin-bottom: 1rem;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* --- Header --- */
.app-header {
  background-color: var(--brand-blue);
  color: white; padding: 1rem;
  text-align: center; position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.app-header h1 { font-size: 1.2rem; font-weight: 800; letter-spacing: 0.05em; }

/* --- Navigation --- */
.category-nav {
    display: flex; gap: 8px; overflow-x: auto; padding: 10px 1rem;
    background: var(--background-color);
    scrollbar-width: none;
    position: sticky; top: 58px; z-index: 99;
}
.category-nav::-webkit-scrollbar { display: none; }
.category-nav a {
    white-space: nowrap; padding: 8px 16px; background: white; 
    border-radius: 20px; text-decoration: none; 
    color: var(--brand-blue); font-weight: bold; font-size: 0.9rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05); 
    border: 1px solid rgba(30, 80, 162, 0.1); 
    transition: all 0.2s;
}
.category-nav a.active, .category-nav a:active { 
    background-color: var(--brand-blue); color: white; 
}

/* --- Main Menu --- */
#app-main { padding: 0 1rem 1rem 1rem; max-width: 1000px; margin: 0 auto; }
.menu-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 600px) { .menu-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); } }

.category-title { 
    grid-column: 1 / -1; margin-top: 1.5rem; margin-bottom: 0.5rem; 
    color: var(--brand-blue); font-size: 1.1rem; font-weight: 800;
    display: flex; align-items: center;
}
.category-title::before {
    content: ''; display: inline-block; width: 6px; height: 1.2rem;
    background-color: var(--food-orange); margin-right: 8px; border-radius: 3px;
}

/* Menu Card */
.menu-item-card {
  background-color: var(--card-bg-color); border-radius: 16px; 
  box-shadow: 0 2px 8px rgba(0,0,0,0.04); overflow: hidden;
  cursor: pointer; position: relative;
  display: flex; flex-direction: column;
  transition: transform 0.1s;
}
.menu-item-card:active { transform: scale(0.97); }

.menu-item-card img { 
    width: 100%; height: 140px; object-fit: cover; 
    background-color: #eee;
}

.item-info { padding: 10px; flex-grow: 1; display: flex; flex-direction: column; justify-content: space-between; }
.item-name { font-weight: 700; margin-bottom: 4px; font-size: 0.95rem; line-height: 1.4; color: var(--text-color); }
.item-price { color: var(--food-orange); font-weight: 800; font-size: 1.0rem; text-align: right; margin-top: auto; }

/* --- Footer (Cart Button) --- */
.cart-footer {
  position: fixed; bottom: 0; left: 0; width: 100%;
  background-color: rgba(255, 255, 255, 0.95); 
  backdrop-filter: blur(10px);
  padding: 10px 1rem calc(10px + var(--safe-bottom)) 1rem;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.08); z-index: 90;
  border-top: 1px solid #eee;
  display: flex; justify-content: space-between; align-items: center;
}
.view-cart-button {
  background-color: var(--food-orange); color: white; border: none;
  border-radius: 50px; padding: 12px 24px; font-size: 1rem;
  font-weight: 800; cursor: pointer; box-shadow: 0 4px 12px rgba(230, 74, 25, 0.3);
  display: flex; align-items: center; gap: 8px;
  transition: transform 0.1s, opacity 0.2s;
}
.view-cart-button:disabled { background-color: #ccc; box-shadow: none; opacity: 0.8; pointer-events: none; }
.view-cart-button:active { transform: scale(0.96); }

.cart-badge {
    background: white; color: var(--food-orange); 
    border-radius: 12px; padding: 2px 8px; font-size: 0.9rem;
}
.total-price-display { font-size: 1.1rem; font-weight: 800; color: var(--brand-blue); }

/* --- Modal Common --- */
.modal-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: none; justify-content: center; align-items: flex-end; 
  z-index: 200; opacity: 0; transition: opacity 0.2s ease;
}
.modal-overlay.visible { display: flex; opacity: 1; }

.modal-content {
  background-color: #fff; 
  border-radius: 24px 24px 0 0; 
  width: 100%; max-width: 600px; 
  height: 90vh; /* 高さ確保: 画面の90% */
  max-height: 90vh;
  display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 -10px 40px rgba(0,0,0,0.2);
}
.modal-overlay.visible .modal-content { transform: translateY(0); }

.modal-header {
  padding: 1rem 1.5rem; 
  border-bottom: 1px solid #f0f0f0;
  display: flex; justify-content: space-between; align-items: center;
  flex-shrink: 0;
}
.modal-header h2 { font-size: 1.2rem; font-weight: 800; color: var(--brand-blue); }

/* 閉じるボタン（タッチしやすいように大きく） */
.close-button { 
    background: #f5f5f5; border: none; 
    width: 36px; height: 36px; border-radius: 50%;
    font-size: 1.5rem; line-height: 1; color: #666; cursor: pointer; 
    display: flex; align-items: center; justify-content: center;
}
.close-button:active { background: #e0e0e0; }

/* スクロールエリア */
.modal-body { 
    flex-grow: 1; overflow-y: auto; padding: 1rem 1.5rem; 
    -webkit-overflow-scrolling: touch; /* 慣性スクロール */
    padding-bottom: 100px; /* フッターとかぶらないように余白 */
}

.modal-footer { 
  padding: 1rem 1.5rem calc(1rem + var(--safe-bottom)) 1rem;
  border-top: 1px solid #f0f0f0; background-color: #fff; 
  flex-shrink: 0; z-index: 10;
  box-shadow: 0 -4px 10px rgba(0,0,0,0.05);
}

/* --- Item Detail Modal --- */
.item-detail-img { 
    width: 100%; height: 220px; object-fit: cover; 
    border-radius: 16px; margin-bottom: 1rem; 
}
.item-description { color: #666; font-size: 0.9rem; line-height: 1.6; margin-bottom: 1.5rem; }

.option-section { margin-bottom: 2rem; }
.option-section h3 { 
    font-size: 1rem; margin-bottom: 0.8rem; 
    display: flex; align-items: center; gap: 8px; color: var(--brand-blue); 
}

.badge { font-size: 0.75rem; padding: 2px 8px; border-radius: 6px; color: white; }
.badge-req { background-color: var(--food-orange); }
.badge-opt { background-color: #999; }
.flavor-note { font-size: 0.85rem; color: var(--food-orange); margin-bottom: 0.5rem; font-weight: bold; }

/* オプション選択肢（ラジオボタン・チェックボックス修正版） */
.option-label {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; 
  border: 2px solid #eee; /* 枠線を太く */
  border-radius: 12px; margin-bottom: 8px; cursor: pointer;
  background: white; transition: all 0.15s; 
  position: relative;
}
/* inputを非表示ではなく透明にして配置（タップ判定の安定化） */
.option-label input { 
    position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none;
}

/* 選択時のスタイル */
.option-label.selected {
  border-color: var(--brand-blue); 
  background-color: #f0f6ff; 
  color: var(--brand-blue);
}
.option-label.selected .option-name { font-weight: bold; }
.option-label.selected .option-price { color: var(--food-orange); font-weight: bold; }

.option-check-mark {
    width: 20px; height: 20px; border-radius: 50%; border: 2px solid #ccc;
    margin-left: 10px; position: relative;
}
.option-label.selected .option-check-mark {
    border-color: var(--brand-blue); background-color: var(--brand-blue);
}
.option-label.selected .option-check-mark::after {
    content: '✔'; color: white; font-size: 12px;
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
}

/* 数量セレクタ */
.quantity-control-area {
    display: flex; justify-content: space-between; align-items: center;
    background: #f8f8f8; padding: 1rem; border-radius: 16px; margin-top: 2rem;
}
.quantity-controls { display: flex; align-items: center; gap: 15px; }
.qty-btn {
    width: 44px; height: 44px; border-radius: 50%; border: none;
    background-color: white; font-size: 1.5rem; color: var(--brand-blue);
    box-shadow: 0 2px 5px rgba(0,0,0,0.1); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.qty-btn:active { background-color: #eee; transform: scale(0.95); }
.qty-val { font-size: 1.4rem; font-weight: 800; min-width: 40px; text-align: center; }

/* Footer Prices */
.modal-price-preview { 
    text-align: right; margin-bottom: 10px; 
    font-weight: 800; font-size: 1.25rem; color: var(--brand-blue); 
}
.submit-button {
  width: 100%; background-color: var(--food-orange); color: white; border: none; 
  padding: 14px; border-radius: 50px; font-size: 1.1rem; font-weight: 800; cursor: pointer;
  box-shadow: 0 4px 15px rgba(230, 74, 25, 0.3); transition: transform 0.1s;
}
.submit-button:active { transform: scale(0.98); }
.submit-button:disabled { background-color: #ccc; box-shadow: none; opacity: 0.7; }

/* --- Cart Modal Specific (視認性改善) --- */
.cart-items-container {
    padding: 0; /* body padding handles it */
}
.cart-empty-msg {
    text-align: center; padding: 3rem 1rem; color: #999;
}

.cart-item {
    background: white; border: 1px solid #eee;
    padding: 1rem; margin-bottom: 1rem; border-radius: 12px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.03);
    position: relative;
}
.cart-item-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px dashed #eee;
}
.cart-item-name { font-size: 1.05rem; font-weight: 800; color: var(--brand-blue); }
.cart-item-total { font-size: 1.1rem; font-weight: 800; color: var(--text-color); }

.cart-item-details { font-size: 0.9rem; color: #666; margin-bottom: 8px; }
.cart-detail-line { margin-bottom: 4px; display: flex; }
.cart-detail-label { color: #999; min-width: 50px; font-size: 0.8rem; }

.cart-item-actions {
    display: flex; justify-content: space-between; align-items: center; margin-top: 10px;
}
.remove-btn {
    color: #ff4d4f; border: 1px solid #ff4d4f; background: white;
    padding: 6px 16px; border-radius: 20px; font-size: 0.85rem; font-weight: bold;
}

/* Cart Forms */
.form-group { margin-bottom: 1.5rem; }
.form-group label { display: block; font-weight: bold; margin-bottom: 0.5rem; color: var(--brand-blue); }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 12px; border-radius: 12px; border: 1px solid #ccc; 
    font-size: 1rem; background: #fcfcfc; font-family: inherit;
    -webkit-appearance: none; appearance: none;
}
.form-group select {
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23333' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat; background-position: right 12px center; background-size: 16px;
}

/* Alert Modal */
.alert-body { padding: 1.5rem; text-align: center; }
.alert-msg { white-space: pre-wrap; margin-bottom: 1.5rem; line-height: 1.6; }

/* ===== 移行版で追加: 限定商品・受取日選択 ===== */
.badge-limited {
    display: inline-block; background: #E60012; color: #fff;
    font-size: 0.7rem; font-weight: bold; padding: 2px 8px;
    border-radius: 10px; margin-left: 6px; vertical-align: middle;
}
.stock-note { font-size: 0.78rem; font-weight: bold; margin-top: 2px; }
.stock-few { color: #E64A19; }
.stock-out { color: #999; }
.menu-item-card.sold-out { opacity: 0.55; position: relative; }
.menu-item-card.sold-out::after {
    content: "売切"; position: absolute; top: 8px; left: 8px;
    background: rgba(0,0,0,0.65); color: #fff; font-weight: bold;
    padding: 3px 10px; border-radius: 6px; font-size: 0.8rem;
}
.advance-cta {
    display: inline-block; margin-top: 4px; font-size: 0.78rem; font-weight: bold;
    color: var(--brand-blue); text-decoration: underline; cursor: pointer;
}
.pickup-date-row { display: flex; gap: 10px; }
.pickup-date-row > div { flex: 1; }
.date-hint { color: #E64A19; font-size: 0.8rem; margin-top: 5px; display: block; }

/* ===== #4 レスポンシブ最適化 ===== */
* { box-sizing: border-box; }
img { max-width: 100%; }
html, body { overflow-x: hidden; }

/* 本文は広画面で中央寄せ・最大幅を制限（間延び防止） */
#app-main { max-width: 720px; margin: 0 auto; }
.app-header h1 { margin: 0; }
.category-nav { max-width: 720px; margin: 0 auto; }

/* 極小画面: メニューは1列に */
@media (max-width: 360px) {
  .menu-grid { grid-template-columns: 1fr; }
  .app-header h1 { font-size: 1.05rem; }
}

/* タブレット/PC: モーダルを中央ダイアログ化（下シートの間延び回避） */
@media (min-width: 600px) {
  .modal-overlay { align-items: center; }
  .modal-content {
    height: auto; max-height: 88vh; max-width: 480px; margin: 0 auto;
    border-radius: 20px;
  }
  .cart-footer { max-width: 720px; left: 50%; transform: translateX(-50%); }
}

/* タップ領域の最低確保 */
.category-nav a, .qty-btn, .option-label, .submit-button, .remove-btn { min-height: 40px; }
