:root {
  --page: #f5f5f5;
  --surface: #ffffff;
  --surface-soft: #f7f7f7;
  --ink: #111111;
  --muted: #666666;
  --line: #d9d9d9;
  --accent: #0058a3;
  --accent-dark: #00477f;
  --accent-soft: #e8f1f8;
  --accent-bright: #ffda1a;
  --danger: #c8102e;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    linear-gradient(180deg, var(--accent-bright) 0 10px, var(--accent) 10px 16px, transparent 16px),
    var(--page);
  font-family: Arial, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button,
input {
  font: inherit;
}

button,
input,
.habit-label {
  touch-action: manipulation;
}

button {
  cursor: pointer;
}

.page-glow {
  display: none;
}

.app {
  width: min(820px, calc(100% - 40px));
  margin: 0 auto;
  padding: 58px 0 38px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  align-items: stretch;
  margin-bottom: 24px;
}

.hero-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  justify-content: center;
  padding: 18px 4px;
}

.date-line,
.section-eyebrow,
.progress-eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.hero h1 {
  width: max-content;
  max-width: 100%;
  margin: 12px 0 11px;
  font-size: clamp(2rem, 4.4vw, 3.25rem);
  line-height: 1;
  letter-spacing: -0.055em;
  white-space: nowrap;
}

.intro {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
}

.progress-card {
  display: flex;
  min-height: 218px;
  flex-direction: column;
  justify-content: space-between;
  padding: 26px;
  color: #ffffff;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  box-shadow: none;
}

.progress-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.progress-eyebrow {
  margin-bottom: 8px;
  color: rgba(255, 255, 255, 0.78);
}

.progress-count {
  margin: 0;
  font-size: clamp(1.9rem, 4vw, 2.55rem);
  font-weight: 700;
  letter-spacing: -0.04em;
}

.progress-percent {
  display: grid;
  min-width: 58px;
  height: 48px;
  padding: 0 9px;
  place-items: center;
  color: var(--accent);
  background: var(--accent-bright);
  border-radius: 3px;
  font-size: 0.84rem;
  font-weight: 800;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.28);
  border-radius: 2px;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent-bright);
  border-radius: inherit;
  transition: width 320ms ease;
}

.progress-hint {
  min-height: 1.4em;
  margin: 0;
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.84rem;
}

.habits-card {
  padding: 30px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: none;
}

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.section-eyebrow {
  margin-bottom: 7px;
  font-size: 0.68rem;
}

.section-heading h2 {
  margin: 0;
  font-size: 1.55rem;
  letter-spacing: -0.03em;
}

.section-summary {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.88rem;
  white-space: nowrap;
}

.add-form {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-bottom: 20px;
}

.add-form input {
  min-width: 0;
  height: 52px;
  padding: 0 16px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid #b8b8b8;
  border-radius: 3px;
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.add-form input::placeholder {
  color: #888888;
}

.add-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 88, 163, 0.15);
}

.add-form input.input-error {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(200, 16, 46, 0.1);
}

.add-form button {
  display: inline-flex;
  height: 52px;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0 22px;
  color: #ffffff;
  background: var(--accent);
  border: 0;
  border-bottom: 5px solid var(--accent-bright);
  border-radius: 3px;
  font-weight: 700;
  transition: background 140ms ease;
}

.add-form button:hover {
  background: var(--accent-dark);
}

.add-form button:active {
  border-bottom-width: 3px;
  transform: translateY(2px);
}

.add-form button:focus-visible,
.delete-button:focus-visible,
.habit-checkbox:focus-visible + .checkmark {
  outline: 3px solid rgba(0, 88, 163, 0.28);
  outline-offset: 3px;
}

.form-message {
  position: absolute;
  top: calc(100% + 4px);
  left: 3px;
  margin: 0;
  color: var(--danger);
  font-size: 0.76rem;
}

.form-message:empty {
  display: none;
}

.habit-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.habit-item {
  position: relative;
  display: flex;
  min-height: 66px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 12px 10px 16px;
  overflow: hidden;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 3px;
  transition: background 180ms ease, border-color 180ms ease;
}

.habit-item:hover {
  border-color: #a9a9a9;
}

.habit-item.is-done {
  background: var(--accent-soft);
  border-color: #9ec1dc;
}

.habit-label {
  display: flex;
  min-width: 0;
  flex: 1;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  user-select: none;
}

.habit-checkbox {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.checkmark {
  position: relative;
  display: grid;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  place-items: center;
  color: transparent;
  background: #ffffff;
  border: 2px solid #767676;
  border-radius: 50%;
  transition: color 150ms ease, background 150ms ease, border-color 150ms ease, transform 150ms ease;
}

.checkmark svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.8;
}

.habit-checkbox:checked + .checkmark {
  color: #ffffff;
  background: var(--accent);
  border-color: var(--accent);
}

