:root {
  color-scheme: light;
  --bg: #f6f3ec;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --ink: #25231f;
  --muted: #746f66;
  --line: #ded7c9;
  --green: #3fb26d;
  --green-soft: #dff4e8;
  --red: #e45c4f;
  --red-soft: #ffe5e0;
  --yellow: #f4b942;
  --blue: #5372df;
  --blue-soft: #e4e9ff;
  --pink: #f2769a;
  --shadow: 0 16px 44px rgba(51, 45, 34, .12);
  --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:
    radial-gradient(circle at 12% 0%, rgba(244, 185, 66, .2), transparent 26rem),
    linear-gradient(160deg, #f7f1e7 0%, #eef3f0 52%, #f8f2ef 100%);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 430px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 10px calc(88px + env(safe-area-inset-bottom));
}

.screen {
  min-height: calc(100vh - 32px);
}

.login-screen {
  display: grid;
  align-content: center;
  gap: 18px;
}

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

.brand-mark {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: var(--surface-strong);
  box-shadow: var(--shadow);
}

.pill-logo {
  width: 36px;
  height: 18px;
  border-radius: 999px;
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr 1fr;
  transform: rotate(-25deg);
  border: 2px solid var(--ink);
}

.pill-logo::before {
  content: "";
  background: var(--pink);
}

.pill-logo::after {
  content: "";
  background: var(--yellow);
}

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

h1 {
  font-size: 38px;
  line-height: 1.02;
  letter-spacing: 0;
}

h2 {
  font-size: 24px;
  line-height: 1.12;
}

h3 {
  font-size: 17px;
  line-height: 1.2;
}

.subtle {
  color: var(--muted);
  line-height: 1.45;
}

.panel {
  background: rgba(255, 253, 248, .9);
  border: 1px solid rgba(222, 215, 201, .8);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-card,
.form-card {
  padding: 16px;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 13px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(83, 114, 223, .16);
}

.check-field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  color: var(--ink);
}

.check-field input {
  width: 22px;
  min-height: 22px;
}

.button {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius);
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease;
}

.button:active {
  transform: scale(.97);
}

.button.secondary {
  color: var(--ink);
  background: var(--surface-strong);
  border: 1px solid var(--line);
}

.button.ghost {
  color: var(--ink);
  background: transparent;
  border: 1px solid transparent;
}

.button.danger {
  color: #fff;
  background: var(--red);
}

.icon-button {
  width: 44px;
  min-width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: var(--surface-strong);
  color: var(--ink);
  font-size: 20px;
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0 12px;
  backdrop-filter: blur(16px);
}

.title-stack {
  min-width: 0;
}

.title-stack p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 4px;
  margin: 2px 0 12px;
  background: rgba(255, 253, 248, .8);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.segment {
  height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.segment.active {
  color: var(--ink);
  background: var(--surface-strong);
  box-shadow: 0 4px 14px rgba(51, 45, 34, .08);
}

.calendar-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.calendar-range {
  min-width: 0;
  text-align: center;
  font-size: 14px;
  font-weight: 800;
}

.calendar-wrap {
  --med-column: 148px;
  --day-column: minmax(0, 1fr);
  overflow-x: hidden;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, .88);
  box-shadow: var(--shadow);
}

.calendar-wrap.wide-range {
  --med-column: 148px;
  --day-column: 34px;
  overflow-x: auto;
}

.calendar-grid {
  display: grid;
  min-width: 100%;
}

.calendar-cell {
  min-height: 48px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .58);
}

