:root {
  color-scheme: light;
  --paper: #f3f7f2;
  --surface: #ffffff;
  --surface-soft: #eef4f6;
  --ink: #202428;
  --muted: #627079;
  --line: #d8e0df;
  --earn: #17725f;
  --earn-soft: #dff2e8;
  --spend: #b4473d;
  --spend-soft: #f8e6df;
  --amber: #b7791f;
  --amber-soft: #f7edd4;
  --blue: #246a8d;
  --blue-soft: #e0eef5;
  --shadow: 0 18px 45px rgba(30, 41, 48, 0.11);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  border: 0;
}

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 18px 14px 88px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--blue);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.65rem, 8vw, 3.4rem);
  line-height: 0.95;
}

h2 {
  margin-bottom: 14px;
  font-size: 1.2rem;
}

h3 {
  margin-bottom: 8px;
  font-size: 0.96rem;
}

.balance-tile {
  min-width: 118px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: right;
}

.balance-tile span,
.balance-tile small,
.metric span,
.form-hint,
.item-meta,
.event-meta,
.empty-state,
.report-caption {
  color: var(--muted);
}

.balance-tile span,
.balance-tile small {
  display: block;
  font-size: 0.73rem;
  font-weight: 700;
}

.balance-tile strong {
  display: block;
  margin: 2px 0;
  font-size: clamp(1.6rem, 8vw, 2.65rem);
  line-height: 1;
}

.balance-tile.is-pulsing {
  animation: tile-pop 420ms cubic-bezier(0.2, 1.1, 0.2, 1);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.metric {
  min-height: 74px;
  padding: 12px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--blue);
  border-radius: var(--radius);
  background: var(--surface);
}

.metric span {
  display: block;
  margin-bottom: 9px;
  font-size: 0.73rem;
  font-weight: 750;
}

.metric strong {
  font-size: 1.35rem;
}

.metric-earn {
  border-left-color: var(--earn);
}

.metric-spend {
  border-left-color: var(--spend);
}

.metric-net {
  border-left-color: var(--amber);
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 5px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 10px 28px rgba(30, 41, 48, 0.08);
  backdrop-filter: blur(14px);
}

.tab {
  min-height: 40px;
  padding: 8px 5px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: clamp(0.72rem, 2.5vw, 0.92rem);
  font-weight: 750;
}

.tab.is-active {
  background: var(--ink);
  color: white;
}

.view-root {
  padding-top: 16px;
}

.layout-grid,
.dashboard-grid,
.setup-grid {
  display: grid;
  gap: 16px;
}

.dashboard-grid,
.setup-grid {
  grid-template-columns: 1fr;
}

.panel {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.review-panel {
  margin-bottom: 16px;
  border-color: #d8a23d;
  box-shadow: 0 0 0 3px rgba(216, 162, 61, 0.18);
}

#itemEditorPanel {
  scroll-margin-top: 18px;
}

#itemEditorPanel.is-editing {
  border-color: rgba(36, 106, 141, 0.55);
  box-shadow: 0 0 0 4px var(--blue-soft);
}

.panel-header {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}

.panel-header h2 {
  margin-bottom: 0;
}

.panel-header p {
  margin: 4px 0 0;
}

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

.category-section {
  display: grid;
  gap: 8px;
}

.category-title {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0;
  font-size: 0.9rem;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 99px;
  background: var(--blue);
}

.item-grid,
.event-list,
.report-grid,
.item-admin-list,
.category-list {
  display: grid;
  gap: 10px;
}

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

.item-grid-list {
  gap: 7px;
}

.item-card,
.event-row,
.admin-row,
.report-card,
.category-row {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.item-card {
  display: grid;
  grid-template-columns: 1fr;
  align-content: space-between;
  gap: 12px;
  min-height: 170px;
  padding: 14px;
  overflow: hidden;
}

.item-card-list {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  min-height: 0;
  padding: 10px 12px;
}

.item-text {
  min-width: 0;
}

.item-title {
  margin: 0 0 6px;
  font-size: 1rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.item-card-list .item-title {
  margin-bottom: 4px;
  font-size: 0.94rem;
}

.item-description,
.event-meta,
.form-hint,
.empty-state,
.report-caption {
  font-size: 0.82rem;
  line-height: 1.35;
}

.item-description {
  margin: 8px 0 0;
  color: var(--muted);
}

.item-card-list .item-description {
  display: none;
}

.item-card.is-complete-today {
  border-color: rgba(23, 114, 95, 0.32);
  background: linear-gradient(0deg, rgba(216, 243, 232, 0.42), rgba(255, 255, 255, 0.96));
}

.item-card.is-complete-today .item-title {
  color: var(--muted);
}

.item-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.item-tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.item-tag-done {
  background: var(--earn-soft);
  color: var(--earn);
}

.item-tag-progress {
  background: rgba(196, 126, 32, 0.13);
  color: var(--amber);
}

.item-card-list .item-tag {
  min-height: 20px;
  padding: 2px 7px;
  font-size: 0.66rem;
}

.point-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 68px;
  min-height: 32px;
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 850;
}

.point-badge.earn {
  background: var(--earn-soft);
  color: var(--earn);
}

.point-badge.spend {
  background: var(--spend-soft);
  color: var(--spend);
}

.item-action {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.item-action-controls {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
}

.item-card-list .item-action {
  width: auto;
  min-width: 222px;
  justify-content: flex-end;
}

.item-card-list .point-badge {
  min-width: 56px;
  min-height: 30px;
  padding: 5px 9px;
}

.item-card-list .action-button {
  min-height: 36px;
  min-width: 82px;
  padding: 8px 11px;
}

.item-more-button {
  min-width: 36px;
  min-height: 36px;
  padding: 0 8px;
  letter-spacing: 0;
}

.item-menu-wrapper {
  position: relative;
}

.item-action-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  display: grid;
  min-width: 172px;
  gap: 3px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  box-shadow: 0 14px 34px rgba(30, 41, 48, 0.16);
}

.item-action-menu[hidden] {
  display: none;
}

.menu-action {
  min-height: 34px;
  padding: 8px 10px;
  border-radius: 5px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  font-weight: 800;
}

.menu-action:hover,
.menu-action:focus-visible {
  background: var(--surface-soft);
}

.menu-action:disabled {
  cursor: not-allowed;
  color: var(--muted);
  opacity: 0.55;
}

.action-button,
.secondary-button,
.danger-button,
.ghost-button,
.icon-button {
  min-height: 40px;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 800;
  transition: transform 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
}

.action-button {
  min-width: 92px;
  max-width: 100%;
  padding: 10px 13px;
  color: white;
  box-shadow: 0 9px 20px rgba(23, 114, 95, 0.22);
}

.action-button.earn {
  background: var(--earn);
}

.action-button.spend {
  background: var(--spend);
  box-shadow: 0 9px 20px rgba(180, 71, 61, 0.2);
}

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

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
}

