/* Kids Routine Tracker — iPad-optimized styles */

:root {
  --green: #4CAF50;
  --green-light: #C8E6C9;
  --orange: #FF9800;
  --orange-light: #FFE0B2;
  --red: #F44336;
  --red-light: #FFCDD2;
  --bg: #F5F5F5;
  --card-bg: #FFFFFF;
  --card-done: #E8F5E9;
  --card-shadow: 0 2px 8px rgba(0,0,0,0.1);
  --text: #333333;
  --text-light: #757575;
  --header-bg: #FFFFFF;
  --radius: 16px;
  --star-color: #FFD600;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* Standalone (home-screen) mode: account for safe area */
@media all and (display-mode: standalone) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* --- Header --- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 24px 8px 24px;
  background: var(--header-bg);
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  position: relative;
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 24px;
  font-weight: 700;
}

#routine-icon {
  font-size: 28px;
}

.header-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 22px;
  font-weight: 600;
  color: var(--text-light);
}

.header-right select {
  font-size: 18px;
  padding: 8px 16px;
  border-radius: 10px;
  border: 2px solid #E0E0E0;
  background: white;
  color: var(--text);
  min-height: 44px;
  min-width: 44px;
  cursor: pointer;
}

/* --- Main content area --- */
main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Use flex layout for full-height distribution */
body {
  display: flex;
  flex-direction: column;
}

/* --- Child Row --- */
.child-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.child-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 100px;
}

.child-photo {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid #E0E0E0;
}

.child-name {
  font-size: 18px;
  font-weight: 700;
}

.child-stars {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 18px;
  font-weight: 700;
  color: var(--star-color);
}

.child-stars svg {
  width: 22px;
  height: 22px;
  fill: var(--star-color);
}

/* --- Task Cards --- */
.task-cards {
  display: flex;
  gap: 12px;
  flex: 1;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px;
}

.task-card {
  flex: 0 0 auto;
  width: 130px;
  min-height: 150px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 10px;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  border: 3px solid transparent;
}

.task-card:active {
  transform: scale(0.95);
}

.task-card.done {
  background: var(--card-done);
  border-color: var(--green);
  opacity: 0.7;
}

.task-card .task-icon {
  width: 56px;
  height: 56px;
}

.task-card .task-icon img {
  width: 100%;
  height: 100%;
}

.task-card .task-name {
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  line-height: 1.2;
}

.task-card .task-duration {
  font-size: 12px;
  color: var(--text-light);
}

/* Checkmark overlay */
.task-card .checkmark {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0);
  transition: all 0.3s ease;
}

.task-card.done .checkmark {
  opacity: 1;
  transform: scale(1);
}

.checkmark svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: white;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --- Footer (unused, hidden) --- */
footer {
  display: none !important;
}

/* --- Progress Section (inside main, at top) --- */
.progress-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--header-bg);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  padding: 14px 24px;
  flex-shrink: 0;
}

.progress-child-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.progress-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.progress-track-wrapper {
  flex: 1;
  position: relative;
  height: 66px;
}

.progress-track {
  display: flex;
  height: 100%;
  background: #E8E8E8;
  border-radius: 8px;
  overflow: hidden;
}

/* Elapsed time spacer — pushes blocks to the right of the marker */
.elapsed-block {
  flex-shrink: 0;
  height: 100%;
}

.task-block {
  flex-shrink: 1;
  height: 100%;
  background: var(--orange-light);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  min-width: 0;
  border-left: 2px solid rgba(0,0,0,0.08);
}

.task-block:first-of-type {
  border-left: none;
}

.task-block img {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  opacity: 0.85;
}

.task-block.overdue {
  background: var(--red-light);
}

.free-block {
  flex: 1 0 0;
  height: 100%;
  background: var(--green-light);
  min-width: 0;
}

.progress-marker {
  position: absolute;
  top: -4px;
  width: 3px;
  height: 74px;
  background: var(--text);
  border-radius: 2px;
  transition: left 1s linear;
  left: 0%;
  z-index: 2;
  pointer-events: none;
}

.progress-marker::after {
  content: '';
  position: absolute;
  top: -4px;
  left: -4px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--text);
}

.progress-time-labels {
  display: flex;
  justify-content: space-between;
  padding: 0 38px;
}

.progress-time-labels span {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-light);
}

