:root {
      --green-deep:  #1a5c38;
      --green-mid:   #2d8a55;
      --green-light: #4abe7a;
      --amber:       #f5a623;
      --amber-light: #fde68a;
      --cream:       #fdf8ee;
      --earth:       #7c4b1e;
      --red:         #c0392b;
      --text-main:   #1e1e1e;
      --text-muted:  #6b7280;
      --radius:      1.2rem;
      --shadow:      0 4px 24px rgba(0,0,0,.08);
    }
    * { box-sizing: border-box; margin: 0; padding: 0; }
    body {
      font-family: 'Mulish', sans-serif;
      background: #f4fbf7;
      color: var(--text-main);
      padding-top: 4.2rem;
      padding-bottom: 4rem;
    }

    /* ── CONTAINER ── */
    .container { max-width: 1200px; /* Nới rộng container một chút */ margin: 2rem auto; padding: 0 1rem; }
    .page-title {
      font-family: 'Baloo 2', sans-serif;
      font-size: 2.2rem;
      color: var(--green-deep);
      margin-bottom: .5rem;
      text-align: center;
    }
    .page-subtitle {
      text-align: center;
      color: var(--text-muted);
      margin-bottom: 2rem;
      font-weight: 500;
    }

    /* ── BUTTONS ── */
    .btn-main {
      background: var(--green-mid);
      color: white;
      border: none;
      padding: .6rem 1.2rem;
      font-weight: 700;
      border-radius: .6rem;
      cursor: pointer;
      font-family: inherit;
      transition: background .2s;
    }
    .btn-main:hover { background: var(--green-deep); }
    .btn-secondary {
      background: #edf7f1;
      color: var(--green-deep);
      border: 1px dashed var(--green-mid);
      padding: .5rem 1rem;
      font-weight: 700;
      border-radius: .6rem;
      cursor: pointer;
      font-family: inherit;
    }
    .btn-secondary:disabled {
      opacity: 0.55;
      cursor: not-allowed;
    }
    .add-profile-bar {
      display: flex;
      justify-content: flex-end;
      align-items: center;
      gap: 0.75rem;
      margin-bottom: 1.5rem;
    }
    .add-profile-hint {
      font-size: 0.875rem;
      color: var(--text-muted);
      margin: 0;
      text-align: right;
    }

    /* ═════════ UI THẺ BÉ DASHBOARD ═════════ */
    .profile-grid {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
      gap: 1.25rem;
      margin-bottom: 2.5rem;
    }
    .profile-card {
      background: white; border: 2px solid #e2e8f0; border-radius: var(--radius);
      padding: 1.25rem; padding-right: 3.25rem; cursor: pointer; transition: all 0.3s ease;
      box-shadow: var(--shadow); position: relative;
    }
    .profile-card:hover { transform: translateY(-2px); border-color: var(--green-light); }
    .profile-card.active { border-color: var(--green-mid); background: #f0faf4; box-shadow: 0 8px 30px rgba(45,138,85,0.12); }
    .profile-card.active::after {
      content: '✓'; position: absolute; top: 10px; left: 15px; color: var(--green-mid); font-weight: bold; font-size: 1.2rem;
    }
    .profile-actions {
      position: absolute; top: 8px; right: 8px;
      display: flex; align-items: center; gap: 0.3rem; z-index: 1;
    }
    .profile-action-btn {
      background: none; border: none; cursor: pointer;
      font-size: 1rem; padding: 0.2rem 0.35rem; line-height: 1;
      opacity: 0; transition: opacity 0.2s, color 0.2s, transform 0.15s;
    }
    .profile-card:hover .profile-action-btn,
    .profile-card.active .profile-action-btn { opacity: 1; }
    .profile-delete-btn { color: #cbd5e1; }
    .profile-delete-btn:hover { color: var(--red); }
    .profile-header { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.75rem; }
    .profile-avatar { font-size: 2.2rem; }
    .profile-info { flex: 1; }
    .profile-name-row {
      display: flex;
      align-items: center;
      gap: 0.45rem;
      min-width: 0;
    }
    .profile-name { font-family: 'Baloo 2', sans-serif; font-size: 1.3rem; font-weight: 800; color: var(--text-main); margin: 0; line-height: 1.2; flex: 1; min-width: 0; }
    .profile-penalty-btn { color: var(--earth-light); }
    .profile-penalty-btn:hover { color: var(--earth); transform: scale(1.08); }
    .profile-level-badge { display: inline-block; font-size: 0.75rem; background: var(--green-deep); color: white; padding: 0.1rem 0.5rem; border-radius: 1rem; font-weight: 700; margin-top: 0.2rem; }
    .profile-stats-container { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin-bottom: 0.75rem; }
    .p-stat-box { padding: 0.5rem; border-radius: 0.6rem; font-size: 0.85rem; font-weight: 700; display: flex; flex-direction: column; }
    .p-stat-box span { font-size: 0.7rem; color: var(--text-muted); font-weight: 500; margin-bottom: 0.1rem; }
    .p-stat-box.grain { color: var(--amber); background: #fffbeb; }
    .p-stat-box.money { color: var(--green-deep); background: #edf7f1; }
    .profile-progress-block { font-size: 0.75rem; color: var(--text-muted); font-weight: 600; }
    .profile-bar-bg { background: #e2e8f0; border-radius: 1rem; height: 8px; overflow: hidden; margin-top: 0.25rem; }
    .profile-bar-fill { background: linear-gradient(90deg, var(--green-light), var(--green-mid)); height: 100%; width: 0%; transition: width 0.5s ease; }

    /* ═════════ LƯỚI BỐ CỤC CHÍNH (TASKS & REWARDS) ═════════ */
    .main-dashboard-grid {
      display: grid;
      /* Tỷ lệ 1.8 : 1.2 giúp cột Nhiệm vụ rộng hơn cột Quà để chia được 2 thẻ/hàng thoải mái */
      grid-template-columns: 1.7fr 1.3fr; 
      gap: 1.5rem;
      margin-bottom: 2rem;
      align-items: start;
    }
    @media (max-width: 992px) {
      .main-dashboard-grid { grid-template-columns: 1fr; }
    }

    /* ═════════ UI NHIỆM VỤ 2 CỘT TỐI ƯU HIỂN THỊ ═════════ */
    .tasks-compact-container { margin-bottom: 1rem; }

    .task-category-title {
      font-size: 0.9rem; font-weight: 800; color: var(--green-deep);
      margin: 1.2rem 0 0.6rem 0; text-transform: uppercase; letter-spacing: 0.5px;
      border-bottom: 1px dashed #c5e3d1; padding-bottom: 0.3rem;
    }

    .tasks-compact-grid {
      display: grid;
      grid-template-columns: 1fr 1fr; /* Chia 2 cột cố định */
      gap: 0.8rem; /* Tăng khoảng cách giữa các thẻ */
    }

    .task-compact-card {
      display: flex;
      align-items: center;
      background: white;
      border: 1px solid #e2e8f0;
      border-radius: 0.75rem;
      padding: 0.8rem 0.7rem; /* Phục hồi padding top/bottom cho thoáng */
      cursor: pointer;
      transition: all 0.2s ease;
      user-select: none;
      min-height: 4.8rem; /* Chiều cao đồng đều */
    }
    .task-compact-card:hover { border-color: var(--green-light); background: #fcfdfc; }
    .task-compact-card.checked { background: #edf8f2; border-color: var(--green-mid); }
    
    .task-compact-card.epic-task { border: 2px solid #fde68a; background: #fffbeb; }
    .task-compact-card.epic-task.checked { border-color: var(--amber); background: #fef3c7; }

    .task-cb {
      margin-right: 0.6rem;
      transform: scale(1.2);
      accent-color: var(--green-mid);
      cursor: pointer;
      flex-shrink: 0;
    }
    .task-emoji { font-size: 1.4rem; margin-right: 0.5rem; flex-shrink: 0; }

    .task-compact-details {
      flex: 1;
      font-size: 0.85rem;
      font-weight: 700;
      color: var(--text-main);
      line-height: 1.2;
      overflow: hidden;
    }
    .task-compact-details div {
      white-space: nowrap; 
      overflow: hidden;
      text-overflow: ellipsis; /* Tự động ẩn chữ nếu quá dài */
    }
    .task-sub { font-size: 0.7rem; font-weight: 500; color: var(--text-muted); margin-top: 0.15rem; }

    .task-compact-rewards {
      font-size: 0.7rem;
      font-weight: 800;
      color: #c47d3a;
      background: #fdf5ed;
      padding: 0.2rem 0.4rem;
      border-radius: 0.4rem;
      white-space: nowrap;
      margin-left: 0.5rem;
      text-align: right;
      flex-shrink: 0;
    }
    .task-compact-card.checked .task-compact-rewards { background: var(--green-mid); color: white; }

    @media (max-width: 600px) {
      .tasks-compact-grid { grid-template-columns: 1fr; /* Điện thoại thì dồn về 1 thẻ/hàng */ }
    }

    /* Bonus Toggle UI & Totals */
    .bonus-box {
      background: #fef9c3; border: 1px dashed var(--amber); border-radius: 0.6rem;
      padding: 1rem; margin-top: 1.5rem; display: flex; align-items: center; gap: 1rem; cursor: pointer;
    }
    .toggle-switch { width: 40px; height: 22px; background: #cbd5e1; border-radius: 20px; position: relative; transition: background 0.3s; flex-shrink: 0; }
    .toggle-switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; background: white; border-radius: 50%; transition: transform 0.3s; }
    .bonus-box.active .toggle-switch { background: var(--green-mid); }
    .bonus-box.active .toggle-switch::after { transform: translateX(18px); }

    .totals-bar { display: flex; gap: 1rem; align-items: center; background: #edf7f1; padding: 0.8rem 1rem; border-radius: 0.6rem; margin-top: 1rem; font-weight: 800; font-size: 1rem; }

    /* ═════════ UI THẺ QUÀ NHỎ ═════════ */
    .rewards-small-grid {
      display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 0.8rem; align-content: start;
      padding-top: 0.55rem;
    }
    .reward-small-card {
      background: white; border: 2px solid #e2e8f0; border-radius: 0.8rem; padding: 1rem 0.5rem; text-align: center; cursor: pointer;
      transition: all 0.2s ease; display: flex; flex-direction: column; align-items: center; justify-content: space-between; min-height: 120px;
      position: relative;
    }
    .reward-small-card:hover { border-color: var(--amber); transform: translateY(-2px); }
    .reward-small-card.affordable {
      background: linear-gradient(160deg, #fffbeb 0%, #fef3c7 55%, #fde68a 100%);
      border: 2px solid var(--amber);
      box-shadow: 0 4px 16px rgba(245, 166, 35, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.7);
    }
    .reward-small-card.affordable:hover {
      border-color: #e09010;
      box-shadow: 0 6px 20px rgba(245, 166, 35, 0.38);
      transform: translateY(-3px);
    }
    .reward-small-card.affordable .rw-s-name { color: var(--earth); }
    .reward-small-card.affordable .rw-s-cost {
      background: var(--amber);
      color: white;
      box-shadow: 0 2px 6px rgba(245, 166, 35, 0.35);
    }
    .reward-small-card.selected {
      background: linear-gradient(160deg, #fef3c7 0%, #fde68a 100%);
      border-color: #e09010;
      box-shadow: 0 0 0 3px rgba(245, 166, 35, 0.35), 0 6px 20px rgba(245, 166, 35, 0.3);
      transform: translateY(-2px);
    }
    .reward-small-card.selected::after {
      content: '✓';
      position: absolute;
      top: 6px;
      right: 8px;
      width: 1.35rem;
      height: 1.35rem;
      background: var(--green-mid);
      color: white;
      border-radius: 50%;
      font-size: 0.75rem;
      font-weight: 800;
      display: flex;
      align-items: center;
      justify-content: center;
      line-height: 1;
      box-shadow: 0 2px 6px rgba(45, 138, 85, 0.35);
    }
    .reward-small-card.disabled {
      opacity: 0.42;
      filter: grayscale(55%);
      cursor: not-allowed;
      border-style: dashed;
      background: #f8fafc;
    }
    .reward-small-card.disabled:hover { transform: none; border-color: #e2e8f0; }
    .rw-s-badge {
      position: absolute;
      top: -0.45rem;
      left: 50%;
      transform: translateX(-50%);
      font-size: 0.62rem;
      font-weight: 800;
      color: white;
      background: var(--green-mid);
      padding: 0.15rem 0.45rem;
      border-radius: 1rem;
      white-space: nowrap;
      letter-spacing: 0.02em;
      box-shadow: 0 2px 6px rgba(45, 138, 85, 0.3);
    }
    .rw-s-emoji { font-size: 2rem; margin-bottom: 0.3rem; }
    .reward-small-card.affordable .rw-s-emoji { font-size: 2.15rem; }
    .rw-s-name { font-size: 0.85rem; font-weight: 700; color: var(--text-main); line-height: 1.3; margin-bottom: 0.5rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; height: 32px; }
    .rw-s-cost { font-size: 0.8rem; font-weight: 800; color: var(--amber); background: rgba(245,166,35,0.08); padding: 0.2rem 0.6rem; border-radius: 1rem; width: 90%; }
    .rewards-afford-hint {
      font-size: 0.85rem;
      font-weight: 700;
      color: var(--green-mid);
      font-family: 'Mulish', sans-serif;
    }
    .rewards-afford-hint.is-empty { color: var(--text-muted); font-weight: 500; }

    /* ── LỊCH SỬ NHẬT KÝ ── */
    .history-card { background: white; border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); margin-top: 2rem; }
    .history-item { display: flex; justify-content: space-between; align-items: center; padding: 1rem 0; border-bottom: 1px dashed #e2e8f0; }
    .history-item:last-child { border-bottom: none; }
    .h-date { font-weight: 800; color: var(--green-deep); margin-bottom: .3rem; font-size: 0.95rem; }
    .h-note { font-size: .85rem; color: var(--text-muted); font-weight: 500; }
    .h-gains { font-weight: 800; font-size: 1rem; }
    .btn-delete { background: none; border: none; color: #cbd5e1; cursor: pointer; font-size: 1.2rem; padding: .2rem .5rem; transition: color .2s; }
    .btn-delete:hover { color: var(--red); }

    /* ── MODAL ── */
    .modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; opacity: 0; pointer-events: none; transition: opacity .3s; z-index: 1000; }
    .modal-overlay.open { opacity: 1; pointer-events: auto; }
    .modal-box { background: white; border-radius: var(--radius); padding: 2rem; width: 100%; max-width: 400px; box-shadow: 0 10px 40px rgba(0,0,0,.15); }
    .modal-title { font-family: 'Baloo 2', sans-serif; font-size: 1.5rem; margin-bottom: 1rem; color: var(--green-deep); }
    .btn-penalty { background: var(--red); color: white; }
    .btn-penalty:hover { background: #a93226; }
    .passcode-reveal-box { background: #fffbeb; border: 2px dashed var(--amber); border-radius: .75rem; padding: 1.25rem; text-align: center; }
    .passcode-reveal-code { font-family: 'Baloo 2', sans-serif; font-size: 2.5rem; letter-spacing: .35em; color: var(--earth); }
    .form-group { margin-bottom: 1.2rem; }
    .form-group label { display: block; font-weight: 700; margin-bottom: .4rem; font-size: .9rem; }
    .form-control { width: 100%; padding: .6rem; border: 1px solid #e2e8f0; border-radius: .6rem; font-family: inherit; font-size: .95rem; }

    /* ── TOAST ── */
    .toast { position: fixed; bottom: 2rem; left: 50%; transform: translateX(-50%) translateY(100px); background: #1a5c38; color: white; padding: .8rem 2rem; border-radius: 2rem; font-weight: 700; box-shadow: 0 4px 20px rgba(0,0,0,.15); transition: transform .3s cubic-bezier(0.4, 0, 0.2, 1); z-index: 2000; }
    .toast.show { transform: translateX(-50%) translateY(0); }

    /* ── LOADING / SYNC ── */
    .sync-status {
      text-align: center;
      font-size: 0.82rem;
      color: var(--text-muted);
      margin: -1rem 0 1.2rem;
      min-height: 1.2rem;
    }
    .sync-status.syncing { color: var(--green-mid); }
    .session-banner {
      background: #fff8e6;
      border: 1px solid #f0d78c;
      border-radius: var(--radius);
      padding: 1rem 1.25rem;
      margin-bottom: 1.25rem;
      text-align: center;
    }
    .session-banner p {
      margin: 0 0 0.75rem;
      font-size: 0.92rem;
      color: var(--earth);
      line-height: 1.5;
    }
    .session-banner-actions {
      display: flex;
      flex-wrap: wrap;
      gap: 0.65rem;
      justify-content: center;
      align-items: center;
    }
    .forgot-passcode-list {
      margin: 0 0 0.25rem 1.1rem;
      padding: 0;
      font-size: 0.92rem;
      color: var(--text-muted);
      line-height: 1.55;
    }
    .forgot-passcode-list li + li {
      margin-top: 0.5rem;
    }
    .forgot-passcode-contact {
      margin-top: 1rem;
      padding: 0.85rem 1rem;
      background: rgba(26, 92, 56, 0.06);
      border-left: 3px solid var(--green-deep);
      border-radius: 0 8px 8px 0;
      font-size: 0.92rem;
      color: var(--text-muted);
      line-height: 1.55;
    }
    .forgot-passcode-contact a {
      color: var(--green-deep);
      font-weight: 700;
      word-break: break-all;
    }
    .link-btn {
      background: none;
      border: none;
      color: var(--green-deep);
      font-weight: 700;
      cursor: pointer;
      font-family: inherit;
      font-size: inherit;
      text-decoration: underline;
      padding: 0;
    }
    .profile-skeleton {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
      gap: 1rem;
      margin-bottom: 1.5rem;
    }
    .skeleton-card {
      background: white;
      border-radius: var(--radius);
      padding: 1.2rem;
      box-shadow: var(--shadow);
      animation: pulse-skeleton 1.2s ease-in-out infinite;
    }
    .skeleton-line {
      height: 12px;
      background: linear-gradient(90deg, #edf7f1 25%, #e2f0e8 50%, #edf7f1 75%);
      background-size: 200% 100%;
      border-radius: 6px;
      margin-bottom: 0.6rem;
    }
    .skeleton-line.w60 { width: 60%; }
    .skeleton-line.w40 { width: 40%; }
    .skeleton-line.h24 { height: 24px; margin-bottom: 1rem; }
    @keyframes pulse-skeleton {
      0%, 100% { opacity: 1; }
      50% { opacity: 0.65; }
    }
    .history-more {
      display: block;
      width: 100%;
      margin-top: 1rem;
      padding: 0.7rem;
      border: 1px dashed var(--green-mid);
      background: #f4fbf7;
      color: var(--green-deep);
      font-weight: 700;
      border-radius: 0.6rem;
      cursor: pointer;
      font-family: inherit;
      font-size: 0.9rem;
    }
    .history-more:hover { background: #edf7f1; }
