/* ===========================================================================
   SND Calendar — mobile-first, no framework, no build step.
   =========================================================================== */

/* The app is dark-only on purpose: one look on every phone, no light mode. */
:root {
  color-scheme: dark;

  --bg:        #0c0c0f;
  --surface:   #17171c;
  --surface-2: #1f1f26;
  --line:      #2a2a33;
  --line-soft: #232329;
  --text:      #f0f0f4;
  --text-2:    #9a9aa8;
  --text-3:    #63636f;
  --accent:    #8b8cf5;
  --accent-bg: #23233a;
  --danger:    #ff6b5e;
  --shadow-s:  0 1px 2px rgba(0, 0, 0, .4);
  --shadow-m:  0 6px 24px rgba(0, 0, 0, .5);
  --shadow-l:  0 -8px 40px rgba(0, 0, 0, .6);

  --k-birthday:    #ef5f8b;
  --k-holiday:     #2fb37a;
  --k-anniversary: #e79a1f;
  --k-reminder:    #4b8ef0;
  --k-other:       #9b7bf0;

  --r-s: 10px;
  --r-m: 14px;
  --r-l: 20px;
  --r-xl: 26px;

  --pad: 14px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);

  --ease: cubic-bezier(.32, .72, 0, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text",
        "Segoe UI", Roboto, "Helvetica Neue", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
}