/* Per-child inline time labels (shown when start/end differ between children) */
.progress-time-labels-inline {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 0 2px;
  flex-shrink: 0;
}

.progress-time-labels-inline span {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-light);
  opacity: 0.8;
}

/* --- "Trop tard" overlay for expired routine time --- */
.task-cards.time-expired {
  position: relative;
}

.time-expired-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  z-index: 5;
  pointer-events: auto;
  color: white;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.time-expired-icon {
  width: 48px;
  height: 48px;
  opacity: 0.9;
}

/* --- Star Animation Overlay --- */
.star-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.star-overlay.hidden {
  display: none;
}

.star-burst {
  font-size: 120px;
  animation: starPop 1.2s ease-out forwards;
}

@keyframes starPop {
  0% {
    transform: scale(0) rotate(-20deg);
    opacity: 0;
  }
  40% {
    transform: scale(1.3) rotate(10deg);
    opacity: 1;
  }
  60% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: scale(1.5) rotate(0deg);
    opacity: 0;
  }
}

.sparkle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--star-color);
  border-radius: 50%;
  animation: sparkle 1s ease-out forwards;
}

@keyframes sparkle {
  0% {
    transform: translate(0, 0) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(var(--tx), var(--ty)) scale(0);
    opacity: 0;
  }
}

/* --- Hidden utility --- */
.hidden {
  display: none !important;
}

/* --- Tab Bar --- */
#tab-bar {
  display: flex;
  background: var(--header-bg);
  border-bottom: 2px solid #E0E0E0;
  padding: 0 24px;
  gap: 8px;
}

.tab {
  flex: 1;
  background: none;
  border: none;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-light);
  padding: 10px 16px;
  min-height: 48px;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.2s ease;
}

.tab.active {
  color: var(--green);
  border-bottom-color: var(--green);
}

.tab:active {
  background: #F0F0F0;
}

/* --- Rule Cards --- */
.rule-card {
  flex: 0 0 auto;
  width: 200px;
  min-height: 210px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 18px 14px;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 3px solid transparent;
  position: relative;
  overflow: hidden;
  z-index: 0;
}

.rule-card::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--fill, 0%);
  background: var(--red-light);
  transition: height 0.4s ease;
  z-index: -1;
  border-radius: 0 0 calc(var(--radius) - 3px) calc(var(--radius) - 3px);
}

.rule-card:active {
  transform: scale(0.95);
}

.rule-card.maxed {
  border-color: var(--red);
  opacity: 0.6;
  pointer-events: none;
}

body.admin-mode .rule-card.maxed {
  pointer-events: auto;
  opacity: 0.75;
}

.rule-card .rule-icon {
  width: 82px;
  height: 82px;
}

.rule-card .rule-icon img {
  width: 100%;
  height: 100%;
}

.rule-card .rule-name {
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  line-height: 1.2;
}

.rule-stars {
  display: flex;
  gap: 6px;
  font-size: 24px;
}

.rule-star.filled {
  color: var(--star-color);
}

.rule-star.lost {
  filter: grayscale(1) opacity(0.3);
}

/* Infraction shake animation */
@keyframes infractionShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.infraction-flash {
  animation: infractionShake 0.5s ease;
}

/* --- Admin Lock Button --- */
.admin-lock-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: background 0.2s ease;
}

.admin-lock-btn:active {
  background: #F0F0F0;
}

.lock-icon {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: var(--text-light);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

body.admin-mode .lock-icon {
  stroke: var(--green);
  fill: var(--green-light);
}

body.admin-mode header {
  border-bottom: 3px solid var(--green);
}

/* --- Modal Overlay --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-card {
  background: white;
  border-radius: 20px;
  padding: 32px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  text-align: center;
  max-width: 400px;
  width: 90%;
}

/* --- PIN Modal --- */
.pin-modal-card h2 {
  font-size: 22px;
  margin-bottom: 20px;
  color: var(--text);
}

.pin-display {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-bottom: 24px;
}

.pin-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 3px solid #CCC;
  transition: all 0.15s ease;
}

.pin-dot.filled {
  background: var(--text);
  border-color: var(--text);
}

.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-width: 280px;
  margin: 0 auto;
}

.pin-key {
  height: 56px;
  border: none;
  border-radius: 12px;
  background: #F0F0F0;
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease;
}

