:root {
  --paper: #fffdf8;
  --ink: #243036;
  --muted: #687477;
  --line: #ded8ca;
  --green: #2f8f6b;
  --green-dark: #1f6b51;
  --blue: #33658a;
  --yellow: #f0b84f;
  --red: #d85f4f;
  --shadow: 0 18px 45px rgba(42, 49, 54, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(240, 184, 79, 0.24), transparent 34rem),
    linear-gradient(135deg, #f6f3ec 0%, #edf4ef 52%, #eef3f8 100%);
  color: var(--ink);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1060px, calc(100% - 28px));
  margin: 0 auto;
  padding: 22px 0 34px;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

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

.nav-link {
  display: inline-grid;
  place-items: center;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--blue);
  font-weight: 800;
  text-decoration: none;
}

.eyebrow,
.section-label,
.group-kicker {
  margin: 0;
  color: var(--green-dark);
  font-size: 0.78rem;
  font-weight: 800;
}

h1 {
  margin: 4px 0 0;
  font-size: clamp(1.7rem, 4vw, 2.7rem);
  line-height: 1.12;
  letter-spacing: 0;
}

.day-card,
.panel,
.hero-panel,
.redeem-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.88);
  box-shadow: var(--shadow);
}

.day-card {
  min-width: 112px;
  padding: 12px 14px;
  text-align: right;
}

.day-card span,
.day-card strong {
  display: block;
}

.day-card span,
.setup-form span,
.identity-box span,
.redeem-head span {
  color: var(--muted);
  font-size: 0.82rem;
}

.day-card strong {
  margin-top: 2px;
  font-size: 1.1rem;
}

.panel {
  margin-bottom: 18px;
  padding: 18px;
}

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

.entry-card {
  display: grid;
  min-height: 230px;
  align-content: end;
  gap: 12px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
  box-shadow: var(--shadow);
}

.entry-card span {
  color: var(--green-dark);
  font-size: 0.82rem;
  font-weight: 900;
}

.entry-card strong {
  font-size: clamp(1.4rem, 3vw, 2.1rem);
  line-height: 1.16;
}

.entry-card p {
  max-width: 34rem;
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.child-entry {
  background: linear-gradient(145deg, rgba(255, 253, 248, 0.94), rgba(223, 238, 231, 0.94));
}

.parent-entry {
  background: linear-gradient(145deg, rgba(255, 253, 248, 0.94), rgba(238, 243, 248, 0.94));
}

.setup-panel {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 18px;
  align-items: end;
}

.setup-panel h2,
.redeem-head h2,
.group-head h2 {
  margin: 3px 0 0;
  font-size: 1.08rem;
  letter-spacing: 0;
}

.setup-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
}

label {
  display: grid;
  gap: 5px;
}

input {
  width: 100%;
  min-height: 40px;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

.setup-form button,
.secondary-button {
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #fff;
  background: var(--green-dark);
  font-weight: 800;
}

.secondary-button {
  color: var(--blue);
  background: var(--paper);
}

.secondary-button.primary {
  color: #fff;
  background: var(--green-dark);
}

.secondary-button.danger {
  color: var(--red);
}

.hero-panel {
  display: grid;
  grid-template-columns: 190px 1fr;
  gap: 24px;
  align-items: center;
  min-height: 170px;
  padding: 24px;
}

.progress-visual {
  position: relative;
  height: 126px;
  border-radius: 8px;
  background: linear-gradient(160deg, #dfeee7, #f9f1d8);
  overflow: hidden;
}

.progress-visual::before,
.progress-visual::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 40px;
  background: linear-gradient(90deg, #4f9b77, #77b255);
}

.progress-visual::after {
  left: auto;
  width: 56px;
  height: 78px;
  right: 22px;
  bottom: 20px;
  border-radius: 28px 28px 4px 4px;
  background: var(--green);
  box-shadow: -52px 30px 0 -18px var(--blue);
}

.sun {
  position: absolute;
  width: 38px;
  height: 38px;
  top: 18px;
  left: 20px;
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 0 0 0 10px rgba(240, 184, 79, 0.2);
}

.book {
  position: absolute;
  left: 42px;
  bottom: 28px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 84px;
  height: 46px;
  transform: rotate(-5deg);
  filter: drop-shadow(0 8px 9px rgba(36, 48, 54, 0.22));
}

.book span {
  background: #fffdf8;
  border: 3px solid var(--blue);
}

.book span:first-child {
  border-radius: 6px 0 0 6px;
}

.book span:last-child {
  border-left: 0;
  border-radius: 0 6px 6px 0;
}

.progress-row {
  display: grid;
  grid-template-columns: 1fr 58px;
  gap: 12px;
  align-items: center;
  margin-top: 12px;
}

.progress-track {
  height: 18px;
  border-radius: 999px;
  background: #e7e0d2;
  overflow: hidden;
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--yellow));
  transition: width 180ms ease;
}

#progressText {
  text-align: right;
  font-size: 1.18rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 150px));
  gap: 10px;
  margin-top: 14px;
}

.stats-grid div {
  min-height: 62px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.54);
}

.stats-grid span,
.stats-grid strong {
  display: block;
}

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

