:root {
  color-scheme: light;
  --ink: #211f1b;
  --muted: #6f6a60;
  --paper: #fffaf1;
  --panel: rgba(255, 250, 241, 0.9);
  --line: rgba(33, 31, 27, 0.13);
  --line-strong: rgba(33, 31, 27, 0.2);
  --tomato: #d9472f;
  --tomato-dark: #a93122;
  --leaf: #2c7559;
  --leaf-soft: #dcebe1;
  --yolk: #f6bc3f;
  --steam: #f5f0e4;
  --shadow: 0 22px 70px rgba(44, 35, 24, 0.12);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #f7efe3;
}

body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    linear-gradient(115deg, rgba(217, 71, 47, 0.1) 0 14%, transparent 14% 100%),
    linear-gradient(245deg, rgba(44, 117, 89, 0.12) 0 18%, transparent 18% 100%),
    linear-gradient(180deg, #fff7e8 0%, #f3ebdd 62%, #e8f0e7 100%);
}

body::before {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  content: "";
  background-image:
    linear-gradient(rgba(33, 31, 27, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(33, 31, 27, 0.035) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.7), transparent 78%);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

#ambient-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.page {
  position: relative;
  z-index: 1;
  width: min(1160px, calc(100% - 40px));
  margin: 0 auto;
  padding: 20px 0 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 68px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  color: #fffaf1;
  background: var(--tomato);
  font-weight: 950;
  box-shadow: 0 12px 26px rgba(217, 71, 47, 0.22);
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 1rem;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.topnav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.topnav a,
.history-filter,
.meal-tab {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 250, 241, 0.66);
  font-weight: 850;
}

.topnav a {
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
}

.app-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.85fr);
  gap: 18px;
  align-items: stretch;
  padding: 34px 0 18px;
}

.picker-panel,
.history-panel,
.menu-section,
.gallery-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.picker-panel {
  min-height: 520px;
  padding: clamp(24px, 4vw, 44px);
}

.history-panel {
  padding: 22px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--tomato-dark);
  font-size: 0.78rem;
  font-weight: 950;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  max-width: 11ch;
  font-size: clamp(2.7rem, 7vw, 5.8rem);
  line-height: 0.98;
}

h2 {
  font-size: clamp(1.55rem, 3vw, 2.35rem);
  line-height: 1.08;
}

.lead {
  max-width: 660px;
  margin: 20px 0 28px;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.14rem);
  line-height: 1.8;
}

.field-group {
  display: grid;
  gap: 10px;
}

.field-label {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 900;
}

.meal-tabs,
.history-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.meal-tab,
.history-filter {
  padding: 0 16px;
  transition:
    color 160ms ease,
    background 160ms ease,
    border-color 160ms ease,
    transform 160ms ease;
}

.meal-tab.is-active,
.history-filter.is-active {
  color: #fffaf1;
  border-color: transparent;
  background: var(--leaf);
}

.choice-card {
  display: grid;
  gap: 8px;
  width: min(100%, 520px);
  margin: 26px 0 18px;
  padding: 20px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(246, 188, 63, 0.18), rgba(44, 117, 89, 0.1)),
    #fffaf1;
}

.choice-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.choice-card strong {
  min-height: 1.2em;
  color: var(--tomato-dark);
  font-size: clamp(2rem, 5vw, 3.5rem);
  line-height: 1;
  word-break: break-word;
}

.choice-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.record-row {
  display: grid;
  grid-template-columns: minmax(160px, 220px) max-content max-content;
  gap: 10px;
  align-items: end;
}

.date-field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 900;
}

.date-field input,
.add-menu-form input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.74);
  outline: 0;
}

.date-field input {
  padding: 0 12px;
}

.add-menu-form input {
  min-width: 220px;
  padding: 0 14px;
}

.primary-btn,
.solid-btn {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  font-weight: 950;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

.primary-btn {
  color: #211f1b;
  background: var(--yolk);
  box-shadow: 0 14px 28px rgba(246, 188, 63, 0.24);
}

.solid-btn {
  color: #fffaf1;
  background: var(--tomato);
  box-shadow: 0 14px 28px rgba(217, 71, 47, 0.2);
}

.primary-btn:hover,
.solid-btn:hover,
.meal-tab:hover,
.history-filter:hover,
.dish-card:hover,
.topnav a:hover {
  transform: translateY(-1px);
}

.status-message {
  min-height: 24px;
  margin: 16px 0 0;
  color: var(--leaf);
  font-weight: 850;
  line-height: 1.5;
}

.section-title {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
}

.compact-title {
  align-items: start;
  margin-bottom: 14px;
}

.icon-btn {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.68);
  font-size: 1.35rem;
  line-height: 1;
}

.history-tabs {
  margin-bottom: 14px;
}

.history-filter {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.86rem;
}

.history-list {
  display: grid;
  gap: 10px;
  max-height: 386px;
  overflow: auto;
  padding-right: 4px;
}

.history-item,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
}

.history-item {
  position: relative;
  display: grid;
  gap: 7px;
  min-height: 86px;
  padding: 14px 72px 14px 14px;
}

.history-item span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
}

.history-item strong {
  color: var(--ink);
  font-size: 1.1rem;
  line-height: 1.25;
  word-break: break-word;
}

.delete-record {
  position: absolute;
  top: 12px;
  right: 12px;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  color: var(--muted);
  background: rgba(255, 250, 241, 0.78);
  font-size: 0.78rem;
  font-weight: 900;
}

.empty-state {
  padding: 20px;
  color: var(--muted);
  line-height: 1.6;
}

.menu-section,
.gallery-section {
  margin-top: 18px;
  padding: 22px;
}