.habit-name {
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 180ms ease;
}

.habit-item.is-done .habit-name {
  color: #536c80;
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.delete-button {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  place-items: center;
  color: #767676;
  background: transparent;
  border: 0;
  border-radius: 3px;
  opacity: 0.35;
  transition: color 140ms ease, background 140ms ease, opacity 140ms ease;
}

.habit-item:hover .delete-button,
.delete-button:focus-visible {
  opacity: 1;
}

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

.delete-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.empty-state {
  padding: 42px 20px 38px;
  text-align: center;
  background: #fafafa;
  border: 1px dashed #b8b8b8;
  border-radius: 3px;
}

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

.empty-icon {
  display: grid;
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
  place-items: center;
  color: var(--accent);
  background: var(--accent-bright);
  border-radius: 3px;
  font-size: 1.3rem;
  font-weight: 800;
}

.empty-state h3 {
  margin: 0 0 7px;
  font-size: 1rem;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.page-footer {
  padding: 18px 8px 0;
  color: #777777;
  font-size: 0.76rem;
  text-align: center;
}

.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;
}

.shatter-piece {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  width: var(--piece-size, 7px);
  height: var(--piece-size, 7px);
  background: var(--piece-color, var(--accent));
  border-radius: 1px;
  pointer-events: none;
  will-change: transform, opacity;
}

.habit-item.is-shattering .checkmark svg {
  animation: check-shatter 430ms cubic-bezier(0.2, 0.85, 0.3, 1) both;
}

.habit-item.is-recovering .checkmark svg {
  animation: check-recover 520ms cubic-bezier(0.2, 0.8, 0.25, 1) both;
}

.habit-item.is-shattering {
  animation: item-shatter 430ms ease;
}

.habit-item.is-recovering {
  animation: item-recover 520ms ease;
}

@keyframes check-shatter {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  30% {
    opacity: 1;
    transform: scale(1.08) rotate(-5deg);
  }
  58% {
    opacity: 0;
    transform: scale(0.15) rotate(7deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
}

@keyframes check-recover {
  0% {
    opacity: 0;
    transform: scale(0.15) rotate(-7deg);
  }
  58% {
    opacity: 0.55;
    transform: scale(0.72) rotate(4deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
}

@keyframes item-shatter {
  0%,
  100% {
    transform: translateX(0);
  }
  28% {
    transform: translateX(-3px);
  }
  54% {
    transform: translateX(3px);
  }
  76% {
    transform: translateX(-1px);
  }
}

@keyframes item-recover {
  0%,
  100% {
    transform: translateX(0);
  }
  35% {
    transform: translateX(2px);
  }
  65% {
    transform: translateX(-2px);
  }
}

@media (max-width: 680px) {
  .app {
    width: calc(100% - 28px);
    padding: calc(18px + env(safe-area-inset-top)) 0 calc(24px + env(safe-area-inset-bottom));
  }

  .hero {
    grid-template-columns: 1fr;
    gap: 16px;
    margin-bottom: 16px;
  }

  .hero-copy {
    padding: 4px 5px;
  }

  .hero h1 {
    margin: 8px 0 9px;
    font-size: clamp(1.75rem, 8.3vw, 2.35rem);
    line-height: 1;
  }

  .intro {
    font-size: 0.96rem;
  }

  .progress-card {
    min-height: 174px;
    padding: 20px;
  }

  .progress-count {
    font-size: 2rem;
  }

  .progress-percent {
    min-width: 54px;
    height: 44px;
  }

  .habits-card {
    padding: 18px;
  }

  .section-heading {
    margin-bottom: 16px;
  }

  .add-form {
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 20px;
  }

  .add-form input,
  .add-form button {
    height: 54px;
    font-size: 16px;
  }

  .add-form button {
    width: 100%;
  }

  .form-message {
    position: static;
    grid-column: 1 / -1;
  }

  .habit-item {
    min-height: 68px;
    padding: 12px 9px 12px 14px;
  }

  .habit-label {
    gap: 16px;
  }

  .checkmark {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
  }

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

  .delete-button {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
    opacity: 0.68;
  }

  .page-footer {
    padding: 16px 10px 0;
    font-size: 0.72rem;
    line-height: 1.55;
  }
}

@media (hover: none) {
  .habit-item:hover {
    border-color: var(--line);
  }

  .habit-item.is-done:hover {
    border-color: #9ec1dc;
  }

  .add-form button:hover {
    background: var(--accent);
  }

  .delete-button:hover {
    color: #767676;
    background: transparent;
  }
}

@media (max-width: 380px) {
  .app {
    width: calc(100% - 20px);
  }

  .habits-card {
    padding: 16px;
  }

  .progress-card {
    padding: 18px;
  }

  .habit-item {
    gap: 8px;
    padding-left: 12px;
  }
}

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