:root {
  --bg: #111116;
  --panel: #09090d;
  --panel-2: #111118;
  --stroke: #282833;
  --text: #f4f0ee;
  --muted: #918b94;
  --cell: 18px;
  --gap: 2px;
  --radius: 22px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 20% -10%, rgba(255, 255, 255, .06), transparent 28%),
    linear-gradient(180deg, #17171d 0%, var(--bg) 50%, #0d0d12 100%);
  color: var(--text);
  overscroll-behavior-y: none;
}

button {
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  padding: 0;
  margin: 0;
  min-width: 0;
  min-height: 0;
  color: inherit;
  font: inherit;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

.app {
  width: min(100%, 520px);
  min-height: 100svh;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top, 0px)) 14px calc(24px + var(--safe-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding: 4px 4px 0;
}

h1 {
  margin: 0;
  font-size: clamp(36px, 11vw, 54px);
  line-height: .95;
  letter-spacing: -0.06em;
  font-weight: 760;
}

.subtitle {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
  letter-spacing: .02em;
}

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

.zoom-toggle,
.add-btn {
  width: 58px;
  height: 58px;
  border-radius: 19px;
  background: linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.02));
  border: 1px solid var(--stroke);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 12px 30px rgba(0,0,0,.25);
  font-size: 38px;
  line-height: 1;
  font-weight: 250;
}

.zoom-toggle {
  font-size: 23px;
  font-weight: 500;
  position: relative;
}

.zoom-toggle::after {
  content: attr(data-zoom-state);
  position: absolute;
  left: 50%;
  bottom: 7px;
  transform: translateX(-50%);
  max-width: 48px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 7px;
  line-height: 1;
  color: rgba(255,255,255,.52);
}

.zoom-toggle.is-zoom-out {
  background: linear-gradient(180deg, rgba(255,255,255,.13), rgba(255,255,255,.035));
}

.add-btn:active,
.zoom-toggle:active,
.today-btn:active,
.icon-btn:active,
.move-buttons button:active {
  transform: scale(.96);
}

.habits {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.habit-card {
  --accent: #ff6b6b;
  --accent-soft: rgba(255, 107, 107, .14);
  position: relative;
  overflow: hidden;
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255,255,255,.025), transparent 28%), var(--panel);
  box-shadow: 0 16px 40px rgba(0,0,0,.28), inset 0 1px 0 rgba(255,255,255,.04);
  padding: 14px 14px 16px;
}

.habit-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 86% 0%, var(--accent-soft), transparent 32%);
  opacity: .9;
  pointer-events: none;
}

.habit-head {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) 34px 31px 58px;
  gap: 8px;
  align-items: center;
  margin-bottom: 18px;
}

.icon-btn,
.today-btn {
  width: 58px;
  height: 58px;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,.09);
  background: color-mix(in srgb, var(--accent) 15%, #101014);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08);
  display: grid;
  place-items: center;
}

.icon-btn {
  font-size: 26px;
  line-height: 1;
  pointer-events: none;
}

.habit-settings {
  width: 34px;
  height: 58px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.04);
  display: grid;
  place-items: center;
  font-size: 14px;
  line-height: 1;
}

.habit-settings:active {
  transform: scale(.96);
}


.today-btn {
  font-size: 34px;
  font-weight: 330;
}

.today-btn.is-active {
  background: color-mix(in srgb, var(--accent) 33%, #111014);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 50%, transparent), 0 0 28px var(--accent-soft), inset 0 1px 0 rgba(255,255,255,.1);
}

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

.habit-title {
  display: block;
  width: 100%;
  padding: 0;
  text-align: left;
  font-size: 24px;
  line-height: 1.12;
  letter-spacing: -.035em;
  font-weight: 520;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.habit-hint {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: .72;
}

.move-buttons {
  display: grid;
  gap: 5px;
}

.move-buttons button {
  width: 31px;
  height: 26px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.035);
  color: rgba(255,255,255,.86);
  font-size: 14px;
  line-height: 1;
}

.move-buttons button:disabled {
  opacity: .25;
}

.grid-shell {
  position: relative;
  z-index: 1;
  overflow-x: auto;
  overflow-y: hidden;
  padding-left: 1px;
  padding-right: 8px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  touch-action: pan-x;
}

.grid-shell::-webkit-scrollbar {
  display: none;
}

.habit-grid {
  --weeks: 8;
  display: grid;
  grid-template-columns: repeat(var(--weeks), var(--cell));
  grid-template-rows: repeat(7, var(--cell));
  gap: var(--gap);
  justify-content: end;
  align-content: start;
  width: calc((var(--weeks) * var(--cell)) + ((var(--weeks) - 1) * var(--gap)));
  margin-left: 0;
  margin-right: 0;
  background: rgba(0, 0, 0, .18);
}

.day-cell {
  display: grid;
  place-items: center;
  inline-size: var(--cell);
  block-size: var(--cell);
  width: var(--cell);
  height: var(--cell);
  aspect-ratio: 1 / 1;
  padding: 0;
  margin: 0;
  min-width: 0;
  min-height: 0;
  line-height: 1;
  flex: 0 0 auto;
  border-radius: 2px;
  background: color-mix(in srgb, var(--accent) 12%, #15151a);
  border: 0;
}

.day-date {
  display: block;
  font-size: 5px;
  line-height: 1;
  font-weight: 650;
  letter-spacing: -0.08em;
  color: rgba(255,255,255,.52);
  pointer-events: none;
  user-select: none;
  transform: translateY(.2px);
}

.day-cell.is-on .day-date {
  color: rgba(0,0,0,.58);
}

.day-cell.is-today .day-date {
  color: rgba(255,255,255,.92);
}

.day-cell.is-today.is-on .day-date {
  color: rgba(0,0,0,.72);
}

.day-cell.is-on {
  background: var(--accent);
  box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 35%, transparent);
}

.day-cell.is-today {
  outline: 1px solid rgba(255,255,255,.62);
  outline-offset: 1px;
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--accent) 42%, transparent),
    0 0 10px color-mix(in srgb, var(--accent) 52%, transparent),
    0 0 18px color-mix(in srgb, var(--accent) 30%, transparent);
}