.pin-key:active {
  background: #E0E0E0;
}

.pin-cancel {
  color: var(--red);
  font-size: 20px;
}

.pin-backspace {
  font-size: 20px;
}

.pin-error {
  color: var(--red);
  font-size: 14px;
  font-weight: 600;
  margin-top: 12px;
}

/* --- Reward Cards --- */
.rewards-children-summary {
  display: flex;
  gap: 32px;
  justify-content: center;
  padding: 10px 0 18px;
}

.reward-child-summary {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.reward-child-summary .child-photo {
  width: 70px;
  height: 70px;
}

.child-points {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.child-points .available {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 26px;
  font-weight: 700;
  color: var(--star-color);
}

.child-points .available svg {
  width: 24px;
  height: 24px;
  fill: var(--star-color);
}

.child-points .pending {
  font-size: 14px;
  color: var(--text-light);
  font-weight: 600;
}

.rewards-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
  padding: 10px 0;
}

.reward-card {
  width: 170px;
  min-height: 220px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 3px solid transparent;
}

.reward-card:active {
  transform: scale(0.95);
}

.reward-card.disabled {
  opacity: 0.5;
  pointer-events: none;
  filter: grayscale(0.3);
}

.reward-emoji {
  font-size: 52px;
}

.reward-image {
  width: 68px;
  height: 68px;
}

.reward-image img {
  width: 100%;
  height: 100%;
}

.reward-name {
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  line-height: 1.2;
}

.reward-cost {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 17px;
  font-weight: 700;
  color: var(--star-color);
}

.reward-cost svg {
  width: 18px;
  height: 18px;
  fill: var(--star-color);
}

/* --- Reward Modal --- */
.reward-modal-card {
  max-width: 420px;
}

.reward-modal-emoji {
  font-size: 64px;
  margin-bottom: 8px;
}

.reward-modal-title {
  font-size: 20px;
  margin-bottom: 4px;
  color: var(--text);
}

.reward-modal-cost {
  font-size: 16px;
  color: var(--text-light);
  margin-bottom: 20px;
}

.reward-modal-body {
  margin-bottom: 16px;
}

.reward-modal-error {
  color: var(--red);
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
}

.child-select-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 16px;
  margin: 0 8px;
  border: 3px solid #E0E0E0;
  border-radius: 16px;
  background: white;
  cursor: pointer;
  transition: all 0.2s ease;
}

.child-select-btn img {
  width: 50px;
  height: 50px;
  border-radius: 50%;
}

.child-select-btn span {
  font-size: 14px;
  font-weight: 600;
}

.child-select-btn .child-avail {
  font-size: 12px;
  color: var(--text-light);
}

.child-select-btn.selected {
  border-color: var(--green);
  background: var(--card-done);
}

.split-inputs {
  display: flex;
  justify-content: center;
  gap: 24px;
}

.split-input {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.split-input label {
  font-size: 14px;
  font-weight: 600;
}

.split-input input {
  width: 70px;
  height: 44px;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  border: 2px solid #E0E0E0;
  border-radius: 10px;
  color: var(--text);
}

.split-input .split-avail {
  font-size: 12px;
  color: var(--text-light);
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 20px;
}

.modal-btn {
  min-width: 120px;
  min-height: 44px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
}

.modal-btn.cancel {
  background: #F0F0F0;
  color: var(--text);
}

.modal-btn.cancel:active {
  background: #E0E0E0;
}

.modal-btn.confirm {
  background: var(--green);
  color: white;
}

.modal-btn.confirm:active {
  background: #388E3C;
}

.modal-btn.confirm:disabled {
  background: #CCC;
  cursor: not-allowed;
}

/* --- Undo infraction button --- */
.undo-infraction-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--orange);
  color: white;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 4px;
  transition: background 0.2s ease;
}

.undo-infraction-btn:active {
  background: #F57C00;
}

/* --- Rewards history --- */
.rewards-history {
  padding: 12px 0;
}

.rewards-history h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-light);
}

.reward-history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  font-size: 14px;
  border-bottom: 1px solid #F0F0F0;
}

.reward-history-item .history-emoji {
  font-size: 20px;
}

.reward-history-item .history-reward-img {
  width: 24px;
  height: 24px;
  object-fit: contain;
  flex-shrink: 0;
}

