:root {
  color-scheme: light;
  --bg: #f6f8f4;
  --surface: #ffffff;
  --surface-2: #eef4ee;
  --surface-3: #f9fbf8;
  --ink: #17211c;
  --muted: #66746d;
  --soft: #d9e4db;
  --line: #dfe8df;
  --accent: #1f7d67;
  --accent-dark: #145c4d;
  --accent-soft: #dcefe7;
  --amber: #d99b2b;
  --amber-soft: #fff2d3;
  --danger: #b45b4f;
  --danger-soft: #f8e5e1;
  --shadow: 0 18px 45px rgba(27, 50, 38, 0.1);
  --shadow-soft: 0 8px 24px rgba(27, 50, 38, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(246, 248, 244, 0.96)),
    var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 16px;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  border: 0;
}

.noscript {
  margin: 24px;
  padding: 16px 18px;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: var(--ink);
}

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
  height: 100vh;
  padding: 28px 20px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 24px rgba(31, 125, 103, 0.22);
}

.brand-copy strong {
  display: block;
  font-size: 1.05rem;
  line-height: 1.1;
}

.brand-copy span {
  color: var(--muted);
  font-size: 0.82rem;
}

.side-nav {
  display: grid;
  gap: 7px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  padding: 10px 11px;
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
  transition:
    background 180ms ease,
    color 180ms ease,
    transform 180ms ease;
}

.nav-link:hover,
.nav-link:focus-visible {
  background: var(--surface-2);
  color: var(--ink);
  outline: none;
  transform: translateX(2px);
}

.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-weight: 700;
}

.sidebar-footer {
  margin-top: auto;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-3);
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.main {
  min-width: 0;
  padding: 28px;
}

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

.topbar h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(1.9rem, 3vw, 3.1rem);
  font-weight: 800;
  line-height: 1.02;
}

.date-line {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.98rem;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.42fr) minmax(320px, 0.58fr);
  gap: 18px;
  align-items: start;
}

.stack {
  display: grid;
  gap: 18px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow-soft);
}

.panel-inner {
  padding: 20px;
}

.hero-panel {
  position: relative;
  overflow: hidden;
  border-color: #cfe0d2;
  background:
    linear-gradient(135deg, rgba(220, 239, 231, 0.92), rgba(255, 255, 255, 0.72) 55%),
    var(--surface);
  box-shadow: var(--shadow);
}

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

.status-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--accent-dark);
  font-size: 0.92rem;
  font-weight: 700;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 99px;
  background: var(--amber);
  box-shadow: 0 0 0 6px rgba(217, 155, 43, 0.18);
}

.status-dot.done {
  background: var(--accent);
  box-shadow: 0 0 0 6px rgba(31, 125, 103, 0.18);
}

.status-dot.reset {
  background: var(--danger);
  box-shadow: 0 0 0 6px rgba(180, 91, 79, 0.16);
}

.hero-title {
  max-width: 760px;
  margin: 0;
  font-size: clamp(2.4rem, 5vw, 5.1rem);
  font-weight: 850;
  line-height: 0.95;
}

.hero-title .quiet {
  color: var(--accent-dark);
}

.hero-copy {
  max-width: 650px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.6;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
}

.day-card {
  display: grid;
  gap: 13px;
  min-height: 218px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.86);
}

.day-number {
  font-size: 3rem;
  font-weight: 850;
  line-height: 1;
}

.day-label {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.4;
}

.progress-ring {
  --progress: 0deg;
  position: relative;
  display: grid;
  width: 132px;
  height: 132px;
  place-items: center;
  margin: 6px auto 0;
  border-radius: 50%;
  background: conic-gradient(var(--accent) var(--progress), var(--soft) 0deg);
}

.progress-ring::before {
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  background: var(--surface);
  content: "";
}

.progress-ring span {
  position: relative;
  z-index: 1;
  color: var(--accent-dark);
  font-size: 1.35rem;
  font-weight: 800;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 42px;
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 750;
  line-height: 1;
  text-decoration: none;
  transition:
    transform 180ms ease,
    box-shadow 180ms ease,
    background 180ms ease,
    border-color 180ms ease;
}

.button:hover,
.button:focus-visible {
  transform: translateY(-1px);
  outline: none;
  box-shadow: 0 10px 20px rgba(23, 33, 28, 0.12);
}

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

.button.primary:hover,
.button.primary:focus-visible {
  background: var(--accent-dark);
}

.button.secondary {
  border-color: var(--line);
}

.button.soft {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.button.warning {
  background: var(--danger-soft);
  color: #883e35;
}

.button.icon-only {
  width: 42px;
  padding: 0;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
  transform: none;
  box-shadow: none;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.section-title h2 {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 800;
}

.section-title p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

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

.metric {
  min-height: 108px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-3);
}

.metric span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 9px;
  color: var(--ink);
  font-size: 2rem;
  line-height: 1;
}

.metric small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.checkin-form {
  display: grid;
  gap: 20px;
}

.control-row {
  display: grid;
  gap: 10px;
}

.control-row label,
.control-label {
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 800;
}

.chip-row,
.mood-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip,
.mood-button {
  min-height: 38px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 750;
  transition:
    background 180ms ease,
    color 180ms ease,
    border-color 180ms ease;
}

