/* Family Calendar — "sunny kitchen" light theme.
   Palette: warm paper + deep-plum ink + marigold signature + sky accent. */

:root {
  --paper:   #FCF9F4;
  --surface: #FFFFFF;
  --ink:     #33304A;
  --ink-2:   #5A5670;
  --muted:   #8A879B;
  --line:    #ECE6DC;
  --line-2:  #E2DCD0;
  --primary: #F4A52E;   /* marigold */
  --primary-d: #E08C12;
  --sky:     #2E7FB8;
  --sky-soft:#E6F0F8;
  --good:    #2E9E6B;
  --good-soft:#E4F4EC;
  --warn:    #C9772A;
  --warn-soft:#FBEFE0;
  --bad:     #C0492F;
  --bad-soft:#FBE9E4;

  --r-lg: 22px;
  --r-md: 16px;
  --r-sm: 11px;
  --shadow-1: 0 1px 2px rgba(51,48,74,.06), 0 2px 8px rgba(51,48,74,.06);
  --shadow-2: 0 6px 22px rgba(51,48,74,.14);
  --shadow-key: 0 2px 0 var(--line-2), 0 4px 10px rgba(51,48,74,.10);

  --display: "Fredoka", "Trebuchet MS", system-ui, sans-serif;
  --body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--body);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
  overscroll-behavior-y: none;
}

button { font-family: inherit; color: inherit; cursor: pointer; border: none; background: none; }
:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; border-radius: 6px; }

/* ============================ LOCK SCREEN ============================ */

