* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { 
    touch-action: manipulation; 
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; 
    background: #f5f5f7; 
    overflow: hidden; 
    height: 100%;
    width: 100%;
}

input {
    -webkit-user-select: text;
    user-select: text;
}

body { font-size: 18px; }

.app {
  max-width: 480px;
  height: 100%;        
  max-height: 100dvh;  
  margin: 0 auto;
  background: white;
  position: relative; 
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 20px rgba(0,0,0,0.1);
}

@media (min-width: 500px) {
    .app {
        height: 90vh;
        margin: 5vh auto;
        border-radius: 24px;
        overflow: hidden; 
    }
}

.app.boy header { background: linear-gradient(135deg,#4f8cf7,#7ab8ff); }
.app.girl header { background: linear-gradient(135deg,#ff7eb3,#ff9a9e); }

header {
  color: white;
  padding: 18px 18px 14px;
  flex-shrink: 0;
  z-index: 50;
}
.header-top { display:flex; justify-content:space-between; align-items:center; }
.kid-main { display:flex; align-items:center; gap:10px; }
.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #ffdd66;
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight: 700;
  font-size: 22px;
  color: #333;
  flex-shrink: 0;
  position: relative; 
}

.connection-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 14px;
    height: 14px;
    background-color: #ccc; 
    border: 2px solid #fff;
    border-radius: 50%;
    transition: background-color 0.3s ease, transform 0.3s ease;
    z-index: 10;
}
.connection-dot.online { background-color: #4caf50; box-shadow: 0 0 6px rgba(76, 175, 80, 0.6); }
.connection-dot.offline { background-color: #f44336; }
.connection-dot.syncing { background-color: #ff9800; animation: pulse 1s infinite; }

@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.5; } 100% { opacity: 1; } }

.kid-info-block { display: flex; flex-direction: column; }

.name-row { display: flex; align-items: center; gap: 8px; }
.kid-name { font-size: 22px; font-weight: 700; }

.save-badge {
    font-size: 12px;
    background: rgba(255,255,255,0.25);
    padding: 2px 8px;
    border-radius: 10px;
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none;
    white-space: nowrap;
}
.save-badge.show { opacity: 1; }

.kid-sub { font-size: 14px; opacity: 0.95; }

.switch-btn {
  border: none;
  background: rgba(255,255,255,0.25);
  color: white;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  cursor: pointer;
}
.header-bottom {
  margin-top: 12px;
  display:flex;
  justify-content:space-between;
  align-items:flex-end;
  gap: 8px;
}

.date-chip {
  background: rgba(255,255,255,0.25);
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
  font-size: 14px;
  cursor: pointer; 
  display: flex;
  align-items: center;
  gap: 4px;
  border: 1px solid rgba(255,255,255,0.1);
  align-self: center;
}
.date-chip:active { background: rgba(255,255,255,0.4); }
.date-chip::after { content: "▾"; font-size: 12px; opacity: 0.8; }

.points-container {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.total-points {
  font-size: 26px;
  font-weight: 800;
  display:flex;
  align-items:center;
  gap: 6px;
  white-space: nowrap;
  line-height: 1.1;
}

.weekly-points {
    font-size: 13px;
    opacity: 0.9;
    margin-top: 2px;
    font-weight: 500;
}

main {
  padding: 10px 16px 20px; 
  flex: 1; 
  overflow-y: auto; 
  -webkit-overflow-scrolling: touch; 
  scroll-behavior: smooth;
}

h2 { font-size: 18px; margin: 10px 0 6px; }
.card {
  background:#fff;
  border-radius:16px;
  padding:14px;
  margin-bottom:12px;
  box-shadow:0 2px 6px rgba(0,0,0,0.05);
}

.week-wrapper {
  overflow-x:auto;
  padding-bottom: 6px;
  position: relative;
}
.week-table {
  min-width: 640px; 
  border-radius: 16px;
  background:#fff;
  box-shadow:0 2px 4px rgba(0,0,0,0.04);
  padding:10px;
}
.week-header, .task-row, .day-summary-row {
  display:flex;
  align-items:center;
  gap: 6px;
  font-size: 14px;
}

.week-header { 
    font-weight:700; 
    padding-bottom:8px;
    margin-bottom: 0;
    position: sticky;
    top: 0;
    z-index: 20;
    background: #fff;
    border-bottom: 1px solid #eee;
}

.task-name-header, .task-name, .task-name-summary {
  flex:0 0 120px;
  min-width:120px;
  font-size:14px;
  font-weight:600;
  position: sticky;
  left: 0;
  background: #fff; 
  z-index: 10;
  box-shadow: 2px 0 5px rgba(0,0,0,0.05); 
  margin-right: -1px;
  align-self: stretch; 
  display: flex;
  align-items: center;
}

.task-name-header { z-index: 30; }
.task-name-summary { z-index: 30; }

.week-list-item {
    padding: 12px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.week-list-item:last-child { border-bottom: none; }
.week-list-item.active {
    background-color: #e3f2fd;
    color: #1565c0;
    font-weight: bold;
}

.day-header, .day-cell-wrapper, .day-summary-cell {
  flex:1;
  text-align:center;
  display: flex;
  flex-direction: column; 
  justify-content: center;
  align-items: center;
}
.date-label {
    font-size: 11px;
    color: #888;
    margin-top: 2px;
    font-weight: normal;
}

.custom-check {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 2px solid #ddd;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.1s ease; 
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.custom-check.checked {
  background: #4caf50;
  border-color: #4caf50;
  color: white;
}
.custom-check.crossed {
  background: #ffebee;
  border-color: #ffcdd2;
  color: #c62828;
}
.task-row.bonus-row .custom-check.checked {
    background: #ff9800; 
    border-color: #ff9800;
}
.bonus-separator {
    padding: 8px 0;
    text-align: center;
    font-size: 12px;
    color: #888;
    background: #fafafa;
    margin: 4px 0;
    border-radius: 4px;
    font-weight: bold;
    letter-spacing: 1px;
}

.task-row { margin-bottom:6px; }

.day-summary-row {
  margin-top: 0;
  padding-top: 8px;
  padding-bottom: 4px;
  border-top: 2px solid #eee;
  font-size:13px;
  color:#555;
  position: sticky;
  bottom: 0;
  z-index: 20;
  background: #fff;
  box-shadow: 0 -2px 4px rgba(0,0,0,0.02);
}
.day-summary-cell-positive { color:#2e7d32; font-weight:600; }
.day-summary-cell-negative { color:#c62828; font-weight:600; }
.today-col { background:#e3f2fd; border-radius:8px; }

.history-item { display:flex; justify-content:space-between; margin-bottom:10px; font-size: 15px; }
.history-main { max-width: 70%; }
.history-date { font-size: 13px; color:#888; }
.history-delta { font-weight: 600; font-size: 16px; }
.history-delete-btn {
  margin-top: 4px;
  padding: 2px 8px;
  font-size: 12px;
  border-radius: 999px;
  border: 1px solid #ddd;
  background: #fafafa;
  cursor: pointer;
}
.settings-group { margin-bottom: 16px; }
.settings-item {
  display:flex;
  justify-content:space-between;
  align-items:center;
  padding:10px 0;
  border-bottom:1px solid #eee;
  font-size: 15px;
}
.settings-label { font-weight: 600; }
.settings-sub { font-size: 13px; color:#777; margin-top:2px; }
.settings-btn {
  border-radius:999px;
  border:1px solid #ddd;
  background:#fafafa;
  padding:6px 12px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}
.delete-task-btn { color: #c62828; border-color: #ffcdd2; background: #ffebee; }

.quick-row { display:flex; gap:10px; margin-top:6px; }
.pill-btn {
  flex:1;
  border-radius:999px;
  border:none;
  padding:14px 8px; 
  font-size:16px;
  font-weight: 700;
  cursor:pointer;
}
.pill-plus { background:#e3f2fd; color:#1565c0; }
.pill-minus { background:#ffebee; color:#c62828; }
.small-label { font-size: 13px; color:#777; margin-top:6px; }
.small-input {
  width:100%;
  padding:8px 10px;
  border-radius:10px;
  border:1px solid #ddd;
  margin-top:4px;
  font-size: 15px;
}

/* 智慧標籤樣式 */
.chip-container {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
}
.chip-btn {
    background: #f0f0f5;
    border: 1px solid #e0e0e0;
    border-radius: 16px;
    padding: 4px 12px;
    font-size: 13px;
    color: #555;
    cursor: pointer;
    transition: all 0.2s;
}
.chip-btn:active {
    background: #e0e0e5;
    transform: scale(0.95);
}

.tab-page { display:none; }
.tab-page.active { display:block; }

nav {
  display:flex;
  justify-content:space-around;
  border-top:1px solid #ddd;
  background:#fff;
  padding-bottom: env(safe-area-inset-bottom);
  flex-shrink: 0;
  z-index: 50;
}
.nav-item {
  flex:1;
  text-align:center;
  padding:10px 0 12px;
  font-size: 14px;
  cursor:pointer;
  color:#777;
  position: relative; 
}
.nav-icon { display:block; font-size: 20px; margin-bottom:2px; }
.nav-item.active { color:#3366cc; font-weight:600; }

.nav-notification {
    position: absolute;
    top: 8px;
    right: 25%;
    width: 10px;
    height: 10px;
    background-color: #f44336;
    border-radius: 50%;
    border: 2px solid #fff;
    display: none; 
}
.nav-notification.show { display: block; }

#toast-msg { pointer-events: none; }

#update-banner {
    display: none;
    position: fixed;
    bottom: 70px; 
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 12px 24px;
    border-radius: 50px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 10000;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    animation: slideUp 0.5s ease;
}
@keyframes slideUp {
    from { transform: translate(-50%, 20px); opacity: 0; }
    to { transform: translate(-50%, 0); opacity: 1; }
}

.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 9990;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: white;
  width: 90%;
  max-width: 400px;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  max-height: 80vh; 
  overflow-y: auto;
}
.modal h3 { margin-bottom: 16px; font-size: 20px; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; color: #555; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.btn-cancel { background: #f5f5f5; border: none; padding: 8px 16px; border-radius: 8px; cursor: pointer; font-size: 15px; }
.btn-save { background: #4f8cf7; color: white; border: none; padding: 8px 16px; border-radius: 8px; cursor: pointer; font-size: 15px; font-weight: 600; }

.radio-group { display: flex; gap: 16px; }
.radio-label { display: flex; align-items: center; gap: 6px; font-size: 15px; cursor: pointer; }

input[type="number"], input[type="text"] { font-size: 16px; }

/* 特效動畫 */
.coin-effect {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  font-size: 80px;
  pointer-events: none;
  z-index: 10000;
  display: none;
}
.coin-effect.animate {
  display: block;
  animation: coinUp 0.6s ease-out forwards;
}
@keyframes coinUp {
  0% { transform: translate(-50%, -20%) scale(0); opacity: 0; }
  20% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
  100% { transform: translate(-50%, -200%) scale(1); opacity: 0; }
}

.deduct-effect {
  position: fixed;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  font-size: 80px;
  pointer-events: none;
  z-index: 10000;
  display: none;
  color: #c62828;
}
.deduct-effect.animate {
  display: block;
  animation: dropDown 0.6s ease-in forwards;
}
@keyframes dropDown {
  0% { transform: translate(-50%, -100%) scale(0); opacity: 0; }
  20% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
  100% { transform: translate(-50%, 150%) scale(0.8); opacity: 0; }
}

.empty-state { text-align: center; color: #999; padding: 20px; font-size: 14px; }

.version-info {
    text-align: center;
    font-size: 12px;
    color: #aaa;
    padding: 10px 0 20px;
    font-family: monospace;
}

.login-modal-content {
    text-align: center;
    padding-top: 10px;
}
.login-logo {
    font-size: 48px;
    margin-bottom: 16px;
}
.login-desc {
    color: #666;
    margin-bottom: 24px;
    font-size: 15px;
    line-height: 1.5;
}
.login-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #ddd;
    border-radius: 12px;
    font-size: 18px;
    text-align: center;
    margin-bottom: 20px;
    outline: none;
    transition: border-color 0.3s;
}
.login-input:focus {
    border-color: #4f8cf7;
}
.login-btn {
    width: 100%;
    background: #4f8cf7;
    color: white;
    border: none;
    padding: 14px;
    border-radius: 12px;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(79, 140, 247, 0.3);
}
.login-btn:active {
    transform: scale(0.98);
}
.login-secondary-btn {
    width: 100%;
    margin-top: 10px;
    background: #fff;
    color: #1565c0;
    border: 1px solid #90caf9;
    padding: 12px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
}
.login-error {
    min-height: 20px;
    margin-top: 10px;
    color: #c62828;
    font-size: 13px;
    text-align: left;
}

.family-id-tag {
    display: inline-block;
    background: #eee;
    color: #555;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 11px;
    margin-left: 4px;
}
.backup-warning {
    color: #c62828;
    font-size: 13px;
    margin-top: 4px;
    font-weight: bold;
    display: none;
}