.secondary-button,
.ghost-button,
.danger-button,
.icon-button {
  padding: 9px 11px;
}

.secondary-button {
  background: var(--ink);
  color: white;
}

.ghost-button {
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--ink);
}

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

.icon-button {
  display: inline-grid;
  place-items: center;
  min-width: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
}

.action-button:active,
.secondary-button:active,
.ghost-button:active,
.danger-button:active,
.icon-button:active,
.tab:active {
  transform: translateY(2px) scale(0.98);
}

.button-row,
.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.event-row,
.admin-row,
.category-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
}

.event-title,
.admin-title {
  margin: 0 0 5px;
  font-weight: 800;
}

.event-delta {
  min-width: 56px;
  text-align: right;
  font-weight: 900;
}

.event-delta.earn {
  color: var(--earn);
}

.event-delta.spend {
  color: var(--spend);
}

.event-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.empty-state {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.62);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.filter-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.field {
  display: grid;
  gap: 6px;
}

.field label,
.toggle-field {
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 800;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
}

.field textarea {
  min-height: 72px;
  resize: vertical;
}

.field.is-disabled {
  opacity: 0.45;
}

.field.is-disabled input,
.field.is-disabled select,
.field.is-disabled textarea {
  cursor: not-allowed;
  background: var(--surface-soft);
}

.toggle-field {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 42px;
}

.toggle-field input {
  width: 18px;
  height: 18px;
}

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

.day-toggle {
  display: flex;
  gap: 7px;
  align-items: center;
  min-height: 36px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 800;
}

.day-toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
}

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

.report-card {
  min-height: 100px;
  padding: 14px;
}

.report-card strong {
  display: block;
  margin: 7px 0 4px;
  font-size: 1.6rem;
}

.bar-list {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.bar-row {
  display: grid;
  gap: 5px;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.82rem;
  font-weight: 800;
}

.bar-track {
  height: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--surface-soft);
}

.bar-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
}

.bar-fill.earn {
  background: var(--earn);
}

.bar-fill.spend {
  background: var(--spend);
}

.toast-root {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 50;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 24px));
}

.toast {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--blue);
  border-radius: var(--radius);
  background: white;
  box-shadow: var(--shadow);
  animation: toast-in 180ms ease-out;
  font-weight: 800;
}

.toast.earn {
  border-left-color: var(--earn);
}

.toast.spend {
  border-left-color: var(--spend);
}

.toast.warn {
  border-left-color: var(--amber);
}

.burst-root {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
}

.burst {
  position: absolute;
  transform: translate(-50%, -50%);
}

.burst-value {
  display: inline-grid;
  place-items: center;
  min-width: 60px;
  min-height: 34px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--ink);
  color: white;
  font-weight: 950;
  box-shadow: var(--shadow);
  animation: burst-value 820ms ease-out forwards;
}

.spark {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 7px;
  height: 7px;
  border-radius: 99px;
  background: var(--earn);
  animation: spark-pop 650ms ease-out forwards;
}

.spark.spend {
  background: var(--spend);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@keyframes tile-pop {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.045);
  }
  100% {
    transform: scale(1);
  }
}

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

@keyframes burst-value {
  0% {
    opacity: 0;
    transform: translateY(10px) scale(0.86);
  }
  20% {
    opacity: 1;
    transform: translateY(0) scale(1.04);
  }
  100% {
    opacity: 0;
    transform: translateY(-34px) scale(0.98);
  }
}

@keyframes spark-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.8);
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) scale(0.2);
  }
}

@media (min-width: 680px) {
  .app-shell {
    padding: 28px 22px 72px;
  }

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

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

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

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

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

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

  .field-wide {
    grid-column: 1 / -1;
  }

  .tabs {
    position: static;
  }
}

@media (min-width: 980px) {
  .dashboard-grid {
    grid-template-columns: 1.08fr 0.92fr;
  }

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

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

  .dashboard-grid .item-grid-list,
  .item-grid-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .item-card-list {
    grid-template-columns: 1fr;
  }

  .item-card-list .item-action {
    width: 100%;
    min-width: 0;
    justify-content: space-between;
  }
}

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