:root {
  --bg: #f4f7f4;
  --surface: #ffffff;
  --primary: #2d6a4f;
  --primary-light: #40916c;
  --primary-soft: #d8f3dc;
  --accent: #f4a261;
  --text: #1b4332;
  --text-muted: #52796f;
  --border: #b7e4c7;
  --fasting: #fff3e0;
  --fasting-border: #ffb74d;
  --free: #e8eaf6;
  --free-border: #7986cb;
  --today-ring: #e76f51;
  --shadow: 0 4px 24px rgba(27, 67, 50, 0.08);
  --radius: 16px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: linear-gradient(160deg, #f4f7f4 0%, #e8f5e9 50%, #f0f4f8 100%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: clip;
}

body.print-page {
  overflow-x: auto;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.app-nav {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 20px;
}

.app-nav a {
  padding: 8px 20px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--text-muted);
  background: var(--surface);
  border: 1.5px solid var(--border);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.app-nav a:hover {
  color: var(--primary);
  border-color: var(--primary-light);
}

.app-nav a.active {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
}

.btn-print-inline {
  margin-left: 8px;
  padding: 8px 18px;
  border: none;
  border-radius: 999px;
  background: var(--accent, #f4a261);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-print-inline:hover {
  filter: brightness(1.05);
}

header {
  text-align: center;
  margin-bottom: 28px;
}

header h1 {
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--primary);
}

header p {
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.progress-counter {
  display: inline-block;
  margin-top: 10px;
  padding: 6px 14px;
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 700;
}

/* ── Phase banner (header) ── */
.phase-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 12px;
  margin: 14px auto 0;
  max-width: 640px;
  padding: 12px 16px;
  background: linear-gradient(135deg, var(--primary-soft) 0%, #e8f5e9 100%);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.45;
}

.phase-banner-stage {
  flex-shrink: 0;
  padding: 4px 10px;
  background: var(--primary);
  color: #fff;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 800;
}

.phase-banner-title {
  font-weight: 700;
  color: var(--primary);
}

.phase-banner-desc {
  width: 100%;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
}

/* ── Phase info (detail panel) ── */
.phase-info {
  margin-bottom: 14px;
  padding: 12px 14px;
  background: linear-gradient(160deg, #f0faf4 0%, #fafcfa 100%);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.phase-info-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.phase-stage-badge {
  flex-shrink: 0;
  padding: 3px 9px;
  background: var(--primary);
  color: #fff;
  border-radius: 16px;
  font-size: 0.72rem;
  font-weight: 800;
}

.phase-info-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--primary);
}

.phase-info-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  line-height: 1.5;
}

.phase-info-tips {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.phase-info-tips li {
  font-size: 0.78rem;
  color: var(--text-muted);
  padding-left: 14px;
  position: relative;
}

.phase-info-tips li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--primary-light);
  font-weight: 700;
}

/* ── Allowed foods (per phase) ── */
.phase-allowed-foods {
  margin-top: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.75);
  border: 1px dashed var(--border);
  border-radius: 10px;
}

.phase-allowed-foods--compact {
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  text-align: left;
}

.phase-allowed-foods summary {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 4px;
  -webkit-tap-highlight-color: transparent;
}

.phase-allowed-foods summary::-webkit-details-marker {
  display: none;
}

.phase-allowed-foods summary::after {
  content: "▾";
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--text-muted);
  transition: transform 0.15s;
}

.phase-allowed-foods[open] summary::after {
  transform: rotate(180deg);
}

.allowed-foods-summary {
  margin: 8px 0 6px;
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.allowed-foods-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin: 0;
  padding: 0;
}

.allowed-foods-list li {
  font-size: 0.74rem;
  color: var(--text-muted);
  padding-left: 12px;
  position: relative;
  line-height: 1.4;
}

.allowed-foods-list li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: var(--primary-light);
  font-size: 0.65rem;
  font-weight: 700;
}

.allowed-foods-list--compact li {
  font-size: 0.72rem;
}

/* ── Encouragement toast ── */
.toast-container {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  pointer-events: none;
}

