* {
  box-sizing: border-box;
}

:root {
  --bg: #f4efe6;
  --paper: #fffdf7;
  --paper-2: #fbf6ec;
  --paper-3: #f1e8da;

  --ink: #3b332d;
  --muted: #7b7067;
  --light-ink: #9a8d82;

  --line: #dfd2c2;
  --line-dark: #c9b9a6;

  --stamp: #b85f4b;
  --stamp-soft: rgba(184, 95, 75, 0.12);
  --stamp-line: rgba(184, 95, 75, 0.38);

  --green: #8fa783;
  --green-dark: #607855;
  --green-soft: rgba(143, 167, 131, 0.18);

  --gold: #d8a85f;
  --gold-soft: rgba(216, 168, 95, 0.18);

  --pink: #d7aa9b;
  --pink-soft: rgba(215, 170, 155, 0.22);

  --subcategory-video: #6f7fa8;
  --subcategory-practice: #6e9b72;
  --subcategory-note: #c28a5a;
  --subcategory-w3schools-bg: #f1dde0;
  --subcategory-w3schools-text: #7a4b52;
  --subcategory-w3schools-line: rgba(122, 75, 82, 0.22);

  --shadow: 0 18px 42px rgba(59, 51, 45, 0.1);
  --soft-shadow: 0 10px 26px rgba(59, 51, 45, 0.075);

  --radius-xl: 30px;
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-pill: 999px;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: #f4efe6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  content: none;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  opacity: 0.55;
}

body.is-busy button {
  cursor: not-allowed;
}

.app {
  position: relative;
  width: min(100% - 32px, 760px);
  margin: 0 auto;
  padding: 24px 0 56px;
}

/* === 首頁封面公文 === */

.hero {
  position: relative;
  overflow: hidden;
  padding: 30px 24px 24px;
  border-radius: var(--radius-xl);
  background:
    linear-gradient(135deg, rgba(255, 253, 247, 0.95), rgba(250, 244, 235, 0.92)),
    var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.hero::before {
  content: "";
  position: absolute;
  inset: 14px;
  border: 1px dashed rgba(184, 95, 75, 0.24);
  border-radius: 22px;
  pointer-events: none;
}

.hero::after {
  content: "本週限定";
  position: absolute;
  right: 18px;
  bottom: 18px;
  width: 86px;
  height: 86px;
  display: grid;
  place-items: center;
  border: 3px double var(--stamp-line);
  border-radius: 50%;
  color: rgba(184, 95, 75, 0.48);
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0.08em;
  transform: rotate(-13deg);
  pointer-events: none;
}

.eyebrow {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  padding: 6px 10px;
  border-radius: var(--radius-pill);
  background: var(--stamp-soft);
  color: var(--stamp);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.16em;
}

.eyebrow::before {
  content: "●";
  font-size: 9px;
}

.hero h1 {
  position: relative;
  z-index: 1;
  max-width: 11em;
  margin: 0;
  font-size: clamp(32px, 8vw, 44px);
  line-height: 1.1;
  letter-spacing: -0.045em;
}

.quote {
  position: relative;
  z-index: 1;
  margin: 18px 0 0;
  padding: 13px 15px;
  border-radius: var(--radius-md);
  background: #fff1d6;
  border: 1px solid rgba(216, 168, 95, 0.34);
  color: #6d451a;
  font-size: 15px;
  font-weight: 650;
  line-height: 1.6;
}

.refresh-btn {
  position: relative;
  z-index: 1;
  margin-top: 16px;
  border: 0;
  border-radius: var(--radius-pill);
  padding: 10px 15px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  font-weight: 850;
  box-shadow: 0 8px 18px rgba(59, 51, 45, 0.16);
}

.refresh-btn:hover {
  background: var(--green-dark);
}

.week-range {
  position: relative;
  z-index: 1;
  margin-top: 15px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.week-range span:first-child {
  padding: 5px 10px;
  border-radius: var(--radius-pill);
  background: var(--paper-3);
  color: #815c32;
  font-size: 13px;
  font-weight: 850;
}

.week-range time {
  font-weight: 900;
  color: var(--ink);
}

/* === 區塊公文紙 === */

.plan-card,
.progress-card,
.task-section,
.standard-section {
  position: relative;
  margin-top: 18px;
  padding: 21px;
  border-radius: var(--radius-lg);
  background:
    linear-gradient(180deg, rgba(255, 253, 247, 0.95), rgba(251, 246, 236, 0.92)),
    var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--soft-shadow);
}

.plan-card::before,
.progress-card::before,
.task-section::before,
.standard-section::before {
  content: "";
  position: absolute;
  top: 14px;
  left: 16px;
  right: 16px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(184, 95, 75, 0.22), transparent);
}