.reward-history-item .history-date {
  color: var(--text-light);
  font-size: 12px;
  margin-left: auto;
}

/* --- Admin-only tab visibility --- */
.admin-only-tab {
  display: none !important;
}

body.admin-mode .admin-only-tab {
  display: flex !important;
}

/* --- Reward child progress bars --- */
.reward-child-bars {
  width: 100%;
  padding: 8px 0 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.reward-child-bar {
  display: flex;
  align-items: center;
  gap: 6px;
}

.reward-child-bar .bar-avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.reward-bar-track {
  flex: 1;
  height: 6px;
  background: #E8E8E8;
  border-radius: 3px;
  overflow: hidden;
}

.reward-bar-fill {
  height: 100%;
  background: var(--green);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.reward-bar-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-light);
  min-width: 36px;
  text-align: right;
  flex-shrink: 0;
}

/* --- Admin tab sections --- */
.admin-section {
  margin-bottom: 24px;
}

.admin-section h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text);
}

/* Star override */
.star-overrides {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}

.star-override {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  padding: 12px 16px;
}

.star-override img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

.star-override .override-name {
  font-size: 16px;
  font-weight: 700;
  min-width: 50px;
}

.star-override-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: #F0F0F0;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.star-override-btn:active {
  background: #E0E0E0;
}

.star-override input {
  width: 60px;
  height: 36px;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  border: 2px solid #E0E0E0;
  border-radius: 8px;
  color: var(--text);
}

.star-override .override-save {
  min-width: 70px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: var(--green);
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.star-override .override-save:active {
  background: #388E3C;
}

/* History list */
.history-list {
  max-height: 70vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.history-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  font-size: 14px;
  border-bottom: 1px solid #F0F0F0;
}

.history-entry .history-time {
  font-size: 12px;
  color: var(--text-light);
  min-width: 40px;
  flex-shrink: 0;
}

.history-entry .history-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.history-entry .history-desc {
  flex: 1;
}

.actor-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  flex-shrink: 0;
}

.actor-badge.child {
  background: #E3F2FD;
  color: #1565C0;
}

.actor-badge.admin {
  background: #FFF3E0;
  color: #E65100;
}

.actor-badge.system {
  background: #E8F5E9;
  color: #2E7D32;
}

/* History date group headers */
.history-date-header {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  padding: 10px 0 4px;
  margin-top: 8px;
  border-bottom: 2px solid #E0E0E0;
  text-transform: capitalize;
}

.history-date-header:first-child {
  margin-top: 0;
}

/* --- Responsive tweaks --- */

/* iPad landscape (primary target) */
@media (min-width: 1024px) and (orientation: landscape) {
  .task-card {
    width: 140px;
    min-height: 160px;
  }

  .task-card .task-icon {
    width: 64px;
    height: 64px;
  }

  .rule-card {
    width: 220px;
    min-height: 240px;
    gap: 12px;
    padding: 20px 14px;
  }

  .rule-card .rule-icon {
    width: 90px;
    height: 90px;
  }

  .rule-card .rule-name {
    font-size: 16px;
  }

  .rule-stars {
    font-size: 26px;
    gap: 8px;
  }

  .child-photo {
    width: 100px;
    height: 100px;
  }

  .child-name {
    font-size: 20px;
  }

  .child-stars {
    font-size: 20px;
  }

  .reward-card {
    width: 190px;
    min-height: 250px;
    gap: 10px;
    padding: 18px 12px;
  }

  .reward-image img {
    width: 80px;
    height: 80px;
  }

  .reward-name {
    font-size: 15px;
  }

  .reward-cost {
    font-size: 20px;
  }

  .reward-cost svg {
    width: 22px;
    height: 22px;
  }

  .rewards-children-summary {
    gap: 40px;
    padding: 12px 0 20px;
  }

  .reward-child-summary .child-photo {
    width: 80px;
    height: 80px;
  }

  .child-points .available {
    font-size: 28px;
  }

  .child-points .available svg {
    width: 26px;
    height: 26px;
  }

  .child-points .pending {
    font-size: 15px;
  }

  .rewards-grid {
    gap: 16px;
  }

  .reward-child-bar .bar-avatar {
    width: 24px;
    height: 24px;
  }

  .reward-bar-track {
    height: 8px;
  }

  .reward-bar-label {
    font-size: 12px;
  }
}