.encouragement-toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 420px;
  width: 100%;
  padding: 14px 16px;
  background: var(--surface);
  border: 1.5px solid var(--primary-light);
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(27, 67, 50, 0.18);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.28s ease, transform 0.28s ease;
}

.encouragement-toast.toast-in {
  opacity: 1;
  transform: translateY(0);
}

.encouragement-toast.toast-out {
  opacity: 0;
  transform: translateY(8px);
}

.encouragement-toast .toast-icon {
  font-size: 1.4rem;
  flex-shrink: 0;
  line-height: 1.2;
}

.encouragement-toast .toast-message {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.5;
  margin: 0;
}

.encouragement-toast .toast-close {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: none;
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 8px;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s;
}

.encouragement-toast .toast-close:hover {
  background: var(--border);
}

.start-date-picker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 6px 12px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  font-size: 0.85rem;
}

.start-date-picker label {
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.start-date-picker input[type="date"] {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  background: #fafcfa;
  cursor: pointer;
}

.start-date-picker input[type="date"]:focus {
  outline: 2px solid var(--primary-light);
  outline-offset: 1px;
}

.main-layout {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.calendar-card,
.bottom-panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.calendar-card {
  padding: 20px;
}

.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.month-nav h2 {
  font-size: 1.25rem;
  font-weight: 700;
}

.month-nav button {
  background: var(--primary-soft);
  border: none;
  color: var(--primary);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.1rem;
  transition: background 0.15s;
}

.month-nav button:hover {
  background: var(--border);
}

.month-nav button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 6px;
}

.weekdays span {
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 4px 0;
}

.weekdays span:first-child {
  color: #c62828;
}

.weekdays span:last-child {
  color: #1565c0;
}

.days-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.day-cell {
  aspect-ratio: 1;
  min-height: 72px;
  border-radius: 12px;
  border: 1.5px solid transparent;
  background: #fafcfa;
  padding: 6px;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
  display: flex;
  flex-direction: column;
  position: relative;
}

.day-cell:hover:not(.empty) {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(45, 106, 79, 0.15);
  border-color: var(--primary-light);
}

.day-cell.empty {
  background: transparent;
  cursor: default;
}

.day-cell.out-of-plan {
  background: #f5f5f5;
  color: #aaa;
  cursor: default;
}

.day-cell.fasting {
  background: var(--fasting);
  border-color: var(--fasting-border);
}

.day-cell.free-day {
  background: var(--free);
  border-color: var(--free-border);
}

.day-cell.today {
  outline: 2.5px solid var(--today-ring);
  outline-offset: 1px;
}

.day-cell.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.day-cell.completed {
  border-color: var(--primary-light);
}

.day-cell.completed .day-num {
  color: var(--primary);
}

.day-check {
  position: absolute;
  top: 4px;
  right: 5px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.day-num {
  font-size: 0.85rem;
  font-weight: 700;
}

.diet-badge {
  margin-top: auto;
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--primary);
  background: rgba(45, 106, 79, 0.1);
  border-radius: 6px;
  padding: 2px 4px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.day-cell.fasting .diet-badge {
  color: #e65100;
  background: rgba(230, 81, 0, 0.12);
}

.day-cell.free-day .diet-badge {
  color: #3949ab;
  background: rgba(57, 73, 171, 0.12);
}

/* ── Bottom tab panel ── */
.bottom-panel {
  overflow: hidden;
}

.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 1.5px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tab-bar::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  flex: 1 0 auto;
  min-width: max-content;
  min-height: 44px;
  padding: 12px 20px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2.5px solid transparent;
  margin-bottom: -1.5px;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.tab-btn:hover {
  color: var(--primary);
  background: rgba(216, 243, 220, 0.35);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 700;
}

.tab-panels {
  padding: 0;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.panel-toolbar {
  display: flex;
  justify-content: flex-end;
  padding: 12px 18px 0;
}

.btn-today {
  min-height: 44px;
  padding: 8px 16px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn-today:hover {
  background: var(--border);
  border-color: var(--primary-light);
}

.panel-content {
  padding: 16px 18px 20px;
}

.rules-section + .rules-section {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.rules-section h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--primary);
}

.phase-day-range {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-left: auto;
}

.guide-list,
.forbidden-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.guide-list li,
.forbidden-list li {
  font-size: 0.82rem;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.forbidden-list li::before {
  content: "🚫";
  flex-shrink: 0;
}

.detail-empty {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 32px 12px;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 6px;
}

.detail-header h3 {
  font-size: 1.1rem;
  font-weight: 800;
}

.detail-header .phase-tag {
  font-size: 0.75rem;
  background: var(--primary-soft);
  color: var(--primary);
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 600;
}

.meal-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.meal-item {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  background: #f8fbf9;
  border-radius: 10px;
  border: 1px solid #e8f0eb;
}

.meal-item .meal-time {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  min-width: 36px;
}

.meal-item .meal-icon {
  font-size: 1.2rem;
}

.meal-item .meal-label {
  font-size: 0.88rem;
  font-weight: 500;
}

.exercise-row {
  margin-top: 12px;
  padding: 10px 12px;
  background: linear-gradient(135deg, #e8f5e9, #f1f8e9);
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  display: flex;
  gap: 8px;
  align-items: center;
}

.complete-btn {
  width: 100%;
  margin-top: 14px;
  padding: 12px 16px;
  border: 2px solid var(--primary);
  border-radius: 12px;
  background: #fff;
  color: var(--primary);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.complete-btn:hover:not(:disabled) {
  background: var(--primary-soft);
}

.complete-btn.is-done {
  background: var(--primary);
  color: #fff;
}

.complete-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.legend-item {
  font-size: 0.72rem;
  padding: 4px 8px;
  border-radius: 8px;
  font-weight: 600;
}

.legend-item.normal { background: #fafcfa; color: var(--primary); }
.legend-item.fasting { background: var(--fasting); color: #e65100; }
.legend-item.free { background: var(--free); color: #3949ab; }
.legend-item.completed { background: var(--primary-soft); color: var(--primary); }

footer {
  text-align: center;
  margin-top: 24px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.app-footer {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.app-footer-copyright {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.app-footer-copyright a {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}

.app-footer-copyright a:hover {
  text-decoration: underline;
}

.family-site-container {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
  justify-content: flex-end;
}

.family-site-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--primary);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 6px 12px;
  min-height: 36px;
  min-width: 0;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.family-site-btn:hover {
  border-color: var(--primary-light);
  background: var(--primary-soft);
}

.family-site-btn:focus-visible {
  outline: 2px solid var(--primary-light);
  outline-offset: 2px;
}

.family-site-btn .arrow {
  display: inline-block;
  font-size: 0.65rem;
  line-height: 1;
  transition: transform 0.2s ease;
}

.family-site-container.is-open .family-site-btn .arrow {
  transform: rotate(180deg);
}

.family-site-popup {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  min-width: min(280px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  text-align: left;
}

.family-site-popup[hidden] {
  display: none;
}

.popup-list {
  list-style: none;
  margin: 0;
  padding: 6px 0;
  max-height: 240px;
  overflow-y: auto;
}

.popup-list li a {
  display: block;
  padding: 10px 14px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
}

.popup-list li a:hover {
  background: var(--primary-soft);
  color: var(--primary);
}

.popup-list li a.is-current {
  color: var(--primary);
  font-weight: 700;
  background: rgba(216, 243, 220, 0.5);
  pointer-events: none;
}

@media print {
  .no-print {
    display: none !important;
  }
}

/* ── Mobile: tablet & phone ── */
@media (max-width: 768px) {
  .app {
    padding: 16px 12px 36px;
  }

  header {
    margin-bottom: 20px;
  }

  header p {
    font-size: 0.88rem;
    padding: 0 4px;
  }

  .app-nav {
    flex-wrap: wrap;
    gap: 6px;
  }

  .app-nav a,
  .btn-print-inline {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 18px;
    -webkit-tap-highlight-color: transparent;
  }

  .btn-print-inline {
    margin-left: 0;
  }

  .start-date-picker {
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
    max-width: 320px;
    margin-left: auto;
    margin-right: auto;
    padding: 10px 14px;
    gap: 10px;
  }

  .phase-banner {
    max-width: 100%;
    padding: 10px 12px;
    font-size: 0.84rem;
  }

  .phase-allowed-foods summary {
    min-height: 40px;
    align-items: center;
  }

  .allowed-foods-summary,
  .allowed-foods-list li {
    font-size: 0.78rem;
  }

  .start-date-picker input[type="date"] {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    padding: 8px 10px;
    font-size: 0.9rem;
  }

  .calendar-card {
    padding: 14px 12px;
  }

  .month-nav h2 {
    font-size: 1.1rem;
  }

  .month-nav button {
    width: 44px;
    height: 44px;
    font-size: 1.25rem;
    flex-shrink: 0;
  }

  .weekdays,
  .days-grid {
    gap: 4px;
  }

  .weekdays span {
    font-size: 0.72rem;
    padding: 2px 0;
  }

  .day-cell {
    aspect-ratio: auto;
    min-height: 58px;
    padding: 4px 3px;
    border-radius: 10px;
    -webkit-tap-highlight-color: rgba(45, 106, 79, 0.15);
  }

  .day-cell:hover:not(.empty) {
    transform: none;
  }

  .day-num {
    font-size: 0.8rem;
  }

  .diet-badge {
    font-size: 0.55rem;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.2;
    padding: 2px 3px;
  }

  .day-check {
    width: 16px;
    height: 16px;
    font-size: 0.6rem;
    top: 3px;
    right: 3px;
  }

  .legend {
    justify-content: center;
    gap: 6px;
    margin-top: 12px;
    padding-top: 12px;
  }

  .legend-item {
    font-size: 0.68rem;
    padding: 5px 8px;
  }

  .tab-btn {
    min-height: 44px;
    padding: 12px 16px;
    font-size: 0.85rem;
  }

  .panel-content {
    padding: 14px 14px 18px;
  }

  .panel-toolbar {
    padding: 10px 14px 0;
  }

  .rules-section h3 {
    font-size: 0.92rem;
  }

  .guide-list li,
  .forbidden-list li {
    font-size: 0.85rem;
  }

  .detail-header h3 {
    font-size: 1rem;
  }

  .meal-item {
    padding: 12px;
    min-height: 44px;
  }

  .complete-btn {
    min-height: 48px;
    padding: 14px 16px;
  }

  .btn-today {
    min-height: 44px;
    padding: 10px 16px;
  }

  .app-footer {
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 12px;
    padding-left: 8px;
    padding-right: 8px;
  }

  .app-footer-copyright {
    flex: 1 1 auto;
    text-align: center;
    font-size: 0.72rem;
    white-space: nowrap;
  }

  .family-site-container {
    flex-shrink: 0;
  }

  .family-site-btn {
    min-height: 36px;
    padding: 6px 12px;
    font-size: 0.72rem;
  }

  .family-site-popup {
    right: 0;
    left: auto;
    transform: none;
    min-width: min(280px, calc(100vw - 32px));
  }
}

@media (max-width: 480px) {
  .app {
    padding: 12px 10px 32px;
  }

  header h1 {
    font-size: 1.35rem;
  }

  .progress-counter {
    font-size: 0.8rem;
    padding: 6px 12px;
  }

  .calendar-card {
    padding: 10px 8px;
  }

  .weekdays,
  .days-grid {
    gap: 3px;
  }

  .day-cell {
    min-height: 50px;
    padding: 3px 2px;
    border-radius: 8px;
  }

  .day-num {
    font-size: 0.75rem;
  }

  .diet-badge {
    font-size: 0.5rem;
    -webkit-line-clamp: 2;
  }

  .weekdays span {
    font-size: 0.68rem;
  }

  .legend-item {
    font-size: 0.62rem;
    padding: 4px 6px;
  }

  .month-nav h2 {
    font-size: 1rem;
  }
}