.section-header {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 17px;
}

.section-header h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.25;
  letter-spacing: -0.025em;
}

.section-note {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

/* === 12 週主線卡片 === */

.plan-card {
  overflow: hidden;
}

.plan-card::after {
  content: "12W";
  position: absolute;
  right: 18px;
  top: 18px;
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid rgba(96, 120, 85, 0.28);
  color: rgba(96, 120, 85, 0.48);
  font-size: 15px;
  font-weight: 950;
  letter-spacing: 0.05em;
  transform: rotate(8deg);
  pointer-events: none;
}

.plan-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 8px;
  padding: 5px 10px;
  border-radius: var(--radius-pill);
  background: var(--green-soft);
  color: var(--green-dark);
  font-size: 13px;
  font-weight: 950;
  letter-spacing: 0.08em;
}

.plan-label::before {
  content: "▣";
  font-size: 12px;
}

.week-tabs {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
  padding: 6px;
  border-radius: var(--radius-pill);
  background: var(--paper-3);
  border: 1px solid rgba(223, 210, 194, 0.8);
}

.week-tab {
  border: 0;
  border-radius: var(--radius-pill);
  padding: 9px 12px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 900;
}

.week-tab.is-active {
  background: var(--ink);
  color: #fff;
  box-shadow: 0 8px 18px rgba(59, 51, 45, 0.14);
}

.plan-content {
  position: relative;
  z-index: 1;
  padding: 17px;
  border-radius: 20px;
  background:
    linear-gradient(135deg, rgba(255, 253, 247, 0.96), rgba(244, 239, 230, 0.9)),
    var(--paper-2);
  border: 1px solid rgba(223, 210, 194, 0.92);
}

.plan-kicker {
  margin: 0 0 7px;
  color: var(--stamp);
  font-size: 13px;
  font-weight: 950;
  letter-spacing: 0.12em;
}

.plan-content h3 {
  margin: 0;
  color: var(--ink);
  font-size: 21px;
  line-height: 1.35;
  letter-spacing: -0.02em;
}

.achievement-box {
  margin-top: 14px;
  padding: 14px 15px;
  border-radius: var(--radius-md);
  background: #fff8e8;
  border: 1px solid rgba(216, 168, 95, 0.3);
}

.achievement-box span {
  display: inline-flex;
  margin-bottom: 7px;
  color: #8a5a28;
  font-size: 13px;
  font-weight: 950;
  letter-spacing: 0.08em;
}

.achievement-box p {
  margin: 0;
  color: #5f4630;
  font-size: 15px;
  font-weight: 650;
  line-height: 1.7;
}

.complete-week-btn {
  position: relative;
  z-index: 1;
  width: 100%;
  margin-top: 14px;
  border: 0;
  border-radius: var(--radius-pill);
  padding: 11px 16px;
  background: var(--green-dark);
  color: #fff;
  font-size: 14px;
  font-weight: 950;
  box-shadow: 0 8px 18px rgba(96, 120, 85, 0.16);
}

.complete-week-btn:hover {
  background: var(--stamp);
}

/* === 本週進度 === */

.progress-list {
  display: grid;
  gap: 12px;
}