.stats-grid strong {
  margin-top: 2px;
  color: var(--green-dark);
  font-size: 1.35rem;
}

.status-text {
  min-height: 28px;
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.status-banner {
  margin: 0 0 18px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.78);
  color: var(--muted);
  line-height: 1.5;
}

.controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: end;
  margin: 18px 0;
}

.child-controls {
  grid-template-columns: 1fr auto;
}

.identity-box {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 160px));
  gap: 10px;
}

.control-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(78px, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.8);
}

.segment,
.icon-button {
  border: 0;
  border-radius: 6px;
}

.segment {
  min-height: 40px;
  padding: 0 14px;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
}

.segment.active {
  color: #fff;
  background: var(--green-dark);
}

.icon-button {
  width: 42px;
  height: 42px;
  color: var(--blue);
  background: var(--paper);
  border: 1px solid var(--line);
  font-size: 1.15rem;
}

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

.task-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.9);
  overflow: hidden;
}

.group-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
}

.group-count {
  min-width: 44px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #edf4ef;
  color: var(--green-dark);
  text-align: center;
  font-size: 0.78rem;
  font-weight: 800;
}

.task-list {
  display: grid;
}

.task-item {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 48px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(222, 216, 202, 0.72);
  cursor: pointer;
}

.task-item:last-child {
  border-bottom: 0;
}

.task-item input {
  position: absolute;
  opacity: 0;
}

.checkmark {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 2px solid #9aa7a6;
  border-radius: 6px;
  background: #fff;
}

.checkmark::after {
  content: "";
  width: 11px;
  height: 6px;
  border-left: 3px solid #fff;
  border-bottom: 3px solid #fff;
  transform: rotate(-45deg) translate(1px, -1px);
  opacity: 0;
}

.task-item input:checked + .checkmark {
  border-color: var(--green);
  background: var(--green);
}

.task-item input:checked + .checkmark::after {
  opacity: 1;
}

.task-item input:checked ~ .task-text {
  color: var(--muted);
  text-decoration: line-through;
}

.task-text {
  line-height: 1.42;
}

.points-badge {
  min-width: 44px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #f9f1d8;
  color: #8a5e14;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 800;
}

.redeem-panel {
  margin-top: 18px;
  padding: 18px;
}

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

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

.redeem-card {
  min-height: 112px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}

.redeem-card strong,
.redeem-card span {
  display: block;
}

.redeem-card strong {
  font-size: 0.98rem;
  line-height: 1.35;
}

.redeem-card span {
  margin: 6px 0 10px;
  color: var(--muted);
  font-size: 0.84rem;
}

.redeem-card button {
  width: 100%;
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  color: #fff;
  background: var(--blue);
  font-weight: 800;
}

.redeem-card button:disabled {
  color: #7b8588;
  background: #e5e2d8;
  cursor: not-allowed;
}

.history-panel {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.history-panel ul {
  margin: 8px 0 0;
  padding-left: 1.2rem;
  color: var(--muted);
  line-height: 1.65;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.75fr);
  gap: 16px;
  margin-bottom: 18px;
}

.admin-panel {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.88);
  box-shadow: var(--shadow);
}

.admin-panel + .admin-panel {
  margin-top: 18px;
}

.admin-list {
  display: grid;
  gap: 8px;
}

.admin-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}

.admin-row strong,
.admin-row span {
  display: block;
}

.admin-row strong {
  line-height: 1.35;
}

.admin-row span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.86rem;
}

.plain-list {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--muted);
  line-height: 1.7;
}

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

.template-editor {
  display: grid;
  gap: 12px;
}

.edit-group {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(222, 216, 202, 0.9);
  border-radius: 8px;
  background: #fbfaf5;
}

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

.edit-group-head {
  grid-template-columns: minmax(0, 0.75fr) minmax(0, 1fr) auto;
}

.edit-reward-row {
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr) 86px 86px auto;
}

.inline-check {
  display: flex;
  gap: 6px;
  align-items: center;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
}

.inline-check input {
  width: 18px;
  min-height: 18px;
}

.mini-button {
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--blue);
  cursor: pointer;
  font-weight: 800;
}

.mini-button:disabled {
  color: #7b8588;
  background: #e5e2d8;
  cursor: not-allowed;
}

.mini-button.danger {
  color: var(--red);
}

.empty-state {
  grid-column: 1 / -1;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.78);
  color: var(--muted);
}

@media (max-width: 780px) {
  .app-shell {
    width: min(100% - 20px, 540px);
    padding-top: 14px;
  }

  .topbar,
  .setup-panel,
  .hero-panel,
  .controls,
  .admin-grid,
  .entry-grid {
    grid-template-columns: 1fr;
  }

  .header-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .day-card {
    text-align: left;
  }

  .setup-form,
  .identity-box,
  .checklist,
  .redeem-options,
  .edit-row,
  .edit-group-head,
  .edit-reward-row {
    grid-template-columns: 1fr;
  }

  .entry-card {
    min-height: 180px;
  }

  .control-actions {
    justify-content: stretch;
    flex-wrap: wrap;
  }

  .segmented {
    flex: 1;
  }

  .editor-head {
    align-items: stretch;
    flex-direction: column;
  }

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