:root {
  color-scheme: light;
  --page: #f4f1ea;
  --text: #24221f;
  --muted: #777066;
  --subtle: #625d55;
  --panel: #ebe6dc;
  --surface: #fbf8f1;
  --input: #f8f5ee;
  --border: #d9d3c8;
  --border-soft: #ded8cd;
  --divider: #ece7df;
  --soft: #e7e1d6;
  --soft-2: #f1ece3;
  --soft-3: #ebe5da;
  --badge: #e3ddd2;
  --button: #24221f;
  --button-text: #f8f5ee;
  --danger: #6b3b31;
  --danger-bg: #e5ddd1;
  --placeholder: #938b80;
  --warning-bg: #eee7da;
  --warning-border: #cfc6b7;
  --warning-text: #655d52;
  --shadow: rgba(50, 45, 38, 0.04);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #171816;
  --text: #ecebe6;
  --muted: #a7a39a;
  --subtle: #bbb7ae;
  --panel: #232420;
  --surface: #20211e;
  --input: #292a26;
  --border: #3a3b36;
  --border-soft: #343530;
  --divider: #30312d;
  --soft: #2e302b;
  --soft-2: #292a26;
  --soft-3: #33342f;
  --badge: #2b2c28;
  --button: #ecebe6;
  --button-text: #1b1c19;
  --danger: #e0a99f;
  --danger-bg: #392b28;
  --placeholder: #77786f;
  --warning-bg: #312d25;
  --warning-border: #4a4337;
  --warning-text: #c9bda9;
  --shadow: rgba(0, 0, 0, 0.2);
}

html {
  background: var(--page);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  background: var(--page);
  color: var(--text);
}

button,
input,
textarea,
select {
  font: inherit;
}

button,
summary {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  box-sizing: border-box;
  min-height: 100dvh;
  padding: max(20px, env(safe-area-inset-top)) 20px max(32px, env(safe-area-inset-bottom));
}

.app {
  width: min(100%, 620px);
  margin: 0 auto;
}

.top-bar {
  display: flex;
  justify-content: flex-end;
}

.theme-toggle {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--subtle);
  font-size: 0.8rem;
  font-weight: 750;
  cursor: pointer;
}

.theme-toggle:active {
  transform: translateY(1px);
}

.app-header {
  padding: 12px 2px 28px;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: clamp(3.4rem, 15vw, 5.8rem);
  letter-spacing: -0.075em;
  line-height: 0.9;
}

.subtitle {
  max-width: 31rem;
  margin: 20px 0 0;
  color: var(--subtle);
  font-size: 1rem;
  line-height: 1.55;
}

.add-activity {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel);
}

.activity-input,
.edit-input {
  box-sizing: border-box;
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  outline: none;
  background: var(--input);
  color: var(--text);
  -webkit-text-fill-color: var(--text);
  caret-color: var(--text);
  -webkit-appearance: none;
  appearance: none;
  opacity: 1;
}

.activity-input::placeholder,
.edit-input::placeholder {
  color: var(--placeholder);
  -webkit-text-fill-color: var(--placeholder);
  opacity: 1;
}

.activity-input:focus-visible,
.edit-input:focus-visible {
  box-shadow: 0 0 0 2px var(--text);
}

.add-button,
.done-button,
.save-button,
.delete-button,
.cancel-delete-button {
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  font-weight: 750;
  cursor: pointer;
}

.add-button {
  padding: 0 18px;
  background: var(--button);
  color: var(--button-text);
}

.add-button:disabled,
.save-button:disabled {
  cursor: default;
  opacity: 0.38;
}

.storage-warning {
  margin: 12px 4px 0;
  padding: 10px 12px;
  border: 1px solid var(--warning-border);
  border-radius: 12px;
  background: var(--warning-bg);
  color: var(--warning-text);
  font-size: 0.86rem;
  line-height: 1.45;
}

.activities {
  margin-top: 34px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding: 0 2px;
}

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

