:root {
  --bg: #f5efe2;
  --surface: rgba(255, 252, 246, 0.84);
  --surface-strong: #fffaf0;
  --ink: #182026;
  --ink-muted: #4d5765;
  --line: rgba(24, 32, 38, 0.16);
  --accent: #d24b2a;
  --accent-strong: #ab391e;
  --mint: #2a8f72;
  --mint-soft: #d6efe7;
  --sand: #f0e1c4;
  --radius-xl: 24px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 10px;
  --shadow: 0 18px 44px rgba(34, 22, 8, 0.14);
  --max-w: 980px;
  --font-display: "Fraunces", "Times New Roman", serif;
  --font-ui: "Space Grotesk", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-ui);
  background:
    radial-gradient(1000px 520px at -12% -20%, rgba(210, 75, 42, 0.2), transparent 55%),
    radial-gradient(900px 520px at 112% -12%, rgba(42, 143, 114, 0.24), transparent 56%),
    linear-gradient(180deg, #f9f4e8 0%, var(--bg) 100%);
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -100px;
  z-index: 10;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
}

.skip-link:focus {
  top: 10px;
}

.topbar,
.footer,
.shell {
  width: min(calc(100% - 28px), var(--max-w));
  margin: 0 auto;
}

.topbar,
.footer {
  margin-top: 18px;
  margin-bottom: 18px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand,
.day-tag,
.footer p {
  margin: 0;
}

.brand {
  font-family: var(--font-display);
  letter-spacing: 0.02em;
  font-size: 1.1rem;
}

.day-tag {
  color: var(--ink-muted);
  font-size: 0.9rem;
}

.shell {
  display: grid;
  gap: 16px;
  margin-bottom: 16px;
}

.card {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hero {
  position: relative;
  overflow: hidden;
}

.hero::after {
  content: "";
  position: absolute;
  width: 320px;
  height: 320px;
  right: -100px;
  bottom: -160px;
  border-radius: 50%;
  background: radial-gradient(circle at center, rgba(42, 143, 114, 0.18), transparent 70%);
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.75rem;
  color: var(--ink-muted);
}

h1,
h2 {
  font-family: var(--font-display);
}

h1 {
  margin: 8px 0 10px;
  font-size: clamp(1.9rem, 3.8vw, 2.8rem);
  line-height: 1.1;
}

h2 {
  margin: 0;
  font-size: clamp(1.35rem, 2.2vw, 1.8rem);
  line-height: 1.15;
}

.hero-copy {
  margin: 0;
  color: var(--ink-muted);
  max-width: 60ch;
}

.stats {
  display: grid;
  grid-template-columns: minmax(140px, 180px) minmax(0, 1fr);
  gap: 18px;
  align-items: center;
}

.ring-wrap {
  display: grid;
  place-items: center;
}

.ring {
  --progress: 0;
  width: 145px;
  height: 145px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  background:
    radial-gradient(var(--surface-strong) 58%, transparent 59%),
    conic-gradient(var(--accent) calc(var(--progress) * 1%), #e5d4b7 0);
}

.ring span {
  font-size: 1.2rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.stat-grid article {
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px;
}

.label,
.legend,
.today-label,
.hint {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.92rem;
}

.value {
  margin: 8px 0 0;
  font-weight: 700;
  font-size: 1.25rem;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

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

.habit-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-strong);
  padding: 12px;
}

.habit-name {
  margin: 0;
  font-weight: 600;
}

.habit-streak {
  margin: 3px 0 0;
  font-size: 0.85rem;
  color: var(--ink-muted);
}

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

.btn-mark,
.btn-delete,
.habit-form button {
  min-height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  cursor: pointer;
  padding: 0 12px;
}

.btn-mark {
  background: var(--mint-soft);
  color: #185744;
}

.btn-mark.is-done {
  background: var(--mint);
  color: #fff;
}

.btn-delete {
  background: transparent;
  border-color: var(--line);
  color: var(--ink-muted);
}

.habit-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.habit-form input {
  width: 100%;
  min-height: 42px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  padding: 0 12px;
  font: inherit;
  background: var(--surface-strong);
}

.habit-form button {
  background: var(--accent);
  color: #fff;
}

.panel-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-soft {
  min-height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--ink);
  font: inherit;
  padding: 0 12px;
  cursor: pointer;
}

.btn-soft.danger {
  color: #8a2f2a;
  border-color: rgba(138, 47, 42, 0.3);
}

.shortcut-note {
  margin: 10px 0 0;
  color: var(--ink-muted);
  font-size: 0.88rem;
}

.modal {
  border: 0;
  padding: 0;
  border-radius: var(--radius-lg);
  background: transparent;
}

.modal::backdrop {
  background: rgba(18, 21, 25, 0.45);
  backdrop-filter: blur(2px);
}

.modal-card {
  min-width: min(92vw, 420px);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface-strong);
  box-shadow: var(--shadow);
  padding: 16px;
  display: grid;
  gap: 12px;
}

.modal-card input {
  width: 100%;
  min-height: 42px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  padding: 0 12px;
  font: inherit;
  background: #fff;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.habit-form button:hover,
.btn-mark:hover,
.btn-delete:hover,
.btn-soft:hover {
  filter: brightness(0.97);
}

.habit-form input:focus,
.habit-form button:focus,
.btn-mark:focus,
.btn-delete:focus,
.btn-soft:focus,
.modal-card input:focus,
a:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}

.day-cell {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px;
  background: var(--surface-strong);
  min-height: 86px;
}

.day-name {
  margin: 0;
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.day-score {
  margin: 6px 0 0;
  font-weight: 700;
  font-size: 1.1rem;
}

.day-cell[data-level="0"] { background: #f8f0df; }
.day-cell[data-level="1"] { background: #efe2c7; }
.day-cell[data-level="2"] { background: #e6d2aa; }
.day-cell[data-level="3"] { background: #dec48d; }
.day-cell[data-level="4"] { background: #d7b36e; }

.footer a {
  color: var(--accent-strong);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.reveal-1,
.reveal-2,
.reveal-3,
.reveal-4,
.reveal-5 {
  opacity: 0;
  transform: translateY(12px);
  animation: reveal 520ms ease forwards;
}

.reveal-2 { animation-delay: 70ms; }
.reveal-3 { animation-delay: 140ms; }
.reveal-4 { animation-delay: 210ms; }
.reveal-5 { animation-delay: 280ms; }

@keyframes reveal {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 860px) {
  .stats {
    grid-template-columns: 1fr;
  }

  .ring-wrap {
    justify-self: start;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }

  .history-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .topbar,
  .footer {
    flex-direction: column;
    align-items: flex-start;
  }

  .habit-item {
    grid-template-columns: 1fr;
  }

  .habit-actions {
    justify-content: space-between;
  }

  .history-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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

  .reveal-1,
  .reveal-2,
  .reveal-3,
  .reveal-4,
  .reveal-5 {
    opacity: 1;
    transform: none;
    animation: none;
  }
}
