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

:root {
  color-scheme: dark;

  /* Deep charcoal layered surfaces (iOS Dark + GitHub Primer inspired) */
  --bg: #0b0d10;
  --header-bg: rgba(11, 13, 16, 0.78);
  --surface: #15181e;
  --surface-elevated: #1b1f27;
  --surface-recessed: #12151a;
  --surface-done: #121d16;
  --surface-done-hover: #15241b;

  /* Hairline borders & subtle specular highlights */
  --border: rgba(255, 255, 255, 0.075);
  --border-strong: rgba(255, 255, 255, 0.14);
  --border-done: rgba(57, 211, 83, 0.26);
  --specular: inset 0 1px 0 rgba(255, 255, 255, 0.045);
  --specular-done: inset 0 1px 0 rgba(57, 211, 83, 0.12);

  /* Semantic label hierarchy */
  --label: #f3f4f6;
  --label-secondary: rgba(235, 238, 245, 0.62);
  --label-tertiary: rgba(235, 238, 245, 0.38);

  /* Restrained consistency green */
  --accent: #26a641;
  --accent-bright: #39d353;
  --accent-soft: rgba(57, 211, 83, 0.13);
  --accent-glow: rgba(57, 211, 83, 0.28);

  /* Destructive accent */
  --danger: #ff6b6b;
  --danger-soft: rgba(255, 107, 107, 0.12);

  --radius-card: 18px;
  --radius-input: 14px;
  --ease-spring: cubic-bezier(0.22, 1, 0.36, 1);
}

html {
  background-color: var(--bg);
  -webkit-text-size-adjust: 100%;
}

html,
body {
  min-height: 100%;
  min-height: 100dvh;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg);
  background-image: radial-gradient(
    ellipse 90% 42% at 50% -8%,
    rgba(57, 211, 83, 0.04),
    transparent 70%
  );
  color: var(--label);
  line-height: 1.45;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

/* Native iOS-style sticky frosted header */
.header {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  background: var(--header-bg);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.header-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 24px 16px;
}

.header-title-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.today-date {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--label-tertiary);
}

.title {
  margin: 0;
  font-size: 2.1rem;
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.12;
  color: var(--label);
}

/* Main content container */
.app {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 20px calc(24px + env(safe-area-inset-right, 0px)) calc(48px + env(safe-area-inset-bottom, 0px)) calc(24px + env(safe-area-inset-left, 0px));
}

/* Unified sleek add-streak capsule */
.add-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  margin-bottom: 24px;
  background: var(--surface-recessed);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--specular);
  transition: border-color 180ms ease, background-color 180ms ease, box-shadow 180ms ease;
}

.add-form:hover {
  border-color: var(--border-strong);
}

.add-form:focus-within {
  background: var(--surface);
  border-color: rgba(255, 255, 255, 0.22);
  box-shadow: var(--specular), 0 0 0 3px rgba(255, 255, 255, 0.04);
}

.add-input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 12px;
  font-family: inherit;
  font-size: 1rem; /* 16px prevents iOS Safari auto-zoom on focus */
  color: var(--label);
  background: transparent;
  border: none;
  outline: none;
}

.add-input::placeholder {
  color: var(--label-tertiary);
}

.add-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 44px;
  padding: 0 18px;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--label);
  background: var(--surface-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 11px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 160ms ease, border-color 160ms ease, transform 140ms var(--ease-spring);
}

.add-button:hover {
  background: #232833;
  border-color: rgba(255, 255, 255, 0.22);
}

.add-button:active {
  transform: scale(0.96);
}

.add-icon {
  width: 15px;
  height: 15px;
}

.add-button:focus-visible,
.check-button:focus-visible,
.undo-button:focus-visible,
.delete-button:focus-visible {
  outline: 2px solid var(--accent-bright);
  outline-offset: 2px;
}