.calendar-group-row {
  min-height: 28px;
  display: flex;
  align-items: center;
  padding: 0 8px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.calendar-group-row span {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  border-radius: 999px;
  padding: 0 9px;
  background: rgba(255, 255, 255, .72);
}

.calendar-group-row.morning {
  background: #fff4d8;
}

.calendar-group-row.day {
  background: #e5f4ef;
}

.calendar-group-row.evening {
  background: #ece8ff;
}

.date-head {
  min-height: 48px;
  display: grid;
  place-items: center;
  gap: 2px;
  padding: 7px 4px;
  background: #fbf7ee;
  position: sticky;
  top: 0;
  z-index: 2;
}

.date-head.today {
  background: var(--blue-soft);
}

.date-day {
  font-size: 9px;
  color: var(--muted);
  text-transform: uppercase;
  font-weight: 800;
}

.date-num {
  width: 24px;
  height: 24px;
  font-size: 14px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-weight: 900;
}

.today .date-num {
  color: #fff;
  background: var(--blue);
}

.med-head {
  position: sticky;
  left: 0;
  z-index: 3;
  display: grid;
  align-content: center;
  gap: 0;
  padding: 7px 8px;
  background: var(--surface-strong);
}

.med-name {
  min-width: 0;
  overflow-wrap: anywhere;
  white-space: normal;
  font-size: 12px;
  line-height: 1.16;
  font-weight: 900;
}

.med-time {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.2;
}

.take-cell {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 48px;
  border: 0;
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  overflow: hidden;
  transition: background .22s ease, color .22s ease;
}

.take-cell:disabled {
  cursor: not-allowed;
}

.take-cell.inactive {
  background: repeating-linear-gradient(
    -45deg,
    rgba(222, 215, 201, .22),
    rgba(222, 215, 201, .22) 8px,
    rgba(255, 255, 255, .22) 8px,
    rgba(255, 255, 255, .22) 16px
  );
}

.take-cell.missed {
  background: var(--red-soft);
  color: var(--red);
}

.take-cell.taken {
  background: var(--green-soft);
  color: var(--green);
}

.take-cell.just-taken {
  animation: cellGlow .58s ease both;
}

.check-mark {
  width: 22px;
  height: 22px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 13px;
  transform: scale(.9);
}

.taken .check-mark {
  color: #fff;
  border-color: var(--green);
  background: var(--green);
}

.just-taken .check-mark {
  animation: popIn .24s ease both;
}

.missed .check-mark {
  border-color: var(--red);
}

.pill-burst {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.mini-pill {
  --x: 0px;
  --y: 0px;
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 9px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--pink) 0 50%, #fff 50% 100%);
  border: 1px solid rgba(37, 35, 31, .18);
  transform: translate(-50%, -50%) rotate(var(--rot));
  animation: pillFly .78s ease-out forwards;
}

.empty-state {
  display: grid;
  gap: 14px;
  justify-items: start;
  padding: 20px;
  margin-top: 12px;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 18;
  width: min(calc(100% - 20px), 410px);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 0;
  padding: 6px;
  background: rgba(255, 253, 248, .9);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  transform: translateX(-50%);
}

.nav-item {
  height: 46px;
  border: 0;
  border-radius: 6px;
  display: grid;
  place-items: center;
  gap: 2px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.nav-item span:first-child {
  font-size: 18px;
}

.nav-item.active {
  background: var(--blue-soft);
  color: var(--blue);
}

.med-list,
.settings-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

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

.med-card,
.achievement-card,
.settings-card {
  padding: 13px;
}

.med-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.badge {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 9px;
  background: var(--blue-soft);
  color: #344eb2;
  font-size: 12px;
  font-weight: 800;
}

.badge.green {
  background: var(--green-soft);
  color: #247346;
}

.badge.red {
  background: var(--red-soft);
  color: #ab3328;
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.time-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.time-choice {
  min-height: 42px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.time-choice input {
  width: 20px;
  min-height: 20px;
}

.toast-stack {
  position: fixed;
  left: 50%;
  bottom: calc(74px + env(safe-area-inset-bottom));
  z-index: 99;
  width: min(calc(100% - 28px), 492px);
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
}

.toast {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface-strong);
  box-shadow: var(--shadow);
  animation: toastIn .22s ease both;
}

.toast-icon,
.achievement-icon {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--yellow);
  font-size: 20px;
}

.achievement-card {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
  align-content: start;
  min-height: 164px;
  opacity: .62;
}

.achievement-card.unlocked {
  opacity: 1;
  background: var(--surface-strong);
}

.achievement-card.unlocked .achievement-icon {
  background: var(--green-soft);
}

.achievement-card:not(.unlocked) {
  filter: saturate(.65);
}

.achievement-card:not(.unlocked) .achievement-icon {
  background: #e8e3d8;
  color: var(--muted);
}

.achievement-card h3 {
  font-size: 15px;
}

.achievement-card .subtle {
  font-size: 12px;
}

.error {
  min-height: 20px;
  color: var(--red);
  font-size: 13px;
  font-weight: 800;
}

.hidden {
  display: none !important;
}

@keyframes cellGlow {
  0% {
    background: #fff;
  }
  45% {
    background: #c3f1d4;
  }
  100% {
    background: var(--green-soft);
  }
}

@keyframes popIn {
  from {
    transform: scale(.5);
  }
  to {
    transform: scale(1);
  }
}

@keyframes pillFly {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(var(--rot)) scale(.8);
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) rotate(calc(var(--rot) + 140deg)) scale(1.08);
  }
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (min-width: 700px) {
  .app-shell {
    padding-top: 26px;
    padding-bottom: 26px;
  }

  .screen {
    min-height: calc(100vh - 52px);
  }
}