.chip[aria-pressed="true"],
.mood-button[aria-pressed="true"] {
  border-color: rgba(31, 125, 103, 0.34);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.slider-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 52px;
  gap: 12px;
  align-items: center;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.slider-value {
  display: grid;
  min-height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-3);
  color: var(--accent-dark);
  font-weight: 850;
}

textarea,
input[type="text"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  outline: none;
  transition:
    border-color 180ms ease,
    box-shadow 180ms ease;
}

textarea {
  min-height: 112px;
  resize: vertical;
  padding: 12px;
  line-height: 1.5;
}

input[type="text"] {
  min-height: 42px;
  padding: 0 12px;
}

textarea:focus,
input[type="text"]:focus {
  border-color: rgba(31, 125, 103, 0.58);
  box-shadow: 0 0 0 4px rgba(31, 125, 103, 0.12);
}

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

.calendar-head {
  color: var(--muted);
  text-align: center;
  font-size: 0.72rem;
  font-weight: 800;
}

.day-cell {
  display: grid;
  min-height: 58px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-3);
  color: var(--muted);
  cursor: pointer;
  text-align: left;
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    background 180ms ease;
}

.day-cell:hover,
.day-cell:focus-visible {
  transform: translateY(-1px);
  outline: none;
  border-color: rgba(31, 125, 103, 0.38);
}

.day-cell .num {
  font-size: 0.8rem;
  font-weight: 850;
}

.day-cell .state {
  align-self: end;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--soft);
}

.day-cell.sober {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.day-cell.sober .state {
  background: var(--accent);
}

.day-cell.reset {
  background: var(--danger-soft);
  color: #883e35;
}

.day-cell.reset .state {
  background: var(--danger);
}

.day-cell.today {
  border-color: var(--amber);
  box-shadow: inset 0 0 0 1px rgba(217, 155, 43, 0.32);
}

.day-cell.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 125, 103, 0.14);
}

.detail-card {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-3);
}

.detail-card strong {
  display: block;
  margin-bottom: 8px;
}

.detail-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.milestone {
  display: grid;
  gap: 14px;
}

.milestone-track {
  height: 10px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--soft);
}

.milestone-fill {
  width: var(--fill, 0%);
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent), #71b78d);
}

.milestone-copy {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.milestone-copy strong {
  font-size: 1.65rem;
}

.milestone-copy span {
  color: var(--muted);
  font-size: 0.86rem;
}

.encouragement {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid rgba(217, 155, 43, 0.34);
  border-radius: var(--radius);
  background: var(--amber-soft);
}

.encouragement p {
  margin: 0;
  color: #654713;
  line-height: 1.5;
}

.focus-timer {
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr);
  gap: 15px;
  align-items: center;
}

.timer-face {
  display: grid;
  width: 108px;
  height: 108px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--accent-dark);
  font-size: 1.5rem;
  font-weight: 850;
}

.focus-copy p {
  margin: 0 0 12px;
  color: var(--muted);
  line-height: 1.5;
}

.plan-list {
  display: grid;
  gap: 9px;
  margin-top: 14px;
}

.plan-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-3);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 700;
}

.plan-item input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.reason-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.reason-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.reason {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-3);
  color: var(--muted);
  line-height: 1.4;
}

.reason button {
  flex: 0 0 auto;
}

.reflections {
  display: grid;
  gap: 10px;
}

.reflection {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-3);
}

.reflection strong {
  display: block;
  margin-bottom: 6px;
  font-size: 0.86rem;
}

.reflection p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.empty {
  padding: 16px;
  border: 1px dashed var(--soft);
  border-radius: var(--radius);
  color: var(--muted);
  line-height: 1.5;
}

.confetti {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  overflow: hidden;
}

.confetti i {
  position: absolute;
  top: -16px;
  display: block;
  width: 8px;
  height: 16px;
  border-radius: 2px;
  background: var(--accent);
  animation: fall 1200ms ease-out forwards;
}

.confetti i:nth-child(3n) {
  background: var(--amber);
}

.confetti i:nth-child(4n) {
  background: #8ec3a1;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 30;
  max-width: min(360px, calc(100vw - 44px));
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
  font-weight: 700;
  animation: slide-in 220ms ease-out;
}

.hidden {
  display: none !important;
}

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

@keyframes fall {
  0% {
    transform: translate3d(0, -20px, 0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translate3d(var(--x, 0), calc(100vh + 60px), 0) rotate(520deg);
    opacity: 0;
  }
}

@keyframes slide-in {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

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

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 16px;
  }

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

  .sidebar-footer {
    display: none;
  }

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

@media (max-width: 760px) {
  .main {
    padding: 18px 14px 24px;
  }

  .topbar,
  .hero-grid,
  .focus-timer {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .hero-title {
    font-size: clamp(2.15rem, 15vw, 4.2rem);
  }

  .day-card {
    min-height: auto;
  }

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

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

  .calendar-grid {
    gap: 6px;
  }

  .day-cell {
    min-height: 48px;
    padding: 6px;
  }
}

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

  .hero-actions,
  .top-actions,
  .reason-row {
    display: grid;
    grid-template-columns: 1fr;
  }

  .button {
    width: 100%;
  }
}
