:root {
  color-scheme: light;
  --ink: #111318;
  --muted: #69707c;
  --paper: #fbfaf7;
  --panel: #ffffff;
  --line: #e7e1d8;
  --green: #1f9f62;
  --green-soft: #dbf7e5;
  --orange: #f15a3b;
  --amber: #ffb33f;
  --blue: #3c6df0;
  --shadow: 0 24px 70px rgba(17, 19, 24, 0.14);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #dfe7df;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(31, 159, 98, 0.18), transparent 28%),
    linear-gradient(315deg, rgba(60, 109, 240, 0.16), transparent 32%),
    var(--paper);
}

body.modal-open {
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  display: flex;
  flex-direction: column;
  width: min(100vw, 460px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  background: rgba(251, 250, 247, 0.86);
  box-shadow: var(--shadow);
}

.topbar,
.panel-title-row,
.calorie-form,
.key-actions,
.brand-lockup,
.top-actions,
.week-title,
.week-nav,
.summary-band,
.today-pill {
  display: flex;
  align-items: center;
}

.topbar,
.panel-title-row,
.summary-band {
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 18px;
}

.brand-lockup {
  gap: 12px;
  min-width: 0;
}

.logo {
  width: 54px;
  height: 54px;
  border-radius: 14px;
  box-shadow: 0 12px 22px rgba(17, 19, 24, 0.16);
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 2rem;
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
  letter-spacing: 0;
}

.icon-button {
  display: inline-grid;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  place-items: center;
  border: 0;
  border-radius: 999px;
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 10px 22px rgba(17, 19, 24, 0.1);
}

.icon-button.ghost {
  width: 38px;
  height: 38px;
  flex-basis: 38px;
  background: #f2f0ec;
  box-shadow: none;
}

.mini-icon-button {
  display: inline-grid;
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  place-items: center;
  border: 0;
  border-radius: 999px;
  color: var(--ink);
  background: #f2f0ec;
}

.icon-button svg,
.mini-icon-button svg,
.primary-button svg,
.danger-action-button svg {
  width: 19px;
  height: 19px;
  stroke-width: 2.4;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.week-title {
  min-width: 0;
  gap: 8px;
}

.week-nav {
  gap: 4px;
}

.summary-band {
  align-items: flex-start;
  margin-bottom: 12px;
  padding: 20px;
  border-radius: var(--radius);
  color: #fff;
  background: linear-gradient(135deg, #111318, #26332d);
}

.week-total {
  margin: 0;
  font-size: clamp(2.15rem, 14vw, 4.1rem);
  font-weight: 850;
  line-height: 0.96;
  letter-spacing: 0;
}

.week-total span:last-child {
  display: block;
  margin-top: 4px;
  color: #cae8d6;
  font-size: 0.9rem;
  font-weight: 800;
}

.goal-delta {
  display: inline-flex;
  max-width: 100%;
  min-height: 30px;
  align-items: center;
  margin: 12px 0 0;
  padding: 6px 10px;
  border-radius: 999px;
  color: #cae8d6;
  background: rgba(255, 255, 255, 0.1);
  font-size: 0.84rem;
  font-weight: 850;
  line-height: 1.25;
}

.goal-delta.is-under {
  color: #56f09c;
}

.goal-delta.is-over {
  color: #ff725d;
}

.today-pill {
  min-width: 94px;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 14px 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.1);
}

.today-pill span {
  color: #cae8d6;
  font-size: 0.78rem;
  font-weight: 700;
}

.today-pill strong {
  font-size: 1.6rem;
}

.chart-panel,
.entry-panel {
  margin-top: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.86);
}

.panel-title-row span {
  min-width: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-align: right;
}

.chart-panel .panel-title-row span {
  font-size: 0.78rem;
  white-space: nowrap;
}

.chart-wrap {
  height: 230px;
  margin-top: 12px;
}

.calorie-form {
  align-items: start;
  gap: 10px;
  margin-top: 14px;
}

.calorie-input,
.key-form label {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.calorie-input {
  flex: 1;
}

.calorie-input span,
.key-form span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.calorie-input input,
.key-form input {
  width: 100%;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 14px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

.calorie-input input {
  font-size: 1.35rem;
  font-weight: 800;
}

.calorie-input input:focus,
.key-form input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 4px var(--green-soft);
}

.primary-button,
.secondary-button,
.text-button,
.quick-row button {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius);
  font-weight: 800;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 98px;
  min-height: 54px;
  margin-top: 25px;
  padding: 0 16px;
  color: #fff;
  background: var(--green);
}

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

.quick-row button {
  color: var(--ink);
  background: #f2f0ec;
}

.key-form {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  align-items: end;
  justify-items: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 19, 24, 0.48);
}

.modal-panel {
  position: relative;
  z-index: 1;
  width: min(100%, 428px);
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.modal-panel .key-form {
  border-top: 0;
  padding-top: 12px;
}

.setup-link {
  color: var(--green);
  font-size: 0.86rem;
  font-weight: 800;
  text-decoration: none;
}

.key-actions {
  gap: 8px;
}

.secondary-button {
  padding: 0 16px;
  color: #fff;
  background: var(--ink);
}

.text-button {
  padding: 0 12px;
  color: var(--muted);
  background: transparent;
}

.danger-zone {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.danger-action-button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: var(--radius);
  padding: 0 14px;
  color: #b42318;
  background: #fff0ed;
  font-weight: 850;
}

.app-footer {
  margin-top: auto;
  padding-top: 12px;
}

.status-message {
  display: flex;
  min-height: 22px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin: 0 2px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  text-align: center;
}

.status-message.is-syncing::before {
  width: 13px;
  height: 13px;
  border: 2px solid #c6ccd3;
  border-top-color: var(--green);
  border-radius: 999px;
  content: "";
  animation: status-spin 0.7s linear infinite;
}

.status-message.is-error {
  color: #b42318;
}

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

@media (min-width: 760px) {
  body {
    padding: 24px 0;
  }

  .app {
    min-height: calc(100vh - 48px);
    border-radius: 28px;
  }
}

@media (max-width: 360px) {
  .calorie-form {
    align-items: stretch;
    flex-direction: column;
  }

  .primary-button {
    margin-top: 0;
    width: 100%;
  }

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

@media (max-width: 430px) {
  .app {
    padding-left: 12px;
    padding-right: 12px;
  }

  .topbar {
    gap: 6px;
  }

  .brand-lockup {
    gap: 8px;
  }

  .logo {
    width: 44px;
    height: 44px;
  }

  h1 {
    font-size: 1.42rem;
  }

  .top-actions {
    gap: 4px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
    flex-basis: 36px;
  }

  .refresh-button {
    display: none;
  }

  .icon-button svg,
  .mini-icon-button svg,
  .primary-button svg,
  .danger-action-button svg {
    width: 17px;
    height: 17px;
  }

  .summary-band {
    gap: 10px;
    padding: 16px;
  }

  .today-pill {
    min-width: 80px;
    padding: 12px 9px;
  }

  .today-pill strong {
    font-size: 1.35rem;
  }
}