.progress-item {
  padding: 14px 15px 15px;
  border-radius: var(--radius-md);
  background:
    linear-gradient(180deg, rgba(255, 253, 247, 0.96), rgba(251, 246, 236, 0.92)),
    var(--paper-2);
  border: 1px solid rgba(223, 210, 194, 0.82);
  box-shadow: 0 8px 18px rgba(59, 51, 45, 0.045);
}

.progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.progress-row span {
  color: var(--muted);
  font-weight: 850;
}

.progress-row strong {
  min-width: 72px;
  text-align: right;
  color: var(--ink);
  font-size: 20px;
  font-weight: 950;
}

.progress-track {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 15px;
  border-radius: var(--radius-pill);
  background:
    linear-gradient(180deg, rgba(241, 232, 218, 0.95), rgba(232, 219, 203, 0.9)),
    var(--paper-3);
  border: 1px solid rgba(201, 185, 166, 0.55);
}

.progress-track::after {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: var(--radius-pill);
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.22),
    rgba(255, 255, 255, 0)
  );
  pointer-events: none;
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: var(--radius-pill);
  background:
    linear-gradient(90deg, #9fbd8c, #6f9a65),
    var(--green);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
  transition: width 0.32s ease;
}

#standardProgressFill {
  background:
    linear-gradient(90deg, #dfbd78, #b9854a),
    var(--gold);
}

/* === 新增表單 === */

.add-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-bottom: 17px;
}

.task-add-form {
  grid-template-columns: 1fr 132px 132px 98px auto;
}

.add-form input,
.add-form select {
  width: 100%;
  min-height: 43px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 10px 14px;
  background: #fffefb;
  color: var(--ink);
  font-size: 14px;
}

.add-form input::placeholder {
  color: #a7998c;
}

.add-form select {
  appearance: none;
  padding-right: 34px;
  background:
    linear-gradient(45deg, transparent 50%, var(--light-ink) 50%),
    linear-gradient(135deg, var(--light-ink) 50%, transparent 50%),
    #fffefb;
  background-position:
    calc(100% - 17px) 18px,
    calc(100% - 12px) 18px,
    100% 0;
  background-size:
    5px 5px,
    5px 5px,
    2.5em 100%;
  background-repeat: no-repeat;
}

.add-form input:focus,
.add-form select:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgba(143, 167, 131, 0.18);
}

.add-btn {
  border: 0;
  border-radius: var(--radius-pill);
  padding: 10px 16px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  font-weight: 900;
  white-space: nowrap;
}

.add-btn:hover {
  background: var(--stamp);
}

/* === 清單 === */

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

.category-heading {
  position: relative;
  margin-top: 13px;
  padding: 10px 13px 10px 15px;
  border-radius: 15px;
  font-weight: 950;
  letter-spacing: 0.04em;
}

.category-heading:first-child {
  margin-top: 0;
}

.category-heading::after {
  content: "分類章";
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%) rotate(-5deg);
  padding: 3px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 900;
}

.category-heading.programming {
  background: #e7edf3;
  border: 1px solid rgba(69, 99, 122, 0.18);
  color: #45637a;
}

.category-heading.programming::after {
  border: 1px solid rgba(69, 99, 122, 0.24);
  color: rgba(69, 99, 122, 0.52);
}

.category-heading.wellness {
  background: #efe7ea;
  border: 1px solid rgba(122, 93, 105, 0.18);
  color: #7a5d69;
}

.category-heading.wellness::after {
  border: 1px solid rgba(122, 93, 105, 0.24);
  color: rgba(122, 93, 105, 0.52);
}

.category-heading.interest {
  background: #f0e4d5;
  border: 1px solid rgba(138, 95, 50, 0.18);
  color: #8a5f32;
}

.category-heading.interest::after {
  border: 1px solid rgba(138, 95, 50, 0.24);
  color: rgba(138, 95, 50, 0.52);
}

.subcategory-heading {
  display: none;
}

