:root {
  --blush: #f3d5d0;
  --mist: #e8e4df;
  --stone: #6f675f;
  --ink: #2c2622;
  --berry: #b03d4f;
  --berry-deep: #8a2f3d;
  --berry-soft: rgba(176, 61, 79, 0.18);
  --predict: rgba(176, 61, 79, 0.1);
  --predict-border: rgba(176, 61, 79, 0.45);
  --glass: rgba(255, 250, 247, 0.72);
  --line: rgba(44, 38, 34, 0.08);
  --shadow: 0 18px 50px rgba(80, 40, 45, 0.12);
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-synthesis: none;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: "Figtree", sans-serif;
  background: #f6ebe6;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  min-height: 100svh;
  overflow-x: hidden;
  overscroll-behavior: none;
}

/* Installed home-screen app */
@media (display-mode: standalone) {
  body {
    user-select: none;
    -webkit-user-select: none;
  }

  #pin-input {
    user-select: text;
    -webkit-user-select: text;
  }
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(120% 80% at 10% -10%, #f8cfc8 0%, transparent 55%),
    radial-gradient(90% 70% at 100% 0%, #dfe8e4 0%, transparent 50%),
    linear-gradient(165deg, #f7e7e2 0%, #efe6df 48%, #e4ebe8 100%);
  animation: drift 18s ease-in-out infinite alternate;
}

@keyframes drift {
  from {
    transform: scale(1) translateY(0);
  }
  to {
    transform: scale(1.04) translateY(-1.5%);
  }
}

#app {
  width: min(440px, 100%);
  margin: 0 auto;
  padding: calc(28px + var(--safe-top)) 20px calc(28px + var(--safe-bottom));
}

.screen {
  animation: rise 0.45s ease both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.brand {
  margin: 0 0 0.35rem;
  font-family: "Fraunces", serif;
  font-weight: 700;
  font-size: clamp(2.6rem, 9vw, 3.4rem);
  letter-spacing: -0.03em;
  line-height: 0.95;
  color: var(--berry-deep);
}

.brand.small {
  font-size: 1.35rem;
  margin-bottom: 0.2rem;
}

.gate {
  min-height: calc(100dvh - 56px - var(--safe-top) - var(--safe-bottom));
  min-height: calc(100svh - 56px - var(--safe-top) - var(--safe-bottom));
  display: grid;
  place-items: center;
}

.gate-inner {
  width: 100%;
  text-align: center;
}

.mark {
  width: 4.5rem;
  height: 4.5rem;
  margin: 0 auto 1.1rem;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, #c45c6a 0%, transparent 42%),
    radial-gradient(circle at 70% 68%, rgba(255, 250, 247, 0.55) 0 18%, transparent 19%),
    #b03d4f;
  box-shadow: 0 14px 36px rgba(138, 47, 61, 0.22);
  animation: settle 0.55s ease both;
}

.gate h1 {
  margin: 0.4rem 0 0.35rem;
  font-family: "Fraunces", serif;
  font-weight: 600;
  font-size: 1.55rem;
}

.subtitle,
.status,
.hint,
.sheet-range {
  margin: 0;
  color: var(--stone);
  line-height: 1.45;
}

.pin-form {
  margin-top: 1.75rem;
  display: grid;
  gap: 0.85rem;
}

#pin-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem 1.1rem;
  font-size: 1.45rem;
  letter-spacing: 0.35em;
  text-align: center;
  background: var(--glass);
  color: var(--ink);
  backdrop-filter: blur(10px);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#pin-input:focus {
  border-color: rgba(176, 61, 79, 0.45);
  box-shadow: 0 0 0 4px var(--berry-soft);
}

.error {
  color: var(--berry);
  font-size: 0.92rem;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease, opacity 0.2s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn.primary {
  background: var(--berry);
  color: #fffaf7;
  padding: 0.95rem 1.4rem;
}

.btn.primary:hover {
  background: var(--berry-deep);
}

.btn.ghost {
  background: transparent;
  color: var(--stone);
  padding: 0.45rem 0.7rem;
  font-weight: 500;
}

.btn.icon {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: var(--glass);
  color: var(--ink);
  font-size: 1.4rem;
  line-height: 1;
  border: 1px solid var(--line);
}

.btn.danger {
  background: transparent;
  color: var(--berry);
  border: 1px solid rgba(176, 61, 79, 0.25);
  padding: 0.85rem 1.2rem;
}

.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.4rem;
}

.status {
  font-size: 0.98rem;
  max-width: 16rem;
}

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.85rem;
}

.month-label {
  margin: 0;
  font-family: "Fraunces", serif;
  font-weight: 600;
  font-size: 1.45rem;
  letter-spacing: -0.02em;
}

.weekday-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.25rem;
  margin-bottom: 0.35rem;
  color: var(--stone);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: center;
}

.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.3rem;
  min-height: 18.5rem;
}

.day {
  aspect-ratio: 1;
  border: none;
  border-radius: 16px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  font-size: 0.95rem;
  position: relative;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease, color 0.2s ease;
}

.day:disabled {
  opacity: 0;
  pointer-events: none;
}

.day:not(:disabled):hover {
  background: rgba(255, 255, 255, 0.45);
}

.day.today::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 6px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--stone);
  transform: translateX(-50%);
}

.day.logged {
  background: var(--berry);
  color: #fffaf7;
  animation: settle 0.35s ease both;
}

.day.logged.today::after {
  background: #fffaf7;
}

.day.predicted {
  background: var(--predict);
  color: var(--berry-deep);
  box-shadow: inset 0 0 0 1.5px var(--predict-border);
  animation: softIn 0.5s ease both;
}

.day.selecting,
.day.in-range {
  background: var(--berry-soft);
  color: var(--berry-deep);
  animation: pulse 0.35s ease;
}

.day.range-edge {
  background: var(--berry);
  color: #fffaf7;
}

@keyframes settle {
  from {
    transform: scale(0.92);
    opacity: 0.6;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

@keyframes softIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes pulse {
  from {
    transform: scale(0.94);
  }
  to {
    transform: none;
  }
}

.hint {
  margin-top: 1.1rem;
  font-size: 0.92rem;
  text-align: center;
  min-height: 1.35em;
}

.legend {
  margin-top: 1.25rem;
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  color: var(--stone);
  font-size: 0.82rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.swatch {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  display: inline-block;
}

.swatch.logged {
  background: var(--berry);
}

.swatch.predicted {
  background: var(--predict);
  box-shadow: inset 0 0 0 1.5px var(--predict-border);
}

.swatch.today {
  background: var(--stone);
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(44, 38, 34, 0.28);
  backdrop-filter: blur(2px);
  animation: fade 0.2s ease;
}

.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  width: min(440px, 100%);
  transform: translateX(-50%);
  background: #fffaf7;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 0.7rem 1.35rem calc(1.35rem + var(--safe-bottom));
  box-shadow: var(--shadow);
  animation: slideUp 0.28s ease;
}

.sheet-handle {
  width: 2.4rem;
  height: 0.28rem;
  border-radius: 999px;
  background: rgba(44, 38, 34, 0.14);
  margin: 0.15rem auto 1rem;
}

@keyframes fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    transform: translate(-50%, 20%);
  }
  to {
    transform: translate(-50%, 0);
  }
}

.sheet h3 {
  margin: 0 0 0.35rem;
  font-family: "Fraunces", serif;
  font-size: 1.35rem;
}

.sheet-actions {
  margin-top: 1.25rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
}

[hidden] {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
