:root {
  color-scheme: light;
  --bg: #f4ecd5;
  --ink: #101010;
  --muted: #46423a;
  --panel: #ffffff;
  --soft: #ffe165;
  --line: #101010;
  --accent: #d54136;
  --accent-2: #59b8d7;
  --accent-ink: #ffffff;
  --warn: #a15c23;
  --shadow: 5px 5px 0 #101010;
  --border: 3px solid var(--line);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 18px 18px, rgba(16, 16, 16, 0.04) 0 2px, transparent 3px),
    var(--bg);
  background-size: 34px 34px;
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
  white-space: normal;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.shell {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 12px 12px 30px;
}

.topbar,
.section-head,
.day-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar {
  margin-bottom: 10px;
}

.comic-title {
  border: var(--border);
  border-radius: 8px;
  background: var(--panel);
  padding: 10px 12px;
  box-shadow: var(--shadow);
}

.comic-title > div {
  min-width: 0;
}

.comic-title h1 {
  font-size: 26px;
  overflow-wrap: anywhere;
}

.eyebrow,
.card-kicker {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
  letter-spacing: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
  line-height: 1.04;
}

h2 {
  margin-bottom: 0;
  font-size: 22px;
  line-height: 1.08;
}

h3 {
  margin-bottom: 8px;
  font-size: 16px;
}

.hero,
.panel,
.meal-card,
.day-card,
.empty-card,
.info-card {
  border: var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 118px;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
  padding: 14px;
}

.comic-hero {
  position: relative;
  overflow: hidden;
}

.comic-hero::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 14px;
  width: 66px;
  height: 66px;
  border-radius: 50%;
  background: var(--soft);
}

.hero-copy,
.peter-panel,
.hero .primary {
  position: relative;
  z-index: 1;
}

.hero h2 {
  margin: 4px 0 6px;
  font-size: 23px;
  line-height: 1.15;
}

.hero p,
.muted {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.4;
}

.hero .primary {
  grid-column: 1 / -1;
}

.peter-panel {
  display: grid;
  min-height: 126px;
  place-items: center;
  border: var(--border);
  border-radius: 8px;
  background:
    radial-gradient(circle at 18% 16%, rgba(255, 225, 101, 0.92) 0 18%, transparent 19%),
    linear-gradient(180deg, #75cde6 0%, var(--accent-2) 100%);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.peter-face-svg {
  width: 114px;
  max-width: 100%;
  height: auto;
  overflow: visible;
}

.peter-face-svg * {
  vector-effect: non-scaling-stroke;
}

.peter-face-svg .svg-head,
.peter-face-svg .svg-ear,
.peter-face-svg .svg-neck,
.peter-face-svg .svg-nose {
  fill: #f4b39d;
  stroke: var(--line);
  stroke-linejoin: round;
  stroke-width: 5;
}

.peter-face-svg .svg-shirt {
  fill: #fffaf2;
  stroke: var(--line);
  stroke-linejoin: round;
  stroke-width: 5;
}

.peter-face-svg .svg-hair {
  fill: #744531;
  stroke: var(--line);
  stroke-linejoin: round;
  stroke-width: 5;
}

.peter-face-svg .svg-band {
  fill: #f35f55;
  stroke: var(--line);
  stroke-width: 5;
}

.peter-face-svg .svg-eye {
  fill: #ffffff;
  stroke: var(--line);
  stroke-width: 5;
}

.peter-face-svg .svg-pupil {
  fill: var(--line);
}

.peter-face-svg .svg-smile,
.peter-face-svg .svg-chin {
  fill: none;
  stroke: var(--line);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 5;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  border: 0;
  background: var(--soft);
  color: var(--accent);
  padding: 0 10px;
  font-size: 12px;
  font-weight: 900;
}

.icon-button,
button,
select {
  min-height: 40px;
  border: var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 0 12px;
  box-shadow: 3px 3px 0 var(--line);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  flex: 0 0 42px;
  width: 42px;
  padding: 0;
  font-size: 22px;
}

.refresh-icon {
  display: block;
  line-height: 1;
}

.icon-button.is-loading .refresh-icon {
  animation: refresh-spin 0.75s linear infinite;
}

.icon-button.is-done {
  background: var(--soft);
}

@keyframes refresh-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .icon-button.is-loading .refresh-icon {
    animation: none;
  }
}

.primary {
  border: var(--border);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 900;
}