.empty-message {
  padding: 15px 16px;
  border-radius: var(--radius-md);
  background: var(--paper-2);
  color: #6b5b48;
  line-height: 1.65;
  border: 1px dashed rgba(123, 112, 103, 0.32);
}

/* === 任務案件單 === */

.task-item {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "check content actions";
  align-items: center;
  gap: 12px;
  padding: 15px 16px;
  border-radius: 20px;
  background:
    linear-gradient(180deg, rgba(255, 253, 247, 0.96), rgba(250, 246, 238, 0.96)),
    var(--paper);
  border: 1px solid rgba(223, 210, 194, 0.92);
  box-shadow: 0 8px 18px rgba(59, 51, 45, 0.06);
}

.task-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 12px;
  bottom: 12px;
  width: 4px;
  border-radius: 0 8px 8px 0;
  background: var(--green);
  opacity: 0.72;
}

.task-item input[type="checkbox"] {
  grid-area: check;
  width: 20px;
  height: 20px;
  accent-color: var(--green-dark);
  z-index: 1;
}

.item-content {
  grid-area: content;
  min-width: 0;
  z-index: 1;
}

.item-topline {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 8px;
}

.item-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 24px;
  padding: 0 8px;
  border-radius: var(--radius-pill);
  background: var(--paper-3);
  color: var(--muted);
  font-size: 12px;
  font-weight: 950;
}

.item-title {
  display: block;
  color: #2f2a25;
  font-size: 17px;
  font-weight: 750;
  line-height: 1.65;
  letter-spacing: 0.01em;
  word-break: break-word;
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  line-height: 1;
  white-space: nowrap;
}

.chip-category {
  padding: 6px 12px;
  border-radius: 10px;
  background: #efe5d4;
  color: #65513d;
  border: 1px solid rgba(101, 81, 61, 0.18);
  font-size: 14px;
  font-weight: 850;
  letter-spacing: 0.03em;
}

.chip-category.programming {
  background: #e7edf3;
  color: #45637a;
  border-color: rgba(69, 99, 122, 0.18);
}

.chip-category.wellness {
  background: #efe7ea;
  color: #7a5d69;
  border-color: rgba(122, 93, 105, 0.18);
}

.chip-category.interest {
  background: #f0e4d5;
  color: #8a5f32;
  border-color: rgba(138, 95, 50, 0.18);
}