.add-menu-form {
  display: flex;
  gap: 10px;
  align-items: center;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.dish-card {
  display: grid;
  gap: 16px;
  min-height: 112px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.68);
  text-align: left;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease;
}

.dish-card span {
  align-self: start;
  font-size: clamp(1.18rem, 2vw, 1.45rem);
  font-weight: 950;
  line-height: 1.2;
  word-break: break-word;
}

.dish-card small {
  align-self: end;
  width: fit-content;
  min-height: 28px;
  border-radius: 999px;
  padding: 5px 10px;
  color: var(--leaf);
  background: var(--leaf-soft);
  font-size: 0.78rem;
  font-weight: 950;
}

.dish-card.is-selected {
  border-color: rgba(217, 71, 47, 0.52);
  background:
    linear-gradient(135deg, rgba(217, 71, 47, 0.1), rgba(246, 188, 63, 0.13)),
    rgba(255, 255, 255, 0.84);
  box-shadow: 0 16px 34px rgba(217, 71, 47, 0.14);
}

.dish-card.is-selected small {
  color: #fffaf1;
  background: var(--tomato);
}

.gallery-section {
  box-shadow: none;
}

.gallery-note {
  max-width: 260px;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.6;
  text-align: right;
}

.photo-strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 72px;
  gap: 8px;
  margin-top: 16px;
  overflow-x: auto;
  padding: 2px 2px 10px;
  scrollbar-color: rgba(33, 31, 27, 0.3) transparent;
}

.photo-thumb {
  width: 72px;
  height: 72px;
  padding: 0;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 8px;
  background: var(--steam);
}

.photo-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 180ms ease;
}

.photo-thumb:hover img {
  transform: scale(1.06);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 5;
  max-width: min(320px, calc(100% - 36px));
  padding: 12px 14px;
  visibility: hidden;
  border-radius: 8px;
  color: #fffaf1;
  background: #211f1b;
  box-shadow: 0 18px 38px rgba(33, 31, 27, 0.22);
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity 180ms ease,
    transform 180ms ease,
    visibility 180ms ease;
}

.toast.is-visible {
  visibility: visible;
  opacity: 1;
  transform: translateY(0);
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: 22px;
  visibility: hidden;
  opacity: 0;
  background: rgba(20, 18, 15, 0.82);
  backdrop-filter: blur(14px);
  transition:
    opacity 180ms ease,
    visibility 180ms ease;
}

.lightbox.is-open {
  visibility: visible;
  opacity: 1;
}

.lightbox-dialog {
  position: relative;
  display: grid;
  place-items: center;
  width: min(780px, 100%);
}

.lightbox-dialog img {
  display: block;
  max-width: min(100%, 72vh);
  max-height: 80vh;
  border-radius: 8px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.36);
}

.lightbox-dialog p {
  margin: 12px 0 0;
  color: #fffaf1;
  font-weight: 900;
}

.lightbox-close,
.lightbox-nav {
  position: absolute;
  z-index: 1;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 50%;
  color: #fffaf1;
  background: rgba(20, 18, 15, 0.72);
  backdrop-filter: blur(10px);
}

.lightbox-close {
  top: -12px;
  right: -12px;
  width: 42px;
  height: 42px;
  font-size: 1.5rem;
  line-height: 1;
}

.lightbox-nav {
  top: 50%;
  width: 48px;
  height: 48px;
  transform: translateY(-50%);
  font-size: 2rem;
  line-height: 1;
}

.lightbox-nav.prev {
  left: -62px;
}

.lightbox-nav.next {
  right: -62px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.topnav a:focus-visible,
.meal-tab:focus-visible,
.history-filter:focus-visible,
.primary-btn:focus-visible,
.solid-btn:focus-visible,
.icon-btn:focus-visible,
.dish-card:focus-visible,
.delete-record:focus-visible,
.photo-thumb:focus-visible,
.lightbox-close:focus-visible,
.lightbox-nav:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(44, 117, 89, 0.42);
  outline-offset: 3px;
}

input:focus-visible {
  border-color: var(--leaf);
}

@media (max-width: 920px) {
  .page {
    width: min(100% - 28px, 680px);
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topnav {
    justify-content: flex-start;
  }

  .app-grid {
    grid-template-columns: 1fr;
    padding-top: 22px;
  }

  .picker-panel {
    min-height: auto;
  }

  .record-row {
    grid-template-columns: 1fr 1fr;
  }

  .date-field {
    grid-column: 1 / -1;
  }

  .menu-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .page {
    width: min(100% - 22px, 440px);
    padding-top: 14px;
  }

  h1 {
    max-width: 10ch;
    font-size: clamp(2.6rem, 15vw, 4.4rem);
  }

  .picker-panel,
  .history-panel,
  .menu-section,
  .gallery-section {
    padding: 18px;
  }

  .record-row,
  .menu-grid,
  .add-menu-form {
    grid-template-columns: 1fr;
  }

  .record-row,
  .add-menu-form {
    display: grid;
  }

  .primary-btn,
  .solid-btn {
    width: 100%;
  }

  .section-title {
    align-items: start;
    flex-direction: column;
  }

  .compact-title {
    flex-direction: row;
  }

  .gallery-note {
    max-width: none;
    text-align: left;
  }

  .photo-strip {
    grid-auto-columns: 58px;
  }

  .photo-thumb {
    width: 58px;
    height: 58px;
  }

  .lightbox {
    padding: 12px;
  }

  .lightbox-dialog img {
    max-width: 100%;
    max-height: 76vh;
  }

  .lightbox-close {
    top: 8px;
    right: 8px;
  }

  .lightbox-nav.prev {
    left: 10px;
  }

  .lightbox-nav.next {
    right: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
