:root {
  --bg: #f5f2ea;
  --panel: #fffdf8;
  --text: #23211e;
  --muted: #65615b;
  --accent: #1f7a62;
  --accent-soft: #d5eee7;
  --danger: #a51d2d;
  --border: #dad1c2;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 20% 10%, #fff9e5, transparent 35%),
    radial-gradient(circle at 90% 80%, #ebfff4, transparent 30%),
    var(--bg);
}

.app {
  width: min(980px, 94vw);
  margin: 2rem auto 3rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-family: "Iowan Old Style", Georgia, serif;
  letter-spacing: 0.03em;
}

#monthLabel {
  color: var(--muted);
  margin-top: 0.35rem;
}

.topbar-actions,
.month-controls,
.settings-actions {
  display: flex;
  gap: 0.6rem;
}

button {
  border: 0;
  border-radius: 0.7rem;
  background: var(--accent);
  color: #fff;
  padding: 0.6rem 1rem;
  font-weight: 600;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.04);
}

button.ghost {
  background: var(--accent-soft);
  color: var(--text);
}

.month-controls {
  margin: 1.2rem 0 0.7rem;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.65rem;
}

.day-cell {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  min-height: 118px;
  padding: 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  cursor: pointer;
  transition: transform 120ms ease;
}

.day-cell:hover {
  transform: translateY(-1px);
}

.day-cell.empty {
  opacity: 0.3;
  pointer-events: none;
}

.day-number {
  font-weight: 700;
}

.mini-macro {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.2;
}

.met-target {
  color: var(--accent);
  font-weight: 700;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0.95rem;
  padding: 1rem;
}

.entry-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.7rem;
}

label {
  display: block;
  margin-bottom: 0.4rem;
}

textarea,
input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  font: inherit;
  padding: 0.6rem 0.7rem;
  background: #fff;
}

textarea {
  min-height: 170px;
  resize: vertical;
}

#calculateBtn {
  margin-top: 0.8rem;
}

.entry-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.8rem;
}

.entry-meta-grid {
  margin-top: 0.8rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.switch-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.6rem 0.7rem;
  background: #fff;
}

.switch-label input {
  width: auto;
  margin: 0;
}

.macro-bars {
  margin-top: 1rem;
  display: grid;
  gap: 0.75rem;
}

.macro-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.3rem;
  font-weight: 700;
}

.overage {
  color: var(--danger);
  font-size: 0.85rem;
}

.progress-track {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 999px;
  height: 34px;
  background: #f3eee3;
  overflow: hidden;
}

.progress-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: linear-gradient(90deg, #2f9c7f, #1f7a62);
  transition: width 160ms ease;
}

.progress-fill.over {
  background: repeating-linear-gradient(
    -45deg,
    #c23c3c,
    #c23c3c 8px,
    #a51d2d 8px,
    #a51d2d 16px
  );
}

.progress-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.9rem;
}

.status {
  min-height: 1.2rem;
  margin-top: 0.5rem;
  color: var(--muted);
}

.status.error {
  color: var(--danger);
}

.hidden {
  display: none;
}

dialog {
  border: none;
  background: transparent;
}

.settings-form {
  width: min(400px, 92vw);
  display: grid;
  gap: 0.8rem;
}

@media (max-width: 760px) {
  .topbar {
    flex-direction: column;
  }

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

  .entry-actions,
  .entry-meta-grid {
    grid-template-columns: 1fr;
    display: grid;
  }
}