.chip-subcategory {
  padding: 5px 10px;
  border-radius: var(--radius-pill);
  color: #fffdf7;
  border: 1px solid rgba(255, 253, 247, 0.32);
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: 0.01em;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.chip-subcategory.video {
  background: var(--subcategory-video);
}

.chip-subcategory.practice {
  background: var(--subcategory-practice);
}

.chip-subcategory.note {
  background: var(--subcategory-note);
}

.chip-subcategory.w3schools {
  background: var(--subcategory-w3schools-bg);
  color: var(--subcategory-w3schools-text);
  border-color: var(--subcategory-w3schools-line);
}

.chip-subcategory.uncategorized {
  background: var(--light-ink);
}

.chip-difficulty {
  padding: 4px 8px;
  border-radius: 6px 14px 14px 6px;
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.03em;
  border-left: 3px solid currentColor;
}

.chip-difficulty.easy {
  background: rgba(143, 167, 131, 0.16);
  color: #607855;
  border-color: rgba(96, 120, 85, 0.34);
}

.chip-difficulty.medium {
  background: rgba(216, 168, 95, 0.18);
  color: #8a5a28;
  border-color: rgba(138, 90, 40, 0.34);
}

.chip-difficulty.hard {
  background: rgba(215, 170, 155, 0.22);
  color: #9d5245;
  border-color: rgba(157, 82, 69, 0.36);
}

/* === 驗收標準關聯任務提示 === */

.item-relation {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 9px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.chip-parent {
  flex: 0 0 auto;
  background: var(--gold-soft);
  color: #8a5a28;
  border: 1px solid rgba(216, 168, 95, 0.26);
}

.relation-title {
  min-width: 0;
  color: #6b5b48;
  word-break: break-word;
}

.task-item.is-done .item-relation {
  opacity: 0.82;
}

.item-actions {
  grid-area: actions;
  display: flex;
  align-items: center;
  gap: 4px;
  z-index: 1;
}

.text-btn {
  border: 0;
  border-radius: var(--radius-pill);
  padding: 7px 10px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
  white-space: nowrap;
}

.text-btn:hover {
  background: var(--paper-3);
  color: var(--ink);
}

.text-btn.danger {
  color: #bd4634;
}

.text-btn.danger:hover {
  background: rgba(189, 70, 52, 0.08);
}

/* === 完成狀態蓋章 === */

.task-item.is-done {
  opacity: 0.76;
}

.task-item.is-done::after {
  content: "已辦理";
  position: absolute;
  right: 64px;
  bottom: 10px;
  padding: 5px 10px;
  border: 2px solid rgba(184, 95, 75, 0.4);
  border-radius: 7px;
  color: rgba(184, 95, 75, 0.48);
  font-size: 13px;
  font-weight: 950;
  letter-spacing: 0.12em;
  transform: rotate(-8deg);
  pointer-events: none;
}

.task-item.is-done .item-title {
  text-decoration: line-through;
  text-decoration-thickness: 2px;
  text-decoration-color: var(--stamp);
  color: #7c6e63;
  font-weight: 650;
}

.task-item.is-done::before {
  background: var(--stamp);
  opacity: 0.52;
}

/* === loading toast === */

.loading-toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 9999;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  pointer-events: none;

  padding: 11px 17px;
  border-radius: var(--radius-pill);
  background: rgba(59, 51, 45, 0.92);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);

  transition: opacity 0.2s ease, transform 0.2s ease;
}

.loading-toast.is-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* === 手機版 === */

@media (max-width: 680px) {
  .app {
    width: min(100% - 24px, 760px);
    padding-top: 16px;
  }

  .hero,
  .plan-card,
  .progress-card,
  .task-section,
  .standard-section {
    border-radius: 24px;
    padding: 18px;
  }

  .hero::after {
    width: 72px;
    height: 72px;
    right: 14px;
    bottom: 16px;
    font-size: 14px;
  }

  .hero h1 {
    max-width: 8.4em;
  }

  .plan-card::after {
    width: 46px;
    height: 46px;
    right: 14px;
    top: 16px;
    font-size: 13px;
  }

  .plan-content {
    padding: 15px;
  }

  .plan-content h3 {
    font-size: 19px;
  }

  .task-add-form {
    grid-template-columns: 1fr 1fr;
  }

  .task-add-form input {
    grid-column: 1 / -1;
  }

  .task-add-form .add-btn {
    grid-column: 1 / -1;
    width: 100%;
  }

  .add-form:not(.task-add-form) {
    grid-template-columns: 1fr;
  }

  .add-form .add-btn {
    width: 100%;
  }

  .task-item {
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "check content"
      ". actions";
    align-items: start;
  }

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

  .task-item.is-done::after {
    right: 14px;
    bottom: 12px;
    font-size: 12px;
  }
}

@media (max-width: 440px) {
  .task-add-form {
    grid-template-columns: 1fr;
  }

  .hero::after {
    opacity: 0.6;
  }

  .plan-card::after {
    opacity: 0.5;
  }

  .category-heading::after {
    display: none;
  }

  .item-topline {
    gap: 6px;
  }

  .item-title {
    font-size: 18px;
    line-height: 1.65;
  }

  .chip-category {
    font-size: 14px;
  }

  .chip-subcategory {
    font-size: 12px;
  }

  .chip-difficulty {
    font-size: 11.5px;
  }

  .chip {
    min-height: 25px;
  }

  .progress-row strong {
    font-size: 18px;
  }

  .progress-track {
    height: 14px;
  }
}