.ghost {
  background: #ffffff;
  color: var(--ink);
  font-weight: 800;
}

.wide {
  width: 100%;
  margin-top: 8px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.metrics article {
  min-height: 74px;
  border: var(--border);
  border-radius: 8px;
  background: var(--soft);
  padding: 10px;
  box-shadow: var(--shadow);
}

.metrics span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.metrics strong {
  font-size: 24px;
  line-height: 1.1;
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin: 8px -2px 12px;
  padding: 8px 2px;
  background: rgba(244, 236, 213, 0.94);
  backdrop-filter: blur(10px);
}

.tab {
  min-height: 38px;
  padding: 0 6px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
}

.tab.active {
  border-color: var(--line);
  background: var(--soft);
  color: var(--ink);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.stack {
  display: grid;
  gap: 10px;
}

.panel,
.meal-card,
.day-card,
.empty-card,
.info-card {
  padding: 12px;
}

.meal-card {
  display: grid;
  gap: 10px;
}

.macro-line {
  border-radius: 8px;
  background: var(--soft);
  border: var(--border);
  padding: 8px 10px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chips span {
  border: 2px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  padding: 5px 8px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.quick-actions button {
  padding-inline: 6px;
  font-weight: 900;
}

.inline-status {
  min-height: 18px;
  margin: 8px 0 0;
  color: var(--accent);
  font-size: 13px;
  line-height: 1.35;
}

.info-card {
  background: var(--soft);
  color: var(--ink);
}

.info-card p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.4;
}

.action-banner {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  margin: 10px 0;
}

.action-banner[hidden] {
  display: none;
}

.day-card ol {
  margin: 10px 0 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.45;
}

.day-head span {
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
  text-align: right;
}

.meal-title {
  margin-bottom: 0;
  font-weight: 800;
}

.shopping-items,
.fact-list {
  display: grid;
  gap: 8px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.shopping-items li,
.fact-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-top: 2px solid rgba(16, 16, 16, 0.16);
  padding-top: 8px;
}

.shopping-items strong,
.fact-list small {
  white-space: nowrap;
  color: var(--muted);
}

.fact-list span strong,
.fact-list span em {
  display: block;
}

.fact-list span strong {
  font-weight: 900;
}

.fact-list span em {
  margin-top: 2px;
  color: var(--muted);
  font-style: normal;
  line-height: 1.3;
}

.profile-grid {
  display: grid;
  grid-template-columns: minmax(86px, auto) 1fr;
  gap: 8px 12px;
  margin: 12px 0 16px;
}

.memory-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.memory-grid article {
  min-height: 74px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff8cf;
  padding: 10px;
}

.memory-grid span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.memory-grid strong {
  display: block;
  white-space: pre-line;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.3;
}

.profile-grid span {
  color: var(--muted);
}

.profile-grid strong {
  font-weight: 700;
}

pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 42vh;
  overflow: auto;
  margin: 10px 0 0;
  padding: 10px;
  border-radius: 8px;
  border: 2px solid var(--line);
  background: #fff8cf;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
}

textarea {
  width: 100%;
  resize: vertical;
  border: var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-top: 8px;
  color: var(--ink);
  background: #fff;
}

input {
  width: 100%;
  min-height: 40px;
  border: var(--border);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: #fff;
}

.profile-form {
  display: grid;
  gap: 10px;
  margin: 14px 0 18px;
  border-top: 2px solid rgba(16, 16, 16, 0.18);
  padding-top: 14px;
}

.profile-form label {
  display: grid;
  gap: 6px;
}

.profile-form label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.feedback-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 8px;
}

.status {
  min-height: 20px;
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.4;
}

.status.error {
  color: #9a2f2f;
}

.status.ok {
  color: var(--accent);
}

@media (max-width: 520px) {
  .shell {
    padding-inline: 10px;
  }

  .hero {
    grid-template-columns: minmax(0, 1fr) 104px;
  }

  .hero .primary {
    width: 100%;
  }

  .peter-panel {
    min-height: 112px;
  }

  .peter-face-svg {
    width: 100px;
  }

  .metrics strong {
    font-size: 22px;
  }

  .tab {
    font-size: 12px;
  }

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

  .form-grid,
  .memory-grid,
  .action-banner {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 360px) {
  .hero {
    grid-template-columns: 1fr;
  }

  .peter-panel {
    min-height: 120px;
  }
}