/* Streaks list section */
.streaks-section {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.streak-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Visually distinctive native iOS-style streak card */
.streak-card {
  position: relative;
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--specular);
  overflow: hidden;
  transition:
    background-color 220ms var(--ease-spring),
    border-color 220ms var(--ease-spring),
    transform 180ms var(--ease-spring),
    box-shadow 220ms var(--ease-spring);
}

/* Subtle left consistency accent bar */
.streak-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 14px;
  bottom: 14px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: rgba(255, 255, 255, 0.08);
  transition: background-color 240ms var(--ease-spring), box-shadow 240ms var(--ease-spring);
}

.streak-card:hover {
  background: var(--surface-elevated);
  border-color: var(--border-strong);
}

.streak-card.is-done {
  background: var(--surface-done);
  border-color: var(--border-done);
  box-shadow: var(--specular-done);
}

.streak-card.is-done::before {
  background: var(--accent-bright);
  box-shadow: 0 0 12px var(--accent-glow);
}

.streak-card.is-done:hover {
  background: var(--surface-done-hover);
  border-color: rgba(57, 211, 83, 0.36);
}

/* Hero streak counter */
.streak-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid rgba(255, 255, 255, 0.045);
  transition: background-color 220ms ease, border-color 220ms ease;
}

.streak-card.is-done .streak-hero {
  background: rgba(57, 211, 83, 0.08);
  border-color: rgba(57, 211, 83, 0.16);
}

.streak-count {
  font-size: 2.15rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums;
  color: var(--label);
  transition: color 220ms ease;
}

.streak-card.is-done .streak-count {
  color: var(--accent-bright);
}

.streak-unit {
  margin-top: 3px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--label-tertiary);
}

.streak-card.is-done .streak-unit {
  color: rgba(57, 211, 83, 0.8);
}

/* Middle: name + clean metadata */
.streak-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.streak-name {
  margin: 0;
  font-size: 1.0625rem; /* 17px iOS Headline */
  font-weight: 600;
  letter-spacing: -0.018em;
  color: var(--label);
  word-break: break-word;
}

.streak-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 12px;
  font-size: 0.82rem;
  color: var(--label-secondary);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  color: var(--label-tertiary);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--label-tertiary);
  transition: background-color 220ms ease, box-shadow 220ms ease;
}

.streak-card.is-done .status-badge {
  color: var(--accent-bright);
}

.streak-card.is-done .status-dot {
  background: var(--accent-bright);
  box-shadow: 0 0 8px var(--accent-glow);
}

.meta-sep {
  color: var(--label-tertiary);
  opacity: 0.45;
}

.best-stat {
  color: var(--label-tertiary);
  font-variant-numeric: tabular-nums;
}

.best-value {
  font-weight: 600;
  color: var(--label-secondary);
}

/* Right: prominent circular daily check button + quiet actions */
.streak-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.undo-button {
  min-height: 36px;
  padding: 0 10px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--label-secondary);
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
  transition: color 150ms ease, background-color 150ms ease;
}

.undo-button:hover {
  color: var(--label);
  background: rgba(255, 255, 255, 0.06);
}

.delete-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  color: var(--label-tertiary);
  background: transparent;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
  opacity: 0.55;
  transition: color 150ms ease, background-color 150ms ease, opacity 150ms ease;
}

.delete-button svg {
  width: 16px;
  height: 16px;
}

.streak-card:hover .delete-button,
.delete-button:focus-visible {
  opacity: 1;
}

.delete-button:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

/* Tactile circular daily check button (inspired by Streaks iOS) */
.check-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  padding: 0;
  border-radius: 999px;
  color: var(--label-tertiary);
  background: var(--surface-recessed);
  border: 1.5px solid rgba(255, 255, 255, 0.16);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  touch-action: manipulation;
  transition:
    background-color 200ms var(--ease-spring),
    border-color 200ms var(--ease-spring),
    color 200ms var(--ease-spring),
    transform 160ms var(--ease-spring),
    box-shadow 220ms var(--ease-spring);
}

.check-button:hover {
  border-color: rgba(57, 211, 83, 0.6);
  background: var(--accent-soft);
  color: var(--accent-bright);
  transform: scale(1.04);
}