.lock {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(var(--safe-top) + 1.25rem) 1.25rem calc(var(--safe-bot) + 1.25rem);
  background:
    radial-gradient(120% 80% at 50% -10%, #FFE6B8 0%, rgba(255,230,184,0) 60%),
    radial-gradient(90% 60% at 110% 110%, #FBD9E0 0%, rgba(251,217,224,0) 55%),
    var(--paper);
}

.lock__card {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.lock__sun {
  width: 64px; height: 64px;
  margin: 0 auto 1rem;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, #FFD36B, var(--primary) 70%);
  box-shadow: 0 0 0 10px rgba(244,165,46,.16), 0 10px 24px rgba(244,165,46,.35);
}

.lock__title {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.9rem;
  letter-spacing: -.01em;
}

.lock__prompt { color: var(--ink-2); margin-top: .25rem; }
.lock__prompt.is-error { color: var(--bad); font-weight: 600; }

.dots {
  display: flex; gap: 12px; justify-content: center;
  height: 16px; margin: 1.4rem 0 1.6rem;
}
.dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--line-2);
  transition: transform .12s ease, background .12s ease;
}
.dot.is-on { background: var(--primary); transform: scale(1.15); }

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  max-width: 300px;
  margin: 0 auto;
}
.key {
  font-family: var(--display);
  font-weight: 500;
  font-size: 1.7rem;
  aspect-ratio: 1 / 1;
  background: var(--surface);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-key);
  color: var(--ink);
  transition: transform .07s ease, box-shadow .07s ease, background .1s ease;
  user-select: none;
}
.key:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line-2); }
.key--ghost { background: transparent; box-shadow: none; color: var(--muted); font-size: 1.4rem; }
.key--ghost:active { background: rgba(51,48,74,.05); }
.key--go { background: var(--primary); color: #fff; box-shadow: 0 2px 0 var(--primary-d), 0 6px 14px rgba(244,165,46,.4); }
.key--go:active { box-shadow: 0 1px 0 var(--primary-d); }

.lock__hint { margin-top: 1.6rem; color: var(--muted); font-size: .82rem; }

.shake { animation: shake .4s; }
@keyframes shake {
  10%,90% { transform: translateX(-2px); }
  30%,70% { transform: translateX(5px); }
  50% { transform: translateX(-7px); }
}

/* ============================ APP SHELL ============================ */

.shell { min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .25rem;
  padding: calc(var(--safe-top) + .5rem) .6rem .5rem;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: saturate(1.2) blur(8px);
  border-bottom: 1px solid var(--line);
}

.iconbtn {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border-radius: 12px;
  font-size: 1.5rem; color: var(--ink);
  transition: background .12s ease;
}
.iconbtn:active { background: rgba(51,48,74,.07); }
.iconbtn--sm { width: 34px; height: 34px; font-size: 1.6rem; color: var(--ink-2); }
.iconbtn--add { background: var(--primary); color: #fff; box-shadow: var(--shadow-1); font-size: 1.4rem; }
.iconbtn--add:active { background: var(--primary-d); }

.burger, .burger::before, .burger::after {
  display: block; width: 20px; height: 2.4px; border-radius: 2px; background: var(--ink);
  content: ""; position: relative;
}
.burger::before { position: absolute; top: -6px; }
.burger::after  { position: absolute; top: 6px; }

.period { flex: 1; display: flex; align-items: center; justify-content: center; gap: .15rem; min-width: 0; }
.period__label {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.18rem;
  padding: .2rem .5rem;
  border-radius: 10px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 62vw;
}
.period__label:active { background: rgba(51,48,74,.06); }

.segmented {
  display: flex; gap: 4px;
  margin: .6rem auto 0;
  padding: 4px;
  background: var(--line);
  border-radius: 999px;
  width: calc(100% - 1.2rem); max-width: 360px;
}
.seg {
  flex: 1; padding: .5rem 0;
  border-radius: 999px;
  font-weight: 600; font-size: .92rem; color: var(--ink-2);
  transition: background .15s ease, color .15s ease, box-shadow .15s ease;
}
.seg[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }

.viewroot {
  flex: 1;
  width: 100%; max-width: 560px;
  margin: 0 auto;
  padding: .85rem .75rem calc(var(--safe-bot) + 5rem);
}

/* Loading / empty */
.empty { text-align: center; color: var(--muted); padding: 3.5rem 1rem; }
.empty__sun { font-size: 2.4rem; }
.empty p { margin-top: .5rem; }

/* ============================ AGENDA ============================ */

.day-group { margin-bottom: 1.4rem; }
.day-head {
  display: flex; align-items: baseline; gap: .5rem;
  margin: 0 .15rem .55rem;
}
.day-head__num {
  font-family: var(--display); font-weight: 600; font-size: 1.5rem; line-height: 1;
}
.day-head__dow { font-weight: 600; color: var(--ink-2); text-transform: uppercase; font-size: .72rem; letter-spacing: .08em; }
.day-head__rest { color: var(--muted); font-size: .85rem; margin-left: auto; }
.day-head.is-today .day-head__num { color: var(--primary-d); }
.day-head.is-today .day-head__badge {
  font-family: var(--body); font-size: .68rem; font-weight: 700; letter-spacing: .04em;
  color: #fff; background: var(--primary); padding: .12rem .45rem; border-radius: 999px; text-transform: uppercase;
}

.evt {
  display: flex; gap: .7rem; align-items: stretch;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: .7rem .8rem;
  margin-bottom: .5rem;
  box-shadow: var(--shadow-1);
  text-align: left; width: 100%;
}
.evt__rail { width: 4px; border-radius: 4px; background: var(--primary); flex: none; }
.evt__time { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink); min-width: 64px; flex: none; }
.evt__time small { display: block; font-weight: 500; color: var(--muted); font-size: .72rem; }
.evt__body { min-width: 0; flex: 1; }
.evt__title { font-weight: 600; }
.evt__meta { color: var(--muted); font-size: .85rem; margin-top: .1rem; }
.evt__meta span + span::before { content: " · "; }
.evt__emoji { font-size: 1.1rem; flex: none; }

/* ============================ WEEK GRID ============================ */

.weekgrid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--line-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  overflow: hidden;
}
.wcol { background: var(--surface); min-height: 96px; display: flex; flex-direction: column; }
.wcol__head { text-align: center; padding: .35rem 0 .3rem; border-bottom: 1px solid var(--line); }
.wcol__dow { font-size: .62rem; font-weight: 700; letter-spacing: .04em; color: var(--muted); text-transform: uppercase; }
.wcol__num { font-family: var(--display); font-weight: 600; font-size: 1.05rem; }
.wcol.is-today .wcol__num { color: #fff; background: var(--primary); border-radius: 999px; display: inline-block; min-width: 1.6em; line-height: 1.6em; }
.wcol__body { padding: 3px; display: flex; flex-direction: column; gap: 3px; }
.wchip {
  font-size: .64rem; line-height: 1.25;
  padding: 2px 4px; border-radius: 5px;
  background: var(--sky-soft); color: var(--ink);
  border-left: 3px solid var(--primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-align: left; width: 100%;
}
.wchip--allday { background: var(--good-soft); border-left-color: var(--good); }
.wmore { font-size: .6rem; color: var(--muted); text-align: center; padding-top: 1px; }

/* ============================ MONTH GRID ============================ */

.monthgrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--line-2); border: 1px solid var(--line-2); border-radius: var(--r-md); overflow: hidden; }
.mdow { background: var(--paper); text-align: center; font-size: .6rem; font-weight: 700; letter-spacing: .04em; color: var(--muted); text-transform: uppercase; padding: .35rem 0; }
.mcell {
  background: var(--surface);
  min-height: 58px; aspect-ratio: 1 / 1.12;
  display: flex; flex-direction: column; align-items: center;
  padding: 3px 2px; gap: 1px;
  text-align: center;
}
.mcell--out { background: #FBF8F3; }
.mcell--out .mcell__num { color: var(--line-2); }
.mcell__num { font-family: var(--display); font-weight: 500; font-size: .92rem; color: var(--ink-2); line-height: 1.3; }
.mcell.is-today .mcell__num { color: #fff; background: var(--primary); border-radius: 999px; min-width: 1.55em; line-height: 1.55em; font-weight: 600; }
.mcell__icons { display: flex; flex-wrap: wrap; justify-content: center; gap: 1px; font-size: .82rem; line-height: 1; }
.mcell__dot { width: 6px; height: 6px; border-radius: 50%; background: var(--primary); }
.mcell__more { font-size: .58rem; color: var(--muted); font-weight: 600; }

/* ============================ DRAWER ============================ */

.scrim, .sheet-scrim {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(51,48,74,.4);
  opacity: 0; transition: opacity .2s ease;
}
.scrim.is-open, .sheet-scrim.is-open { opacity: 1; }

.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 31;
  width: 80%; max-width: 310px;
  background: var(--surface);
  box-shadow: var(--shadow-2);
  transform: translateX(-100%);
  transition: transform .24s cubic-bezier(.2,.7,.3,1);
  display: flex; flex-direction: column;
  padding: calc(var(--safe-top) + 1rem) 1rem calc(var(--safe-bot) + 1rem);
}
.drawer.is-open { transform: translateX(0); }
.drawer__head { display: flex; align-items: center; gap: .7rem; padding: .4rem .25rem 1.1rem; border-bottom: 1px solid var(--line); }
.drawer__sun { width: 38px; height: 38px; border-radius: 50%; background: radial-gradient(circle at 50% 45%, #FFD36B, var(--primary) 70%); flex: none; box-shadow: 0 4px 10px rgba(244,165,46,.35); }
.drawer__title { font-family: var(--display); font-weight: 600; font-size: 1.15rem; }
.drawer__role { font-size: .8rem; color: var(--muted); }
.drawer__nav { display: flex; flex-direction: column; gap: 2px; margin-top: 1rem; flex: 1; }
.drawer__item { display: flex; align-items: center; gap: .75rem; padding: .8rem .6rem; border-radius: 12px; font-size: 1.02rem; font-weight: 500; text-align: left; }
.drawer__item:active { background: rgba(51,48,74,.06); }
.drawer__item.is-active { background: var(--sky-soft); color: var(--sky); font-weight: 600; }
.di-ico { width: 1.4rem; text-align: center; font-size: 1.1rem; color: var(--muted); }
.drawer__item.is-active .di-ico { color: var(--sky); }
.drawer__sep { border: none; border-top: 1px solid var(--line); margin: .5rem .2rem; }
.drawer__logout { margin-top: .5rem; padding: .8rem; border-radius: 12px; font-weight: 600; color: var(--bad); background: var(--bad-soft); }

/* ============================ QUICK-ADD SHEET ============================ */

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  box-shadow: var(--shadow-2);
  padding: .6rem 1.1rem calc(var(--safe-bot) + 1.2rem);
  transform: translateY(110%);
  transition: transform .26s cubic-bezier(.2,.7,.3,1);
  max-width: 560px; margin: 0 auto;
}
.sheet.is-open { transform: translateY(0); }
.sheet__grab { width: 40px; height: 4px; border-radius: 4px; background: var(--line-2); margin: .35rem auto 1rem; }
.sheet__title { font-family: var(--display); font-weight: 600; font-size: 1.35rem; }
.sheet__sub { color: var(--muted); margin: .1rem 0 1rem; }
.addrow { display: flex; gap: .5rem; }
.addrow input[type=text] {
  flex: 1; min-width: 0;
  font-size: 1.05rem; padding: .85rem .9rem;
  border: 2px solid var(--line-2); border-radius: var(--r-md);
  background: var(--paper); color: var(--ink);
}
.addrow input[type=text]:focus { border-color: var(--primary); outline: none; }
.iconbtn--cam { background: var(--paper); border: 2px solid var(--line-2); border-radius: var(--r-md); width: 52px; height: auto; font-size: 1.3rem; }
.addpreview { width: 100%; max-height: 220px; object-fit: contain; border-radius: var(--r-md); margin-top: .7rem; background: var(--paper); }

.btn { width: 100%; padding: .9rem; border-radius: var(--r-md); font-weight: 700; font-size: 1.02rem; transition: transform .07s ease, background .12s; margin-top: .8rem; }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(244,165,46,.35); }
.btn--primary:disabled { background: var(--line-2); color: var(--muted); box-shadow: none; }

.addresult { margin-top: .9rem; padding: .8rem .9rem; border-radius: var(--r-md); font-size: .95rem; }
.addresult.is-ok { background: var(--good-soft); color: var(--good); }
.addresult.is-warn { background: var(--warn-soft); color: var(--warn); }
.addresult.is-bad { background: var(--bad-soft); color: var(--bad); }
.addresult .res-evt { color: var(--ink); margin-top: .35rem; font-weight: 600; }

/* ============================ TOAST ============================ */

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bot) + 1.2rem); transform: translateX(-50%);
  z-index: 40;
  background: var(--ink); color: #fff;
  padding: .65rem 1.1rem; border-radius: 999px;
  font-size: .9rem; font-weight: 500; box-shadow: var(--shadow-2);
  max-width: 88vw; text-align: center;
}

[hidden] { display: none !important; }

/* ============================ DESKTOP polish ============================ */
@media (min-width: 620px) {
  .viewroot { padding-top: 1.1rem; }
  .mcell { min-height: 78px; }
  .wcol { min-height: 130px; }
}

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