button, input, textarea { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; }
svg { width: 100%; height: 100%; fill: none; stroke: currentColor;
      stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.muted { color: var(--text-2); }
.tiny  { font-size: 12px; }

/* ------------------------------------------------------------------ shell */

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 620px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

/* ----------------------------------------------------------------- topbar */

.topbar {
  padding: calc(var(--safe-t) + 8px) var(--pad) 8px;
  background: var(--bg);
  flex: 0 0 auto;
  z-index: 5;
}

.titlerow {
  display: flex;
  align-items: center;
  gap: 4px;
}

.periodtitle {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 4px 0;
  border-radius: var(--r-m);
  transition: background .15s;
}
.periodtitle:active { background: var(--surface-2); }

.periodtitle__main {
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.periodtitle__sub {
  font-size: 11.5px;
  color: var(--text-3);
  letter-spacing: .02em;
}

.iconbtn {
  width: 38px; height: 38px;
  flex: 0 0 38px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: var(--text-2);
  transition: background .15s, color .15s, transform .1s;
}
.iconbtn svg { width: 21px; height: 21px; }
.iconbtn:active { background: var(--surface-2); transform: scale(.92); }
.iconbtn--ghost svg { width: 19px; height: 19px; stroke-width: 1.8; }

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

/* segmented control — fills the whole row, one equal share per view */
.segmented {
  --tabs: 2;
  position: relative;
  flex: 1;
  display: grid;
  grid-template-columns: repeat(var(--tabs), 1fr);
  background: var(--surface-2);
  border-radius: 11px;
  padding: 3px;
  isolation: isolate;
}
.segmented button {
  position: relative;
  z-index: 1;
  padding: 7px 0;
  font-size: 13.5px;
  font-weight: 550;
  color: var(--text-2);
  border-radius: 9px;
  transition: color .2s;
}
.segmented button[aria-selected="true"] { color: var(--text); }
.segmented__thumb {
  position: absolute;
  z-index: 0;
  top: 3px; bottom: 3px; left: 3px;
  width: calc((100% - 6px) / var(--tabs));
  background: var(--surface);
  border-radius: 9px;
  box-shadow: var(--shadow-s);
  transition: transform .28s var(--ease);
}

/* ------------------------------------------------------------------ stage */

.stage {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  position: relative;
  touch-action: pan-y;
}

.track {
  display: flex;
  height: 100%;
  will-change: transform;
  transform: translate3d(-100%, 0, 0);
}
.track.animate { transition: transform .32s var(--ease); }

.pane {
  flex: 0 0 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 0 var(--pad) calc(var(--safe-b) + 24px);
}

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

/* Three stacked sections: grid, the next date, the button — and when there is
   room to spare the button settles at the bottom instead of floating loose. */
.month {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding-top: 2px;
}

.dowrow {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 4px;
}
.dowrow span {
  text-align: center;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 4px 0;
}
.dowrow span:nth-child(n+6) { color: var(--k-birthday); opacity: .75; }

.mgrid {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}

.mcell {
  position: relative;
  aspect-ratio: 1 / 1.12;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 6px;
  border-radius: var(--r-s);
  transition: background .15s, transform .1s;
}
.mcell:active { transform: scale(.9); }
.mcell--off .mcell__num { color: var(--text-3); opacity: .5; }
.mcell--weekend .mcell__num { color: var(--k-birthday); }

.mcell__num {
  font-size: 15.5px;
  font-weight: 500;
  line-height: 22px;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-variant-numeric: tabular-nums;
  transition: background .18s, color .18s;
}
.mcell--today .mcell__num {
  background: var(--accent);
  color: #fff;
  font-weight: 640;
}
.mcell__dots {
  display: flex;
  gap: 2.5px;
  margin-top: 3px;
  height: 5px;
  align-items: center;
}
.mcell__dots i {
  width: 4.5px; height: 4.5px;
  border-radius: 50%;
  background: var(--c);
  display: block;
}
.mcell__dots i.plus {
  width: 3px; height: 3px;
  background: var(--text-3);
}

.mlist {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.mlist__foot {
  margin-top: auto;      /* eats the spare room, so the pill lands at the end */
  padding-top: 10px;
  display: flex;
  justify-content: center;
}
/* Third section: one centred pill leading to the full upcoming list. */
.morebtn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: fit-content;
  padding: 11px 20px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-s);
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -.005em;
  transition: transform .12s, background .15s, color .15s;
}
.morebtn:active {
  transform: scale(.96);
  background: var(--surface-2);
  color: var(--text);
}
.morebtn svg {
  width: 14px; height: 14px;
  flex: 0 0 14px;
  stroke-width: 2.4;
  opacity: .7;
}

/* ============================== YEAR ====================================== */

.year {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px 7px;
  padding-top: 6px;
}

.ymonth {
  background: var(--surface);
  border-radius: var(--r-m);
  padding: 8px 6px 9px;
  box-shadow: var(--shadow-s);
  text-align: left;
  transition: transform .12s;
}
.ymonth:active { transform: scale(.96); }
.ymonth--cur { background: var(--accent-bg); box-shadow: none; }

.ymonth__name {
  display: block;
  font-size: 12px;
  font-weight: 620;
  margin: 0 0 5px 3px;
  letter-spacing: -.01em;
}
.ymonth--cur .ymonth__name { color: var(--accent); }

.ygrid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
}
.ygrid b {
  font-size: 8.5px;
  font-weight: 500;
  line-height: 1;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  position: relative;
}
.ygrid b.off { color: transparent; }
.ygrid b.we  { color: var(--text-3); }
.ygrid b.has { color: var(--text); font-weight: 700; }
.ygrid b.has::after {
  content: "";
  position: absolute;
  bottom: -1px; left: 50%;
  transform: translateX(-50%);
  width: 3px; height: 3px;
  border-radius: 50%;
  background: var(--c, var(--accent));
}
.ygrid b.today {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}
.ygrid b.today::after { background: #fff; }

/* ------------------------------------------------------------- event cards */

.card {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  text-align: left;
  padding: 11px 12px;
  background: var(--surface);
  border-radius: var(--r-m);
  box-shadow: var(--shadow-s);
  margin-bottom: 7px;
  transition: transform .12s;
}
.card:active { transform: scale(.98); }

/* Happening today: accent ring plus a slow, quiet glow. */
.card--today {
  background: var(--accent-bg);
  box-shadow: 0 0 0 1.5px var(--accent),
              0 0 16px color-mix(in srgb, var(--accent) 26%, transparent);
  animation: cardGlow 3s var(--ease) infinite alternate;
}
.card--today .card__right { color: var(--accent); font-weight: 650; }

@keyframes cardGlow {
  from { box-shadow: 0 0 0 1.5px var(--accent),
                     0 0 10px color-mix(in srgb, var(--accent) 18%, transparent); }
  to   { box-shadow: 0 0 0 1.5px var(--accent),
                     0 0 22px color-mix(in srgb, var(--accent) 38%, transparent); }
}

.card__icon {
  flex: 0 0 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  font-size: 16px;
  background: color-mix(in srgb, var(--c) 15%, transparent);
}

.card__body { flex: 1; min-width: 0; display: block; }
.card__title {
  display: block;
  font-size: 15px;
  font-weight: 550;
  letter-spacing: -.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card__sub {
  display: block;
  font-size: 12.5px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.card__right {
  flex: 0 0 auto;
  display: block;
  font-size: 12px;
  line-height: 1.25;
  color: var(--text-3);
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.empty {
  text-align: center;
  padding: 34px 20px;
  color: var(--text-3);
  font-size: 14px;
}
.empty span { display: block; font-size: 28px; margin-bottom: 8px; opacity: .55; }

/* ------------------------------------------------------------------ sheets */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet[hidden] { display: none; }

.sheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 16, .42);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity .28s var(--ease);
}
.sheet.open .sheet__backdrop { opacity: 1; }

.sheet__panel {
  position: relative;
  width: 100%;
  max-width: 620px;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-l);
  transform: translateY(102%);
  transition: transform .34s var(--ease);
  padding-bottom: var(--safe-b);
}
.sheet.open .sheet__panel { transform: translateY(0); }
.sheet__panel--tall { height: 88dvh; }

.sheet__grip {
  width: 36px; height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 8px auto 0;
  flex: 0 0 auto;
}

.sheet__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px 8px;
  flex: 0 0 auto;
}
.sheet__title {
  margin: 0;
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -.02em;
}
.sheet__sub {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-2);
}

