/* build v5 */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #09090b;
  --surface: #131316;
  --card: #1c1c22;
  --card-hover: #242430;
  --border: #2a2a35;
  --text: #f0f0f5;
  --text-secondary: #8b8b9e;
  --text-muted: #55556a;
  --accent: #8b5cf6;
  --accent-dim: #7c3aed;
  --accent-glow: rgba(139, 92, 246, 0.15);
  --success: #22c55e;
  --success-dim: rgba(34, 197, 94, 0.15);
  --warning: #f59e0b;
  --warning-dim: rgba(245, 158, 11, 0.15);
  --danger: #ef4444;
  --danger-dim: rgba(239, 68, 68, 0.15);
  --radius: 14px;
  --radius-sm: 10px;
  --tab-height: 72px;
  --header-height: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Header */
#header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 12px) 16px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

#header-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.day-nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.day-nav-btn:active {
  color: var(--accent);
  transform: scale(0.9);
}

.day-nav-btn[hidden] {
  display: none;
}

#upload-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

#upload-btn:active {
  background: var(--card-hover);
  color: var(--accent);
  transform: scale(0.95);
}

/* Main */
#main {
  flex: 1;
  padding: 16px 16px calc(var(--tab-height) + var(--safe-bottom) + 16px);
  position: relative;
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Tab Bar */
#tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  justify-content: space-around;
  padding: 8px 16px calc(var(--safe-bottom) + 8px);
  background: rgba(9, 9, 11, 0.92);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 20px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: all 0.2s;
}

.tab.active {
  color: var(--accent);
}

.tab:active {
  transform: scale(0.95);
}

/* Cards */
.meal-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.meal-card:active {
  background: var(--card-hover);
  border-color: var(--border);
  transform: scale(0.98);
}

.meal-card.done {
  opacity: 0.4;
}

.meal-card.done .meal-name {
  text-decoration: line-through;
  text-decoration-color: var(--text-muted);
}

.meal-done-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 2px solid var(--border);
  border-radius: 50%;
  background: none;
  color: transparent;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s;
}

.meal-done-btn:active {
  transform: scale(0.9);
}

.meal-card.done .meal-done-btn {
  background: var(--success);
  border-color: var(--success);
  color: var(--bg);
}

.meal-done-btn svg {
  width: 16px;
  height: 16px;
}

.meal-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}

.meal-emoji {
  font-size: 1.6rem;
  line-height: 1;
  flex-shrink: 0;
}

.meal-info {
  flex: 1;
  min-width: 0;
}

.meal-type {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.meal-name {
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meal-meta {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.meal-meta-item {
  font-size: 0.75rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
}

.meal-meta-item svg {
  width: 14px;
  height: 14px;
  opacity: 0.6;
}

.meal-time {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

/* Prep Ahead Badge */
.prep-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--warning-dim);
  color: var(--warning);
  font-size: 0.7rem;
  font-weight: 600;
  margin-top: 8px;
}

/* Day Section */
.day-section {
  margin-bottom: 24px;
}

.day-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.day-name {
  font-size: 1.1rem;
  font-weight: 700;
}

.day-date {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.day-today-badge {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--accent-glow);
  color: var(--accent);
}

/* Week View */
.week-day-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: all 0.2s;
}

.week-day-card:active {
  transform: scale(0.98);
  background: var(--card-hover);
}

.week-day-card.is-today {
  border: 1px solid var(--accent);
  box-shadow: 0 0 20px var(--accent-glow);
}

.week-day-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.week-day-title {
  font-weight: 700;
  font-size: 1rem;
}

.week-meals-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.week-meal-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
}

.week-meal-type {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  width: 60px;
  flex-shrink: 0;
}