/* Mobile phones */
@media (max-width: 768px) {
  /* Header — compact, no overlap */
  header {
    padding: 6px 12px;
    flex-wrap: wrap;
    gap: 4px;
  }

  .header-left {
    font-size: 16px;
    gap: 4px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
  }

  #routine-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #routine-icon {
    font-size: 20px;
    flex-shrink: 0;
  }

  .header-center {
    position: static;
    transform: none;
    font-size: 15px;
    gap: 4px;
    flex-shrink: 0;
  }

  .header-right select {
    font-size: 14px;
    padding: 4px 8px;
    min-height: 36px;
  }

  .admin-lock-btn {
    width: 32px;
    height: 32px;
    padding: 4px;
  }

  .lock-icon {
    width: 22px;
    height: 22px;
  }

  .day-type-badge {
    font-size: 10px;
    padding: 2px 6px;
  }

  /* Tab bar — tighter */
  #tab-bar {
    padding: 0 8px;
    gap: 2px;
  }

  .tab {
    font-size: 13px;
    padding: 8px 6px;
    min-height: 42px;
  }

  /* Main content */
  main {
    padding: 10px 12px;
    gap: 14px;
  }

  /* Child rows — stack vertically */
  .child-row {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
  }

  .child-info {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    min-width: unset;
  }

  .child-photo {
    width: 36px;
    height: 36px;
    border-width: 2px;
  }

  .child-name {
    font-size: 16px;
  }

  .child-stars {
    font-size: 15px;
  }

  .child-stars svg {
    width: 17px;
    height: 17px;
  }

  .time-expired-overlay {
    font-size: 18px;
  }

  .time-expired-icon {
    width: 36px;
    height: 36px;
  }

  /* Task cards — smaller for phones */
  .task-card {
    width: 100px;
    min-height: 115px;
    padding: 10px 8px;
    gap: 6px;
    border-width: 2px;
  }

  .task-card .task-icon {
    width: 42px;
    height: 42px;
  }

  .task-card .task-name {
    font-size: 12px;
  }

  .task-card .task-duration {
    font-size: 11px;
  }

  .checkmark {
    width: 24px;
    height: 24px;
    top: 5px;
    right: 5px;
  }

  .checkmark svg {
    width: 14px;
    height: 14px;
  }

  /* Progress bar — compact on mobile */
  .progress-section {
    padding: 10px 12px;
    gap: 6px;
  }

  .progress-track-wrapper {
    height: 44px;
  }

  .progress-avatar {
    width: 28px;
    height: 28px;
  }

  .task-block img {
    width: 28px;
    height: 28px;
  }

  .progress-marker {
    height: 52px;
    top: -3px;
  }

  .progress-marker::after {
    width: 9px;
    height: 9px;
    left: -3px;
    top: -3px;
  }

  .progress-time-labels {
    padding: 0 30px;
  }

  .progress-time-labels span {
    font-size: 11px;
  }

  .progress-time-labels-inline span {
    font-size: 10px;
  }

  .progress-child-row {
    flex-wrap: wrap;
  }

  /* Rules tab — compact */
  .rule-card {
    width: 110px;
    min-height: 120px;
    padding: 12px 8px;
    gap: 6px;
  }

  .rule-card .rule-icon {
    width: 42px;
    height: 42px;
  }

  .rule-card .rule-name {
    font-size: 11px;
  }

  .rule-stars {
    font-size: 20px;
    gap: 4px;
  }

  /* Rewards tab — compact */
  .rewards-children-summary {
    gap: 16px;
    padding: 6px 0 10px;
  }

  .reward-child-summary .child-photo {
    width: 50px;
    height: 50px;
  }

  .child-points .available {
    font-size: 22px;
  }

  .child-points .available svg {
    width: 20px;
    height: 20px;
  }

  .child-points .pending {
    font-size: 12px;
  }

  .rewards-grid {
    gap: 10px;
  }

  .reward-card {
    width: 110px;
    min-height: 120px;
    padding: 10px 8px;
  }

  .reward-emoji {
    font-size: 32px;
  }

  .reward-image {
    width: 48px;
    height: 48px;
  }

  .reward-name {
    font-size: 11px;
  }

  .reward-cost {
    font-size: 14px;
  }

  .reward-cost svg {
    width: 15px;
    height: 15px;
  }

  .reward-child-bars {
    padding: 4px 0 0;
  }

  /* Template editor — time inputs wider for mobile clock icon */
  .routine-times-grid {
    width: 100%;
  }

  .routine-times-child-label {
    min-width: 32px;
    font-size: 11px;
  }

  .template-routine-header .routine-time-input,
  .day-detail-routine .routine-time-input {
    width: 100px;
    height: 40px;
    font-size: 15px;
  }

  .template-routine-header .routine-icon-input {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }

  .template-routine-header .routine-name-input {
    min-width: 80px;
    height: 36px;
    font-size: 14px;
  }

  .routine-id-input {
    width: 80px;
    height: 36px;
    font-size: 13px;
  }

  .template-routine-header {
    gap: 6px;
  }
}

