:root {
  color-scheme: light;
  --bg: #f6f3ee;
  --card: #fffdf9;
  --ink: #22211f;
  --muted: #6f6a63;
  --line: #e6e0d6;
  --accent: #2f6f5e;
  --danger: #9a4a3c;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "PingFang TC", "Noto Sans TC", sans-serif;
  font-size: 18px;
  line-height: 1.45;
}

.page {
  max-width: 28rem;
  margin: 0 auto;
  padding: 1.25rem 1rem 2.5rem;
}

.page.is-readonly .card input,
.page.is-readonly .card textarea,
.page.is-readonly .card button,
.page.is-readonly .add-row button,
.page.is-readonly .day-tag select,
.page.is-readonly .day-tag input {
  pointer-events: none;
  opacity: 0.72;
}

.page.is-readonly .date-bar button,
.page.is-readonly .fold-toggle,
.page.is-readonly .export-btn,
.page.is-readonly .sync-bar button {
  pointer-events: auto;
  opacity: 1;
}

.sync-bar {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 1rem;
  padding: 0.85rem;
  margin-bottom: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.sync-meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.sync-status,
.sync-user {
  margin: 0;
  font-size: 0.9rem;
}

.sync-status {
  font-weight: 650;
}

.sync-user {
  color: var(--muted);
}

.sync-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.sync-actions input {
  flex: 1 1 8rem;
  min-width: 0;
  padding: 0.5rem 0.65rem;
  font-size: 0.95rem;
}

.sync-actions button,
.ghost-btn {
  border: 0;
  border-radius: 0.7rem;
  padding: 0.5rem 0.75rem;
  font: inherit;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
}

.ghost-btn {
  background: #ece7df;
  color: var(--ink);
}

.readonly-banner {
  margin: 0 0 0.85rem;
  padding: 0.65rem 0.8rem;
  border-radius: 0.7rem;
  background: #f3e6e2;
  color: var(--danger);
  font-size: 0.92rem;
}

.date-bar {
  display: grid;
  grid-template-columns: 2.75rem 1fr 2.75rem;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.date-bar button,
.add-row button,
.item button {
  border: 0;
  background: #ece7df;
  color: var(--ink);
  border-radius: 0.7rem;
  font: inherit;
  cursor: pointer;
}

.date-bar button {
  height: 2.75rem;
  font-size: 1.6rem;
}

.date-meta {
  text-align: center;
}

.date-label,
.date-hint,
.kcal-label,
.kcal-value,
h2 {
  margin: 0;
}

.date-label {
  font-size: 1.15rem;
  font-weight: 650;
}

.date-hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.kcal-card,
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 1rem;
  padding: 1rem;
  margin-bottom: 0.85rem;
}

.kcal-card {
  display: grid;
  grid-template-columns: 7.5rem 1fr 7.5rem;
  align-items: center;
  gap: 0.5rem;
}

.day-status {
  width: 1.85rem;
  height: 1.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  justify-self: start;
}

.day-status.filled {
  background: #e2f0ea;
  color: var(--accent);
}

.day-status.empty {
  background: #f3e6e2;
  color: var(--danger);
}

.kcal-block {
  text-align: center;
  justify-self: center;
}

.kcal-label {
  color: var(--muted);
  font-size: 0.9rem;
}

.kcal-value {
  font-size: 1.35rem;
  font-weight: 700;
}

.day-tag {
  justify-self: end;
  width: 100%;
  max-width: 7.5rem;
}

.day-tag select,
.day-tag input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  padding: 0.45rem 0.5rem;
  font: inherit;
  font-size: 0.9rem;
  background: #fff;
  color: var(--ink);
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) calc(50% - 2px),
    calc(100% - 9px) calc(50% - 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 1.5rem;
}

.day-tag input {
  background-image: none;
  padding-right: 0.5rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

h2 {
  font-size: 1rem;
  margin-bottom: 0.7rem;
}

textarea,
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  padding: 0.7rem 0.8rem;
  font: inherit;
  background: #fff;
  color: var(--ink);
}

textarea {
  resize: vertical;
  min-height: 7rem;
}

.list {
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0;
}

.item {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.55rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--line);
}

.item:last-child {
  border-bottom: 0;
}

.item label {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.item.done span {
  color: var(--muted);
  text-decoration: line-through;
}

.meal-name {
  flex: 1;
}

.meal-kcal {
  color: var(--muted);
  white-space: nowrap;
}

.item-actions {
  display: flex;
  flex-shrink: 0;
  gap: 0.15rem;
}

.item button {
  background: transparent;
  color: var(--danger);
  padding: 0.2rem 0.4rem;
  font-size: 0.85rem;
}

.item button.defer,
.item button.done-btn {
  color: var(--accent);
}

.goals-fold {
  margin-top: 0.9rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--line);
}

.fold-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #ece7df;
  color: var(--ink);
  border: 0;
  border-radius: 0.7rem;
  padding: 0.55rem 0.8rem;
  font: inherit;
  cursor: pointer;
}

.fold-hint {
  margin: 0.7rem 0 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
}

#goals-count {
  color: var(--muted);
  font-size: 0.9rem;
}

.add-row {
  display: flex;
  gap: 0.45rem;
}

.add-row button {
  padding: 0 0.9rem;
  background: var(--accent);
  color: #fff;
  white-space: nowrap;
}

.meal-row {
  display: grid;
  grid-template-columns: 1fr 5.5rem auto;
}

input[type="checkbox"] {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--accent);
}

.page-foot {
  margin-top: 0.5rem;
  padding: 0.85rem 0 0.25rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.65rem;
}

.export-btn {
  border: 1px solid var(--line);
  background: #ece7df;
  color: var(--ink);
  border-radius: 0.7rem;
  padding: 0.7rem 0.9rem;
  font: inherit;
  cursor: pointer;
}