.day-cell.is-today.is-on {
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--accent) 72%, transparent),
    0 0 14px color-mix(in srgb, var(--accent) 80%, transparent),
    0 0 26px color-mix(in srgb, var(--accent) 48%, transparent);
}

.day-cell.is-future {
  opacity: .33;
}

.app.zoom-out {
  --cell: 9px;
}

.app.zoom-out .day-date {
  display: none;
}

.app.zoom-out .day-cell {
  border-radius: 1.5px;
}

.settings-modal[hidden] {
  display: none;
}

.settings-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
}

.settings-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.54);
  backdrop-filter: blur(12px);
}

.settings-sheet {
  position: relative;
  width: min(calc(100% - 28px), 460px);
  max-height: calc(100svh - 36px - var(--safe-bottom));
  overflow: auto;
  margin: 0 auto;
  padding: 18px 16px;
  border-radius: 26px;
  border: 1px solid rgba(255,255,255,.11);
  background: linear-gradient(180deg, rgba(255,255,255,.055), transparent 26%), #101016;
  box-shadow: 0 24px 80px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,255,255,.06);
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.settings-head h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1;
  letter-spacing: -.04em;
}

.settings-close {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.09);
  background: rgba(255,255,255,.045);
  font-size: 28px;
  line-height: 1;
  color: rgba(255,255,255,.78);
}

.field-label {
  display: block;
  margin: 14px 0 7px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .02em;
}

.settings-input {
  width: 100%;
  height: 48px;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 16px;
  outline: none;
  padding: 0 14px;
  background: rgba(255,255,255,.045);
  color: var(--text);
  font: inherit;
  font-size: 18px;
}

.settings-input:focus {
  border-color: rgba(255,255,255,.24);
  box-shadow: 0 0 0 3px rgba(255,255,255,.055);
}

.color-palette {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 8px;
}

.color-choice {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.16);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.16);
}

.color-choice.is-selected {
  outline: 2px solid rgba(255,255,255,.9);
  outline-offset: 2px;
}

.settings-save {
  width: 100%;
  height: 52px;
  margin-top: 18px;
  border-radius: 18px;
  background: rgba(255,255,255,.92);
  color: #111116;
  font-size: 17px;
  font-weight: 680;
}

.settings-delete {
  width: 100%;
  height: 48px;
  margin-top: 10px;
  border-radius: 17px;
  border: 1px solid rgba(255, 107, 107, .28);
  background: rgba(255, 107, 107, .09);
  color: #ff9b9b;
  font-size: 16px;
  font-weight: 650;
}

.settings-delete:active {
  transform: scale(.985);
}

.empty {
  margin: 36px 8px;
  padding: 28px 18px;
  text-align: center;
  border: 1px dashed var(--stroke);
  border-radius: 22px;
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-bottom));
  transform: translateX(-50%) translateY(18px);
  opacity: 0;
  max-width: calc(100% - 28px);
  padding: 11px 14px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: rgba(12,12,16,.86);
  backdrop-filter: blur(18px);
  color: var(--text);
  font-size: 14px;
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
  z-index: 20;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 380px) {
  :root { --cell: 17px; --gap: 2px; }
  .app.zoom-out { --cell: 8.5px; }
  .habit-head { grid-template-columns: 54px minmax(0, 1fr) 32px 29px 54px; gap: 7px; }
  .icon-btn, .today-btn { width: 54px; height: 54px; border-radius: 17px; }
  .habit-settings { width: 32px; height: 54px; border-radius: 13px; font-size: 17px; }
  .habit-title { font-size: 22px; }
}

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

.day-cell.just-toggled {
  animation: cellPulse .22s ease-out;
}

@keyframes cellPulse {
  0% { transform: scale(.82); }
  100% { transform: scale(1); }
}

.day-id.just-toggled {
  animation: dayPulse .26s ease-out;
}

@keyframes dayPulse {
  0% { transform: scale(1); }
  45% { transform: scale(1.45); }
  100% { transform: scale(1); }
}