.activity-count {
  display: grid;
  min-width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 999px;
  background: var(--badge);
  color: var(--subtle);
  font-size: 0.78rem;
  font-weight: 750;
}

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

.activity-card {
  padding: 16px;
  border: 1px solid var(--border-soft);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 8px 24px var(--shadow);
  animation: card-in 180ms ease-out both;
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
}

.activity-card:active {
  transform: scale(0.997);
}

.activity-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
}

.activity-copy {
  min-width: 0;
}

.activity-copy h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 750;
  letter-spacing: -0.015em;
  line-height: 1.3;
}

.last-done {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.last-done-exact {
  margin: 3px 0 0;
  color: var(--subtle);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.done-button {
  padding: 0 14px;
  background: var(--soft);
  color: var(--text);
  white-space: nowrap;
}

.activity-secondary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--divider);
}

.history-panel,
.manage-panel {
  min-width: 0;
}

.history-panel summary,
.manage-panel summary {
  box-sizing: border-box;
  min-height: 42px;
  padding: 11px 12px;
  border-radius: 11px;
  background: var(--soft-2);
  color: var(--subtle);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
  list-style-position: inside;
}

.history-panel[open] summary,
.manage-panel[open] summary {
  background: var(--soft-3);
  color: var(--text);
}

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

.history-entry {
  display: grid;
  gap: 2px;
  padding: 9px 10px;
  border: 1px solid var(--divider);
  border-radius: 10px;
  background: var(--surface);
}

.history-date {
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.history-relative {
  color: var(--muted);
  font-size: 0.76rem;
}

.history-empty,
.history-more {
  margin: 10px 2px 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

.history-more {
  padding: 0 8px;
}

.manage-content {
  margin-top: 10px;
  padding: 12px;
  border-radius: 12px;
  background: var(--soft-2);
}

.manage-label {
  display: block;
  margin: 0 0 6px 2px;
  color: var(--subtle);
  font-size: 0.78rem;
  font-weight: 700;
}

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

.edit-input {
  min-height: 44px;
  background: var(--surface);
}

.save-button {
  min-height: 44px;
  padding: 0 14px;
  background: var(--button);
  color: var(--button-text);
}

.delete-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.delete-button,
.cancel-delete-button {
  min-height: 40px;
  padding: 0 12px;
}

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

.cancel-delete-button {
  background: transparent;
  color: var(--subtle);
}

.delete-hint {
  flex-basis: 100%;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.35;
}

.add-button:active,
.done-button:active,
.save-button:active,
.delete-button:active,
.cancel-delete-button:active {
  transform: translateY(1px);
}

.empty-state {
  padding: 34px 22px;
  border: 1px dashed var(--border);
  border-radius: 18px;
  background: linear-gradient(180deg, transparent, var(--surface));
  color: var(--muted);
  text-align: center;
}

.empty-state::before {
  content: "◷";
  display: grid;
  width: 46px;
  height: 46px;
  margin: 0 auto 12px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--soft-2);
  color: var(--subtle);
  font-size: 1.35rem;
}

.empty-state p {
  margin: 5px auto 0;
  max-width: 25rem;
  font-size: 0.9rem;
  line-height: 1.5;
}

.empty-state .empty-title {
  margin-top: 0;
  color: var(--text);
  font-size: 1rem;
  font-weight: 750;
}

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

@media (prefers-reduced-motion: reduce) {
  .activity-card {
    animation: none;
    transition: none;
  }

  .theme-toggle:active,
  .add-button:active,
  .done-button:active,
  .save-button:active,
  .delete-button:active,
  .cancel-delete-button:active {
    transform: none;
  }
}

@media (max-width: 540px) {
  .activity-secondary {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 430px) {
  .app-shell {
    padding-right: 16px;
    padding-left: 16px;
  }

  .activity-main {
    grid-template-columns: 1fr;
    gap: 13px;
  }

  .done-button {
    width: 100%;
  }

  .edit-row {
    grid-template-columns: 1fr;
  }

  .save-button {
    width: 100%;
  }
}