.sheet__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 16px 8px;
  -webkit-overflow-scrolling: touch;
}

.sheet__foot {
  flex: 0 0 auto;
  padding: 10px 16px calc(12px + var(--safe-b));
  border-top: 1px solid var(--line-soft);
  background: var(--bg);
}
.sheet__foot--split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.sheet__foot--split .btn--primary { flex: 1; }

/* ------------------------------------------------------------------ inputs */

.form { display: flex; flex-direction: column; gap: 14px; padding-top: 6px; }

.field { display: block; }
.field__label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-2);
  margin: 0 0 6px 3px;
  letter-spacing: .01em;
}
.field__label em { font-style: normal; color: var(--text-3); font-weight: 500; }

.input {
  width: 100%;
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  font-size: 16px;
  outline: none;
  transition: border-color .18s, box-shadow .18s;
  -webkit-appearance: none;
  appearance: none;
}
.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}
.input--area { resize: none; line-height: 1.45; min-height: 62px; }
input[type="date"] { min-height: 48px; }
input[type="date"]::-webkit-calendar-picker-indicator { opacity: .55; }

.kinds {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.kinds button {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px 8px 10px;
  font-size: 13.5px;
  font-weight: 520;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: all .18s;
}
.kinds button[aria-pressed="true"] {
  border-color: var(--c);
  background: color-mix(in srgb, var(--c) 13%, transparent);
  color: var(--c);
  font-weight: 600;
}

.switchrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
}
.switchrow__title { display: block; font-size: 15px; font-weight: 500; }
.switchrow__hint  { display: block; font-size: 12.5px; color: var(--text-2); margin-top: 1px; }

.switch { position: absolute; opacity: 0; pointer-events: none; }
.switch__ui {
  flex: 0 0 46px;
  width: 46px; height: 28px;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  transition: background .22s var(--ease);
}
.switch__ui::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .22s var(--ease);
}
.switch:checked ~ .switch__ui { background: var(--accent); }
.switch:checked ~ .switch__ui::after { transform: translateX(18px); }

.formerror {
  margin: 0;
  font-size: 13px;
  color: var(--danger);
  text-align: center;
}

/* ------------------------------------------------------------------ buttons */

.btn {
  padding: 14px 18px;
  border-radius: var(--r-m);
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: -.01em;
  transition: transform .12s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn--primary { background: var(--accent); color: #fff; width: 100%; }
.btn--danger  { background: color-mix(in srgb, var(--danger) 13%, transparent);
                color: var(--danger); padding-inline: 20px; }
.btn[disabled] { opacity: .5; pointer-events: none; }

/* ------------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 28px);
  transform: translate(-50%, 12px);
  z-index: 90;
  padding: 11px 18px;
  background: var(--text);
  color: var(--bg);
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 550;
  box-shadow: var(--shadow-m);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s var(--ease);
  max-width: calc(100vw - 40px);
  text-align: center;
}
.toast[hidden] { display: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

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