* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, "Segoe UI", Roboto, "Noto Color Emoji", Arial, sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: #FFE082;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  height: 100dvh;
  position: relative;
  overflow: hidden;
}

.view {
  position: absolute;
  inset: 0;
}
.view.hidden { display: none; }

.bg-gradient-main {
  height: 100%;
  background: linear-gradient(to bottom, #FFF9E7 0%, #FFE082 100%);
  display: flex;
  flex-direction: column;
}

.bg-gradient-complete {
  height: 100%;
  background: linear-gradient(135deg, #FFF9E7 0%, #FFD54F 50%, #FF9800 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Cabeçalho comum ─────────────────────────────────────────── */
.header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: max(16px, env(safe-area-inset-top)) 20px 8px 20px;
  gap: 8px;
}
.header-row--settings {
  align-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px 8px 8px;
}
.header-titles { flex: 1; text-align: center; }
.app-title {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  color: #E65100;
}
.progress-label {
  margin: 6px 0 0;
  font-size: 17px;
  color: #6D4C00;
}
.progress-track {
  margin-top: 4px;
  height: 14px;
  border-radius: 7px;
  background: #FFCC80;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 7.7%;
  background: #FF9800;
  border-radius: 7px;
  transition: width 0.3s ease;
}
.icon-btn {
  border: none;
  background: transparent;
  font-size: 22px;
  width: 44px;
  height: 44px;
  cursor: pointer;
  flex-shrink: 0;
}
.back-btn { color: #E65100; font-size: 28px; }
.section-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  color: #E65100;
  flex: 1;
}

/* ── Ecrã principal ───────────────────────────────────────────── */
.grid-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0 20px max(16px, env(safe-area-inset-bottom)) 20px;
  min-height: 0;
}
.task-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px 0;
  position: relative;
  min-height: 0;
}
.task-emoji {
  font-size: 96px;
  line-height: 1;
}
.task-title {
  font-size: 38px;
  font-weight: 700;
  color: #212121;
  text-align: center;
  line-height: 1.15;
}
.star-overlay {
  position: absolute;
  font-size: 100px;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.3);
}

.btn {
  border: none;
  border-radius: 22px;
  font-size: 20px;
  font-weight: 700;
  color: white;
  cursor: pointer;
  padding: 14px;
  min-height: 44px;
}
.btn:active { filter: brightness(0.92); }
.btn:disabled { opacity: 0.55; }

.btn-complete {
  background: #43A047;
  font-size: 28px;
  height: 82px;
  margin-bottom: 10px;
}
.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.btn-secondary {
  font-size: 16px;
  height: 52px;
  border-radius: 14px;
  font-weight: 400;
}
.btn-orange { background: #FF9800; }
.btn-gray { background: #9E9E9E; }
.btn-save {
  background: #43A047;
  border-radius: 16px;
  height: 60px;
}
.full-width { width: 100%; margin-top: 6px; }
.no-radius { border-radius: 0; }

/* ── Configurações ────────────────────────────────────────────── */
.grid-settings {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-bottom: env(safe-area-inset-bottom);
}
.tasks-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 12px;
  -webkit-overflow-scrolling: touch;
}
.task-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: white;
  border-radius: 14px;
  padding: 8px 10px;
  margin: 4px 0;
}
.task-card-updown {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.task-card-updown button {
  border: none;
  background: #FF9800;
  color: white;
  font-size: 14px;
  width: 40px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
}
.task-card-emoji { font-size: 34px; width: 50px; text-align: center; }
.task-card-title { flex: 1; font-size: 15px; font-weight: 700; color: #212121; }
.task-card-edit {
  border: none;
  background: #E8F5E9;
  font-size: 22px;
  width: 54px;
  height: 54px;
  border-radius: 12px;
  cursor: pointer;
}
.bottom-row { padding: 8px 12px 18px; }

/* ── Editar tarefa ────────────────────────────────────────────── */
.scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: 8px 20px 28px;
  -webkit-overflow-scrolling: touch;
}
.field-label {
  display: block;
  font-size: 15px;
  color: #6D4C00;
  margin: 14px 0 6px;
}
.emoji-picker-btn {
  width: 100%;
  height: 110px;
  font-size: 60px;
  background: white;
  color: black;
  border: none;
  border-radius: 20px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.13);
  cursor: pointer;
}
.input-card {
  background: white;
  border-radius: 12px;
  padding: 6px 10px;
}
.input-card input, .input-card textarea {
  width: 100%;
  border: none;
  outline: none;
  font-size: 20px;
  font-weight: 700;
  color: #212121;
  font-family: inherit;
  padding: 6px 0;
  background: transparent;
}
.input-card textarea {
  font-size: 17px;
  font-weight: 400;
  height: 118px;
  resize: none;
}

.emoji-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: stretch;
}
.emoji-overlay.hidden { display: none; }
.emoji-panel {
  background: white;
  margin: 50px 14px 14px;
  border-radius: 22px;
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}
.emoji-panel-title {
  text-align: center;
  font-size: 19px;
  font-weight: 700;
  color: #212121;
  padding: 14px 16px 6px;
  margin: 0;
}
.emoji-categories {
  flex: 1;
  overflow-y: auto;
  padding: 4px 12px 8px;
  -webkit-overflow-scrolling: touch;
}
.emoji-cat-title {
  font-size: 15px;
  font-weight: 700;
  color: #E65100;
  margin: 10px 2px 4px;
}
.emoji-row {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.emoji-cell {
  border: none;
  background: #FFF3E0;
  font-size: 26px;
  width: 50px;
  height: 50px;
  border-radius: 10px;
  margin: 2px;
  cursor: pointer;
}

/* ── Dia completo ─────────────────────────────────────────────── */
.complete-content {
  text-align: center;
  padding: 36px;
}
.complete-emoji { font-size: 110px; }
.complete-title { font-size: 46px; font-weight: 700; color: #212121; margin: 24px 0 0; }
.complete-subtitle { font-size: 34px; font-weight: 700; color: #E65100; margin: 12px 0 0; }
.complete-text { font-size: 22px; color: #4E342E; margin: 20px 0 0; line-height: 1.4; }
.complete-restart-btn { margin-top: 32px; width: 100%; }

/* ── Modais ───────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1000;
}
.modal-backdrop.hidden { display: none; }
.modal-box {
  background: white;
  border-radius: 20px;
  padding: 22px;
  width: 100%;
  max-width: 360px;
}
.modal-title { font-size: 19px; font-weight: 700; color: #212121; margin-bottom: 8px; text-align: center; }
.modal-message { font-size: 15px; color: #4E342E; white-space: pre-line; text-align: center; margin-bottom: 14px; }
.modal-input {
  width: 100%;
  font-size: 28px;
  letter-spacing: 10px;
  text-align: center;
  padding: 10px;
  border-radius: 12px;
  border: 2px solid #FFCC80;
  margin-bottom: 14px;
  outline: none;
}
.modal-input.hidden { display: none; }
.modal-buttons {
  display: flex;
  gap: 10px;
}
.modal-buttons .btn { flex: 1; height: 48px; font-size: 16px; border-radius: 14px; }
.modal-buttons .hidden { display: none; }

/* ── Instalar app ─────────────────────────────────────────────── */
.install-btn {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #212121;
  color: white;
  border: none;
  border-radius: 24px;
  padding: 10px 18px;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 900;
  cursor: pointer;
}
.install-btn.hidden { display: none; }