/* --- Simulation mode: make room for the control bar --- */
body.sim-mode {
  padding-bottom: 56px;
}

/* --- Simulation controls (dev only, ?sim= in URL) --- */
.sim-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #263238;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 20px;
  z-index: 200;
  font-family: monospace;
  font-size: 16px;
}

.sim-bar button {
  background: #455A64;
  color: white;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 16px;
  font-family: monospace;
  cursor: pointer;
  min-height: 44px;
}

.sim-bar button:active {
  background: #607D8B;
}

/* --- Day Type Badge --- */
.day-type-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 10px;
  color: white;
  white-space: nowrap;
}

.day-type-school { background: #2196F3; }
.day-type-wednesday { background: #9C27B0; }
.day-type-weekend { background: #4CAF50; }
.day-type-holiday { background: #FF9800; }
.day-type-custom { background: #FDD835; color: #333; }

/* --- Calendar --- */
.calendar-container {
  max-width: 500px;
}

.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.calendar-nav button {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: #F0F0F0;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.calendar-nav button:active {
  background: #E0E0E0;
}

.cal-title {
  font-size: 18px;
  font-weight: 700;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.calendar-headers {
  margin-bottom: 4px;
}

.cal-header {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-light);
  padding: 4px 0;
}

.cal-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 2px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
  min-height: 50px;
}

.cal-cell:hover {
  background: #F0F0F0;
}

.cal-cell:active {
  background: #E0E0E0;
}

.cal-cell.empty {
  cursor: default;
  pointer-events: none;
}

.cal-cell.today {
  background: #E3F2FD;
  border: 2px solid #2196F3;
}

.cal-cell.past {
  opacity: 0.7;
}

.cal-day-num {
  font-size: 14px;
  font-weight: 600;
}

.cal-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.cal-completion {
  font-size: 10px;
  font-weight: 700;
}

.cal-completion.good { color: #4CAF50; }
.cal-completion.ok { color: #FF9800; }
.cal-completion.low { color: #F44336; }

.calendar-legend {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-light);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

/* --- Day Detail Modal --- */
.day-detail-card {
  max-width: 520px;
  max-height: 80vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  text-align: left;
}

.day-detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  position: relative;
}

.day-detail-header h2 {
  font-size: 18px;
  flex: 1;
  text-transform: capitalize;
}

.day-detail-close {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: #F0F0F0;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.day-detail-close:active {
  background: #E0E0E0;
}

.day-detail-note {
  color: var(--text-light);
  font-style: italic;
  padding: 12px 0;
}

.day-detail-routine {
  margin-bottom: 16px;
}

.day-detail-routine h3 {
  font-size: 16px;
  margin-bottom: 8px;
  color: var(--text);
}

.day-detail-routine .routine-time-input {
  width: 120px;
  height: 36px;
  text-align: center;
  font-size: 14px;
  border: 2px solid #E0E0E0;
  border-radius: 8px;
  color: var(--text);
}

.day-detail-routine .time-sep {
  font-weight: 600;
  color: var(--text-light);
}

.day-detail-child {
  margin-bottom: 8px;
  padding-left: 8px;
}

.day-detail-child ul {
  list-style: none;
  padding: 0;
  margin: 4px 0 0 0;
}

.day-detail-child li {
  padding: 3px 0;
  font-size: 14px;
}

.day-detail-child li.done { color: var(--green); }
.day-detail-child li.missed { color: var(--text-light); }

.day-detail-stars {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #E0E0E0;
}

.day-detail-stars h3 {
  font-size: 16px;
  margin-bottom: 8px;
}

.day-detail-stars p {
  font-size: 14px;
  margin-bottom: 4px;
}

.day-detail-schedule h3 {
  font-size: 16px;
  margin-bottom: 8px;
}

.day-detail-schedule p {
  font-size: 14px;
  margin-bottom: 4px;
}

.day-detail-override {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #E0E0E0;
}

.day-detail-override h3 {
  font-size: 16px;
  margin-bottom: 8px;
}

.day-detail-override select {
  font-size: 16px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 2px solid #E0E0E0;
  background: white;
  color: var(--text);
  min-height: 44px;
  margin-right: 8px;
}

.day-detail-override .modal-btn {
  vertical-align: middle;
}

/* --- Template Editor --- */
.template-editor {
  margin-bottom: 24px;
}

.template-variant-toggle {
  display: flex;
  gap: 0;
  margin-bottom: 12px;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid #E0E0E0;
  width: fit-content;
}

.variant-btn {
  padding: 8px 20px;
  border: none;
  background: #F5F5F5;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-light);
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 40px;
}

.variant-btn.active {
  background: var(--green);
  color: white;
}

.variant-btn:first-child {
  border-right: 1px solid #E0E0E0;
}

.template-day-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.template-day-tab {
  padding: 6px 12px;
  border: 2px solid #E0E0E0;
  border-radius: 8px;
  background: white;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-light);
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 36px;
}

.template-day-tab.active {
  border-color: var(--green);
  background: var(--card-done);
  color: var(--green);
}

.template-day-tab:active {
  background: #F0F0F0;
}

.template-routine-block {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  padding: 16px;
  margin-bottom: 12px;
}

.template-routine-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.template-routine-header .routine-icon-input {
  width: 40px;
  height: 36px;
  text-align: center;
  font-size: 18px;
  border: 2px solid #E0E0E0;
  border-radius: 8px;
}

.template-routine-header .routine-name-input {
  flex: 1;
  min-width: 120px;
  height: 36px;
  font-size: 15px;
  font-weight: 600;
  border: 2px solid #E0E0E0;
  border-radius: 8px;
  padding: 0 10px;
  color: var(--text);
}

.template-routine-header .routine-time-input {
  width: 120px;
  height: 36px;
  text-align: center;
  font-size: 14px;
  border: 2px solid #E0E0E0;
  border-radius: 8px;
  color: var(--text);
}

.template-routine-header .time-sep {
  font-weight: 600;
  color: var(--text-light);
}

/* Per-child time inputs in template editor */
.routine-times-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.routine-times-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.routine-times-child-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-light);
  min-width: 40px;
  text-align: right;
}

.remove-routine-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: var(--red-light);
  color: var(--red);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.remove-routine-btn:active {
  background: var(--red);
  color: white;
}

.template-child-tasks {
  margin-left: 8px;
  padding-left: 12px;
  border-left: 3px solid #E0E0E0;
  margin-bottom: 10px;
}

.template-child-tasks .child-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.template-child-tasks .child-label img {
  width: 24px;
  height: 24px;
  border-radius: 50%;
}

.template-task-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  transition: background 0.15s ease, opacity 0.15s ease;
  border-radius: 6px;
}

.template-task-row.dragging {
  opacity: 0.4;
}

.template-task-row.drag-over {
  background: var(--green-light);
  box-shadow: inset 0 -2px 0 var(--green);
}

.drag-handle {
  cursor: grab;
  font-size: 16px;
  color: #BDBDBD;
  flex-shrink: 0;
  padding: 0 2px;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
}

.drag-handle:active {
  cursor: grabbing;
}

.template-task-row img {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.template-task-row .task-name-label {
  flex: 1;
  font-size: 14px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.template-task-row .task-duration-input {
  width: 50px;
  height: 30px;
  text-align: center;
  font-size: 14px;
  border: 2px solid #E0E0E0;
  border-radius: 6px;
  color: var(--text);
}

.template-task-row .duration-label {
  font-size: 12px;
  color: var(--text-light);
  flex-shrink: 0;
}

.remove-task-btn {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: #FFCDD2;
  color: var(--red);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.remove-task-btn:active {
  background: var(--red);
  color: white;
}

.add-task-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: 2px dashed #BDBDBD;
  border-radius: 8px;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-light);
  cursor: pointer;
  margin-top: 4px;
  transition: all 0.15s ease;
}

.add-task-btn:hover {
  border-color: var(--green);
  color: var(--green);
}

.add-routine-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 10px;
  border: 2px dashed #BDBDBD;
  border-radius: var(--radius);
  background: transparent;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-light);
  cursor: pointer;
  margin-bottom: 12px;
  transition: all 0.15s ease;
}

.add-routine-btn:hover {
  border-color: var(--green);
  color: var(--green);
}

.save-template-btn {
  min-width: 180px;
  min-height: 44px;
  border: none;
  border-radius: 12px;
  background: var(--green);
  color: white;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.save-template-btn:active {
  background: #388E3C;
}

.save-template-btn:disabled {
  background: #CCC;
  cursor: not-allowed;
}

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

.template-save-status {
  font-size: 14px;
  font-weight: 600;
  color: var(--green);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.template-save-status.visible {
  opacity: 1;
}

/* --- Task picker dropdown --- */
.task-picker-select {
  font-size: 14px;
  padding: 4px 8px;
  border: 2px solid #E0E0E0;
  border-radius: 8px;
  background: white;
  color: var(--text);
  min-height: 32px;
  cursor: pointer;
  max-width: 200px;
}

/* --- Day Detail: task toggles for future override --- */
.day-detail-task-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.day-detail-task-toggle input[type="checkbox"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
  accent-color: var(--green);
  flex-shrink: 0;
}

.day-detail-task-toggle img {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.day-detail-task-toggle .toggle-name {
  flex: 1;
  font-size: 14px;
}

.day-detail-task-toggle .toggle-duration {
  font-size: 12px;
  color: var(--text-light);
  flex-shrink: 0;
}

.day-detail-add-task {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.day-detail-add-task select {
  font-size: 14px;
  padding: 4px 8px;
  border: 2px solid #E0E0E0;
  border-radius: 8px;
  background: white;
  color: var(--text);
  min-height: 32px;
}

.day-detail-add-task button {
  min-height: 32px;
  padding: 4px 12px;
  border: none;
  border-radius: 8px;
  background: var(--green);
  color: white;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.day-detail-template-picker {
  margin-bottom: 12px;
}

.day-detail-template-picker select {
  font-size: 15px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 2px solid #E0E0E0;
  background: white;
  color: var(--text);
  min-height: 40px;
}

.day-detail-save-row {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.day-detail-save-row .modal-btn {
  min-width: 100px;
}

/* --- Routine ID select in template editor --- */
.routine-id-input {
  width: 100px;
  height: 36px;
  font-size: 14px;
  border: 2px solid #E0E0E0;
  border-radius: 8px;
  padding: 0 8px;
  color: var(--text);
}

/* --- Admin sub-tabs --- */
.admin-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid #E0E0E0;
  margin-bottom: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.admin-tab {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-light);
  padding: 8px 16px;
  cursor: pointer;
  white-space: nowrap;
  border-radius: 8px 8px 0 0;
  transition: all 0.2s ease;
}

.admin-tab.active {
  color: var(--green);
  border-bottom-color: var(--green);
}

.admin-tab:active {
  background: #F0F0F0;
}

/* --- Collapsible routine blocks in template editor --- */
.routine-collapse-chevron {
  display: inline-block;
  font-size: 16px;
  width: 20px;
  text-align: center;
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s ease;
  color: var(--text-light);
}

.template-routine-header {
  cursor: pointer;
}

.routine-body.collapsed {
  display: none;
}

/* --- Toast notifications --- */
#toast-container {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 80px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
  width: 90%;
  max-width: 400px;
}

.toast {
  padding: 10px 18px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  animation: toast-in 0.25s ease;
  pointer-events: auto;
}

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

.toast-info    { background: #3b82f6; }
.toast-success { background: #22c55e; }
.toast-warning { background: #f97316; }
.toast-error   { background: #ef4444; }


/* --- Infraction confirm modal card --- */
.infraction-confirm-card {
  text-align: center;
  padding: 28px 24px 20px;
  max-width: 300px;
}

.infraction-confirm-text {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 20px;
  line-height: 1.4;
}

.infraction-confirm-card .modal-actions {
  gap: 12px;
}

.infraction-confirm-card .modal-btn {
  min-height: 56px;
  font-size: 18px;
  flex: 1;
}
