:root {
  --green: #ca0e1e;
  --green-dark: #a50c19;
  --text: #171b1f;
  --muted: #6f747a;
  --line: #dfe2e1;
  --red: #ff3b27;
  --orange: #ff981d;
  --page-max: 480px;
  --pad-x: clamp(14px, 4.5vw, 22px);
  --topbar-h: 68px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  background: #f1eeee;
}

body {
  min-width: 320px;
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

button,
select,
textarea {
  font: inherit;
}

button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/*
 * Toàn bộ ứng dụng khóa đúng chiều cao màn hình.
 * Chỉ hàng thứ 3 (.scroll-zone) được phép cuộn.
 */
.app {
  width: min(100%, var(--page-max));
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  background: #fff;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.06);
}

/* ========== PHẦN CỐ ĐỊNH TRÊN ========== */
.topbar {
  min-height: var(--topbar-h);
  padding: max(6px, env(safe-area-inset-top)) var(--pad-x) 6px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  border-bottom: 1px solid #e8e9e9;
  background: #fff;
  z-index: 5;
}

.topbar h1 {
  margin: 0;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--green);
  font-size: clamp(21px, 5.5vw, 29px);
  font-weight: 800;
  line-height: 1.15;
}

.icon-btn {
  width: 42px;
  height: 42px;
  padding: 5px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--green);
}

.icon-btn:active {
  background: #f7f3f3;
}