.week-meal-name {
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Shopping View */
.shop-header-section {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.shop-range-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.shop-range-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.shop-range-row:last-child {
  margin-bottom: 0;
}

.shop-range-row label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  width: 45px;
  flex-shrink: 0;
}

.date-select {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.shop-stats {
  display: flex;
  gap: 12px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.shop-stat {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.shop-stat strong {
  color: var(--text);
}

/* Shopping Categories */
.shop-category {
  margin-bottom: 16px;
}

.shop-category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  cursor: pointer;
}

.shop-category-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.shop-category-count {
  font-size: 0.7rem;
  color: var(--text-muted);
  background: var(--surface);
  padding: 2px 8px;
  border-radius: 10px;
}

.shop-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--card);
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  transition: all 0.2s;
  cursor: pointer;
}

.shop-item.checked {
  opacity: 0.45;
}

.shop-item.checked .shop-item-name {
  text-decoration: line-through;
}

.shop-checkbox {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}

.shop-item.checked .shop-checkbox {
  background: var(--success);
  border-color: var(--success);
}

.shop-checkbox svg {
  width: 14px;
  height: 14px;
  stroke: var(--bg);
  opacity: 0;
  transition: opacity 0.2s;
}

.shop-item.checked .shop-checkbox svg {
  opacity: 1;
}

.shop-item-info {
  flex: 1;
  min-width: 0;
}

.shop-item-name {
  font-size: 0.9rem;
  font-weight: 500;
}

.shop-item-detail {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.shop-item-amount {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}

.shop-item-delete {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.shop-item-delete:active {
  color: var(--danger);
  background: var(--danger-dim);
}

/* Add Item */
.add-item-row {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  margin-bottom: 16px;
}

.add-item-input {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.add-item-input:focus {
  border-color: var(--accent);
}

.add-item-input::placeholder {
  color: var(--text-muted);
}

.add-item-btn {
  padding: 12px 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: white;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.add-item-btn:active {
  transform: scale(0.95);
  background: var(--accent-dim);
}

/* Checked section toggle */
.checked-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  font-family: inherit;
}

.checked-toggle svg {
  width: 16px;
  height: 16px;
  transition: transform 0.2s;
}

.checked-toggle.expanded svg {
  transform: rotate(180deg);
}

/* Overlay / Bottom Sheet */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  visibility: hidden;
  opacity: 0;
  transition: visibility 0.3s, opacity 0.3s;
}

.overlay.active {
  visibility: visible;
  opacity: 1;
}

.overlay::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.overlay-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 90dvh;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  padding: 0 16px calc(var(--safe-bottom) + 24px);
}

.overlay.active .overlay-content {
  transform: translateY(0);
}

.overlay-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 12px auto 20px;
  cursor: pointer;
}

/* Meal Detail */
.detail-header {
  margin-bottom: 20px;
}

.detail-emoji {
  font-size: 2.5rem;
  margin-bottom: 8px;
}

.detail-type {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin-bottom: 4px;
}

.detail-name {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.3;
}

.detail-meta {
  display: flex;
  gap: 16px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.detail-meta-item {
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 5px;
}

.macro-bar {
  display: flex;
  gap: 2px;
  margin-top: 12px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.macro-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  background: var(--card);
}

.macro-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.macro-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-top: 2px;
}

.detail-section {
  margin-top: 24px;
}

.detail-section-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.ingredient-list {
  list-style: none;
}

.ingredient-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--card);
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  font-size: 0.9rem;
}

.ingredient-amount {
  color: var(--text-secondary);
  font-size: 0.8rem;
  flex-shrink: 0;
  margin-left: 12px;
}

.instruction-list {
  list-style: none;
  counter-reset: step;
}

.instruction-item {
  counter-increment: step;
  display: flex;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  line-height: 1.6;
}

.instruction-item:last-child {
  border-bottom: none;
}

.instruction-number {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-glow);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.instruction-text {
  flex: 1;
}

/* Prep Ahead Section */
.prep-ahead-card {
  background: var(--warning-dim);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 6px;
  border-left: 3px solid var(--warning);
}

.prep-ahead-task {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--warning);
  margin-bottom: 4px;
}

.prep-ahead-reason {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.prep-ahead-for {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Notes */
.meal-notes {
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-style: italic;
  line-height: 1.6;
}

/* Upload */
.upload-icon {
  color: var(--accent);
  margin-bottom: 16px;
}

#upload-body {
  text-align: center;
  padding-top: 8px;
}

#upload-body h2 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 6px;
}

#upload-body p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 32px 24px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
}

.upload-area:active,
.upload-area.drag-over {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.upload-area-text {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
}

.upload-area-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.upload-error {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--danger-dim);
  color: var(--danger);
  font-size: 0.8rem;
  text-align: left;
}

.upload-info {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.upload-info p {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.btn-danger {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--danger-dim);
  color: var(--danger);
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-danger:active {
  transform: scale(0.95);
  background: var(--danger);
  color: white;
}

/* Welcome */
.welcome[hidden] {
  display: none !important;
}

.welcome {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.welcome-inner {
  text-align: center;
  padding: 24px;
  max-width: 320px;
}

.welcome-icon {
  color: var(--accent);
  margin-bottom: 20px;
}

.welcome h1 {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
}

.welcome p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 28px;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 28px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary:active {
  transform: scale(0.95);
  background: var(--accent-dim);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state svg {
  margin-bottom: 12px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 0.9rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(var(--tab-height) + var(--safe-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(200px);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  z-index: 500;
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.3s;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
}

.toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* Tablet/Desktop */
@media (min-width: 640px) {
  #main {
    max-width: 600px;
    margin: 0 auto;
    padding-left: 24px;
    padding-right: 24px;
  }

  #header {
    padding-left: 24px;
    padding-right: 24px;
  }

  .overlay-content {
    max-width: 600px;
    margin: 0 auto;
    border-radius: 20px 20px 0 0;
  }
}
