@import url('https://fonts.googleapis.com/css2?family=Kaisei+Decol:wght@400;700&family=Zen+Kaku+Gothic+New:wght@300;400;500;700&display=swap');

/* =====================
   CSS Variables
   ===================== */
:root {
  --terra:    #C8522A;
  --amber:    #E8932A;
  --cream:    #FDF6EC;
  --olive:    #6B7A3A;
  --brown:    #4A2E1A;
  --muted:    #9B8878;
  --white:    #FFFFFF;
  --surface:  #FFF9F2;
  --border:   #EAD9C8;
  --shadow:   rgba(74,46,26,0.10);

  --font-display: 'Kaisei Decol', serif;
  --font-body:    'Zen Kaku Gothic New', sans-serif;

  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;

  --transition: 0.2s ease;
}

/* =====================
   Reset
   ===================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-body);
  background: var(--cream);
  color: var(--brown);
  line-height: 1.6;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, textarea, select { font-family: inherit; }

/* =====================
   Layout
   ===================== */
.app-container {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--white);
  position: relative;
  box-shadow: 0 0 40px var(--shadow);
}

.page {
  padding: 0 0 80px;
}

/* =====================
   Header
   ===================== */
.app-header {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header .logo {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-header .logo img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.app-header .logo-text {
  font-family: var(--font-display);
  font-size: 1.3rem;
  color: var(--terra);
  letter-spacing: 0.02em;
}

.app-header .header-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--brown);
}

/* =====================
   Bottom Navigation
   ===================== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: var(--white);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 0 8px;
  gap: 3px;
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 500;
  transition: color var(--transition);
}

.bottom-nav a.active,
.bottom-nav a:hover {
  color: var(--terra);
}

.bottom-nav a svg {
  width: 22px;
  height: 22px;
  stroke-width: 1.8;
}

/* =====================
   Buttons
   ===================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 0.95rem;
  transition: all var(--transition);
}

.btn-primary {
  background: var(--terra);
  color: var(--white);
  box-shadow: 0 4px 12px rgba(200,82,42,0.30);
}
.btn-primary:hover { background: #b8451f; transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--cream);
  color: var(--terra);
  border: 1.5px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-ghost {
  color: var(--terra);
  padding: 8px 12px;
}
.btn-ghost:hover { background: var(--cream); border-radius: var(--radius-sm); }

.btn-full { width: 100%; }

/* =====================
   Cards
   ===================== */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: 0 2px 8px var(--shadow);
}

.card-surface {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 16px;
}

/* =====================
   Meal Grid (朝昼夜)
   ===================== */
.meal-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.meal-cell {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 12px 8px;
  text-align: center;
  border: 1.5px solid var(--border);
  transition: all var(--transition);
  cursor: pointer;
}

.meal-cell:hover {
  border-color: var(--amber);
  box-shadow: 0 2px 8px rgba(232,147,42,0.15);
}

.meal-cell.has-entry {
  border-color: var(--terra);
  background: #FEF3EC;
}

.meal-cell .meal-type {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.meal-cell .meal-name {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--brown);
  line-height: 1.3;
}

.meal-cell .meal-empty {
  font-size: 0.75rem;
  color: var(--border);
}

/* =====================
   Section Headers
   ===================== */
.section-header {
  padding: 20px 20px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--brown);
}

/* =====================
   Tags / Pills
   ===================== */
.tag {
  display: inline-block;
  background: var(--cream);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 99px;
  padding: 3px 10px;
  font-size: 0.72rem;
  font-weight: 500;
}

.tag-terra {
  background: #FEF3EC;
  border-color: var(--terra);
  color: var(--terra);
}

.tag-olive {
  background: #F0F3E8;
  border-color: var(--olive);
  color: var(--olive);
}

/* =====================
   Rating Stars
   ===================== */
.rating {
  display: flex;
  gap: 2px;
}
.rating .star {
  font-size: 1rem;
  color: var(--border);
  cursor: pointer;
  transition: color var(--transition);
}
.rating .star.active { color: var(--amber); }

/* =====================
   Form Elements
   ===================== */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
  letter-spacing: 0.04em;
}

.form-input {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 0.95rem;
  color: var(--brown);
  background: var(--white);
  transition: border-color var(--transition);
  outline: none;
}

.form-input:focus {
  border-color: var(--terra);
  box-shadow: 0 0 0 3px rgba(200,82,42,0.10);
}

.form-input::placeholder { color: var(--border); }

textarea.form-input { resize: vertical; min-height: 80px; }

/* =====================
   Meal Type Tabs
   ===================== */
.meal-tabs {
  display: flex;
  gap: 8px;
  padding: 16px 20px 0;
}

.meal-tab {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--white);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
  transition: all var(--transition);
}

.meal-tab.active {
  background: var(--terra);
  border-color: var(--terra);
  color: var(--white);
}

/* =====================
   Chat (AI Suggest)
   ===================== */
.chat-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
}

.chat-bubble {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  line-height: 1.6;
}

.chat-bubble.ai {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}

.chat-bubble.user {
  background: var(--terra);
  color: var(--white);
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}

.chat-input-area {
  position: sticky;
  bottom: 80px;
  background: var(--white);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.chat-input-area textarea {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.9rem;
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
}

.chat-input-area textarea:focus { border-color: var(--terra); }

.chat-send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--terra);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition);
}
.chat-send-btn:hover { background: #b8451f; }
.chat-send-btn:disabled { background: var(--border); }

/* =====================
   Calendar
   ===================== */
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  padding: 0 16px 16px;
}

.cal-day-label {
  text-align: center;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--muted);
  padding: 4px 0;
}

.cal-day {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--brown);
  position: relative;
  transition: all var(--transition);
}

.cal-day:hover { background: var(--cream); }

.cal-day.today {
  background: var(--terra);
  color: var(--white);
  font-weight: 700;
}

.cal-day.has-log::after {
  content: '';
  position: absolute;
  bottom: 3px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--amber);
}

.cal-day.today::after { background: var(--white); }

.cal-day.other-month { color: var(--border); }

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

.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 0.9rem;
  margin-bottom: 20px;
}

/* =====================
   Loading
   ===================== */
.loading-dots {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 8px 0;
}

.loading-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: dot-bounce 1.2s infinite;
}

.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-6px); opacity: 1; }
}

/* =====================
   Animations
   ===================== */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.fade-in { animation: fadeInUp 0.4s ease forwards; }

/* =====================
   Utilities
   ===================== */
.px-20 { padding-left: 20px; padding-right: 20px; }
.py-12 { padding-top: 12px; padding-bottom: 12px; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.text-muted { color: var(--muted); }
.text-sm { font-size: 0.85rem; }
.text-xs { font-size: 0.75rem; }
.font-bold { font-weight: 700; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.hidden { display: none !important; }