.icon-btn svg {
  width: 30px;
  height: 30px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.fixed-date {
  padding: 12px var(--pad-x) 11px;
  border-bottom: 1px solid #f0f1f0;
  background: #fff;
  z-index: 4;
}

.field-label {
  display: block;
  margin: 0 0 6px;
  font-size: clamp(15px, 4vw, 19px);
  font-weight: 750;
}

.select-shell {
  position: relative;
  height: clamp(48px, 7.1dvh, 56px);
  min-height: 46px;
  max-height: 56px;
  border: 1.5px solid #c86f76;
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}

.select-shell select {
  width: 100%;
  height: 100%;
  padding: 0 52px 0 14px;
  border: 0;
  outline: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  color: var(--green);
  font-size: clamp(15px, 4.1vw, 19px);
  font-weight: 600;
}

.calendar-icon {
  position: absolute;
  top: 50%;
  right: 12px;
  width: 25px;
  height: 25px;
  transform: translateY(-50%);
  pointer-events: none;
  fill: none;
  stroke: var(--green);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ========== VÙNG CUỘN DUY NHẤT ========== */
.scroll-zone {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 10px var(--pad-x) 16px;
  background: #fff;
}

.scroll-zone::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.menu-card,
.rating-section,
.comment-section,
.upload-section {
  margin-bottom: 16px;
}

.menu-card {
  padding: 13px;
  border: 1px solid #e4e6e5;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.menu-head {
  margin-bottom: 10px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.menu-head h2 {
  margin: 0;
  color: var(--green);
  font-size: clamp(18px, 4.7vw, 23px);
  line-height: 1.15;
}

.menu-head p {
  margin: 5px 0 0;
  font-size: clamp(13px, 3.6vw, 17px);
}

.meal-badge {
  flex: 0 0 auto;
  padding: 7px 10px;
  border: 1.3px solid var(--green);
  border-radius: 8px;
  color: var(--green);
  font-size: clamp(11px, 3.1vw, 15px);
  white-space: nowrap;
}

/*
 * Không crop ảnh thực đơn.
 * Ảnh lớn hơn vùng hiển thị tự co xuống theo chiều rộng,
 * luôn giữ nguyên tỷ lệ và hiển thị toàn bộ ảnh.
 */
.meal-photo-wrap {
  width: 100%;
  overflow: hidden;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
}

.meal-photo {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  max-height: min(45dvh, 390px);
  object-fit: contain;
  object-position: center;
}

.meal-details {
  margin: 12px 0 0;
  padding: 0 4px;
  display: grid;
  gap: 6px;
  font-size: clamp(13px, 3.5vw, 17px);
  line-height: 1.3;
}

.meal-details div {
  display: grid;
  grid-template-columns: minmax(96px, 31%) 1fr;
  gap: 8px;
}

.meal-details dt {
  font-weight: 800;
}

.meal-details dd {
  margin: 0;
}

.prompt-title {
  margin: 0 0 10px;
  font-size: clamp(15px, 3.95vw, 19px);
  line-height: 1.25;
}

.rating-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.rating-card {
  min-width: 0;
  min-height: 106px;
  padding: 8px 5px;
  border: 1.5px solid currentColor;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: #fff;
  transition: transform 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
}

.rating-card:active {
  transform: scale(0.98);
}

.rating-card svg {
  width: clamp(40px, 10.8vw, 52px);
  height: clamp(40px, 10.8vw, 52px);
  fill: none;
  stroke: currentColor;
  stroke-width: 3.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.rating-card .face-fill {
  fill: currentColor;
  stroke: none;
}

.rating-card span {
  max-width: 100%;
  font-size: clamp(10.5px, 3.05vw, 15px);
  line-height: 1.15;
  text-align: center;
}

.rating-bad { color: var(--red); }
.rating-neutral { color: var(--orange); }
.rating-good { color: var(--green); }

.rating-card[aria-checked="true"] {
  box-shadow: 0 0 0 2px currentColor inset;
}

.rating-bad[aria-checked="true"] { background: #fff5f3; }
.rating-neutral[aria-checked="true"] { background: #fff9f1; }
.rating-good[aria-checked="true"] { background: #fcf7f7; }

.comment-section label {
  display: block;
  margin: 0 0 7px;
  font-size: clamp(14px, 3.7vw, 18px);
  font-weight: 750;
}

.comment-section label span {
  font-weight: 500;
}

.textarea-wrap {
  position: relative;
}

textarea {
  display: block;
  width: 100%;
  min-height: 100px;
  padding: 12px 14px 26px;
  border: 1.2px solid #979da3;
  border-radius: 10px;
  outline: 0;
  resize: none;
  color: var(--text);
  background: #fff;
  font-size: clamp(13px, 3.3vw, 16px);
  line-height: 1.4;
}

textarea::placeholder { color: #9da2a8; }

textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 2px rgba(202, 14, 30, 0.08);
}

.counter {
  position: absolute;
  right: 11px;
  bottom: 8px;
  padding-left: 7px;
  background: #fff;
  color: #777c82;
  font-size: 12px;
}

.upload-heading {
  margin-bottom: 8px;
}

.upload-heading h2 {
  margin: 0;
  font-size: clamp(15px, 3.9vw, 19px);
}

.upload-heading p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: clamp(12px, 3.1vw, 15px);
}

.upload-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.upload-btn {
  min-height: 98px;
  padding: 10px 6px;
  border: 1.5px dashed #d84e59;
  border-radius: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: #fff;
  color: var(--green);
}

.upload-btn:active {
  background: #faf5f6;
}

.upload-btn svg {
  width: clamp(33px, 8.8vw, 42px);
  height: clamp(33px, 8.8vw, 42px);
  fill: none;
  stroke: currentColor;
  stroke-width: 2.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.upload-btn span {
  font-size: clamp(12.5px, 3.45vw, 17px);
  line-height: 1.2;
  text-align: center;
}

/*
 * Preview nằm RIÊNG BÊN DƯỚI hai nút upload.
 * Do đó thêm ảnh không làm mất nút Chọn từ thư viện và Chụp ảnh.
 */
.preview-strip {
  display: none;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
  margin-top: 10px;
}

.preview-strip.has-images {
  display: grid;
}

.preview-item {
  position: relative;
  aspect-ratio: 1 / 1;
  min-width: 0;
  overflow: hidden;
  border: 1px solid #d4d8d6;
  border-radius: 10px;
  background: #f4f6f5;
}

.preview-item img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-remove {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 27px;
  height: 27px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.67);
  color: #fff;
  font-size: 20px;
  line-height: 1;
}

/* ========== PHẦN CỐ ĐỊNH DƯỚI ========== */
.fixed-submit {
  padding: 8px var(--pad-x) max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid #ededed;
  background: #fff;
  text-align: center;
  z-index: 5;
}

.submit-btn {
  width: 100%;
  min-height: clamp(50px, 7dvh, 58px);
  padding: 9px 14px;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(90deg, #c40e1d, #d60e1f);
  color: #fff;
  box-shadow: 0 2px 7px rgba(196, 14, 29, 0.20);
  font-size: clamp(18px, 4.8vw, 24px);
  font-weight: 800;
}

.submit-btn:active {
  transform: translateY(1px);
}

.fixed-submit p {
  margin: 5px 0 0;
  color: #666c70;
  font-size: clamp(10px, 2.8vw, 13px);
  line-height: 1.2;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
  clip-path: inset(50%) !important;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  z-index: 50;
  max-width: min(88vw, 420px);
  padding: 10px 15px;
  border-radius: 22px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px);
  background: #301e20;
  color: #fff;
  text-align: center;
  font-size: 13px;
  transition: 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Mobile nhỏ: vẫn giữ cấu trúc cố định trên/dưới và chỉ cuộn ở giữa. */
@media (max-width: 380px) {
  :root {
    --pad-x: 13px;
    --topbar-h: 62px;
  }

  .topbar {
    grid-template-columns: 38px minmax(0, 1fr) 38px;
  }

  .topbar h1 {
    font-size: 20px;
  }

  .icon-btn,
  .icon-btn svg {
    width: 35px;
    height: 35px;
  }

  .fixed-date {
    padding-top: 9px;
    padding-bottom: 9px;
  }

  .menu-card {
    padding: 11px;
  }

  .meal-details div {
    grid-template-columns: 90px 1fr;
  }

  .rating-grid {
    gap: 7px;
  }

  .rating-card {
    min-height: 94px;
  }

  .upload-actions {
    gap: 8px;
  }

  .upload-btn {
    min-height: 88px;
  }
}

@media (max-width: 340px) {
  .rating-card span { font-size: 10px; }

  .meal-badge {
    padding: 6px 7px;
    font-size: 10.5px;
  }

  .meal-details { font-size: 12.5px; }

  .meal-details div {
    grid-template-columns: 84px 1fr;
  }
}

/* Màn hình thấp: thu gọn các phần FIX để dành thêm diện tích cho vùng cuộn giữa. */
@media (max-height: 700px) {
  :root {
    --topbar-h: 58px;
  }

  .topbar {
    padding-top: max(3px, env(safe-area-inset-top));
    padding-bottom: 3px;
  }

  .topbar h1 {
    font-size: clamp(19px, 5vw, 23px);
  }

  .fixed-date {
    padding-top: 7px;
    padding-bottom: 7px;
  }

  .field-label {
    margin-bottom: 4px;
    font-size: 14px;
  }

  .select-shell {
    height: 44px;
    min-height: 44px;
  }

  .fixed-submit {
    padding-top: 6px;
    padding-bottom: max(5px, env(safe-area-inset-bottom));
  }

  .submit-btn {
    min-height: 46px;
    font-size: 18px;
  }

  .fixed-submit p {
    margin-top: 3px;
    font-size: 10px;
  }
}

/* Desktop chỉ để preview giao diện mobile, ứng dụng vẫn là mobile-only. */
@media (min-width: 481px) {
  body {
    padding: 0 12px;
  }
}