.check-button:active {
  transform: scale(0.92);
}

.check-button.is-checked {
  background: linear-gradient(155deg, #34cf56 0%, #21963a 100%);
  border-color: rgba(134, 239, 172, 0.45);
  color: #061409;
  box-shadow:
    0 6px 20px rgba(38, 166, 65, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.check-button.is-checked:hover {
  background: linear-gradient(155deg, #3dd95f 0%, #26a641 100%);
  box-shadow:
    0 8px 24px rgba(38, 166, 65, 0.44),
    inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.check-icon {
  width: 22px;
  height: 22px;
}

.check-icon path {
  stroke-dasharray: 28;
  stroke-dashoffset: 0;
}

/* Completion micro-animations (triggered only on fresh check) */
.streak-card.is-just-completed .streak-count {
  animation: countPop 400ms var(--ease-spring);
}

.streak-card.is-just-completed .check-button {
  animation: checkSpring 380ms var(--ease-spring);
}

.streak-card.is-just-completed .check-button::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 999px;
  border: 2px solid var(--accent-bright);
  pointer-events: none;
  animation: ringExpand 540ms var(--ease-spring) forwards;
}

.streak-card.is-just-completed .check-icon path {
  animation: checkDraw 320ms var(--ease-spring) forwards;
}

@keyframes countPop {
  0% {
    transform: translateY(5px) scale(0.88);
    opacity: 0.65;
  }
  55% {
    transform: translateY(-2px) scale(1.08);
    opacity: 1;
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@keyframes checkSpring {
  0% {
    transform: scale(0.88);
  }
  50% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes ringExpand {
  0% {
    transform: scale(1);
    opacity: 0.75;
  }
  100% {
    transform: scale(1.42);
    opacity: 0;
  }
}

@keyframes checkDraw {
  0% {
    stroke-dashoffset: 28;
  }
  100% {
    stroke-dashoffset: 0;
  }
}

/* Refined, minimal native iOS empty state (no heavy box) */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 72px 24px 96px;
}

.empty-state[hidden] {
  display: none;
}

.empty-glyph {
  width: 52px;
  height: 52px;
  margin-bottom: 16px;
  color: var(--label-tertiary);
}

.empty-glyph svg {
  width: 100%;
  height: 100%;
}

.empty-title {
  margin: 0 0 6px;
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--label-secondary);
}

.empty-subtitle {
  margin: 0;
  max-width: 260px;
  font-size: 0.875rem;
  color: var(--label-tertiary);
  line-height: 1.5;
}

/* Mobile & iPhone 13 Pro Max (428 x 926) native optimization */
@media (max-width: 560px) {
  .header-inner {
    padding: 16px 20px 14px;
  }

  .title {
    font-size: 2rem;
  }

  .app {
    padding: 16px calc(20px + env(safe-area-inset-right, 0px)) calc(36px + env(safe-area-inset-bottom, 0px)) calc(20px + env(safe-area-inset-left, 0px));
  }

  .add-form {
    margin-bottom: 20px;
  }

  .streak-card {
    grid-template-columns: 64px minmax(0, 1fr) auto;
    gap: 14px;
    padding: 16px 16px 16px 18px;
  }

  .streak-hero {
    padding: 7px 0;
  }

  .streak-count {
    font-size: 1.85rem;
  }

  .streak-name {
    font-size: 1rem;
  }

  .streak-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    font-size: 0.78rem;
  }

  .meta-sep {
    display: none;
  }

  .streak-actions {
    gap: 4px;
  }

  .secondary-actions {
    flex-direction: column;
    align-items: center;
    gap: 0;
  }

  .undo-button {
    min-height: 36px;
    padding: 0 8px;
    font-size: 0.76rem;
  }

  .delete-button {
    width: 44px;
    height: 44px;
    opacity: 0.72;
  }

  .check-button {
    width: 54px;
    height: 54px;
  }

  .empty-state {
    padding: 64px 20px 80px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
